heart modes, send, receive

Dependencies:   Terminal TextLCD mbed-rtos mbed

Fork of Heartnew by CIS541

Committer:
sanjeet25
Date:
Wed Dec 02 04:03:46 2015 +0000
Revision:
6:cc4fcc38b9f0
Parent:
5:8e3b9032ddfc
Child:
7:46aeded22784
heartnew

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sanjeet25 0:a307f0abfd4d 1 #include "mbed.h"
sanjeet25 0:a307f0abfd4d 2 #include "TextLCD.h"
sanjeet25 0:a307f0abfd4d 3 #include "rtos.h"
sanjeet25 0:a307f0abfd4d 4
sanjeet25 0:a307f0abfd4d 5 TextLCD lcd(p15, p16, p17, p18, p19, p20);
sanjeet25 0:a307f0abfd4d 6 Serial pc(USBTX, USBRX);
sanjeet25 0:a307f0abfd4d 7
sanjeet25 1:c340c31174a5 8 InterruptIn APace(p23);
sanjeet25 1:c340c31174a5 9 InterruptIn VPace(p24);
sanjeet25 0:a307f0abfd4d 10
sanjeet25 1:c340c31174a5 11 DigitalOut ASignal(p25);
sanjeet25 1:c340c31174a5 12 DigitalOut VSignal(p26);
sanjeet25 1:c340c31174a5 13
sanjeet25 2:fc2f41386ee4 14 DigitalOut APaceReceive(LED1);
sanjeet25 2:fc2f41386ee4 15 DigitalOut VPaceReceive(LED2);
sanjeet25 2:fc2f41386ee4 16
sanjeet25 2:fc2f41386ee4 17 DigitalOut ASignal1(LED3);
sanjeet25 2:fc2f41386ee4 18 DigitalOut VSignal1(LED4);
sanjeet25 0:a307f0abfd4d 19
sanjeet25 0:a307f0abfd4d 20 const int minwait_A=50;
sanjeet25 0:a307f0abfd4d 21 const int minwait_V=50;
sanjeet25 0:a307f0abfd4d 22
sanjeet25 3:b702a21b2990 23 volatile int t=0;
sanjeet25 3:b702a21b2990 24 volatile int k=0;
sanjeet25 0:a307f0abfd4d 25 int m=0;
sanjeet25 0:a307f0abfd4d 26 int s=0;
sanjeet25 0:a307f0abfd4d 27 int ms=0;
sanjeet25 2:fc2f41386ee4 28 int heartInterval;
sanjeet25 0:a307f0abfd4d 29 char key_input;
sanjeet25 3:b702a21b2990 30 int testNumber;
sanjeet25 4:a64a0fea5266 31 bool test_result;
sanjeet25 4:a64a0fea5266 32 const int prop_delay=15;
sanjeet25 4:a64a0fea5266 33 int flag_key=0;
sanjeet25 6:cc4fcc38b9f0 34 Mutex heartmut, keymutex;
sanjeet25 0:a307f0abfd4d 35
sanjeet25 0:a307f0abfd4d 36 int LRI=1500;
sanjeet25 0:a307f0abfd4d 37 int URI=600;
sanjeet25 2:fc2f41386ee4 38 int heartRate;
sanjeet25 0:a307f0abfd4d 39 volatile bool Areceived=false;
sanjeet25 0:a307f0abfd4d 40 volatile bool Vreceived=false;
sanjeet25 3:b702a21b2990 41 bool test=false;
sanjeet25 2:fc2f41386ee4 42 int low[4] = {30,40,100,30};
sanjeet25 2:fc2f41386ee4 43 int high[4] = {60,100,175,175};
sanjeet25 2:fc2f41386ee4 44 int modeset;
sanjeet25 3:b702a21b2990 45 int pulses;
sanjeet25 4:a64a0fea5266 46 //int test;
sanjeet25 4:a64a0fea5266 47 int flag;
sanjeet25 4:a64a0fea5266 48 int delta=15;
sanjeet25 4:a64a0fea5266 49 int observationInterval=10000;
sanjeet25 4:a64a0fea5266 50 const int vrp=100;
sanjeet25 4:a64a0fea5266 51 const int pvarp=150;
sanjeet25 4:a64a0fea5266 52 const int avi=65;
sanjeet25 4:a64a0fea5266 53 const int pvab=10;
sanjeet25 0:a307f0abfd4d 54
sanjeet25 0:a307f0abfd4d 55 const int sleepModeURI = 1000;
sanjeet25 0:a307f0abfd4d 56 const int sleepModeLRI = 2000;
sanjeet25 0:a307f0abfd4d 57
sanjeet25 0:a307f0abfd4d 58 const int normalModeURI = 600;
sanjeet25 0:a307f0abfd4d 59 const int normalModeLRI = 1500;
sanjeet25 0:a307f0abfd4d 60
sanjeet25 0:a307f0abfd4d 61 const int sportsModeURI = 343;
sanjeet25 0:a307f0abfd4d 62 const int sportsModeLRI = 600;
sanjeet25 0:a307f0abfd4d 63
sanjeet25 0:a307f0abfd4d 64 const int manualModeURI = 343;
sanjeet25 0:a307f0abfd4d 65 const int manualModeLRI = 2000;
sanjeet25 0:a307f0abfd4d 66
sanjeet25 4:a64a0fea5266 67 int lri=normalModeLRI;
sanjeet25 4:a64a0fea5266 68 int uri=normalModeURI;
sanjeet25 6:cc4fcc38b9f0 69 int flagr=0;
sanjeet25 4:a64a0fea5266 70
sanjeet25 0:a307f0abfd4d 71 typedef enum Modes {
sanjeet25 0:a307f0abfd4d 72 Test,
sanjeet25 0:a307f0abfd4d 73 Normal,
sanjeet25 0:a307f0abfd4d 74 Sleep,
sanjeet25 0:a307f0abfd4d 75 Random,
sanjeet25 0:a307f0abfd4d 76 Sports,
sanjeet25 0:a307f0abfd4d 77 Manual,
sanjeet25 2:fc2f41386ee4 78 Observer
sanjeet25 0:a307f0abfd4d 79 };
sanjeet25 0:a307f0abfd4d 80 Modes mode;
sanjeet25 0:a307f0abfd4d 81
sanjeet25 0:a307f0abfd4d 82 Mutex HeartMutex;
sanjeet25 0:a307f0abfd4d 83
sanjeet25 2:fc2f41386ee4 84 Thread *heartreceive;
sanjeet25 2:fc2f41386ee4 85 Thread *heartsend;
sanjeet25 2:fc2f41386ee4 86 Thread *heartkeyboard;
sanjeet25 4:a64a0fea5266 87 Thread *testmode;
sanjeet25 4:a64a0fea5266 88 Thread *hmode;
sanjeet25 2:fc2f41386ee4 89
sanjeet25 2:fc2f41386ee4 90
sanjeet25 3:b702a21b2990 91 void resett();
sanjeet25 3:b702a21b2990 92 void resetk();
sanjeet25 2:fc2f41386ee4 93 void VPacereceived();
sanjeet25 2:fc2f41386ee4 94 void APacereceived();
sanjeet25 0:a307f0abfd4d 95 void ASignalsend();
sanjeet25 0:a307f0abfd4d 96 void VSignalsend();
sanjeet25 0:a307f0abfd4d 97 void HeartReceive();
sanjeet25 0:a307f0abfd4d 98 void HeartSend();
sanjeet25 1:c340c31174a5 99 void HeartKeyBoardModeSwitch();
sanjeet25 3:b702a21b2990 100 void sound_lowAlarm();
sanjeet25 3:b702a21b2990 101 void sound_highAlarm();
sanjeet25 4:a64a0fea5266 102 void Testmode();
sanjeet25 0:a307f0abfd4d 103
sanjeet25 0:a307f0abfd4d 104
sanjeet25 0:a307f0abfd4d 105 extern "C" void TIMER0_IRQHandler (void)
sanjeet25 0:a307f0abfd4d 106 {
sanjeet25 3:b702a21b2990 107 if((LPC_TIM0->IR & 0x01) == 0x01) { // if MR0 interrupt, proceed
sanjeet25 0:a307f0abfd4d 108 LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag
sanjeet25 3:b702a21b2990 109 t++;
sanjeet25 3:b702a21b2990 110 k++;
sanjeet25 0:a307f0abfd4d 111 }
sanjeet25 0:a307f0abfd4d 112 }
sanjeet25 0:a307f0abfd4d 113
sanjeet25 3:b702a21b2990 114 //Initializing the timer 0
sanjeet25 3:b702a21b2990 115 void timer0_init(void)
sanjeet25 0:a307f0abfd4d 116 {
sanjeet25 0:a307f0abfd4d 117
sanjeet25 3:b702a21b2990 118 LPC_SC->PCONP |=1<1; //Timer0 Power On
sanjeet25 3:b702a21b2990 119 LPC_TIM0->MR0 = 23990; //1 msec
sanjeet25 3:b702a21b2990 120 LPC_TIM0->MCR = 3; //interrupt and reset control
sanjeet25 3:b702a21b2990 121 NVIC_EnableIRQ(TIMER1_IRQn); //Enable timer0 interrupt
sanjeet25 3:b702a21b2990 122 LPC_TIM0->TCR = 1; //enable Timer0
sanjeet25 3:b702a21b2990 123 t = 0;
sanjeet25 3:b702a21b2990 124 k = 0;
sanjeet25 3:b702a21b2990 125 }
sanjeet25 3:b702a21b2990 126
sanjeet25 3:b702a21b2990 127 void resett()
sanjeet25 3:b702a21b2990 128 {
sanjeet25 3:b702a21b2990 129 t=0;
sanjeet25 3:b702a21b2990 130 }
sanjeet25 3:b702a21b2990 131
sanjeet25 3:b702a21b2990 132 void resetk()
sanjeet25 3:b702a21b2990 133 {
sanjeet25 3:b702a21b2990 134 k=0;
sanjeet25 0:a307f0abfd4d 135 }
sanjeet25 0:a307f0abfd4d 136
sanjeet25 4:a64a0fea5266 137 void sound_lowAlarm()
sanjeet25 4:a64a0fea5266 138 {
sanjeet25 4:a64a0fea5266 139 pc.printf("lowalarm");
sanjeet25 4:a64a0fea5266 140 }
sanjeet25 4:a64a0fea5266 141 void sound_highAlarm()
sanjeet25 4:a64a0fea5266 142 {
sanjeet25 4:a64a0fea5266 143 pc.printf("highalarm");
sanjeet25 4:a64a0fea5266 144 }
sanjeet25 3:b702a21b2990 145 void VPacereceived()
sanjeet25 0:a307f0abfd4d 146 {
sanjeet25 3:b702a21b2990 147 pc.printf("VPace received");
sanjeet25 3:b702a21b2990 148 VPaceReceive=1;
sanjeet25 3:b702a21b2990 149 wait(0.002);
sanjeet25 3:b702a21b2990 150 APaceReceive=0;
sanjeet25 6:cc4fcc38b9f0 151 //pulses++;
sanjeet25 0:a307f0abfd4d 152 Vreceived=true;
sanjeet25 3:b702a21b2990 153 Areceived=false;
sanjeet25 4:a64a0fea5266 154 if(mode == Test && flag==0) {
sanjeet25 4:a64a0fea5266 155 (*testmode).signal_set(0x04);
sanjeet25 3:b702a21b2990 156 }
sanjeet25 3:b702a21b2990 157 if(mode == Test && test) {
sanjeet25 3:b702a21b2990 158 if(testNumber == 2 || testNumber == 0 || testNumber == 3 || testNumber == 1) {
sanjeet25 4:a64a0fea5266 159 test_result = false;
sanjeet25 3:b702a21b2990 160 } else if(testNumber == 6 || testNumber == 4) {
sanjeet25 4:a64a0fea5266 161 test_result = true;
sanjeet25 3:b702a21b2990 162 }
sanjeet25 3:b702a21b2990 163 }
sanjeet25 0:a307f0abfd4d 164 }
sanjeet25 0:a307f0abfd4d 165
sanjeet25 2:fc2f41386ee4 166 void APacereceived()
sanjeet25 3:b702a21b2990 167 {
sanjeet25 3:b702a21b2990 168 pc.printf("APace received");
sanjeet25 3:b702a21b2990 169 APaceReceive=1;
sanjeet25 3:b702a21b2990 170 wait(0.002);
sanjeet25 3:b702a21b2990 171 APaceReceive=0;
sanjeet25 0:a307f0abfd4d 172 Areceived=true;
sanjeet25 3:b702a21b2990 173 if(mode == Test && test) {
sanjeet25 3:b702a21b2990 174 if(testNumber == 0) {
sanjeet25 4:a64a0fea5266 175 test_result = false;
sanjeet25 3:b702a21b2990 176 } else if(testNumber == 4 || testNumber == 7 || testNumber == 3 || testNumber == 1) {
sanjeet25 4:a64a0fea5266 177 test_result = true;
sanjeet25 3:b702a21b2990 178 }
sanjeet25 3:b702a21b2990 179 }
sanjeet25 0:a307f0abfd4d 180 }
sanjeet25 0:a307f0abfd4d 181
sanjeet25 0:a307f0abfd4d 182 void ASignalsend()
sanjeet25 0:a307f0abfd4d 183 {
sanjeet25 0:a307f0abfd4d 184 ASignal=1;
sanjeet25 1:c340c31174a5 185 ASignal1=1;
sanjeet25 3:b702a21b2990 186 wait(0.02);
sanjeet25 3:b702a21b2990 187 Thread::wait(1);
sanjeet25 3:b702a21b2990 188 ASignal1=0;
sanjeet25 3:b702a21b2990 189 ASignal=0;
sanjeet25 0:a307f0abfd4d 190 }
sanjeet25 0:a307f0abfd4d 191
sanjeet25 0:a307f0abfd4d 192 void VSignalsend()
sanjeet25 0:a307f0abfd4d 193 {
sanjeet25 0:a307f0abfd4d 194 VSignal=1;
sanjeet25 1:c340c31174a5 195 VSignal1=1;
sanjeet25 3:b702a21b2990 196 wait(0.02);
sanjeet25 3:b702a21b2990 197 Thread::wait(1);
sanjeet25 3:b702a21b2990 198 VSignal1=0;
sanjeet25 3:b702a21b2990 199 VSignal==0;
sanjeet25 0:a307f0abfd4d 200 }
sanjeet25 2:fc2f41386ee4 201
sanjeet25 2:fc2f41386ee4 202 void updateHeart()
sanjeet25 2:fc2f41386ee4 203 {
sanjeet25 2:fc2f41386ee4 204 int temp = 60/heartInterval;
sanjeet25 6:cc4fcc38b9f0 205 heartmut.lock();
sanjeet25 2:fc2f41386ee4 206 heartRate = heartRate + temp;
sanjeet25 6:cc4fcc38b9f0 207 heartmut.lock();
sanjeet25 2:fc2f41386ee4 208 }
sanjeet25 0:a307f0abfd4d 209 void HeartReceive(void const* args)
sanjeet25 0:a307f0abfd4d 210 {
sanjeet25 0:a307f0abfd4d 211 while(1) {
sanjeet25 0:a307f0abfd4d 212 pc.printf("HR");
sanjeet25 1:c340c31174a5 213 while(Areceived==false||Vreceived==false);
sanjeet25 0:a307f0abfd4d 214 if(Vreceived==true) {
sanjeet25 3:b702a21b2990 215 resett();
sanjeet25 3:b702a21b2990 216
sanjeet25 0:a307f0abfd4d 217 } else if(Areceived==true) {
sanjeet25 3:b702a21b2990 218 resett();
sanjeet25 0:a307f0abfd4d 219 }
sanjeet25 0:a307f0abfd4d 220 }
sanjeet25 0:a307f0abfd4d 221 }
sanjeet25 0:a307f0abfd4d 222
sanjeet25 0:a307f0abfd4d 223 void HeartSend(void const* args)
sanjeet25 0:a307f0abfd4d 224 {
sanjeet25 6:cc4fcc38b9f0 225 while(1) {
sanjeet25 6:cc4fcc38b9f0 226 if(flagr==1){
sanjeet25 1:c340c31174a5 227 int r = rand() % 2;
sanjeet25 0:a307f0abfd4d 228 pc.printf("HS");
sanjeet25 3:b702a21b2990 229 while(t<minwait_V && mode!=Random && (mode==Test || mode==Manual));
sanjeet25 3:b702a21b2990 230 pc.printf("%u",t);
sanjeet25 4:a64a0fea5266 231 if(r==0 && mode!=Test) {
sanjeet25 0:a307f0abfd4d 232 VSignalsend();
sanjeet25 1:c340c31174a5 233 pc.printf("Vsignal");
sanjeet25 3:b702a21b2990 234 resett();
sanjeet25 4:a64a0fea5266 235 } else if(r==1&&mode!=Test) {
sanjeet25 0:a307f0abfd4d 236 ASignalsend();
sanjeet25 1:c340c31174a5 237 pc.printf("ASignal");
sanjeet25 3:b702a21b2990 238 resett();
sanjeet25 6:cc4fcc38b9f0 239 }}
sanjeet25 0:a307f0abfd4d 240 }
sanjeet25 6:cc4fcc38b9f0 241 //keymutex.unlock();
sanjeet25 6:cc4fcc38b9f0 242 // }
sanjeet25 0:a307f0abfd4d 243 }
sanjeet25 0:a307f0abfd4d 244 void HeartKeyBoardModeSwitch(void const* args)
sanjeet25 0:a307f0abfd4d 245 {
sanjeet25 1:c340c31174a5 246 while(1) {
sanjeet25 6:cc4fcc38b9f0 247 keymutex.lock();
sanjeet25 5:8e3b9032ddfc 248 if((key_input=='r'||key_input=='R')&&flag_key==1) {
sanjeet25 6:cc4fcc38b9f0 249 mode=Random;
sanjeet25 6:cc4fcc38b9f0 250 pc.printf("Random");
sanjeet25 6:cc4fcc38b9f0 251 flagr=1;
sanjeet25 6:cc4fcc38b9f0 252 HeartSend("s");
sanjeet25 5:8e3b9032ddfc 253 flag_key=0;
sanjeet25 5:8e3b9032ddfc 254 } else if((key_input=='m'||key_input=='M')&&flag_key) {
sanjeet25 6:cc4fcc38b9f0 255 mode=Manual;
sanjeet25 6:cc4fcc38b9f0 256 pc.printf("Manual");
sanjeet25 5:8e3b9032ddfc 257 flag_key=0;
sanjeet25 6:cc4fcc38b9f0 258
sanjeet25 5:8e3b9032ddfc 259 } else if(mode==Manual&&(key_input=='v'||key_input=='V')&&flag_key==1) {
sanjeet25 6:cc4fcc38b9f0 260 mode=Manual;
sanjeet25 6:cc4fcc38b9f0 261 VSignalsend();
sanjeet25 5:8e3b9032ddfc 262 pc.printf("Ventricular");
sanjeet25 5:8e3b9032ddfc 263 flag_key=0;
sanjeet25 6:cc4fcc38b9f0 264
sanjeet25 5:8e3b9032ddfc 265 } else if(mode==Manual&&flag_key==1&&(key_input=='a'||key_input=='A')) {
sanjeet25 6:cc4fcc38b9f0 266 mode=Manual;
sanjeet25 6:cc4fcc38b9f0 267 ASignalsend();
sanjeet25 5:8e3b9032ddfc 268 pc.printf("Atrial");
sanjeet25 6:cc4fcc38b9f0 269 flag_key=0;
sanjeet25 5:8e3b9032ddfc 270 } else if((key_input=='o'||key_input=='O')&&flag_key==1) {
sanjeet25 6:cc4fcc38b9f0 271 int a = 10 + rand() % 80;
sanjeet25 5:8e3b9032ddfc 272 mode=Observer;
sanjeet25 5:8e3b9032ddfc 273 pc.printf("Observer and %u",a);
sanjeet25 5:8e3b9032ddfc 274 heartInterval =a;
sanjeet25 5:8e3b9032ddfc 275 HeartSend("s");
sanjeet25 5:8e3b9032ddfc 276 flag_key=0;
sanjeet25 6:cc4fcc38b9f0 277
sanjeet25 0:a307f0abfd4d 278
sanjeet25 5:8e3b9032ddfc 279 } else if(flag_key==1&&(key_input=='t'||key_input=='T')) {
sanjeet25 6:cc4fcc38b9f0 280 mode=Test;
sanjeet25 6:cc4fcc38b9f0 281 (*testmode).signal_set(0x03);
sanjeet25 5:8e3b9032ddfc 282 pc.printf("Test");
sanjeet25 6:cc4fcc38b9f0 283 flag_key=0;
sanjeet25 6:cc4fcc38b9f0 284
sanjeet25 0:a307f0abfd4d 285 }
sanjeet25 6:cc4fcc38b9f0 286 keymutex.unlock();
sanjeet25 0:a307f0abfd4d 287 }
sanjeet25 5:8e3b9032ddfc 288 }
sanjeet25 4:a64a0fea5266 289
sanjeet25 2:fc2f41386ee4 290
sanjeet25 3:b702a21b2990 291 void display(void const* args)
sanjeet25 3:b702a21b2990 292 {
sanjeet25 3:b702a21b2990 293 while(1) {
sanjeet25 3:b702a21b2990 294 Thread::wait(observationInterval/1000);
sanjeet25 3:b702a21b2990 295 // if(mode!=Test) {
sanjeet25 3:b702a21b2990 296 // if(mode!= changeobservationinterval) {
sanjeet25 3:b702a21b2990 297 // avgHeartRate=pulseCount*60000/(obsInterval);
sanjeet25 3:b702a21b2990 298 // pulseCount = 0;
sanjeet25 3:b702a21b2990 299 // updateDisplay();
sanjeet25 3:b702a21b2990 300 //
sanjeet25 3:b702a21b2990 301 // }
sanjeet25 3:b702a21b2990 302 // }
sanjeet25 3:b702a21b2990 303 if(!Test) {
sanjeet25 6:cc4fcc38b9f0 304 heartmut.lock();
sanjeet25 3:b702a21b2990 305 pc.printf("Avg Heart Rate: %02d bpm", heartRate);
sanjeet25 6:cc4fcc38b9f0 306 heartmut.unlock();
sanjeet25 3:b702a21b2990 307 while(!Vreceived||!VSignal==0) {
sanjeet25 3:b702a21b2990 308 updateHeart();
sanjeet25 3:b702a21b2990 309 }
sanjeet25 3:b702a21b2990 310 while(k<=heartInterval*1000);
sanjeet25 3:b702a21b2990 311 if(heartRate>high[mode]) {
sanjeet25 3:b702a21b2990 312 sound_highAlarm();
sanjeet25 6:cc4fcc38b9f0 313 heartmut.lock();
sanjeet25 3:b702a21b2990 314 heartRate=0;
sanjeet25 6:cc4fcc38b9f0 315 heartmut.unlock();
sanjeet25 3:b702a21b2990 316 resetk();
sanjeet25 3:b702a21b2990 317 } else if(heartRate<low[mode]) {
sanjeet25 3:b702a21b2990 318 sound_lowAlarm();
sanjeet25 6:cc4fcc38b9f0 319 heartmut.lock();
sanjeet25 3:b702a21b2990 320 heartRate=0;
sanjeet25 6:cc4fcc38b9f0 321 heartmut.unlock();
sanjeet25 3:b702a21b2990 322 resetk();
sanjeet25 3:b702a21b2990 323 } else if(heartRate >= low[mode] && heartRate <= high[mode]) {
sanjeet25 6:cc4fcc38b9f0 324 heartmut.lock();
sanjeet25 3:b702a21b2990 325 heartRate=0;
sanjeet25 6:cc4fcc38b9f0 326 heartmut.unlock();
sanjeet25 3:b702a21b2990 327 resetk();
sanjeet25 3:b702a21b2990 328 }
sanjeet25 3:b702a21b2990 329
sanjeet25 3:b702a21b2990 330
sanjeet25 3:b702a21b2990 331 }
sanjeet25 3:b702a21b2990 332 }
sanjeet25 3:b702a21b2990 333 }
sanjeet25 3:b702a21b2990 334
sanjeet25 2:fc2f41386ee4 335
sanjeet25 4:a64a0fea5266 336 void Testmode(void const* args)
sanjeet25 4:a64a0fea5266 337 {
sanjeet25 4:a64a0fea5266 338 Thread::wait(0x03);
sanjeet25 4:a64a0fea5266 339 test = true;
sanjeet25 4:a64a0fea5266 340 switch(test) {
sanjeet25 4:a64a0fea5266 341 case 1:
sanjeet25 5:8e3b9032ddfc 342 flag=0;
sanjeet25 5:8e3b9032ddfc 343 Thread::signal_wait(0x04);
sanjeet25 4:a64a0fea5266 344 flag=1;
sanjeet25 4:a64a0fea5266 345 t = 0;
sanjeet25 4:a64a0fea5266 346 Thread::wait(vrp);
sanjeet25 4:a64a0fea5266 347 ASignalsend();
sanjeet25 4:a64a0fea5266 348 test = true;
sanjeet25 4:a64a0fea5266 349 Thread::wait(lri-avi-vrp);
sanjeet25 4:a64a0fea5266 350 test_result=false;
sanjeet25 4:a64a0fea5266 351 if(test_result) {
sanjeet25 4:a64a0fea5266 352 pc.printf("Test %u passed",test);
sanjeet25 4:a64a0fea5266 353 test=2;
sanjeet25 4:a64a0fea5266 354 } else {
sanjeet25 4:a64a0fea5266 355 pc.printf("Test %u failed",test);
sanjeet25 4:a64a0fea5266 356 test=2;
sanjeet25 4:a64a0fea5266 357 }
sanjeet25 4:a64a0fea5266 358 break;
sanjeet25 5:8e3b9032ddfc 359
sanjeet25 5:8e3b9032ddfc 360 case 2:
sanjeet25 4:a64a0fea5266 361 flag=0;
sanjeet25 4:a64a0fea5266 362 Thread::signal_wait(0x04); //Send A after PVARP
sanjeet25 4:a64a0fea5266 363 flag=1;
sanjeet25 4:a64a0fea5266 364 t = 0;
sanjeet25 4:a64a0fea5266 365 Thread::wait(pvarp);
sanjeet25 4:a64a0fea5266 366 ASignalsend();
sanjeet25 5:8e3b9032ddfc 367
sanjeet25 4:a64a0fea5266 368 Thread::wait(uri-pvarp-delta);
sanjeet25 5:8e3b9032ddfc 369
sanjeet25 4:a64a0fea5266 370 if(test_result) {
sanjeet25 4:a64a0fea5266 371 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 372 test=3;
sanjeet25 4:a64a0fea5266 373 } else {
sanjeet25 4:a64a0fea5266 374 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 375 test=3;
sanjeet25 4:a64a0fea5266 376 }
sanjeet25 4:a64a0fea5266 377 break;
sanjeet25 4:a64a0fea5266 378
sanjeet25 4:a64a0fea5266 379 case 3:
sanjeet25 4:a64a0fea5266 380 flag=0;
sanjeet25 4:a64a0fea5266 381 Thread::signal_wait(0x04);
sanjeet25 4:a64a0fea5266 382 flag=1;
sanjeet25 4:a64a0fea5266 383 t = 0;
sanjeet25 4:a64a0fea5266 384 Thread::wait(uri);
sanjeet25 4:a64a0fea5266 385 for(int i = 0; i<7; i++) {
sanjeet25 4:a64a0fea5266 386 ASignalsend();
sanjeet25 4:a64a0fea5266 387 Thread::wait(avi-delta);
sanjeet25 4:a64a0fea5266 388 VSignalsend();
sanjeet25 4:a64a0fea5266 389 Thread::wait(lri-avi-delta);
sanjeet25 4:a64a0fea5266 390 }
sanjeet25 4:a64a0fea5266 391 if(test_result) {
sanjeet25 4:a64a0fea5266 392 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 393 test=4;
sanjeet25 4:a64a0fea5266 394 } else {
sanjeet25 4:a64a0fea5266 395 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 396 test=4;
sanjeet25 4:a64a0fea5266 397 }
sanjeet25 4:a64a0fea5266 398 break;
sanjeet25 4:a64a0fea5266 399 case 4:
sanjeet25 4:a64a0fea5266 400 flag=0;
sanjeet25 4:a64a0fea5266 401 Thread::signal_wait(0x04); //Send A after PVARP
sanjeet25 4:a64a0fea5266 402 flag=1;
sanjeet25 4:a64a0fea5266 403 t = 0;
sanjeet25 4:a64a0fea5266 404 Thread::wait(pvarp);
sanjeet25 4:a64a0fea5266 405 ASignalsend();
sanjeet25 5:8e3b9032ddfc 406
sanjeet25 4:a64a0fea5266 407 Thread::wait(uri-pvarp-delta);
sanjeet25 5:8e3b9032ddfc 408
sanjeet25 4:a64a0fea5266 409 if(test_result) {
sanjeet25 4:a64a0fea5266 410 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 411 test=5;
sanjeet25 4:a64a0fea5266 412 } else {
sanjeet25 4:a64a0fea5266 413 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 414 test=5;
sanjeet25 4:a64a0fea5266 415 }
sanjeet25 4:a64a0fea5266 416 break;
sanjeet25 5:8e3b9032ddfc 417 case 5:
sanjeet25 4:a64a0fea5266 418 flag=0;
sanjeet25 4:a64a0fea5266 419 Thread::signal_wait(0x04); //Heart is dead
sanjeet25 4:a64a0fea5266 420 flag=1;
sanjeet25 4:a64a0fea5266 421 t = 0;
sanjeet25 5:8e3b9032ddfc 422
sanjeet25 4:a64a0fea5266 423 Thread::wait(lri);
sanjeet25 4:a64a0fea5266 424 Thread::wait(lri);
sanjeet25 4:a64a0fea5266 425 test = false;
sanjeet25 4:a64a0fea5266 426 if(test_result) {
sanjeet25 4:a64a0fea5266 427 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 428 test=6;
sanjeet25 4:a64a0fea5266 429 } else {
sanjeet25 4:a64a0fea5266 430 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 431 test=6;
sanjeet25 4:a64a0fea5266 432 }
sanjeet25 4:a64a0fea5266 433 break;
sanjeet25 5:8e3b9032ddfc 434
sanjeet25 5:8e3b9032ddfc 435 case 6:
sanjeet25 4:a64a0fea5266 436 flag=0;
sanjeet25 4:a64a0fea5266 437 Thread::signal_wait(0x04); //Heart beating very fast. ASig, VSig
sanjeet25 4:a64a0fea5266 438 flag=1;
sanjeet25 4:a64a0fea5266 439 t = 0;
sanjeet25 4:a64a0fea5266 440 for(int i = 0; i<50; i++) {
sanjeet25 4:a64a0fea5266 441 ASignalsend();
sanjeet25 4:a64a0fea5266 442 VSignalsend();
sanjeet25 4:a64a0fea5266 443 }
sanjeet25 4:a64a0fea5266 444 if(test_result) {
sanjeet25 4:a64a0fea5266 445 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 446 test=7;
sanjeet25 4:a64a0fea5266 447 } else {
sanjeet25 4:a64a0fea5266 448 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 449 test=7;
sanjeet25 5:8e3b9032ddfc 450 }
sanjeet25 4:a64a0fea5266 451 break;
sanjeet25 5:8e3b9032ddfc 452
sanjeet25 5:8e3b9032ddfc 453 case 7:
sanjeet25 4:a64a0fea5266 454 flag=0;
sanjeet25 4:a64a0fea5266 455 Thread::signal_wait(0x04); //Wait for VPace to be received
sanjeet25 4:a64a0fea5266 456 flag=1;
sanjeet25 4:a64a0fea5266 457 t= 0;
sanjeet25 4:a64a0fea5266 458 Thread::wait(uri);
sanjeet25 4:a64a0fea5266 459 ASignalsend();
sanjeet25 4:a64a0fea5266 460 Thread::wait(avi+delta);
sanjeet25 4:a64a0fea5266 461 if(test_result) {
sanjeet25 4:a64a0fea5266 462 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 463 test=8;
sanjeet25 4:a64a0fea5266 464 } else {
sanjeet25 4:a64a0fea5266 465 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 466 test=8;
sanjeet25 5:8e3b9032ddfc 467 }
sanjeet25 5:8e3b9032ddfc 468
sanjeet25 5:8e3b9032ddfc 469 break;
sanjeet25 5:8e3b9032ddfc 470
sanjeet25 5:8e3b9032ddfc 471 case 8:
sanjeet25 4:a64a0fea5266 472 flag=0;
sanjeet25 4:a64a0fea5266 473 Thread::signal_wait(0x04); //Send an extra V to see if LRI starts then
sanjeet25 4:a64a0fea5266 474 flag=1;
sanjeet25 4:a64a0fea5266 475 t = 0;
sanjeet25 4:a64a0fea5266 476 Thread::wait(pvarp);
sanjeet25 4:a64a0fea5266 477 VSignalsend();
sanjeet25 4:a64a0fea5266 478 Thread::wait(lri-avi-delta);
sanjeet25 4:a64a0fea5266 479 if(test_result) {
sanjeet25 4:a64a0fea5266 480 pc.printf("Test %u passed", &test_result);
sanjeet25 4:a64a0fea5266 481 test=0;
sanjeet25 4:a64a0fea5266 482 } else {
sanjeet25 4:a64a0fea5266 483 pc.printf("Test %u failed", &test_result);
sanjeet25 4:a64a0fea5266 484 test=0;
sanjeet25 5:8e3b9032ddfc 485 }
sanjeet25 4:a64a0fea5266 486 break;
sanjeet25 4:a64a0fea5266 487
sanjeet25 3:b702a21b2990 488 }
sanjeet25 4:a64a0fea5266 489 }
sanjeet25 4:a64a0fea5266 490
sanjeet25 3:b702a21b2990 491
sanjeet25 3:b702a21b2990 492
sanjeet25 3:b702a21b2990 493 int main()
sanjeet25 6:cc4fcc38b9f0 494 {
sanjeet25 1:c340c31174a5 495 pc.baud(9600);
sanjeet25 2:fc2f41386ee4 496 VPace.rise(&VPacereceived);
sanjeet25 2:fc2f41386ee4 497 APace.rise(&APacereceived);
sanjeet25 0:a307f0abfd4d 498 timer0_init();
sanjeet25 3:b702a21b2990 499 Thread heartreceive(HeartReceive);
sanjeet25 3:b702a21b2990 500 Thread heartsend(HeartSend);
sanjeet25 3:b702a21b2990 501 Thread heartkeyboard(HeartKeyBoardModeSwitch);
sanjeet25 4:a64a0fea5266 502 hmode = &heartkeyboard;
sanjeet25 3:b702a21b2990 503 Thread disPlay(display);
sanjeet25 4:a64a0fea5266 504 Thread tmode(Testmode);
sanjeet25 4:a64a0fea5266 505 testmode = &tmode;
sanjeet25 0:a307f0abfd4d 506
sanjeet25 6:cc4fcc38b9f0 507 while(1) {
sanjeet25 6:cc4fcc38b9f0 508 if(pc.readable()) {
sanjeet25 6:cc4fcc38b9f0 509 key_input=pc.getc(); //read uart buffer data and clear the interrupt flag
sanjeet25 6:cc4fcc38b9f0 510 //initiate the serial thread to change the state of the timer
sanjeet25 6:cc4fcc38b9f0 511 pc.printf("setting");
sanjeet25 6:cc4fcc38b9f0 512 flag_key=1;
sanjeet25 6:cc4fcc38b9f0 513 if(key_input=='o'||key_input=='O'||key_input=='m'||key_input=='M'||key_input=='t'||key_input=='T')
sanjeet25 6:cc4fcc38b9f0 514 flagr=0;
sanjeet25 6:cc4fcc38b9f0 515 pc.printf("set");
sanjeet25 6:cc4fcc38b9f0 516 }
sanjeet25 6:cc4fcc38b9f0 517 }
sanjeet25 0:a307f0abfd4d 518 }