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