SOLID SM1 slow control module test program

Dependencies:   S_SCTRL_SMlib mbed

Revision:
1:39fce38f6e13
Parent:
0:263895dd3670
Child:
2:0d1f510b851d
--- a/main.cpp	Sun Sep 07 14:27:50 2014 +0000
+++ b/main.cpp	Tue Sep 16 19:36:53 2014 +0000
@@ -1,8 +1,18 @@
+/* program to test the hardware connection of the Slow control board 
+ * for the SM1 of SOLID
+ *
+ * v1.x   used for testing first board
+ * v2.01    make use of libs and structure for io, not tested with hw. 
+ */
+
+
+
+
 #include "mbed.h"
 #include "S_SCTRL_SM1_PinDef.h"
-
-#define VERSION  "1.28"
-#define RELDATE "6 Sept 2014"
+#include "S_SCTRL_SM1_hwfunct.h" 
+#define VERSION  "2.08"
+#define RELDATE "16 Sept 2014"
 #define ORGANISATION "(C) Universiteit Antwerpen" 
 #define AUTHOR  "wim.beaumont@uantwerpen.be" 
 
@@ -10,60 +20,6 @@
 Serial pc(USBTX,USBRX);
 
 
-// devices 
-// SPI BI pins 
-DigitalInOut msio(ADC_STIO);
-DigitalOut sclk(SCLK);
-DigitalOut direction(DIRECTION);
-DigitalOut stio_mo(STIO_MO);
-DigitalOut  csb1_1(ADC1_CSN);
-DigitalOut  csb2_1(ADC2_CSN);
-
-
-
-// SPI pins
-DigitalOut mosi(MOSI); 
-DigitalIn miso(MISO); 
-// DigitalOut sclk(PTC16);  reuse sclk 
-DigitalOut t_cs(TEMP_CSN);
-DigitalOut tc_cs1(TEMP_CABLE_CSN1);
-DigitalOut tc_cs2(TEMP_CABLE_CSN2);
-DigitalOut  dac_cs(DAC_DCEN);
-DigitalOut  dac_rst(DAC_RSTN);
-
-
-
-// SPI BI 2 
-DigitalInOut msio2(ADC_2_STIO);
-DigitalOut sclk2(SCLK_2);
-DigitalOut direction2(DIRECTION2);
-DigitalOut stio_mo2(STIO2_MO);
-DigitalOut  csb1_2(ADC1_2_CSN);
-DigitalOut  csb2_2(ADC2_2_CSN);
-
-//SPI 2 
-DigitalOut mosi2(MOSI_2); 
-DigitalIn miso2(MISO_2); 
-DigitalOut t2_cs(TEMP_2_CSN);
-DigitalOut t2c_cs1(TEMP_2_CABLE_CSN1);
-DigitalOut t2c_cs2(TEMP_2_CABLE_CSN2);
-DigitalOut  dac2_cs(DAC_2_DCEN);
-DigitalOut  dac2_rst(DAC_2_RSTN);
-
-//cal 
-DigitalOut  cal13(CAL_TRIG_1AND3);
-DigitalOut  cal24(CAL_TRIG_2AND4);
-DigitalOut  calint(SEL_CAL_INT);
-DigitalOut  calint2(SEL_2_CAL_INT);
-DigitalOut  calext(SEL_CAL_EXT);
-DigitalOut  calgenext(GEN_EXT_CAL);
-
-DigitalOut ledred(LEDRED);
-DigitalOut ledgreen(LEDGREEN);
-
-AnalogIn  ain1(ADC1), ain2(ADC2);
-
-
 char c='.';
 void callback() {
     // Note: you need to actually read from the serial to clear the RX interrupt  
@@ -80,8 +36,7 @@
     printf("the assigned output will toggle,  z will stop toggling outputs \n\r");
     printf("inputs will be read each cycle,  also the bi directional inputs \n\r");
     printf("no protection for the directions signals (c,d,m,l)  so use with care\n\r");
-    printf("startup values:\n\r\tmsio(2) input\n\r\tdirection(2) set to input\n\r\tstio_mo to input (adc output)\n\r");
-    printf("version 1.0  no io (miso only input) \n\r");   
+    printf("startup values:\n\r\tmsio(2) input\n\r\tdirection(2) set to input\n\r\tstio_mo to input (adc output)\n\r");   
     
 } 
 
@@ -103,7 +58,7 @@
 printf("q: sel int cal\tr: sel ext cal\n\r");
 printf("s: setdefault direction, cal int \n\r");
 printf("t: this table\n\r");
-printf("v: version");
+printf("v: version, serialnr ");
 printf("x: sel con1\ty: sel con2\n\r");
 printf("z: stop toggling\n\r");
 printf("con sel=%d cal dir=%d\n\r",consel, localcaldir);
@@ -112,83 +67,58 @@
            
 
 
-// select intern or extern cal   0 = intern, 1 is extern 
-void setcalsource( int external) {
-    calext=0;    calint=0; calint2=0;  //disable all 
-    if ( external==1 ) calext=1;
-    else {calint=1;calint2=1; }
-
-    
-}
-
-// set tje default , save values 
-void setdefault( ) {
-        msio.input();
-        msio2.input();
-        direction=LDIR_IN;direction2=LDIR_IN;
-        stio_mo=RDIR_IN;stio_mo2=RDIR_IN;
-        setcalsource(0); //intern
-}
 
 int main(){
     
-    pc.attach(&callback);// handles the input on the RS232 interface  
+    pc.attach(&callback);// handles the input on the RS232 interface 
+     HWlines  hwl ;
+    assignports( &hwl );
     DigitalOut* dout = 0; // active signal 
-    ledred=1;ledgreen=1;
-    int consel=1;
-    setdefault();
+    hwl.ledred->write(1);
+    hwl.ledgreen->write(1);
+    int consel=1; //active connector
+    setdefault(hwl);
     printhelp();
     while (true) {
-        if( consel ==1) 
-            switch( c) {
-                case 'a'    : dout=&sclk;     break;
-                case 'b'    : dout=&direction;    break;
-                case 'c'    : dout=&stio_mo;    break;
-                case 'd'    : dout=&csb1_1;  break;
-                case 'e'    : dout=&csb2_1;  break;
-                case 'f'    : dout=&mosi;  break;
-                case 'g'    : dout=&t_cs;  break;
-                case 'i'    : dout=&tc_cs1;  break; 
-                case 'j'    : dout=&tc_cs2;  break; 
-                case 'k'    : dout=&dac_cs;  break; 
-                case 'l'    : dout=&dac_rst;  break; 
-                case 'm'    : dout=&cal13;  break; 
-                case 'n'    : dout=&cal24;  break; 
-                case 'o'    : dout=&calgenext;  break; 
+        int con_idx=consel-1;
+        if( con_idx <0 or con_idx>1 ){ printf("no valid connector %d\n\r",consel); continue;}
+        
+        switch( c) {
+                case 'a'    : dout=hwl.sclk[con_idx];     break;
+                case 'b'    : dout=hwl.direction[con_idx];    break;
+                case 'c'    : dout=NULL; hwl.msio[con_idx]->write(1);    break;
+                case 'd'    : dout=hwl.csb1[con_idx];  break;
+                case 'e'    : dout=hwl.csb2[con_idx];  break;
+                case 'f'    : dout=hwl.mosi[con_idx];  break;
+                case 'g'    : dout=hwl.t_cs[con_idx];  break;
+                case 'i'    : dout=hwl.tc_cs1[con_idx];  break; 
+                case 'j'    : dout=hwl.tc_cs2[con_idx];  break; 
+                case 'k'    : dout=hwl.dac_cs[con_idx];  break; 
+                case 'l'    : dout=hwl.dac_rst[con_idx];  break; 
+                case 'm'    : dout=hwl.cal13[con_idx];  break; 
+                case 'n'    : dout=hwl.cal24[con_idx];  break; 
+                case 'o'    : dout=hwl.calgenext;  break; 
+                 case 'p'    : dout=NULL; hwl.msio[con_idx]->write(0);    break;
                 default :    break;
                 
                 
                 
                 
             }
-        if( consel ==2)          
-            switch( c) {
-                case 'a'    : dout=&sclk2;     break;
-                case 'b'    : dout=&direction2;    break;
-                case 'c'    : dout=&stio_mo2;    break;
-                case 'd'    : dout=&csb1_2;  break;
-                case 'e'    : dout=&csb2_2;  break;
-                case 'f'    : dout=&mosi2;  break;
-                case 'g'    : dout=&t2_cs;  break;
-                case 'i'    : dout=&t2c_cs1;  break; 
-                case 'j'    : dout=&t2c_cs2;  break; 
-                case 'k'    : dout=&dac2_cs;  break; 
-                case 'l'    : dout=&dac2_rst;  break; 
-                case 'm'    : dout=&cal13;  break; 
-                case 'n'    : dout=&cal24;  break; 
-                case 'o'    : dout=&calgenext;  break; 
-                default :    break;
-            }
-
+        
             
         //common 
         switch( c) {        
             case 'h'    : printhelp();wait(5);
-            case 'q'    : setcalsource(0); break; 
-            case 'r'    : setcalsource(1); break; 
-            case 's'    : setdefault(); break;
-            case 't'    : printcommands(consel, &calint); wait(5);break;
+            case 'q'    : setcalsource(0,hwl); break; 
+            case 'r'    : setcalsource(1,hwl); break; 
+            case 's'    : setdefault(hwl); break;
+            case 't'    : printcommands(consel, hwl.calint[0] ); wait(5);break;
+            case 'u'    : set_bi_spi_mo(1,hwl.msio[con_idx],hwl.stio_mo[con_idx],hwl.direction[con_idx]);
+                          break;
             case 'v'    : printf ("version %s  comiled at %s %s\n\r" , VERSION,__DATE__,__TIME__);
+                          printf("%s",hwfunct_lib_version());
+                          printf("board serialnr = %d\n\r", get_serialnr(  &hwl ));
                           wait(2);
                         break;
             case 'x'    : consel=1;break;
@@ -204,8 +134,9 @@
         }
         //ledred!=ledred;
         printf( "miso1:%d msio1:%d miso2:%d msio:%d adc1:%f adc2:%f\n\r", 
-            miso.read(),msio.read(), miso2.read(),miso2.read(),ain1.read(),ain2.read() );                
+            hwl.miso[0]->read(),hwl.msio[0]->read(), hwl.miso[1]->read(),
+            hwl.msio[1]->read(),hwl.ain[0]->read(),hwl.ain[1]->read() );                
 
-        wait(0.5f);
+        wait(0.2f);
     }
 }
\ No newline at end of file