HAHAHAHHA

Dependencies:   TextLCD mbed-rtos mbed

Fork of 541-pacemaker-heart by Terry Fang

Committer:
terryfan
Date:
Thu Dec 01 05:02:25 2016 +0000
Revision:
0:da581483b90d
Child:
1:57cd3ae5f44a
heart_model last

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