![](/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:
- 2:d18b1a1643e8
- Parent:
- 1:f792767b2223
- Child:
- 3:badf265a8898
diff -r f792767b2223 -r d18b1a1643e8 main.cpp --- a/main.cpp Tue Sep 30 13:23:08 2014 +0000 +++ b/main.cpp Thu Oct 02 10:49:22 2014 +0000 @@ -5,17 +5,20 @@ * 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 + * v 1.14 added heartbeat off / in + * v 1.20 added DAC */ #include "SWSPI_BI.h" -#include "AD9249.h" + #include "solid_sctrl_def.h" #include "S_SCTRL_SM1_PinDef.h" #include "S_SCTRL_SM1_hwfunct.h" +#include "AD9249.h" +#include "AD5384.h" -#define VERSION "1.13" +#define VERSION "1.20" #define DEBUGPF(x) printf((x)); @@ -65,15 +68,15 @@ HWlines hwl ; assignports( &hwl ); setdefault(hwl ); - + SWSPI spi(hwl.mosi[0],hwl.miso[0],hwl.sclk[0]); // mosi, miso, sclk + SWSPI spi2(hwl.mosi[1],hwl.miso[1],hwl.sclk[1]); // mosi, miso, sclk 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])}; - - + AD5384 dac[2][1]={AD5384(&spi,hwl.dac_cs[0]), AD5384(&spi2,hwl.dac_cs[1]) }; @@ -94,21 +97,24 @@ u16 do16; 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, "rpa1")) { adc[cmd.con-1][cmd.devnr-1].readPattern1(do16 ); cmd.dataout=do16; cmd.status=0; } + if (!strcmp( cmd.cmd, "rpa2")) { adc[cmd.con-1][cmd.devnr-1].readPattern2(do16 ); cmd.dataout=do16; cmd.status=0; } + if (!strcmp( cmd.cmd, "rr08")) {adc[cmd.con-1][cmd.devnr-1].readReg8(cmd.ch,do8 ); cmd.dataout=(u16)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 DAC : + cmd.status=2; + if (!strcmp( cmd.cmd, "sdac")) { dac[cmd.con-1][cmd.devnr-1].set_dac(cmd.ch,cmd.datain);cmd.dataout=cmd.datain;cmd.status=0;} + if (!strcmp( cmd.cmd, "rdac")) { do16=dac[cmd.con-1][cmd.devnr-1].get_dac(cmd.ch);cmd.dataout=do16;cmd.status=0;} break; case SSCCM: if (!strcmp( cmd.cmd, "t_hb")) { heartbeat=!heartbeat;}