HAHAHAHHA

Dependencies:   TextLCD mbed-rtos mbed

Fork of 541-pacemaker-heart by Terry Fang

Committer:
terryfan
Date:
Fri Dec 02 21:39:47 2016 +0000
Revision:
1:57cd3ae5f44a
Parent:
0:da581483b90d
Child:
2:18b496a20413
heart fixed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terryfan 0:da581483b90d 1 #include "mbed.h"
terryfan 0:da581483b90d 2 #include "rtos.h"
terryfan 0:da581483b90d 3 #include "TextLCD.h"
terryfan 0:da581483b90d 4
terryfan 0:da581483b90d 5 LocalFileSystem local("local");
terryfan 0:da581483b90d 6
terryfan 0:da581483b90d 7 InterruptIn vpace(p5);
terryfan 0:da581483b90d 8 InterruptIn apace(p6);
terryfan 0:da581483b90d 9 DigitalOut vsignal(p7);
terryfan 0:da581483b90d 10 DigitalOut asignal(p8);
terryfan 0:da581483b90d 11
terryfan 0:da581483b90d 12 DigitalOut asignal_led(LED1);
terryfan 0:da581483b90d 13 DigitalOut vsignal_led(LED2);
terryfan 0:da581483b90d 14 DigitalOut apace_led(LED3);
terryfan 0:da581483b90d 15 DigitalOut vpace_led(LED4);
terryfan 0:da581483b90d 16
terryfan 0:da581483b90d 17 Thread *heartmodeThread;
terryfan 0:da581483b90d 18 osThreadId heartmodeTid;
terryfan 0:da581483b90d 19
terryfan 1:57cd3ae5f44a 20 Queue<char,256> mode_q;
terryfan 1:57cd3ae5f44a 21 Queue<char,256> signal_q;
terryfan 1:57cd3ae5f44a 22
terryfan 1:57cd3ae5f44a 23
terryfan 1:57cd3ae5f44a 24 FILE * testresults;
terryfan 1:57cd3ae5f44a 25
terryfan 0:da581483b90d 26 /////////////////
terryfan 0:da581483b90d 27 TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2);
terryfan 0:da581483b90d 28 RawSerial pc(USBTX, USBRX);
terryfan 0:da581483b90d 29 char key = 'n';
terryfan 0:da581483b90d 30 int manual_mode;
terryfan 0:da581483b90d 31 int isChangingObsInt;
terryfan 0:da581483b90d 32 /////////////////
terryfan 1:57cd3ae5f44a 33 volatile char c;
terryfan 1:57cd3ae5f44a 34 volatile int mm = 0;
terryfan 0:da581483b90d 35
terryfan 0:da581483b90d 36 int lri = 1000;
terryfan 0:da581483b90d 37 int uri = 700;
terryfan 0:da581483b90d 38 int avi = 150;
terryfan 0:da581483b90d 39 int pvarp = 300;
terryfan 0:da581483b90d 40 int vrp = 200;
terryfan 0:da581483b90d 41 int arp = 50;
terryfan 0:da581483b90d 42
terryfan 0:da581483b90d 43 int twait = 10;
terryfan 0:da581483b90d 44 int thrsh = 1000;
terryfan 0:da581483b90d 45 int heartmode = 0;
terryfan 1:57cd3ae5f44a 46
terryfan 1:57cd3ae5f44a 47
terryfan 0:da581483b90d 48 void vpace_irq()
terryfan 0:da581483b90d 49 {
terryfan 0:da581483b90d 50 //heartmodeThread->signal_set(0x1);
terryfan 0:da581483b90d 51 osSignalSet(heartmodeTid, 0x1);
terryfan 0:da581483b90d 52 }
terryfan 0:da581483b90d 53
terryfan 0:da581483b90d 54 void apace_irq()
terryfan 0:da581483b90d 55 {
terryfan 0:da581483b90d 56 //heartmodeThread->signal_set(0x10);
terryfan 0:da581483b90d 57 osSignalSet(heartmodeTid, 0x10);
terryfan 0:da581483b90d 58 }
terryfan 0:da581483b90d 59
terryfan 1:57cd3ae5f44a 60
terryfan 1:57cd3ae5f44a 61
terryfan 1:57cd3ae5f44a 62 void Rx_interrupt()
terryfan 1:57cd3ae5f44a 63 {
terryfan 1:57cd3ae5f44a 64 while(pc.readable()) {
terryfan 1:57cd3ae5f44a 65 c = pc.getc();
terryfan 1:57cd3ae5f44a 66 if(c == 'm') {
terryfan 1:57cd3ae5f44a 67 mode_q.put((char*)c);
terryfan 1:57cd3ae5f44a 68 mm = 1;
terryfan 1:57cd3ae5f44a 69 } else if(c == 'r' || c == 't') {
terryfan 1:57cd3ae5f44a 70 mode_q.put((char*)c);
terryfan 1:57cd3ae5f44a 71 mm = 0;
terryfan 1:57cd3ae5f44a 72 } else if((c == 'a' || c == 'v') && mm) {
terryfan 1:57cd3ae5f44a 73 signal_q.put((char*)c);
terryfan 1:57cd3ae5f44a 74 }
terryfan 1:57cd3ae5f44a 75 }
terryfan 1:57cd3ae5f44a 76 }
terryfan 1:57cd3ae5f44a 77
terryfan 1:57cd3ae5f44a 78
terryfan 1:57cd3ae5f44a 79
terryfan 1:57cd3ae5f44a 80
terryfan 1:57cd3ae5f44a 81
terryfan 0:da581483b90d 82 void test_vrp_vv(FILE * results, Timer * ti)
terryfan 0:da581483b90d 83 {
terryfan 0:da581483b90d 84 int vrpwait = vrp/2;
terryfan 0:da581483b90d 85 int adifu,vdifu,difl = 0;
terryfan 0:da581483b90d 86 fprintf(results, " Test VRP VV\n\n Time Action\n");
terryfan 0:da581483b90d 87 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 88 apace_led = 1;
terryfan 0:da581483b90d 89 Thread::wait(twait);
terryfan 0:da581483b90d 90 apace_led = 0;
terryfan 0:da581483b90d 91 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 92 ti->reset();
terryfan 0:da581483b90d 93 vpace_led = 1;
terryfan 0:da581483b90d 94 Thread::wait(twait);
terryfan 0:da581483b90d 95 vpace_led = 0;
terryfan 0:da581483b90d 96
terryfan 0:da581483b90d 97 Thread::wait(vrpwait);
terryfan 0:da581483b90d 98 vsignal = 1;
terryfan 0:da581483b90d 99 vsignal_led = 1;
terryfan 0:da581483b90d 100 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 101 Thread::wait(twait);
terryfan 0:da581483b90d 102 vsignal_led = 0;
terryfan 0:da581483b90d 103 vsignal = 0;
terryfan 0:da581483b90d 104
terryfan 0:da581483b90d 105 Thread::wait(vrpwait);
terryfan 0:da581483b90d 106 vsignal = 1;
terryfan 0:da581483b90d 107 difl = ti->read_us();
terryfan 0:da581483b90d 108 vsignal_led = 1;
terryfan 0:da581483b90d 109 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 110 Thread::wait(twait);
terryfan 0:da581483b90d 111 vsignal = 0;
terryfan 0:da581483b90d 112 vsignal_led = 0;
terryfan 0:da581483b90d 113
terryfan 0:da581483b90d 114 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 115 adifu = ti->read_us();
terryfan 0:da581483b90d 116 apace_led = 1;
terryfan 0:da581483b90d 117 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 118 Thread::wait(twait);
terryfan 0:da581483b90d 119 apace_led = 0;
terryfan 0:da581483b90d 120
terryfan 0:da581483b90d 121 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 122 vdifu = ti->read_us();
terryfan 0:da581483b90d 123 vpace_led = 1;
terryfan 0:da581483b90d 124 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 125 Thread::wait(twait);
terryfan 0:da581483b90d 126 vpace_led = 0;
terryfan 0:da581483b90d 127
terryfan 0:da581483b90d 128 int adif = adifu-difl;
terryfan 0:da581483b90d 129 int vdif = vdifu-difl;
terryfan 0:da581483b90d 130 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 131 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 132 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 133 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 134
terryfan 0:da581483b90d 135 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 136
terryfan 0:da581483b90d 137 }
terryfan 0:da581483b90d 138 void test_pvarp_aa(FILE * results, Timer * ti)
terryfan 0:da581483b90d 139 {
terryfan 0:da581483b90d 140 int pvarpwait = pvarp/2;
terryfan 0:da581483b90d 141 int vdifu = 0;
terryfan 0:da581483b90d 142 fprintf(results, " Test PVARP AA\n\n Time Action\n");
terryfan 0:da581483b90d 143 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 144 apace_led = 1;
terryfan 0:da581483b90d 145 Thread::wait(twait);
terryfan 0:da581483b90d 146 apace_led = 0;
terryfan 0:da581483b90d 147 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 148 ti->reset();
terryfan 0:da581483b90d 149 vpace_led = 1;
terryfan 0:da581483b90d 150 Thread::wait(twait);
terryfan 0:da581483b90d 151 vpace_led = 0;
terryfan 0:da581483b90d 152
terryfan 0:da581483b90d 153 Thread::wait(pvarpwait);
terryfan 0:da581483b90d 154 asignal = 1;
terryfan 0:da581483b90d 155 asignal_led = 1;
terryfan 0:da581483b90d 156 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 157 Thread::wait(twait);
terryfan 0:da581483b90d 158 asignal_led = 0;
terryfan 0:da581483b90d 159 asignal = 0;
terryfan 0:da581483b90d 160
terryfan 0:da581483b90d 161 Thread::wait(pvarpwait);
terryfan 0:da581483b90d 162 asignal = 1;
terryfan 0:da581483b90d 163 //difl = ti->read_us();
terryfan 0:da581483b90d 164 asignal_led = 1;
terryfan 0:da581483b90d 165 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 166 Thread::wait(twait);
terryfan 0:da581483b90d 167 asignal_led = 0;
terryfan 0:da581483b90d 168 asignal = 0;
terryfan 0:da581483b90d 169
terryfan 0:da581483b90d 170 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 171 vdifu = ti->read_us();
terryfan 0:da581483b90d 172 vpace_led = 1;
terryfan 0:da581483b90d 173 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 174 Thread::wait(twait);
terryfan 0:da581483b90d 175 vpace_led = 0;
terryfan 0:da581483b90d 176
terryfan 0:da581483b90d 177 int vdif = vdifu;
terryfan 0:da581483b90d 178 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 179 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 180
terryfan 0:da581483b90d 181 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 182 }
terryfan 0:da581483b90d 183
terryfan 0:da581483b90d 184 void test_pvarp_arp_aaa(FILE * results, Timer * ti)
terryfan 0:da581483b90d 185 {
terryfan 0:da581483b90d 186 int arpwait = arp/2;
terryfan 0:da581483b90d 187 int vdifu = 0;
terryfan 0:da581483b90d 188 fprintf(results, "Test PVARP ARP AAA\n\n Time Action\n");
terryfan 0:da581483b90d 189 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 190 apace_led = 1;
terryfan 0:da581483b90d 191 Thread::wait(twait);
terryfan 0:da581483b90d 192 apace_led = 0;
terryfan 0:da581483b90d 193 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 194 ti->reset();
terryfan 0:da581483b90d 195 vpace_led = 1;
terryfan 0:da581483b90d 196 Thread::wait(twait);
terryfan 0:da581483b90d 197 vpace_led = 0;
terryfan 0:da581483b90d 198
terryfan 0:da581483b90d 199 Thread::wait(pvarp);
terryfan 0:da581483b90d 200 asignal = 1;
terryfan 0:da581483b90d 201 asignal_led = 1;
terryfan 0:da581483b90d 202 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 203 Thread::wait(twait);
terryfan 0:da581483b90d 204 asignal_led = 0;
terryfan 0:da581483b90d 205 asignal = 0;
terryfan 0:da581483b90d 206
terryfan 0:da581483b90d 207 Thread::wait(arpwait);
terryfan 0:da581483b90d 208 asignal = 1;
terryfan 0:da581483b90d 209 asignal_led = 1;
terryfan 0:da581483b90d 210 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 211 Thread::wait(twait);
terryfan 0:da581483b90d 212 asignal_led = 0;
terryfan 0:da581483b90d 213 asignal = 0;
terryfan 0:da581483b90d 214
terryfan 0:da581483b90d 215 Thread::wait(arpwait);
terryfan 0:da581483b90d 216 asignal = 1;
terryfan 0:da581483b90d 217 asignal_led = 1;
terryfan 0:da581483b90d 218 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 219 Thread::wait(twait);
terryfan 0:da581483b90d 220 asignal_led = 0;
terryfan 0:da581483b90d 221 asignal = 0;
terryfan 0:da581483b90d 222
terryfan 0:da581483b90d 223 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 224 vdifu = ti->read_us();
terryfan 0:da581483b90d 225 vpace_led = 1;
terryfan 0:da581483b90d 226 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 227 Thread::wait(twait);
terryfan 0:da581483b90d 228 vpace_led = 0;
terryfan 0:da581483b90d 229
terryfan 0:da581483b90d 230 int vdif = vdifu;
terryfan 0:da581483b90d 231 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 232 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 233
terryfan 0:da581483b90d 234 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 235 }
terryfan 0:da581483b90d 236
terryfan 0:da581483b90d 237 void test_pvarp_arp_aav(FILE * results, Timer * ti)
terryfan 0:da581483b90d 238 {
terryfan 0:da581483b90d 239 int adifu,vdifu,difl = 0;
terryfan 0:da581483b90d 240 fprintf(results, "Test PVARP ARP AAV\n\n Time Action\n");
terryfan 0:da581483b90d 241 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 242 apace_led = 1;
terryfan 0:da581483b90d 243 Thread::wait(twait);
terryfan 0:da581483b90d 244 apace_led = 0;
terryfan 0:da581483b90d 245 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 246 ti->reset();
terryfan 0:da581483b90d 247 vpace_led = 1;
terryfan 0:da581483b90d 248 Thread::wait(twait);
terryfan 0:da581483b90d 249 vpace_led = 0;
terryfan 0:da581483b90d 250
terryfan 0:da581483b90d 251 Thread::wait(pvarp);
terryfan 0:da581483b90d 252 asignal = 1;
terryfan 0:da581483b90d 253 asignal_led = 1;
terryfan 0:da581483b90d 254 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 255 Thread::wait(twait);
terryfan 0:da581483b90d 256 asignal_led = 0;
terryfan 0:da581483b90d 257 asignal = 0;
terryfan 0:da581483b90d 258
terryfan 0:da581483b90d 259 Thread::wait(arp);
terryfan 0:da581483b90d 260 asignal = 1;
terryfan 0:da581483b90d 261 asignal_led = 1;
terryfan 0:da581483b90d 262 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 263 Thread::wait(twait);
terryfan 0:da581483b90d 264 asignal_led = 0;
terryfan 0:da581483b90d 265 asignal = 0;
terryfan 0:da581483b90d 266
terryfan 0:da581483b90d 267 Thread::wait(20);
terryfan 0:da581483b90d 268 vsignal = 1;
terryfan 0:da581483b90d 269 difl = ti->read_us();
terryfan 0:da581483b90d 270 vsignal_led = 1;
terryfan 0:da581483b90d 271 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 272 Thread::wait(twait);
terryfan 0:da581483b90d 273 vsignal = 0;
terryfan 0:da581483b90d 274 vsignal_led = 0;
terryfan 0:da581483b90d 275
terryfan 0:da581483b90d 276 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 277 adifu = ti->read_us();
terryfan 0:da581483b90d 278 apace_led = 1;
terryfan 0:da581483b90d 279 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 280 Thread::wait(twait);
terryfan 0:da581483b90d 281 apace_led = 0;
terryfan 0:da581483b90d 282
terryfan 0:da581483b90d 283 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 284 vdifu = ti->read_us();
terryfan 0:da581483b90d 285 vpace_led = 1;
terryfan 0:da581483b90d 286 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 287 Thread::wait(twait);
terryfan 0:da581483b90d 288 vpace_led = 0;
terryfan 0:da581483b90d 289
terryfan 0:da581483b90d 290 int adif = adifu-difl;
terryfan 0:da581483b90d 291 int vdif = vdifu-difl;
terryfan 0:da581483b90d 292 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 293 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 294 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 295 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 296
terryfan 0:da581483b90d 297 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 298
terryfan 0:da581483b90d 299 }
terryfan 0:da581483b90d 300
terryfan 0:da581483b90d 301 void test_vpace_after_a(FILE * results, Timer * ti)
terryfan 0:da581483b90d 302 {
terryfan 0:da581483b90d 303 int vdifu = 0;
terryfan 0:da581483b90d 304 fprintf(results, "Test VPACE After A\n\n Time Action\n");
terryfan 0:da581483b90d 305 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 306 apace_led = 1;
terryfan 0:da581483b90d 307 Thread::wait(twait);
terryfan 0:da581483b90d 308 apace_led = 0;
terryfan 0:da581483b90d 309 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 310 ti->reset();
terryfan 0:da581483b90d 311 vpace_led = 1;
terryfan 0:da581483b90d 312 Thread::wait(twait);
terryfan 0:da581483b90d 313 vpace_led = 0;
terryfan 0:da581483b90d 314
terryfan 0:da581483b90d 315 Thread::wait(pvarp);
terryfan 0:da581483b90d 316 asignal = 1;
terryfan 0:da581483b90d 317 asignal_led = 1;
terryfan 0:da581483b90d 318 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 319 Thread::wait(twait);
terryfan 0:da581483b90d 320 asignal_led = 0;
terryfan 0:da581483b90d 321 asignal = 0;
terryfan 0:da581483b90d 322
terryfan 0:da581483b90d 323 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 324 vdifu = ti->read_us();
terryfan 0:da581483b90d 325 vpace_led = 1;
terryfan 0:da581483b90d 326 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 327 Thread::wait(twait);
terryfan 0:da581483b90d 328 vpace_led = 0;
terryfan 0:da581483b90d 329
terryfan 0:da581483b90d 330 int vdif = vdifu;
terryfan 0:da581483b90d 331 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 332 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 333
terryfan 0:da581483b90d 334 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 335 }
terryfan 0:da581483b90d 336
terryfan 0:da581483b90d 337 void test_apace_vpace_av(FILE * results, Timer * ti)
terryfan 0:da581483b90d 338 {
terryfan 0:da581483b90d 339 fprintf(results, "Test APACE After V\n\n Time Action\n");
terryfan 0:da581483b90d 340 int adifu,vdifu = 0;
terryfan 0:da581483b90d 341 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 342 apace_led = 1;
terryfan 0:da581483b90d 343 Thread::wait(twait);
terryfan 0:da581483b90d 344 apace_led = 0;
terryfan 0:da581483b90d 345 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 346 ti->reset();
terryfan 0:da581483b90d 347 vpace_led = 1;
terryfan 0:da581483b90d 348 Thread::wait(twait);
terryfan 0:da581483b90d 349 vpace_led = 0;
terryfan 0:da581483b90d 350
terryfan 0:da581483b90d 351 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 352 adifu = ti->read_us();
terryfan 0:da581483b90d 353 apace_led = 1;
terryfan 0:da581483b90d 354 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 355 Thread::wait(twait);
terryfan 0:da581483b90d 356 apace_led = 0;
terryfan 0:da581483b90d 357
terryfan 0:da581483b90d 358 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 359 vdifu = ti->read_us();
terryfan 0:da581483b90d 360 vpace_led = 1;
terryfan 0:da581483b90d 361 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 362 Thread::wait(twait);
terryfan 0:da581483b90d 363 vpace_led = 0;
terryfan 0:da581483b90d 364
terryfan 0:da581483b90d 365 int adif = adifu;
terryfan 0:da581483b90d 366 int vdif = vdifu;
terryfan 0:da581483b90d 367 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 368 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 369 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 370 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 371
terryfan 0:da581483b90d 372 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 373 }
terryfan 0:da581483b90d 374
terryfan 0:da581483b90d 375 void test_avi_a(FILE * results, Timer * ti)
terryfan 0:da581483b90d 376 {
terryfan 0:da581483b90d 377 int vdifu,difl = 0;
terryfan 0:da581483b90d 378 fprintf(results, " Test AVI\n\n Time Action\n");
terryfan 0:da581483b90d 379 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 380 apace_led = 1;
terryfan 0:da581483b90d 381 Thread::wait(twait);
terryfan 0:da581483b90d 382 apace_led = 0;
terryfan 0:da581483b90d 383 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 384 ti->reset();
terryfan 0:da581483b90d 385 vpace_led = 1;
terryfan 0:da581483b90d 386 Thread::wait(twait);
terryfan 0:da581483b90d 387 vpace_led = 0;
terryfan 0:da581483b90d 388
terryfan 0:da581483b90d 389 Thread::wait(uri);
terryfan 0:da581483b90d 390 asignal = 1;
terryfan 0:da581483b90d 391 difl = ti->read_us();
terryfan 0:da581483b90d 392 asignal_led = 1;
terryfan 0:da581483b90d 393 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 394 Thread::wait(twait);
terryfan 0:da581483b90d 395 asignal_led = 0;
terryfan 0:da581483b90d 396 asignal = 0;
terryfan 0:da581483b90d 397
terryfan 0:da581483b90d 398 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 399 vdifu = ti->read_us();
terryfan 0:da581483b90d 400 vpace_led = 1;
terryfan 0:da581483b90d 401 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 402 Thread::wait(twait);
terryfan 0:da581483b90d 403 vpace_led = 0;
terryfan 0:da581483b90d 404
terryfan 0:da581483b90d 405 int vpc = (avi*1000) + difl;
terryfan 0:da581483b90d 406 const char * res = ((vpc >= (vdifu - thrsh)) &&
terryfan 0:da581483b90d 407 (vpc < (vdifu + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 408
terryfan 0:da581483b90d 409 fprintf(results, "\nResult: %s %d\n\n", res, vpc);
terryfan 0:da581483b90d 410
terryfan 0:da581483b90d 411 }
terryfan 0:da581483b90d 412
terryfan 0:da581483b90d 413 void test_uri_a(FILE * results, Timer * ti)
terryfan 0:da581483b90d 414 {
terryfan 0:da581483b90d 415 int vdifu = 0;
terryfan 0:da581483b90d 416 fprintf(results, " Test URI\n\n Time Action\n");
terryfan 0:da581483b90d 417 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 418 apace_led = 1;
terryfan 0:da581483b90d 419 Thread::wait(twait);
terryfan 0:da581483b90d 420 apace_led = 0;
terryfan 0:da581483b90d 421 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 422 ti->reset();
terryfan 0:da581483b90d 423 vpace_led = 1;
terryfan 0:da581483b90d 424 Thread::wait(twait);
terryfan 0:da581483b90d 425 vpace_led = 0;
terryfan 0:da581483b90d 426
terryfan 0:da581483b90d 427 Thread::wait(pvarp);
terryfan 0:da581483b90d 428 asignal = 1;
terryfan 0:da581483b90d 429 asignal_led = 1;
terryfan 0:da581483b90d 430 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 431 Thread::wait(twait);
terryfan 0:da581483b90d 432 asignal_led = 0;
terryfan 0:da581483b90d 433 asignal = 0;
terryfan 0:da581483b90d 434
terryfan 0:da581483b90d 435 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 436 vdifu = ti->read_us();
terryfan 0:da581483b90d 437 vpace_led = 1;
terryfan 0:da581483b90d 438 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 439 Thread::wait(twait);
terryfan 0:da581483b90d 440 vpace_led = 0;
terryfan 0:da581483b90d 441
terryfan 0:da581483b90d 442 int vdif = vdifu;
terryfan 0:da581483b90d 443 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 444 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 445
terryfan 0:da581483b90d 446 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 447
terryfan 0:da581483b90d 448 }
terryfan 0:da581483b90d 449
terryfan 0:da581483b90d 450 void test_normal_10(FILE * results, Timer * ti)
terryfan 0:da581483b90d 451 {
terryfan 0:da581483b90d 452 fprintf(results, " Test Normal x10\n\n Time Action\n");
terryfan 0:da581483b90d 453 int adifu,vdifu,difl,i = 0;
terryfan 0:da581483b90d 454 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 455 apace_led = 1;
terryfan 0:da581483b90d 456 Thread::wait(twait);
terryfan 0:da581483b90d 457 apace_led = 0;
terryfan 0:da581483b90d 458 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 459 ti->reset();
terryfan 0:da581483b90d 460 vpace_led = 1;
terryfan 0:da581483b90d 461 Thread::wait(twait);
terryfan 0:da581483b90d 462 vpace_led = 0;
terryfan 0:da581483b90d 463
terryfan 0:da581483b90d 464 while(i < 10) {
terryfan 0:da581483b90d 465 Thread::wait(pvarp);
terryfan 0:da581483b90d 466 asignal = 1;
terryfan 0:da581483b90d 467 asignal_led = 1;
terryfan 0:da581483b90d 468 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 469 Thread::wait(twait);
terryfan 0:da581483b90d 470 asignal_led = 0;
terryfan 0:da581483b90d 471 asignal = 0;
terryfan 0:da581483b90d 472
terryfan 0:da581483b90d 473 Thread::wait(75);
terryfan 0:da581483b90d 474 vsignal = 1;
terryfan 0:da581483b90d 475 difl = ti->read_us();
terryfan 0:da581483b90d 476 vsignal_led = 1;
terryfan 0:da581483b90d 477 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 478 Thread::wait(twait);
terryfan 0:da581483b90d 479 vsignal = 0;
terryfan 0:da581483b90d 480 vsignal_led = 0;
terryfan 0:da581483b90d 481 i = i+1;
terryfan 0:da581483b90d 482 }
terryfan 0:da581483b90d 483
terryfan 0:da581483b90d 484 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 485 adifu = ti->read_us();
terryfan 0:da581483b90d 486 apace_led = 1;
terryfan 0:da581483b90d 487 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 488 Thread::wait(twait);
terryfan 0:da581483b90d 489 apace_led = 0;
terryfan 0:da581483b90d 490
terryfan 0:da581483b90d 491 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 492 vdifu = ti->read_us();
terryfan 0:da581483b90d 493 vpace_led = 1;
terryfan 0:da581483b90d 494 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 495 Thread::wait(twait);
terryfan 0:da581483b90d 496 vpace_led = 0;
terryfan 0:da581483b90d 497
terryfan 0:da581483b90d 498 int adif = adifu - difl;
terryfan 0:da581483b90d 499 int vdif = vdifu - difl;
terryfan 0:da581483b90d 500 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 501 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 502 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 503 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 504
terryfan 0:da581483b90d 505 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 506 }
terryfan 0:da581483b90d 507
terryfan 0:da581483b90d 508 void testmode(void const *args)
terryfan 0:da581483b90d 509 {
terryfan 0:da581483b90d 510 Timer *t;
terryfan 1:57cd3ae5f44a 511 testresults = fopen("/local/testreport.txt", "w"); // Open "out.txt" on the local file system for writing
terryfan 0:da581483b90d 512 t = new Timer();
terryfan 0:da581483b90d 513 t->start();
terryfan 0:da581483b90d 514
terryfan 0:da581483b90d 515 test_vrp_vv(testresults, t);
terryfan 0:da581483b90d 516 test_pvarp_aa(testresults, t);
terryfan 0:da581483b90d 517 test_pvarp_arp_aaa(testresults, t);
terryfan 0:da581483b90d 518 test_pvarp_arp_aav(testresults, t);
terryfan 0:da581483b90d 519 test_vpace_after_a(testresults, t);
terryfan 0:da581483b90d 520 test_apace_vpace_av(testresults, t);
terryfan 0:da581483b90d 521 test_avi_a(testresults, t);
terryfan 0:da581483b90d 522 test_uri_a(testresults, t);
terryfan 0:da581483b90d 523 test_normal_10(testresults, t);
terryfan 0:da581483b90d 524 fclose(testresults);
terryfan 0:da581483b90d 525 }
terryfan 0:da581483b90d 526
terryfan 0:da581483b90d 527
terryfan 0:da581483b90d 528 void randommode(void const *args)
terryfan 0:da581483b90d 529 {
terryfan 0:da581483b90d 530 int aorv,sig = 0;
terryfan 0:da581483b90d 531 Timer at,vt;
terryfan 0:da581483b90d 532
terryfan 0:da581483b90d 533 at.start();
terryfan 0:da581483b90d 534 vt.start();
terryfan 0:da581483b90d 535
terryfan 0:da581483b90d 536 //osEvent ext_signal = osSignalWait(0, 1);
terryfan 0:da581483b90d 537 //int evt = ext_signal.value.signals;
terryfan 0:da581483b90d 538 //osSignalSet(heartmodeTid, 0x1);
terryfan 0:da581483b90d 539 //osSignalWait(0, osWaitForever);
terryfan 0:da581483b90d 540 while(heartmode == 0) {
terryfan 0:da581483b90d 541 aorv = (float)(rand()%2);
terryfan 0:da581483b90d 542 sig = aorv ? rand()%(lri - avi - at.read_ms()) : rand()%(lri - vt.read_ms());
terryfan 0:da581483b90d 543
terryfan 0:da581483b90d 544 osEvent ext_signal = osSignalWait(0, sig);
terryfan 0:da581483b90d 545 int evt = ext_signal.value.signals;
terryfan 0:da581483b90d 546
terryfan 0:da581483b90d 547 switch(evt) {
terryfan 0:da581483b90d 548 case(0x0):
terryfan 0:da581483b90d 549 if(aorv) {
terryfan 0:da581483b90d 550 asignal = 1;
terryfan 0:da581483b90d 551 asignal_led = 1;
terryfan 0:da581483b90d 552 Thread::wait(twait);
terryfan 0:da581483b90d 553 asignal_led = 0;
terryfan 0:da581483b90d 554 asignal = 0;
terryfan 0:da581483b90d 555 break;
terryfan 0:da581483b90d 556 } else {
terryfan 0:da581483b90d 557 vsignal = 1;
terryfan 0:da581483b90d 558 at.reset();
terryfan 0:da581483b90d 559 vt.reset();
terryfan 0:da581483b90d 560 vsignal_led = 1;
terryfan 0:da581483b90d 561 Thread::wait(twait);
terryfan 0:da581483b90d 562 vsignal_led = 0;
terryfan 0:da581483b90d 563 vsignal = 0;
terryfan 0:da581483b90d 564 break;
terryfan 0:da581483b90d 565 }
terryfan 0:da581483b90d 566 case(0x1):
terryfan 0:da581483b90d 567 at.reset();
terryfan 0:da581483b90d 568 vt.reset();
terryfan 0:da581483b90d 569 vpace_led = 1;
terryfan 0:da581483b90d 570 Thread::wait(twait);
terryfan 0:da581483b90d 571 vpace_led = 0;
terryfan 0:da581483b90d 572 break;
terryfan 0:da581483b90d 573
terryfan 0:da581483b90d 574 case(0x10):
terryfan 0:da581483b90d 575 apace_led = 1;
terryfan 0:da581483b90d 576 Thread::wait(twait);
terryfan 0:da581483b90d 577 apace_led = 0;
terryfan 0:da581483b90d 578 break;
terryfan 1:57cd3ae5f44a 579
terryfan 1:57cd3ae5f44a 580 // case(0x100):
terryfan 1:57cd3ae5f44a 581 //
terryfan 0:da581483b90d 582 }
terryfan 0:da581483b90d 583 }
terryfan 0:da581483b90d 584 }
terryfan 0:da581483b90d 585
terryfan 1:57cd3ae5f44a 586 void manualmode(void const *args)
terryfan 1:57cd3ae5f44a 587 {
terryfan 1:57cd3ae5f44a 588 while(1) {
terryfan 1:57cd3ae5f44a 589 osEvent evt = signal_q.get();
terryfan 1:57cd3ae5f44a 590 if(evt.status == osEventMessage) {
terryfan 1:57cd3ae5f44a 591 if((char)evt.value.p == 'a') {
terryfan 1:57cd3ae5f44a 592 asignal = 1;
terryfan 1:57cd3ae5f44a 593 asignal_led = 1;
terryfan 1:57cd3ae5f44a 594 Thread::wait(twait);
terryfan 1:57cd3ae5f44a 595 asignal_led = 0;
terryfan 1:57cd3ae5f44a 596 asignal = 0;
terryfan 1:57cd3ae5f44a 597 } else if((char)evt.value.p == 'v') {
terryfan 1:57cd3ae5f44a 598 vsignal = 1;
terryfan 1:57cd3ae5f44a 599 vsignal_led = 1;
terryfan 1:57cd3ae5f44a 600 Thread::wait(twait);
terryfan 1:57cd3ae5f44a 601 vsignal = 0;
terryfan 1:57cd3ae5f44a 602 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 603 }
terryfan 1:57cd3ae5f44a 604 }
terryfan 1:57cd3ae5f44a 605 }
terryfan 1:57cd3ae5f44a 606 }
terryfan 0:da581483b90d 607
terryfan 0:da581483b90d 608
terryfan 1:57cd3ae5f44a 609 osThreadDef(randommode, osPriorityNormal, DEFAULT_STACK_SIZE);
terryfan 0:da581483b90d 610 osThreadDef(testmode, osPriorityNormal, DEFAULT_STACK_SIZE);
terryfan 1:57cd3ae5f44a 611 osThreadDef(manualmode, osPriorityNormal, DEFAULT_STACK_SIZE);
terryfan 1:57cd3ae5f44a 612
terryfan 0:da581483b90d 613 int main()
terryfan 0:da581483b90d 614 {
terryfan 0:da581483b90d 615 vpace.rise(&vpace_irq);
terryfan 0:da581483b90d 616 apace.rise(&apace_irq);
terryfan 0:da581483b90d 617
terryfan 1:57cd3ae5f44a 618 pc.attach(&Rx_interrupt, RawSerial::RxIrq);
terryfan 0:da581483b90d 619 //heartmodeThread = new Thread();
terryfan 0:da581483b90d 620
terryfan 0:da581483b90d 621 //Callback<void()> testmodeTask((void*)NULL,(void (*)(void *))&testmode);
terryfan 0:da581483b90d 622
terryfan 1:57cd3ae5f44a 623 heartmodeTid = osThreadCreate(osThread(randommode), NULL);
terryfan 1:57cd3ae5f44a 624 // heartmodeTid = osThreadCreate(osThread(testmode), NULL);
terryfan 1:57cd3ae5f44a 625 // heartmodeTid = osThreadCreate(osThread(manualmode), NULL);
terryfan 0:da581483b90d 626 // lcd.printf();
terryfan 0:da581483b90d 627 while(true) {
terryfan 1:57cd3ae5f44a 628 // while(pc.readable()) {
terryfan 1:57cd3ae5f44a 629 // key = pc.getc();
terryfan 1:57cd3ae5f44a 630 osEvent evt = mode_q.get();
terryfan 1:57cd3ae5f44a 631 if(evt.status == osEventMessage) {
terryfan 1:57cd3ae5f44a 632 switch((char)evt.value.p) {
terryfan 0:da581483b90d 633 //pvarp = 0.3s
terryfan 0:da581483b90d 634 case('r'):
terryfan 0:da581483b90d 635 lcd.printf("R");
terryfan 1:57cd3ae5f44a 636 // randommode.terminate();
terryfan 1:57cd3ae5f44a 637 osThreadTerminate (heartmodeTid);
terryfan 1:57cd3ae5f44a 638 if (testresults != NULL) {
terryfan 1:57cd3ae5f44a 639 fclose(testresults);
terryfan 1:57cd3ae5f44a 640 }
terryfan 1:57cd3ae5f44a 641 asignal_led = 0;
terryfan 1:57cd3ae5f44a 642 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 643 apace_led = 0;
terryfan 1:57cd3ae5f44a 644 vpace_led = 0;
terryfan 1:57cd3ae5f44a 645
terryfan 1:57cd3ae5f44a 646 heartmodeTid = osThreadCreate(osThread(randommode), NULL);
terryfan 0:da581483b90d 647 // Thread::wait(100);
terryfan 0:da581483b90d 648 break;
terryfan 0:da581483b90d 649 case('t'):
terryfan 0:da581483b90d 650 lcd.printf("T");
terryfan 1:57cd3ae5f44a 651 osThreadTerminate (heartmodeTid);
terryfan 1:57cd3ae5f44a 652 if (testresults != NULL) {
terryfan 1:57cd3ae5f44a 653 fclose(testresults);
terryfan 1:57cd3ae5f44a 654 }
terryfan 1:57cd3ae5f44a 655 asignal_led = 0;
terryfan 1:57cd3ae5f44a 656 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 657 apace_led = 0;
terryfan 1:57cd3ae5f44a 658 vpace_led = 0;
terryfan 1:57cd3ae5f44a 659
terryfan 1:57cd3ae5f44a 660 heartmodeTid = osThreadCreate(osThread(testmode), NULL);
terryfan 0:da581483b90d 661 break;
terryfan 0:da581483b90d 662 case('m'):
terryfan 0:da581483b90d 663 lcd.printf("M");
terryfan 1:57cd3ae5f44a 664 osThreadTerminate (heartmodeTid);
terryfan 1:57cd3ae5f44a 665 if (testresults != NULL) {
terryfan 1:57cd3ae5f44a 666 fclose(testresults);
terryfan 1:57cd3ae5f44a 667 }
terryfan 1:57cd3ae5f44a 668 asignal_led = 0;
terryfan 1:57cd3ae5f44a 669 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 670 apace_led = 0;
terryfan 1:57cd3ae5f44a 671 vpace_led = 0;
terryfan 1:57cd3ae5f44a 672
terryfan 1:57cd3ae5f44a 673 heartmodeTid = osThreadCreate(osThread(manualmode), NULL);
terryfan 0:da581483b90d 674 manual_mode = 1;
terryfan 0:da581483b90d 675
terryfan 0:da581483b90d 676 break;
terryfan 0:da581483b90d 677 case('o'):
terryfan 0:da581483b90d 678 isChangingObsInt = 1;
terryfan 0:da581483b90d 679 lcd.printf("O");
terryfan 0:da581483b90d 680 break;
terryfan 0:da581483b90d 681 }
terryfan 0:da581483b90d 682 }
terryfan 0:da581483b90d 683 }
terryfan 0:da581483b90d 684 }