![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
firmware for the SOLID Slow Control Module for SM1
Dependencies: S_SCTRL_SMlib adc_ad9249 mbed sscm_comm AD5384 SWSPI T_adt7320
Diff: main.cpp
- Revision:
- 1:f792767b2223
- Parent:
- 0:dcd70d1b89b1
- Child:
- 2:d18b1a1643e8
--- a/main.cpp Wed Sep 24 10:31:28 2014 +0000 +++ b/main.cpp Tue Sep 30 13:23:08 2014 +0000 @@ -1,5 +1,12 @@ #include "mbed.h" - +/* SOLID SM1 Slow Control firmware + * + + * V 1.0? initial version release + * v 1.11 version , added status field + * v 1.13 corrected error in ADC register write + * v 1.14 added heartbeat off / in +*/ #include "SWSPI_BI.h" @@ -8,7 +15,7 @@ #include "S_SCTRL_SM1_PinDef.h" #include "S_SCTRL_SM1_hwfunct.h" -#define VERSION "1.07" +#define VERSION "1.13" #define DEBUGPF(x) printf((x)); @@ -53,6 +60,7 @@ int main() { pc.attach(pc_callback); ssc_cmd cmd; + bool heartbeat=true; int i = 0; HWlines hwl ; assignports( &hwl ); @@ -79,30 +87,40 @@ cmdready=false; int decresult=decode_cmd(cmdin,&cmd); printf("decode result = %d \n\r" ,decresult); - if( decresult){ continue; } - ; + 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 + cmd.status=1; // use it for the moment as error handling , + switch ( cmd.dev) { + case DAC : + {cmd.status=2;} ; + break; + case ADC : + cmd.status=2; + 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;cmd.status=0;} + if (!strcmp( cmd.cmd, "spa2")) { adc[cmd.con-1][cmd.devnr-1].setPattern2(cmd.datain);cmd.dataout=cmd.datain;cmd.status=0;} + if (!strcmp( cmd.cmd, "rpa1")) { adc[cmd.con-1][cmd.devnr-1].readPattern1(do16 ); cmd.dataout=(u32)do16; cmd.status=0; } + if (!strcmp( cmd.cmd, "rpa2")) { adc[cmd.con-1][cmd.devnr-1].readPattern2(do16 ); cmd.dataout=(u32)do16; cmd.status=0; } + if (!strcmp( cmd.cmd, "rr08")) {adc[cmd.con-1][cmd.devnr-1].readReg8(cmd.ch,do8 ); cmd.dataout=(u32)do8; cmd.status=0; } + if (!strcmp( cmd.cmd, "rr16")) {adc[cmd.con-1][cmd.devnr-1].readReg16(cmd.ch,do16 ); cmd.dataout=(u32)do16;cmd.status=0; } + if (!strcmp( cmd.cmd, "sr08")) { adc[cmd.con-1][cmd.devnr-1].setReg8(cmd.ch, (u8)cmd.datain ); cmd.dataout=cmd.datain; cmd.status=0; } + if (!strcmp( cmd.cmd, "sr16")) { adc[cmd.con-1][cmd.devnr-1].setReg16(cmd.ch, (u16)cmd.datain ); cmd.dataout=cmd.datain; cmd.status=0; } + break; + case SSCCM: + if (!strcmp( cmd.cmd, "t_hb")) { heartbeat=!heartbeat;} + break; + default : cmd.status=1; + break; + } // end switch encode_cmd ( cmdoutstr, &cmd); pc.printf( "%s", cmdoutstr); }//end if cmdready else { - printf( "%s\n\r",cmdin); + if ( heartbeat) printf( "%03d>%s\n\r",(i++ % 1000),cmdin); } }// end while