Solid experiment slow control.

Dependencies:   AD5384 SWSPI S_SCTRL_SMlib T_adt7320 adc_ad9249 mbed sscm_comm

Fork of sscm by wimbeaumont Project

Files at this revision

API Documentation at this revision

Comitter:
wbeaumont
Date:
Wed Sep 24 10:31:28 2014 +0000
Child:
1:f792767b2223
Commit message:
Initial firmware version SOLID Slow Contrl Module for SM1 ; "working " for ADC communication, not tested with DEIMOS board

Changed in this revision

S_SCTRL_SMlib.lib Show annotated file Show diff for this revision Revisions of this file
adc_ad9249.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
sscm_comm.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/S_SCTRL_SMlib.lib	Wed Sep 24 10:31:28 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wbeaumont/code/S_SCTRL_SMlib/#20f21cb7792e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/adc_ad9249.lib	Wed Sep 24 10:31:28 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wbeaumont/code/adc_ad9249/#9efb460e962b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 24 10:31:28 2014 +0000
@@ -0,0 +1,109 @@
+#include "mbed.h"
+
+
+#include "SWSPI_BI.h"
+
+#include "AD9249.h"
+#include "solid_sctrl_def.h"
+#include "S_SCTRL_SM1_PinDef.h" 
+#include "S_SCTRL_SM1_hwfunct.h" 
+
+#define VERSION "1.07"
+
+#define DEBUGPF(x) printf((x));
+
+
+#define MAXCMDLLENGTH 256
+
+#include "sscm_comm.h"
+using namespace sscm_comm ;
+
+
+
+Serial pc(USBTX,USBRX);
+
+
+char cmdin[MAXCMDLLENGTH];
+u8 cmdready;
+bool cmdstart=false;
+
+
+
+
+void pc_callback() {
+    // Note: you need to actually read from the serial to clear the RX interrupt  
+    static unsigned char cnt;
+    
+    char c;
+        c=pc.getc();
+     if( c== CMDSTART && !cmdready ) { cnt=0; cmdstart=true; cmdready=false; }
+     if ( cmdstart) { 
+        cmdin[cnt]=c; cnt++;             
+        if (c== CMDSTOP ) { cmdready=true;} 
+     }   
+        
+    
+        
+    //printf("%c:",c );    
+ }
+
+
+
+
+int main() {
+    pc.attach(pc_callback);
+    ssc_cmd cmd;
+    int i = 0;
+     HWlines  hwl ;
+    assignports( &hwl );
+    setdefault(hwl );
+    
+  
+    SWSPI_BI spi_adc(hwl.msio[0],hwl.direction[0],hwl.stio_mo[0] ,hwl.sclk[0]); // msio, dir , sclk 
+    SWSPI_BI spi_adc2(hwl.msio[1],hwl.direction[1],hwl.stio_mo[1],hwl.sclk[1]); // msio, dir , sclk 
+    // initalize ADC classes 
+    AD9249 adc[2][2]={AD9249( &spi_adc,hwl.csb1[0]), AD9249( &spi_adc,hwl.csb2[0]),
+                          AD9249( &spi_adc2,hwl.csb1[1]),  AD9249  ( &spi_adc2,hwl.csb2[1])};
+     
+  
+      
+    
+  
+    
+    
+      pc.printf("\nSOLID SLOW CONTROL for SM1 version %s %s %s  \n\r",VERSION,__DATE__,__TIME__ );
+    cmdready=false;
+    while (1) {
+        wait(0.5);
+        if (cmdready) {
+            cmdready=false;
+            int decresult=decode_cmd(cmdin,&cmd);
+            printf("decode result = %d \n\r" ,decresult);
+            if( decresult){  continue; }
+           ;
+            char cmdoutstr[100];
+            
+            u8 do8; // dataout
+            u16 do16;
+            cmd.dataout=0xFFFF; // use it for the moment as error handling , 
+            if ( cmd.dev == DAC ) {} ;
+            if (cmd.dev == ADC) {
+                pc.printf("ADC cmd = %s \n\r",cmd.cmd);
+                pc.printf("check now ranges %d %d  \n\r",cmd.con, cmd.devnr);
+                if (!strcmp( cmd.cmd, "spa1")) { adc[cmd.con-1][cmd.devnr-1].setPattern1(cmd.datain);cmd.dataout=cmd.datain;}
+                if (!strcmp( cmd.cmd, "spa2")) { adc[cmd.con-1][cmd.devnr-1].setPattern2(cmd.datain);cmd.dataout=cmd.datain;}
+                if (!strcmp( cmd.cmd, "rpa1")) { adc[cmd.con-1][cmd.devnr-1].readPattern1(do16 ); cmd.dataout=(u32)do16;  }
+                if (!strcmp( cmd.cmd, "rr08")) {adc[cmd.con-1][cmd.devnr-1].readReg8(cmd.ch,do8 ); cmd.dataout=(u32)do8;  }
+                if (!strcmp( cmd.cmd, "rr16")) {adc[cmd.con-1][cmd.devnr-1].readReg16(cmd.ch,do16 ); cmd.dataout=(u32)do16;  }
+                if (!strcmp( cmd.cmd, "sr08")) { adc[cmd.con-1][cmd.devnr-1].setReg8(cmd.ch, (u8)cmd.dataout ); cmd.dataout=cmd.datain;  }
+                if (!strcmp( cmd.cmd, "sr16")) { adc[cmd.con-1][cmd.devnr-1].setReg16(cmd.ch, (u16)cmd.dataout ); cmd.dataout=cmd.datain;  }
+            } // end if ADC 
+         encode_cmd ( cmdoutstr, &cmd);  
+         pc.printf( "%s", cmdoutstr);
+        }//end  if cmdready 
+        else {
+            printf( "%s\n\r",cmdin);
+            }
+    }// end while 
+   
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 24 10:31:28 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sscm_comm.lib	Wed Sep 24 10:31:28 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wbeaumont/code/sscm_comm/#e9053e5e7175