![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ak;jglif;awjd
Test_Routines.cpp@4:1e5639a2a3ae, 2016-05-20 (annotated)
- Committer:
- awmiller
- Date:
- Fri May 20 17:24:57 2016 +0000
- Revision:
- 4:1e5639a2a3ae
sentral tester
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
awmiller | 4:1e5639a2a3ae | 1 | #include "mbed.h" |
awmiller | 4:1e5639a2a3ae | 2 | #include "Sentral.h" |
awmiller | 4:1e5639a2a3ae | 3 | #include "Test_Routines.h" |
awmiller | 4:1e5639a2a3ae | 4 | |
awmiller | 4:1e5639a2a3ae | 5 | BusIn GPIOS(PTE4,PTE3,PTE2,PTB11,PTB10,PTB9,PTB8); |
awmiller | 4:1e5639a2a3ae | 6 | Timeout escape; |
awmiller | 4:1e5639a2a3ae | 7 | |
awmiller | 4:1e5639a2a3ae | 8 | int timeout=0; |
awmiller | 4:1e5639a2a3ae | 9 | |
awmiller | 4:1e5639a2a3ae | 10 | void timeit() |
awmiller | 4:1e5639a2a3ae | 11 | { |
awmiller | 4:1e5639a2a3ae | 12 | timeout =1; |
awmiller | 4:1e5639a2a3ae | 13 | } |
awmiller | 4:1e5639a2a3ae | 14 | |
awmiller | 4:1e5639a2a3ae | 15 | int EV0_test(Serial &pc,I2C &master) |
awmiller | 4:1e5639a2a3ae | 16 | { |
awmiller | 4:1e5639a2a3ae | 17 | |
awmiller | 4:1e5639a2a3ae | 18 | //Set SA0 to 1 |
awmiller | 4:1e5639a2a3ae | 19 | pc.printf("SA0 set to %d \r\n", Set_SA0(1)); |
awmiller | 4:1e5639a2a3ae | 20 | wait(0.1); |
awmiller | 4:1e5639a2a3ae | 21 | //Startup Sentral at SA0 = 1; |
awmiller | 4:1e5639a2a3ae | 22 | if(!SentralSetup(pc,master)){ |
awmiller | 4:1e5639a2a3ae | 23 | pc.printf("[*{10}Sentral Start-up Failure*] SA1 Failed\r\n"); |
awmiller | 4:1e5639a2a3ae | 24 | return 0; |
awmiller | 4:1e5639a2a3ae | 25 | } |
awmiller | 4:1e5639a2a3ae | 26 | int P=0 , trig =0 ; |
awmiller | 4:1e5639a2a3ae | 27 | //Wait for any pin to fire |
awmiller | 4:1e5639a2a3ae | 28 | do |
awmiller | 4:1e5639a2a3ae | 29 | { |
awmiller | 4:1e5639a2a3ae | 30 | P = GPIOS; |
awmiller | 4:1e5639a2a3ae | 31 | |
awmiller | 4:1e5639a2a3ae | 32 | if(P&&0x40) |
awmiller | 4:1e5639a2a3ae | 33 | trig = 0x40; |
awmiller | 4:1e5639a2a3ae | 34 | if(P&&0x01) |
awmiller | 4:1e5639a2a3ae | 35 | trig = 0x01; |
awmiller | 4:1e5639a2a3ae | 36 | if(P&&0x02) |
awmiller | 4:1e5639a2a3ae | 37 | trig = 0x02; |
awmiller | 4:1e5639a2a3ae | 38 | if(P&&0x04) |
awmiller | 4:1e5639a2a3ae | 39 | trig = 0x04; |
awmiller | 4:1e5639a2a3ae | 40 | if(P&&0x08) |
awmiller | 4:1e5639a2a3ae | 41 | trig = 0x08; |
awmiller | 4:1e5639a2a3ae | 42 | if(P&&0x10) |
awmiller | 4:1e5639a2a3ae | 43 | trig = 0x10; |
awmiller | 4:1e5639a2a3ae | 44 | if(P&&0x20) |
awmiller | 4:1e5639a2a3ae | 45 | trig = 0x20; |
awmiller | 4:1e5639a2a3ae | 46 | } while((!(GPIOS) && (timeout++ < 1000))); |
awmiller | 4:1e5639a2a3ae | 47 | |
awmiller | 4:1e5639a2a3ae | 48 | //Wait for pin to go low again |
awmiller | 4:1e5639a2a3ae | 49 | while(GPIOS & trig); |
awmiller | 4:1e5639a2a3ae | 50 | |
awmiller | 4:1e5639a2a3ae | 51 | if(timeout < 1000) |
awmiller | 4:1e5639a2a3ae | 52 | pc.printf("Trigger: Pin %d \r\n",trig); |
awmiller | 4:1e5639a2a3ae | 53 | else |
awmiller | 4:1e5639a2a3ae | 54 | { |
awmiller | 4:1e5639a2a3ae | 55 | pc.printf("[*{10}GPIO Timeout*] \r\n"); |
awmiller | 4:1e5639a2a3ae | 56 | return 0; |
awmiller | 4:1e5639a2a3ae | 57 | } |
awmiller | 4:1e5639a2a3ae | 58 | |
awmiller | 4:1e5639a2a3ae | 59 | //reset timeout |
awmiller | 4:1e5639a2a3ae | 60 | timeout=0; |
awmiller | 4:1e5639a2a3ae | 61 | |
awmiller | 4:1e5639a2a3ae | 62 | //Check for simultaneity |
awmiller | 4:1e5639a2a3ae | 63 | while( ( GPIOS < 0x7F ) && (timeout < 1000) ) |
awmiller | 4:1e5639a2a3ae | 64 | timeout++; |
awmiller | 4:1e5639a2a3ae | 65 | |
awmiller | 4:1e5639a2a3ae | 66 | if(timeout < 100) |
awmiller | 4:1e5639a2a3ae | 67 | pc.printf("Notice: Pins are simultaneous, check continuity \r\n"); |
awmiller | 4:1e5639a2a3ae | 68 | |
awmiller | 4:1e5639a2a3ae | 69 | //reset triger and timeout |
awmiller | 4:1e5639a2a3ae | 70 | timeout=0; |
awmiller | 4:1e5639a2a3ae | 71 | trig =0; |
awmiller | 4:1e5639a2a3ae | 72 | |
awmiller | 4:1e5639a2a3ae | 73 | //start a timer |
awmiller | 4:1e5639a2a3ae | 74 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 75 | |
awmiller | 4:1e5639a2a3ae | 76 | //wait for each pin to fire********** |
awmiller | 4:1e5639a2a3ae | 77 | while(!(GPIOS&&0x40))//6 |
awmiller | 4:1e5639a2a3ae | 78 | if(timeout) { trig = -7; break; } |
awmiller | 4:1e5639a2a3ae | 79 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 80 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 81 | |
awmiller | 4:1e5639a2a3ae | 82 | while(!(GPIOS&&0x01))//0 |
awmiller | 4:1e5639a2a3ae | 83 | if(timeout) { trig = -1; break; } |
awmiller | 4:1e5639a2a3ae | 84 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 85 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 86 | |
awmiller | 4:1e5639a2a3ae | 87 | while(!(GPIOS&&0x02))//1 |
awmiller | 4:1e5639a2a3ae | 88 | if(timeout) { trig = -2; break; } |
awmiller | 4:1e5639a2a3ae | 89 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 90 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 91 | |
awmiller | 4:1e5639a2a3ae | 92 | while(!(GPIOS&&0x04))//2 |
awmiller | 4:1e5639a2a3ae | 93 | if(timeout) { trig = -3; break; } |
awmiller | 4:1e5639a2a3ae | 94 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 95 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 96 | |
awmiller | 4:1e5639a2a3ae | 97 | while(!(GPIOS&&0x08))//3 |
awmiller | 4:1e5639a2a3ae | 98 | if(timeout){ trig = -4; break; } |
awmiller | 4:1e5639a2a3ae | 99 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 100 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 101 | |
awmiller | 4:1e5639a2a3ae | 102 | while(!(GPIOS&&0x10))//4 |
awmiller | 4:1e5639a2a3ae | 103 | if(timeout) { trig = -5; break; } |
awmiller | 4:1e5639a2a3ae | 104 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 105 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 106 | |
awmiller | 4:1e5639a2a3ae | 107 | while(!(GPIOS&&0x20))//5 |
awmiller | 4:1e5639a2a3ae | 108 | if(timeout) { trig = -6; break; } |
awmiller | 4:1e5639a2a3ae | 109 | //END SINGLE PIN TEST |
awmiller | 4:1e5639a2a3ae | 110 | |
awmiller | 4:1e5639a2a3ae | 111 | if(!timeout){ |
awmiller | 4:1e5639a2a3ae | 112 | pc.printf("All Pins Fired\r\n"); |
awmiller | 4:1e5639a2a3ae | 113 | //return 1; |
awmiller | 4:1e5639a2a3ae | 114 | } |
awmiller | 4:1e5639a2a3ae | 115 | else |
awmiller | 4:1e5639a2a3ae | 116 | { |
awmiller | 4:1e5639a2a3ae | 117 | pc.printf("Timeout on %d, [*{10}Test FAILED*] \r\n GPIO Failure at SA0 = 1 \r\n", ( trig * (-1) ) - 1 ); |
awmiller | 4:1e5639a2a3ae | 118 | return 0; |
awmiller | 4:1e5639a2a3ae | 119 | } |
awmiller | 4:1e5639a2a3ae | 120 | |
awmiller | 4:1e5639a2a3ae | 121 | |
awmiller | 4:1e5639a2a3ae | 122 | //Set SA0 to 0 |
awmiller | 4:1e5639a2a3ae | 123 | pc.printf("SA0 set to %d \r\n", Set_SA0(0)); |
awmiller | 4:1e5639a2a3ae | 124 | wait(0.1); |
awmiller | 4:1e5639a2a3ae | 125 | //Startup Sentral at SA0 = 0; |
awmiller | 4:1e5639a2a3ae | 126 | if(!SentralSetup(pc,master)){ |
awmiller | 4:1e5639a2a3ae | 127 | pc.printf("[*{10}Sentral Start-up Failure*] SA0 Failed\r\n"); |
awmiller | 4:1e5639a2a3ae | 128 | return 0; |
awmiller | 4:1e5639a2a3ae | 129 | } |
awmiller | 4:1e5639a2a3ae | 130 | |
awmiller | 4:1e5639a2a3ae | 131 | //Wait for any pin to fire |
awmiller | 4:1e5639a2a3ae | 132 | do |
awmiller | 4:1e5639a2a3ae | 133 | { |
awmiller | 4:1e5639a2a3ae | 134 | P = GPIOS; |
awmiller | 4:1e5639a2a3ae | 135 | |
awmiller | 4:1e5639a2a3ae | 136 | if(P&&0x40) |
awmiller | 4:1e5639a2a3ae | 137 | trig = 0x40; |
awmiller | 4:1e5639a2a3ae | 138 | if(P&&0x01) |
awmiller | 4:1e5639a2a3ae | 139 | trig = 0x01; |
awmiller | 4:1e5639a2a3ae | 140 | if(P&&0x02) |
awmiller | 4:1e5639a2a3ae | 141 | trig = 0x02; |
awmiller | 4:1e5639a2a3ae | 142 | if(P&&0x04) |
awmiller | 4:1e5639a2a3ae | 143 | trig = 0x04; |
awmiller | 4:1e5639a2a3ae | 144 | if(P&&0x08) |
awmiller | 4:1e5639a2a3ae | 145 | trig = 0x08; |
awmiller | 4:1e5639a2a3ae | 146 | if(P&&0x10) |
awmiller | 4:1e5639a2a3ae | 147 | trig = 0x10; |
awmiller | 4:1e5639a2a3ae | 148 | if(P&&0x20) |
awmiller | 4:1e5639a2a3ae | 149 | trig = 0x20; |
awmiller | 4:1e5639a2a3ae | 150 | } while((!(GPIOS) && (timeout++ < 1000))); |
awmiller | 4:1e5639a2a3ae | 151 | |
awmiller | 4:1e5639a2a3ae | 152 | //Wait for pin to go low again |
awmiller | 4:1e5639a2a3ae | 153 | while(GPIOS & trig); |
awmiller | 4:1e5639a2a3ae | 154 | |
awmiller | 4:1e5639a2a3ae | 155 | if(timeout < 1000) |
awmiller | 4:1e5639a2a3ae | 156 | pc.printf("Trigger: Pin%d \r\n",trig); |
awmiller | 4:1e5639a2a3ae | 157 | else |
awmiller | 4:1e5639a2a3ae | 158 | { |
awmiller | 4:1e5639a2a3ae | 159 | pc.printf("[*{10}GPIO Timeout*] \r\n"); |
awmiller | 4:1e5639a2a3ae | 160 | return 0; |
awmiller | 4:1e5639a2a3ae | 161 | } |
awmiller | 4:1e5639a2a3ae | 162 | |
awmiller | 4:1e5639a2a3ae | 163 | //reset timeout |
awmiller | 4:1e5639a2a3ae | 164 | timeout=0; |
awmiller | 4:1e5639a2a3ae | 165 | |
awmiller | 4:1e5639a2a3ae | 166 | //Check for simultaneity |
awmiller | 4:1e5639a2a3ae | 167 | while( ( GPIOS < 0x7F ) && (timeout < 1000) ) |
awmiller | 4:1e5639a2a3ae | 168 | timeout++; |
awmiller | 4:1e5639a2a3ae | 169 | |
awmiller | 4:1e5639a2a3ae | 170 | if(timeout < 100) |
awmiller | 4:1e5639a2a3ae | 171 | pc.printf("Notice: Pins are simultaneous, check continuity \r\n"); |
awmiller | 4:1e5639a2a3ae | 172 | |
awmiller | 4:1e5639a2a3ae | 173 | //reset triger and timeout |
awmiller | 4:1e5639a2a3ae | 174 | timeout=0; |
awmiller | 4:1e5639a2a3ae | 175 | trig =0; |
awmiller | 4:1e5639a2a3ae | 176 | |
awmiller | 4:1e5639a2a3ae | 177 | //start a timer |
awmiller | 4:1e5639a2a3ae | 178 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 179 | |
awmiller | 4:1e5639a2a3ae | 180 | //wait for each pin to fire********** |
awmiller | 4:1e5639a2a3ae | 181 | while(!(GPIOS&&0x40))//6 |
awmiller | 4:1e5639a2a3ae | 182 | if(timeout) { trig = -7; break; } |
awmiller | 4:1e5639a2a3ae | 183 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 184 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 185 | |
awmiller | 4:1e5639a2a3ae | 186 | while(!(GPIOS&&0x01))//0 |
awmiller | 4:1e5639a2a3ae | 187 | if(timeout) { trig = -1; break; } |
awmiller | 4:1e5639a2a3ae | 188 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 189 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 190 | |
awmiller | 4:1e5639a2a3ae | 191 | while(!(GPIOS&&0x02))//1 |
awmiller | 4:1e5639a2a3ae | 192 | if(timeout) { trig = -2; break; } |
awmiller | 4:1e5639a2a3ae | 193 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 194 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 195 | |
awmiller | 4:1e5639a2a3ae | 196 | while(!(GPIOS&&0x04))//2 |
awmiller | 4:1e5639a2a3ae | 197 | if(timeout) { trig = -3; break; } |
awmiller | 4:1e5639a2a3ae | 198 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 199 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 200 | |
awmiller | 4:1e5639a2a3ae | 201 | while(!(GPIOS&&0x08))//3 |
awmiller | 4:1e5639a2a3ae | 202 | if(timeout){ trig = -4; break; } |
awmiller | 4:1e5639a2a3ae | 203 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 204 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 205 | |
awmiller | 4:1e5639a2a3ae | 206 | while(!(GPIOS&&0x10))//4 |
awmiller | 4:1e5639a2a3ae | 207 | if(timeout) { trig = -5; break; } |
awmiller | 4:1e5639a2a3ae | 208 | escape.detach(); |
awmiller | 4:1e5639a2a3ae | 209 | escape.attach(&timeit, 10.0); |
awmiller | 4:1e5639a2a3ae | 210 | |
awmiller | 4:1e5639a2a3ae | 211 | while(!(GPIOS&&0x20))//5 |
awmiller | 4:1e5639a2a3ae | 212 | if(timeout) { trig = -6; break; } |
awmiller | 4:1e5639a2a3ae | 213 | //END SINGLE PIN TEST |
awmiller | 4:1e5639a2a3ae | 214 | |
awmiller | 4:1e5639a2a3ae | 215 | if(!timeout){ |
awmiller | 4:1e5639a2a3ae | 216 | pc.printf("All Pins Fired\r\n"); |
awmiller | 4:1e5639a2a3ae | 217 | //return 1; |
awmiller | 4:1e5639a2a3ae | 218 | } |
awmiller | 4:1e5639a2a3ae | 219 | else |
awmiller | 4:1e5639a2a3ae | 220 | { |
awmiller | 4:1e5639a2a3ae | 221 | pc.printf("Timeout on %d, [*{10}Test FAILED*] \r\n GPIO Failure at SA0 = 0 \r\n", ( trig * (-1) ) - 1 ); |
awmiller | 4:1e5639a2a3ae | 222 | return 0; |
awmiller | 4:1e5639a2a3ae | 223 | } |
awmiller | 4:1e5639a2a3ae | 224 | |
awmiller | 4:1e5639a2a3ae | 225 | |
awmiller | 4:1e5639a2a3ae | 226 | |
awmiller | 4:1e5639a2a3ae | 227 | |
awmiller | 4:1e5639a2a3ae | 228 | //FINALLY, Test pass through mode |
awmiller | 4:1e5639a2a3ae | 229 | |
awmiller | 4:1e5639a2a3ae | 230 | |
awmiller | 4:1e5639a2a3ae | 231 | return 1; |
awmiller | 4:1e5639a2a3ae | 232 | |
awmiller | 4:1e5639a2a3ae | 233 | |
awmiller | 4:1e5639a2a3ae | 234 | |
awmiller | 4:1e5639a2a3ae | 235 | } |
awmiller | 4:1e5639a2a3ae | 236 | |
awmiller | 4:1e5639a2a3ae | 237 | int PassThroughTest(Serial &pc,I2C &master) |
awmiller | 4:1e5639a2a3ae | 238 | { |
awmiller | 4:1e5639a2a3ae | 239 | if( !Sentral_pass_through(pc,master) ) |
awmiller | 4:1e5639a2a3ae | 240 | { |
awmiller | 4:1e5639a2a3ae | 241 | return 0; |
awmiller | 4:1e5639a2a3ae | 242 | } |
awmiller | 4:1e5639a2a3ae | 243 | |
awmiller | 4:1e5639a2a3ae | 244 | char cmd[3]; |
awmiller | 4:1e5639a2a3ae | 245 | char chk[3]; |
awmiller | 4:1e5639a2a3ae | 246 | |
awmiller | 4:1e5639a2a3ae | 247 | cmd[0] = 0x00; |
awmiller | 4:1e5639a2a3ae | 248 | cmd[1] = 0x00; |
awmiller | 4:1e5639a2a3ae | 249 | cmd[2] = 0x00; |
awmiller | 4:1e5639a2a3ae | 250 | for(int i = 0xA0; i < 0xB0; i += 2) |
awmiller | 4:1e5639a2a3ae | 251 | { |
awmiller | 4:1e5639a2a3ae | 252 | int check = master.write(i,cmd,2); |
awmiller | 4:1e5639a2a3ae | 253 | |
awmiller | 4:1e5639a2a3ae | 254 | if(check) |
awmiller | 4:1e5639a2a3ae | 255 | pc.printf("."); |
awmiller | 4:1e5639a2a3ae | 256 | //break;//return 0; |
awmiller | 4:1e5639a2a3ae | 257 | else |
awmiller | 4:1e5639a2a3ae | 258 | { |
awmiller | 4:1e5639a2a3ae | 259 | check = master.read(i,chk,3); |
awmiller | 4:1e5639a2a3ae | 260 | |
awmiller | 4:1e5639a2a3ae | 261 | if(check) |
awmiller | 4:1e5639a2a3ae | 262 | pc.printf(".");//break;//return 0; |
awmiller | 4:1e5639a2a3ae | 263 | else |
awmiller | 4:1e5639a2a3ae | 264 | { |
awmiller | 4:1e5639a2a3ae | 265 | pc.printf("\r\n%X,%X,%X \r\n",chk[0],chk[1],chk[2]); |
awmiller | 4:1e5639a2a3ae | 266 | return 1; |
awmiller | 4:1e5639a2a3ae | 267 | } |
awmiller | 4:1e5639a2a3ae | 268 | } |
awmiller | 4:1e5639a2a3ae | 269 | } |
awmiller | 4:1e5639a2a3ae | 270 | return 0; |
awmiller | 4:1e5639a2a3ae | 271 | } |
awmiller | 4:1e5639a2a3ae | 272 | |
awmiller | 4:1e5639a2a3ae | 273 | //EOF |
awmiller | 4:1e5639a2a3ae | 274 |