SOLID SM1 slow control module test program
Dependencies: S_SCTRL_SMlib mbed
main.cpp@2:0d1f510b851d, 2014-09-19 (annotated)
- Committer:
- wbeaumont
- Date:
- Fri Sep 19 09:39:12 2014 +0000
- Revision:
- 2:0d1f510b851d
- Parent:
- 1:39fce38f6e13
- Child:
- 3:f113cc6358e3
all IO functions on the connector tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 1:39fce38f6e13 | 1 | /* program to test the hardware connection of the Slow control board |
wbeaumont | 1:39fce38f6e13 | 2 | * for the SM1 of SOLID |
wbeaumont | 1:39fce38f6e13 | 3 | * |
wbeaumont | 1:39fce38f6e13 | 4 | * v1.x used for testing first board |
wbeaumont | 1:39fce38f6e13 | 5 | * v2.01 make use of libs and structure for io, not tested with hw. |
wbeaumont | 2:0d1f510b851d | 6 | * v2.08 tested with hw, publised used for mod 1 and 2 |
wbeaumont | 2:0d1f510b851d | 7 | * v2.09 corrected the command help |
wbeaumont | 1:39fce38f6e13 | 8 | */ |
wbeaumont | 1:39fce38f6e13 | 9 | |
wbeaumont | 1:39fce38f6e13 | 10 | |
wbeaumont | 0:263895dd3670 | 11 | #include "mbed.h" |
wbeaumont | 0:263895dd3670 | 12 | #include "S_SCTRL_SM1_PinDef.h" |
wbeaumont | 1:39fce38f6e13 | 13 | #include "S_SCTRL_SM1_hwfunct.h" |
wbeaumont | 2:0d1f510b851d | 14 | #define VERSION "2.09" |
wbeaumont | 2:0d1f510b851d | 15 | #define RELDATE "19 Sept 2014" |
wbeaumont | 0:263895dd3670 | 16 | #define ORGANISATION "(C) Universiteit Antwerpen" |
wbeaumont | 0:263895dd3670 | 17 | #define AUTHOR "wim.beaumont@uantwerpen.be" |
wbeaumont | 0:263895dd3670 | 18 | |
wbeaumont | 0:263895dd3670 | 19 | |
wbeaumont | 0:263895dd3670 | 20 | Serial pc(USBTX,USBRX); |
wbeaumont | 0:263895dd3670 | 21 | |
wbeaumont | 0:263895dd3670 | 22 | |
wbeaumont | 0:263895dd3670 | 23 | char c='.'; |
wbeaumont | 0:263895dd3670 | 24 | void callback() { |
wbeaumont | 0:263895dd3670 | 25 | // Note: you need to actually read from the serial to clear the RX interrupt |
wbeaumont | 0:263895dd3670 | 26 | c = pc.getc(); |
wbeaumont | 0:263895dd3670 | 27 | //printf("%c:",c ); |
wbeaumont | 0:263895dd3670 | 28 | } |
wbeaumont | 0:263895dd3670 | 29 | |
wbeaumont | 0:263895dd3670 | 30 | |
wbeaumont | 0:263895dd3670 | 31 | |
wbeaumont | 0:263895dd3670 | 32 | void printhelp(){ |
wbeaumont | 0:263895dd3670 | 33 | printf("program to test IO lines for the Solid Slow control \n\r"); |
wbeaumont | 0:263895dd3670 | 34 | printf("version : %s\n\r%s %s \n\rAuthor %s\n\r",VERSION, ORGANISATION,RELDATE,AUTHOR ); |
wbeaumont | 0:263895dd3670 | 35 | printf("in terminal push t to see the commands\n\r"); |
wbeaumont | 0:263895dd3670 | 36 | printf("the assigned output will toggle, z will stop toggling outputs \n\r"); |
wbeaumont | 0:263895dd3670 | 37 | printf("inputs will be read each cycle, also the bi directional inputs \n\r"); |
wbeaumont | 0:263895dd3670 | 38 | printf("no protection for the directions signals (c,d,m,l) so use with care\n\r"); |
wbeaumont | 1:39fce38f6e13 | 39 | 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"); |
wbeaumont | 0:263895dd3670 | 40 | |
wbeaumont | 0:263895dd3670 | 41 | } |
wbeaumont | 0:263895dd3670 | 42 | |
wbeaumont | 0:263895dd3670 | 43 | |
wbeaumont | 0:263895dd3670 | 44 | |
wbeaumont | 0:263895dd3670 | 45 | void printcommands(int consel, DigitalOut* caldir) { |
wbeaumont | 0:263895dd3670 | 46 | int localcaldir=caldir->read(); |
wbeaumont | 0:263895dd3670 | 47 | printf("T means toggle output\n\r"); |
wbeaumont | 0:263895dd3670 | 48 | printf("connector 1 or connector 2 signal generation \n\r"); |
wbeaumont | 0:263895dd3670 | 49 | printf("a: T sclk\tb: T direction\n\r"); |
wbeaumont | 2:0d1f510b851d | 50 | printf("c: stio to 1\td: T csb1_1\n\r"); |
wbeaumont | 0:263895dd3670 | 51 | printf("e: T csb2_1\tf: T mosi\n\r"); |
wbeaumont | 0:263895dd3670 | 52 | printf("g: T t_cs\ti: T tc_cs1\n\r"); |
wbeaumont | 0:263895dd3670 | 53 | printf("h: help\n\r"); |
wbeaumont | 0:263895dd3670 | 54 | printf("j: T tc_cs2\tk: T dac_cs\n\r"); |
wbeaumont | 0:263895dd3670 | 55 | printf("l: T dac_rst\tm: T cal_13\n\r"); |
wbeaumont | 0:263895dd3670 | 56 | printf("n: T cal_24\to: T genextcal\n\r"); |
wbeaumont | 2:0d1f510b851d | 57 | printf("p: set stio to 0\n\r"); |
wbeaumont | 0:263895dd3670 | 58 | printf("\n\rcommon\n\r"); |
wbeaumont | 0:263895dd3670 | 59 | printf("q: sel int cal\tr: sel ext cal\n\r"); |
wbeaumont | 0:263895dd3670 | 60 | printf("s: setdefault direction, cal int \n\r"); |
wbeaumont | 2:0d1f510b851d | 61 | printf("u: set STIO of current con to output \n\r"); |
wbeaumont | 2:0d1f510b851d | 62 | printf("t: this table\t"); |
wbeaumont | 1:39fce38f6e13 | 63 | printf("v: version, serialnr "); |
wbeaumont | 0:263895dd3670 | 64 | printf("x: sel con1\ty: sel con2\n\r"); |
wbeaumont | 0:263895dd3670 | 65 | printf("z: stop toggling\n\r"); |
wbeaumont | 0:263895dd3670 | 66 | printf("con sel=%d cal dir=%d\n\r",consel, localcaldir); |
wbeaumont | 0:263895dd3670 | 67 | |
wbeaumont | 0:263895dd3670 | 68 | } |
wbeaumont | 0:263895dd3670 | 69 | |
wbeaumont | 0:263895dd3670 | 70 | |
wbeaumont | 0:263895dd3670 | 71 | |
wbeaumont | 0:263895dd3670 | 72 | |
wbeaumont | 0:263895dd3670 | 73 | int main(){ |
wbeaumont | 0:263895dd3670 | 74 | |
wbeaumont | 1:39fce38f6e13 | 75 | pc.attach(&callback);// handles the input on the RS232 interface |
wbeaumont | 1:39fce38f6e13 | 76 | HWlines hwl ; |
wbeaumont | 1:39fce38f6e13 | 77 | assignports( &hwl ); |
wbeaumont | 0:263895dd3670 | 78 | DigitalOut* dout = 0; // active signal |
wbeaumont | 1:39fce38f6e13 | 79 | hwl.ledred->write(1); |
wbeaumont | 1:39fce38f6e13 | 80 | hwl.ledgreen->write(1); |
wbeaumont | 1:39fce38f6e13 | 81 | int consel=1; //active connector |
wbeaumont | 1:39fce38f6e13 | 82 | setdefault(hwl); |
wbeaumont | 0:263895dd3670 | 83 | printhelp(); |
wbeaumont | 0:263895dd3670 | 84 | while (true) { |
wbeaumont | 1:39fce38f6e13 | 85 | int con_idx=consel-1; |
wbeaumont | 1:39fce38f6e13 | 86 | if( con_idx <0 or con_idx>1 ){ printf("no valid connector %d\n\r",consel); continue;} |
wbeaumont | 1:39fce38f6e13 | 87 | |
wbeaumont | 1:39fce38f6e13 | 88 | switch( c) { |
wbeaumont | 1:39fce38f6e13 | 89 | case 'a' : dout=hwl.sclk[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 90 | case 'b' : dout=hwl.direction[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 91 | case 'c' : dout=NULL; hwl.msio[con_idx]->write(1); break; |
wbeaumont | 1:39fce38f6e13 | 92 | case 'd' : dout=hwl.csb1[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 93 | case 'e' : dout=hwl.csb2[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 94 | case 'f' : dout=hwl.mosi[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 95 | case 'g' : dout=hwl.t_cs[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 96 | case 'i' : dout=hwl.tc_cs1[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 97 | case 'j' : dout=hwl.tc_cs2[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 98 | case 'k' : dout=hwl.dac_cs[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 99 | case 'l' : dout=hwl.dac_rst[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 100 | case 'm' : dout=hwl.cal13[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 101 | case 'n' : dout=hwl.cal24[con_idx]; break; |
wbeaumont | 1:39fce38f6e13 | 102 | case 'o' : dout=hwl.calgenext; break; |
wbeaumont | 1:39fce38f6e13 | 103 | case 'p' : dout=NULL; hwl.msio[con_idx]->write(0); break; |
wbeaumont | 0:263895dd3670 | 104 | default : break; |
wbeaumont | 0:263895dd3670 | 105 | |
wbeaumont | 0:263895dd3670 | 106 | |
wbeaumont | 0:263895dd3670 | 107 | |
wbeaumont | 0:263895dd3670 | 108 | |
wbeaumont | 0:263895dd3670 | 109 | } |
wbeaumont | 1:39fce38f6e13 | 110 | |
wbeaumont | 0:263895dd3670 | 111 | |
wbeaumont | 0:263895dd3670 | 112 | //common |
wbeaumont | 0:263895dd3670 | 113 | switch( c) { |
wbeaumont | 0:263895dd3670 | 114 | case 'h' : printhelp();wait(5); |
wbeaumont | 1:39fce38f6e13 | 115 | case 'q' : setcalsource(0,hwl); break; |
wbeaumont | 1:39fce38f6e13 | 116 | case 'r' : setcalsource(1,hwl); break; |
wbeaumont | 1:39fce38f6e13 | 117 | case 's' : setdefault(hwl); break; |
wbeaumont | 1:39fce38f6e13 | 118 | case 't' : printcommands(consel, hwl.calint[0] ); wait(5);break; |
wbeaumont | 1:39fce38f6e13 | 119 | case 'u' : set_bi_spi_mo(1,hwl.msio[con_idx],hwl.stio_mo[con_idx],hwl.direction[con_idx]); |
wbeaumont | 1:39fce38f6e13 | 120 | break; |
wbeaumont | 0:263895dd3670 | 121 | case 'v' : printf ("version %s comiled at %s %s\n\r" , VERSION,__DATE__,__TIME__); |
wbeaumont | 1:39fce38f6e13 | 122 | printf("%s",hwfunct_lib_version()); |
wbeaumont | 1:39fce38f6e13 | 123 | printf("board serialnr = %d\n\r", get_serialnr( &hwl )); |
wbeaumont | 0:263895dd3670 | 124 | wait(2); |
wbeaumont | 0:263895dd3670 | 125 | break; |
wbeaumont | 0:263895dd3670 | 126 | case 'x' : consel=1;break; |
wbeaumont | 0:263895dd3670 | 127 | case 'y' : consel=2;break; |
wbeaumont | 0:263895dd3670 | 128 | case 'z' : dout=NULL; break; |
wbeaumont | 0:263895dd3670 | 129 | |
wbeaumont | 0:263895dd3670 | 130 | default : break; |
wbeaumont | 0:263895dd3670 | 131 | }; |
wbeaumont | 0:263895dd3670 | 132 | c='.';// reset input to default |
wbeaumont | 0:263895dd3670 | 133 | if ( dout != NULL ) { |
wbeaumont | 0:263895dd3670 | 134 | *dout = !(*dout); // toggle pin ; |
wbeaumont | 0:263895dd3670 | 135 | //ledgreen!=ledgreen; |
wbeaumont | 0:263895dd3670 | 136 | } |
wbeaumont | 0:263895dd3670 | 137 | //ledred!=ledred; |
wbeaumont | 0:263895dd3670 | 138 | printf( "miso1:%d msio1:%d miso2:%d msio:%d adc1:%f adc2:%f\n\r", |
wbeaumont | 1:39fce38f6e13 | 139 | hwl.miso[0]->read(),hwl.msio[0]->read(), hwl.miso[1]->read(), |
wbeaumont | 1:39fce38f6e13 | 140 | hwl.msio[1]->read(),hwl.ain[0]->read(),hwl.ain[1]->read() ); |
wbeaumont | 0:263895dd3670 | 141 | |
wbeaumont | 1:39fce38f6e13 | 142 | wait(0.2f); |
wbeaumont | 0:263895dd3670 | 143 | } |
wbeaumont | 0:263895dd3670 | 144 | } |