SOLID SM1 slow control module test program
Dependencies: S_SCTRL_SMlib mbed
Diff: main.cpp
- Revision:
- 0:263895dd3670
- Child:
- 1:39fce38f6e13
diff -r 000000000000 -r 263895dd3670 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Sep 07 14:27:50 2014 +0000 @@ -0,0 +1,211 @@ +#include "mbed.h" +#include "S_SCTRL_SM1_PinDef.h" + +#define VERSION "1.28" +#define RELDATE "6 Sept 2014" +#define ORGANISATION "(C) Universiteit Antwerpen" +#define AUTHOR "wim.beaumont@uantwerpen.be" + + +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 + c = pc.getc(); + //printf("%c:",c ); + } + + + +void printhelp(){ + printf("program to test IO lines for the Solid Slow control \n\r"); + printf("version : %s\n\r%s %s \n\rAuthor %s\n\r",VERSION, ORGANISATION,RELDATE,AUTHOR ); + printf("in terminal push t to see the commands\n\r"); + 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"); + +} + + + +void printcommands(int consel, DigitalOut* caldir) { + int localcaldir=caldir->read(); +printf("T means toggle output\n\r"); +printf("connector 1 or connector 2 signal generation \n\r"); +printf("a: T sclk\tb: T direction\n\r"); +printf("c: T stio_mo\td: T csb1_1\n\r"); +printf("e: T csb2_1\tf: T mosi\n\r"); +printf("g: T t_cs\ti: T tc_cs1\n\r"); +printf("h: help\n\r"); +printf("j: T tc_cs2\tk: T dac_cs\n\r"); +printf("l: T dac_rst\tm: T cal_13\n\r"); +printf("n: T cal_24\to: T genextcal\n\r"); +printf("\n\rcommon\n\r"); +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("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); + +} + + + +// 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 + DigitalOut* dout = 0; // active signal + ledred=1;ledgreen=1; + int consel=1; + setdefault(); + 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; + 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 'v' : printf ("version %s comiled at %s %s\n\r" , VERSION,__DATE__,__TIME__); + wait(2); + break; + case 'x' : consel=1;break; + case 'y' : consel=2;break; + case 'z' : dout=NULL; break; + + default : break; + }; + c='.';// reset input to default + if ( dout != NULL ) { + *dout = !(*dout); // toggle pin ; + //ledgreen!=ledgreen; + } + //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() ); + + wait(0.5f); + } +} \ No newline at end of file