![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
j,hjgvcjyhchh
Dependencies: TextLCD mbed-rtos mbed
main.cpp@0:1f328e1c709f, 2015-12-01 (annotated)
- Committer:
- sanjeet25
- Date:
- Tue Dec 01 04:37:44 2015 +0000
- Revision:
- 0:1f328e1c709f
dqjetrc euaixfdsbwdqku
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sanjeet25 | 0:1f328e1c709f | 1 | #include "mbed.h" |
sanjeet25 | 0:1f328e1c709f | 2 | #include "TextLCD.h" |
sanjeet25 | 0:1f328e1c709f | 3 | #include "rtos.h" |
sanjeet25 | 0:1f328e1c709f | 4 | |
sanjeet25 | 0:1f328e1c709f | 5 | TextLCD lcd(p15, p16, p17, p18, p19, p20); |
sanjeet25 | 0:1f328e1c709f | 6 | Serial pc(USBTX, USBRX); |
sanjeet25 | 0:1f328e1c709f | 7 | |
sanjeet25 | 0:1f328e1c709f | 8 | int pacemakerRate=0; |
sanjeet25 | 0:1f328e1c709f | 9 | InterruptIn ASignal(p25); |
sanjeet25 | 0:1f328e1c709f | 10 | InterruptIn VSignal(p26); |
sanjeet25 | 0:1f328e1c709f | 11 | int AVI = 65; |
sanjeet25 | 0:1f328e1c709f | 12 | int ASense=0; |
sanjeet25 | 0:1f328e1c709f | 13 | int VSense=0; |
sanjeet25 | 0:1f328e1c709f | 14 | int modeset; |
sanjeet25 | 0:1f328e1c709f | 15 | bool aPace; |
sanjeet25 | 0:1f328e1c709f | 16 | DigitalOut APace(p23); |
sanjeet25 | 0:1f328e1c709f | 17 | DigitalOut VPace(p24); |
sanjeet25 | 0:1f328e1c709f | 18 | Mutex mutex; |
sanjeet25 | 0:1f328e1c709f | 19 | |
sanjeet25 | 0:1f328e1c709f | 20 | DigitalOut APace1(LED1); |
sanjeet25 | 0:1f328e1c709f | 21 | DigitalOut VPace1(LED2); |
sanjeet25 | 0:1f328e1c709f | 22 | |
sanjeet25 | 0:1f328e1c709f | 23 | DigitalOut ASense_LED(LED3); |
sanjeet25 | 0:1f328e1c709f | 24 | DigitalOut VSense_LED(LED4); |
sanjeet25 | 0:1f328e1c709f | 25 | |
sanjeet25 | 0:1f328e1c709f | 26 | InterruptIn ASig(p25); |
sanjeet25 | 0:1f328e1c709f | 27 | InterruptIn VSig(p26); |
sanjeet25 | 0:1f328e1c709f | 28 | |
sanjeet25 | 0:1f328e1c709f | 29 | int pacemakerInterval=10; |
sanjeet25 | 0:1f328e1c709f | 30 | const int minwait_A=50; |
sanjeet25 | 0:1f328e1c709f | 31 | const int minwait_V=50; |
sanjeet25 | 0:1f328e1c709f | 32 | int modeSwitchTimeInterval = 1500; |
sanjeet25 | 0:1f328e1c709f | 33 | volatile int time_count=0; |
sanjeet25 | 0:1f328e1c709f | 34 | int m=0; |
sanjeet25 | 0:1f328e1c709f | 35 | int s=0; |
sanjeet25 | 0:1f328e1c709f | 36 | int ms=0; |
sanjeet25 | 0:1f328e1c709f | 37 | int PVARP=150; |
sanjeet25 | 0:1f328e1c709f | 38 | |
sanjeet25 | 0:1f328e1c709f | 39 | char key_input; |
sanjeet25 | 0:1f328e1c709f | 40 | bool changePacemakerInterval; |
sanjeet25 | 0:1f328e1c709f | 41 | |
sanjeet25 | 0:1f328e1c709f | 42 | int LRI=1500; |
sanjeet25 | 0:1f328e1c709f | 43 | int URI=600; |
sanjeet25 | 0:1f328e1c709f | 44 | |
sanjeet25 | 0:1f328e1c709f | 45 | int low[4] = {30,40,100,30}; |
sanjeet25 | 0:1f328e1c709f | 46 | int high[4] = {60,100,175,175}; |
sanjeet25 | 0:1f328e1c709f | 47 | |
sanjeet25 | 0:1f328e1c709f | 48 | volatile bool asig=false; |
sanjeet25 | 0:1f328e1c709f | 49 | volatile bool vsig=false; |
sanjeet25 | 0:1f328e1c709f | 50 | |
sanjeet25 | 0:1f328e1c709f | 51 | const int sleepModeURI = 1000; |
sanjeet25 | 0:1f328e1c709f | 52 | const int sleepModeLRI = 2000; |
sanjeet25 | 0:1f328e1c709f | 53 | |
sanjeet25 | 0:1f328e1c709f | 54 | const int normalModeURI = 600; |
sanjeet25 | 0:1f328e1c709f | 55 | const int normalModeLRI = 1500; |
sanjeet25 | 0:1f328e1c709f | 56 | |
sanjeet25 | 0:1f328e1c709f | 57 | const int sportsModeURI = 343; |
sanjeet25 | 0:1f328e1c709f | 58 | const int sportsModeLRI = 600; |
sanjeet25 | 0:1f328e1c709f | 59 | |
sanjeet25 | 0:1f328e1c709f | 60 | const int manualModeURI = 343; |
sanjeet25 | 0:1f328e1c709f | 61 | const int manualModeLRI = 2000; |
sanjeet25 | 0:1f328e1c709f | 62 | |
sanjeet25 | 0:1f328e1c709f | 63 | int time1_count=0; |
sanjeet25 | 0:1f328e1c709f | 64 | |
sanjeet25 | 0:1f328e1c709f | 65 | int PVAB = 10; |
sanjeet25 | 0:1f328e1c709f | 66 | int VRP = 150; |
sanjeet25 | 0:1f328e1c709f | 67 | |
sanjeet25 | 0:1f328e1c709f | 68 | typedef enum Modes { |
sanjeet25 | 0:1f328e1c709f | 69 | Test, |
sanjeet25 | 0:1f328e1c709f | 70 | Normal, |
sanjeet25 | 0:1f328e1c709f | 71 | Sleep, |
sanjeet25 | 0:1f328e1c709f | 72 | Random, |
sanjeet25 | 0:1f328e1c709f | 73 | Sports, |
sanjeet25 | 0:1f328e1c709f | 74 | Manual, |
sanjeet25 | 0:1f328e1c709f | 75 | Observer |
sanjeet25 | 0:1f328e1c709f | 76 | }; |
sanjeet25 | 0:1f328e1c709f | 77 | |
sanjeet25 | 0:1f328e1c709f | 78 | typedef enum pacemakersend { |
sanjeet25 | 0:1f328e1c709f | 79 | AVIEvent, |
sanjeet25 | 0:1f328e1c709f | 80 | VentricalEvent, |
sanjeet25 | 0:1f328e1c709f | 81 | ManualMode, |
sanjeet25 | 0:1f328e1c709f | 82 | PostVSense |
sanjeet25 | 0:1f328e1c709f | 83 | }; |
sanjeet25 | 0:1f328e1c709f | 84 | |
sanjeet25 | 0:1f328e1c709f | 85 | typedef enum pacemakerventrical { |
sanjeet25 | 0:1f328e1c709f | 86 | AWait |
sanjeet25 | 0:1f328e1c709f | 87 | }; |
sanjeet25 | 0:1f328e1c709f | 88 | |
sanjeet25 | 0:1f328e1c709f | 89 | pacemakerventrical pventrical; |
sanjeet25 | 0:1f328e1c709f | 90 | pacemakersend psend1; |
sanjeet25 | 0:1f328e1c709f | 91 | Modes mode; |
sanjeet25 | 0:1f328e1c709f | 92 | //mode=Normal; |
sanjeet25 | 0:1f328e1c709f | 93 | |
sanjeet25 | 0:1f328e1c709f | 94 | Mutex PacemakerMutex; |
sanjeet25 | 0:1f328e1c709f | 95 | |
sanjeet25 | 0:1f328e1c709f | 96 | Thread *pa; |
sanjeet25 | 0:1f328e1c709f | 97 | Thread *pv; |
sanjeet25 | 0:1f328e1c709f | 98 | Thread *psend; |
sanjeet25 | 0:1f328e1c709f | 99 | Thread *aorv; |
sanjeet25 | 0:1f328e1c709f | 100 | Thread *pmode; |
sanjeet25 | 0:1f328e1c709f | 101 | |
sanjeet25 | 0:1f328e1c709f | 102 | void resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 103 | void resetTimer1(); |
sanjeet25 | 0:1f328e1c709f | 104 | void AorVPacesend(); |
sanjeet25 | 0:1f328e1c709f | 105 | void ASignalreceive(); |
sanjeet25 | 0:1f328e1c709f | 106 | void VSignalreceive(); |
sanjeet25 | 0:1f328e1c709f | 107 | void PacemakerAtrial(); |
sanjeet25 | 0:1f328e1c709f | 108 | void PacemakerModes(); |
sanjeet25 | 0:1f328e1c709f | 109 | void timer0_init(); |
sanjeet25 | 0:1f328e1c709f | 110 | void timer1_init(); |
sanjeet25 | 0:1f328e1c709f | 111 | void updatePacemaker(); |
sanjeet25 | 0:1f328e1c709f | 112 | void PacemakerVentricularInterval(); |
sanjeet25 | 0:1f328e1c709f | 113 | |
sanjeet25 | 0:1f328e1c709f | 114 | extern "C" void TIMER0_IRQHandler (void) |
sanjeet25 | 0:1f328e1c709f | 115 | { |
sanjeet25 | 0:1f328e1c709f | 116 | if((LPC_TIM0->IR & 0x01) == 0x01) { // if interrupt provided, continue to next line |
sanjeet25 | 0:1f328e1c709f | 117 | LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag |
sanjeet25 | 0:1f328e1c709f | 118 | time_count++; //increment time_count |
sanjeet25 | 0:1f328e1c709f | 119 | } |
sanjeet25 | 0:1f328e1c709f | 120 | } |
sanjeet25 | 0:1f328e1c709f | 121 | |
sanjeet25 | 0:1f328e1c709f | 122 | void timer0_init(void) |
sanjeet25 | 0:1f328e1c709f | 123 | { |
sanjeet25 | 0:1f328e1c709f | 124 | LPC_SC->PCONP |=1<1; //power on the timer |
sanjeet25 | 0:1f328e1c709f | 125 | LPC_TIM0->MR0 = 23980; //10 msec period i.e the timer count will increment every 10ms |
sanjeet25 | 0:1f328e1c709f | 126 | LPC_TIM0->MCR = 3; //reset control |
sanjeet25 | 0:1f328e1c709f | 127 | //3 = Interrupt & reset timer0 on match |
sanjeet25 | 0:1f328e1c709f | 128 | //1 = Interrupt only, no reset |
sanjeet25 | 0:1f328e1c709f | 129 | NVIC_EnableIRQ(TIMER0_IRQn); //enable interrupt |
sanjeet25 | 0:1f328e1c709f | 130 | LPC_TIM0->TCR = 1; //enable the timer |
sanjeet25 | 0:1f328e1c709f | 131 | |
sanjeet25 | 0:1f328e1c709f | 132 | } |
sanjeet25 | 0:1f328e1c709f | 133 | |
sanjeet25 | 0:1f328e1c709f | 134 | extern "C" void TIMER1_IRQHandler (void) |
sanjeet25 | 0:1f328e1c709f | 135 | { |
sanjeet25 | 0:1f328e1c709f | 136 | if((LPC_TIM1->IR & 0x01) == 0x01) { // if interrupt provided, continue to next line |
sanjeet25 | 0:1f328e1c709f | 137 | LPC_TIM1->IR |= 1 << 0; // Clear MR0 interrupt flag |
sanjeet25 | 0:1f328e1c709f | 138 | time1_count++; //increment time_count |
sanjeet25 | 0:1f328e1c709f | 139 | } |
sanjeet25 | 0:1f328e1c709f | 140 | } |
sanjeet25 | 0:1f328e1c709f | 141 | |
sanjeet25 | 0:1f328e1c709f | 142 | void timer1_init(void) |
sanjeet25 | 0:1f328e1c709f | 143 | { |
sanjeet25 | 0:1f328e1c709f | 144 | LPC_SC->PCONP |=1<1; //power on the timer |
sanjeet25 | 0:1f328e1c709f | 145 | LPC_TIM1->MR0 = 23980; //10 msec period i.e the timer count will increment every 10ms |
sanjeet25 | 0:1f328e1c709f | 146 | LPC_TIM1->MCR = 3; //reset control |
sanjeet25 | 0:1f328e1c709f | 147 | //3 = Interrupt & reset timer0 on match |
sanjeet25 | 0:1f328e1c709f | 148 | //1 = Interrupt only, no reset |
sanjeet25 | 0:1f328e1c709f | 149 | NVIC_EnableIRQ(TIMER1_IRQn); //enable interrupt |
sanjeet25 | 0:1f328e1c709f | 150 | LPC_TIM1->TCR = 1; //enable the timer |
sanjeet25 | 0:1f328e1c709f | 151 | |
sanjeet25 | 0:1f328e1c709f | 152 | } |
sanjeet25 | 0:1f328e1c709f | 153 | |
sanjeet25 | 0:1f328e1c709f | 154 | void resetTimer0() |
sanjeet25 | 0:1f328e1c709f | 155 | { |
sanjeet25 | 0:1f328e1c709f | 156 | time_count; |
sanjeet25 | 0:1f328e1c709f | 157 | LPC_TIM0->TCR = 0; |
sanjeet25 | 0:1f328e1c709f | 158 | lcd.locate(0,0); |
sanjeet25 | 0:1f328e1c709f | 159 | lcd.printf("%02d:%02d:%02d", m,s,ms); |
sanjeet25 | 0:1f328e1c709f | 160 | } |
sanjeet25 | 0:1f328e1c709f | 161 | |
sanjeet25 | 0:1f328e1c709f | 162 | void resetTimer1() |
sanjeet25 | 0:1f328e1c709f | 163 | { |
sanjeet25 | 0:1f328e1c709f | 164 | time1_count=0; |
sanjeet25 | 0:1f328e1c709f | 165 | LPC_TIM1->TCR = 0; |
sanjeet25 | 0:1f328e1c709f | 166 | lcd.locate(0,0); |
sanjeet25 | 0:1f328e1c709f | 167 | lcd.printf("%02d:%02d:%02d", m,s,ms); |
sanjeet25 | 0:1f328e1c709f | 168 | } |
sanjeet25 | 0:1f328e1c709f | 169 | |
sanjeet25 | 0:1f328e1c709f | 170 | void AorVPacesend(void const* args) |
sanjeet25 | 0:1f328e1c709f | 171 | { |
sanjeet25 | 0:1f328e1c709f | 172 | while(1) { |
sanjeet25 | 0:1f328e1c709f | 173 | Thread::signal_wait(0x01); |
sanjeet25 | 0:1f328e1c709f | 174 | if(aPace) { |
sanjeet25 | 0:1f328e1c709f | 175 | APace=1; |
sanjeet25 | 0:1f328e1c709f | 176 | VPace1=0; |
sanjeet25 | 0:1f328e1c709f | 177 | //APace1=1; |
sanjeet25 | 0:1f328e1c709f | 178 | wait(0.002); |
sanjeet25 | 0:1f328e1c709f | 179 | APace1=0; |
sanjeet25 | 0:1f328e1c709f | 180 | } else { |
sanjeet25 | 0:1f328e1c709f | 181 | // pc.printf("Sending VPace"); |
sanjeet25 | 0:1f328e1c709f | 182 | VPace=1; |
sanjeet25 | 0:1f328e1c709f | 183 | //VPace1=1; |
sanjeet25 | 0:1f328e1c709f | 184 | wait(0.002); |
sanjeet25 | 0:1f328e1c709f | 185 | VPace1=0; |
sanjeet25 | 0:1f328e1c709f | 186 | //APace1=0; |
sanjeet25 | 0:1f328e1c709f | 187 | } |
sanjeet25 | 0:1f328e1c709f | 188 | } |
sanjeet25 | 0:1f328e1c709f | 189 | } |
sanjeet25 | 0:1f328e1c709f | 190 | |
sanjeet25 | 0:1f328e1c709f | 191 | void ASignalreceive() |
sanjeet25 | 0:1f328e1c709f | 192 | { |
sanjeet25 | 0:1f328e1c709f | 193 | //pc.printf("ASignalreceive"); |
sanjeet25 | 0:1f328e1c709f | 194 | asig=true; |
sanjeet25 | 0:1f328e1c709f | 195 | |
sanjeet25 | 0:1f328e1c709f | 196 | } |
sanjeet25 | 0:1f328e1c709f | 197 | |
sanjeet25 | 0:1f328e1c709f | 198 | void VSignalreceive() |
sanjeet25 | 0:1f328e1c709f | 199 | { |
sanjeet25 | 0:1f328e1c709f | 200 | //pc.printf("VSignalreceive"); |
sanjeet25 | 0:1f328e1c709f | 201 | vsig=true; |
sanjeet25 | 0:1f328e1c709f | 202 | } |
sanjeet25 | 0:1f328e1c709f | 203 | void ASensesend() |
sanjeet25 | 0:1f328e1c709f | 204 | { mutex.unlock(); |
sanjeet25 | 0:1f328e1c709f | 205 | ASense_LED = 1; |
sanjeet25 | 0:1f328e1c709f | 206 | //pc.printf("ASensesend"); |
sanjeet25 | 0:1f328e1c709f | 207 | ASense=1; |
sanjeet25 | 0:1f328e1c709f | 208 | wait(0.002); |
sanjeet25 | 0:1f328e1c709f | 209 | ASense_LED=0; |
sanjeet25 | 0:1f328e1c709f | 210 | //ASense = 0; |
sanjeet25 | 0:1f328e1c709f | 211 | mutex.unlock(); |
sanjeet25 | 0:1f328e1c709f | 212 | } |
sanjeet25 | 0:1f328e1c709f | 213 | |
sanjeet25 | 0:1f328e1c709f | 214 | void VSensesend() |
sanjeet25 | 0:1f328e1c709f | 215 | { mutex.lock(); |
sanjeet25 | 0:1f328e1c709f | 216 | ASense_LED = 1; |
sanjeet25 | 0:1f328e1c709f | 217 | //pc.printf("VSensesend"); |
sanjeet25 | 0:1f328e1c709f | 218 | VSense=1; |
sanjeet25 | 0:1f328e1c709f | 219 | wait(0.002); |
sanjeet25 | 0:1f328e1c709f | 220 | ASense_LED=0; |
sanjeet25 | 0:1f328e1c709f | 221 | //VSense=0; |
sanjeet25 | 0:1f328e1c709f | 222 | mutex.unlock(); |
sanjeet25 | 0:1f328e1c709f | 223 | } |
sanjeet25 | 0:1f328e1c709f | 224 | |
sanjeet25 | 0:1f328e1c709f | 225 | void PacemakerVentricalEvent(void const* args) |
sanjeet25 | 0:1f328e1c709f | 226 | { |
sanjeet25 | 0:1f328e1c709f | 227 | pc.printf("enteredpventricalevent"); |
sanjeet25 | 0:1f328e1c709f | 228 | while(1) { |
sanjeet25 | 0:1f328e1c709f | 229 | switch(pventrical) { |
sanjeet25 | 0:1f328e1c709f | 230 | case AWait: |
sanjeet25 | 0:1f328e1c709f | 231 | pc.printf("AWAIT ENTERED"); |
sanjeet25 | 0:1f328e1c709f | 232 | //while(vsig==false||ASense==0||VPace==0); |
sanjeet25 | 0:1f328e1c709f | 233 | if(vsig==true) { |
sanjeet25 | 0:1f328e1c709f | 234 | vsig=false; |
sanjeet25 | 0:1f328e1c709f | 235 | pc.printf("vsig in"); |
sanjeet25 | 0:1f328e1c709f | 236 | VSensesend(); |
sanjeet25 | 0:1f328e1c709f | 237 | pventrical=AWait; |
sanjeet25 | 0:1f328e1c709f | 238 | break; |
sanjeet25 | 0:1f328e1c709f | 239 | } else if(ASense==1) { |
sanjeet25 | 0:1f328e1c709f | 240 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 241 | ASense=0; |
sanjeet25 | 0:1f328e1c709f | 242 | } else if(APace==1) { |
sanjeet25 | 0:1f328e1c709f | 243 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 244 | } |
sanjeet25 | 0:1f328e1c709f | 245 | while(time_count<PVAB); |
sanjeet25 | 0:1f328e1c709f | 246 | //while(vsig==false||VPace==0); |
sanjeet25 | 0:1f328e1c709f | 247 | if(vsig==true) |
sanjeet25 | 0:1f328e1c709f | 248 | pc.printf("vsig in"); |
sanjeet25 | 0:1f328e1c709f | 249 | VSensesend(); |
sanjeet25 | 0:1f328e1c709f | 250 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 251 | // while(time_count<VRP); |
sanjeet25 | 0:1f328e1c709f | 252 | pc.printf("exiting pventrical event"); |
sanjeet25 | 0:1f328e1c709f | 253 | break; |
sanjeet25 | 0:1f328e1c709f | 254 | |
sanjeet25 | 0:1f328e1c709f | 255 | } |
sanjeet25 | 0:1f328e1c709f | 256 | } |
sanjeet25 | 0:1f328e1c709f | 257 | } |
sanjeet25 | 0:1f328e1c709f | 258 | |
sanjeet25 | 0:1f328e1c709f | 259 | void PacemakerSend(void const* args) |
sanjeet25 | 0:1f328e1c709f | 260 | { |
sanjeet25 | 0:1f328e1c709f | 261 | pc.printf("enteredpsend"); |
sanjeet25 | 0:1f328e1c709f | 262 | while(1) { |
sanjeet25 | 0:1f328e1c709f | 263 | switch(psend1) { |
sanjeet25 | 0:1f328e1c709f | 264 | case AVIEvent: |
sanjeet25 | 0:1f328e1c709f | 265 | // while(time_count<AVI||VSense==0||mode!=Manual); |
sanjeet25 | 0:1f328e1c709f | 266 | if(time_count>=AVI) { |
sanjeet25 | 0:1f328e1c709f | 267 | (*aorv).signal_set(0x01); |
sanjeet25 | 0:1f328e1c709f | 268 | //AorVPacesend("s"); |
sanjeet25 | 0:1f328e1c709f | 269 | psend1=VentricalEvent; |
sanjeet25 | 0:1f328e1c709f | 270 | } else if(mode==Manual) { |
sanjeet25 | 0:1f328e1c709f | 271 | while (mode==Manual); |
sanjeet25 | 0:1f328e1c709f | 272 | psend1=AVIEvent; |
sanjeet25 | 0:1f328e1c709f | 273 | } else if(VSense==1) |
sanjeet25 | 0:1f328e1c709f | 274 | psend1=VentricalEvent; |
sanjeet25 | 0:1f328e1c709f | 275 | VSense=0; |
sanjeet25 | 0:1f328e1c709f | 276 | break; |
sanjeet25 | 0:1f328e1c709f | 277 | case VentricalEvent: |
sanjeet25 | 0:1f328e1c709f | 278 | //while(ASense==0||time_count<LRI||VSense==0||mode!=Manual); |
sanjeet25 | 0:1f328e1c709f | 279 | if(ASense==1) { |
sanjeet25 | 0:1f328e1c709f | 280 | ASense=0; |
sanjeet25 | 0:1f328e1c709f | 281 | if(mode==Manual) { |
sanjeet25 | 0:1f328e1c709f | 282 | while(mode==Manual); |
sanjeet25 | 0:1f328e1c709f | 283 | psend1=AVIEvent; |
sanjeet25 | 0:1f328e1c709f | 284 | } else if(VSense==1) { |
sanjeet25 | 0:1f328e1c709f | 285 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 286 | VSense=0; |
sanjeet25 | 0:1f328e1c709f | 287 | psend1=PostVSense; |
sanjeet25 | 0:1f328e1c709f | 288 | } else { |
sanjeet25 | 0:1f328e1c709f | 289 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 290 | psend1=AVIEvent; |
sanjeet25 | 0:1f328e1c709f | 291 | } |
sanjeet25 | 0:1f328e1c709f | 292 | } |
sanjeet25 | 0:1f328e1c709f | 293 | break; |
sanjeet25 | 0:1f328e1c709f | 294 | case PostVSense: |
sanjeet25 | 0:1f328e1c709f | 295 | //while(mode!=Manual||ASense==0||time_count<LRI-AVI); |
sanjeet25 | 0:1f328e1c709f | 296 | if(mode==Manual) { |
sanjeet25 | 0:1f328e1c709f | 297 | while(mode==Manual); |
sanjeet25 | 0:1f328e1c709f | 298 | psend1=AVIEvent; |
sanjeet25 | 0:1f328e1c709f | 299 | } else if(ASense==1) { |
sanjeet25 | 0:1f328e1c709f | 300 | if(mode==Manual) { |
sanjeet25 | 0:1f328e1c709f | 301 | while(mode==Manual); |
sanjeet25 | 0:1f328e1c709f | 302 | } else { |
sanjeet25 | 0:1f328e1c709f | 303 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 304 | psend1=AVIEvent; |
sanjeet25 | 0:1f328e1c709f | 305 | } |
sanjeet25 | 0:1f328e1c709f | 306 | } else if(time_count>=LRI-AVI) { |
sanjeet25 | 0:1f328e1c709f | 307 | while(mode!=Manual); |
sanjeet25 | 0:1f328e1c709f | 308 | while(mode==Manual); |
sanjeet25 | 0:1f328e1c709f | 309 | psend1=AVIEvent; |
sanjeet25 | 0:1f328e1c709f | 310 | } |
sanjeet25 | 0:1f328e1c709f | 311 | break; |
sanjeet25 | 0:1f328e1c709f | 312 | } |
sanjeet25 | 0:1f328e1c709f | 313 | |
sanjeet25 | 0:1f328e1c709f | 314 | } |
sanjeet25 | 0:1f328e1c709f | 315 | } |
sanjeet25 | 0:1f328e1c709f | 316 | |
sanjeet25 | 0:1f328e1c709f | 317 | void PacemakerAtrial(void const* args) |
sanjeet25 | 0:1f328e1c709f | 318 | { |
sanjeet25 | 0:1f328e1c709f | 319 | pc.printf("enteredpatrial"); |
sanjeet25 | 0:1f328e1c709f | 320 | while(1) { |
sanjeet25 | 0:1f328e1c709f | 321 | //while(asig==false||APace==0); |
sanjeet25 | 0:1f328e1c709f | 322 | if(asig==true) { |
sanjeet25 | 0:1f328e1c709f | 323 | asig=false; |
sanjeet25 | 0:1f328e1c709f | 324 | pc.printf("asig in"); |
sanjeet25 | 0:1f328e1c709f | 325 | ASensesend(); |
sanjeet25 | 0:1f328e1c709f | 326 | } |
sanjeet25 | 0:1f328e1c709f | 327 | pc.printf("%u",time_count); |
sanjeet25 | 0:1f328e1c709f | 328 | resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 329 | pc.printf("%u",time_count); |
sanjeet25 | 0:1f328e1c709f | 330 | //while(VSense==0||VPace==0); |
sanjeet25 | 0:1f328e1c709f | 331 | pc.printf("%u",time1_count); |
sanjeet25 | 0:1f328e1c709f | 332 | resetTimer1(); |
sanjeet25 | 0:1f328e1c709f | 333 | pc.printf("%u",time1_count); |
sanjeet25 | 0:1f328e1c709f | 334 | pc.printf("waiting for pvarp"); |
sanjeet25 | 0:1f328e1c709f | 335 | while(time_count<PVARP); |
sanjeet25 | 0:1f328e1c709f | 336 | while(time1_count<URI); |
sanjeet25 | 0:1f328e1c709f | 337 | pc.printf("exiting patrial event"); |
sanjeet25 | 0:1f328e1c709f | 338 | } |
sanjeet25 | 0:1f328e1c709f | 339 | |
sanjeet25 | 0:1f328e1c709f | 340 | } |
sanjeet25 | 0:1f328e1c709f | 341 | void PacemakerModes(void const* args) |
sanjeet25 | 0:1f328e1c709f | 342 | { |
sanjeet25 | 0:1f328e1c709f | 343 | pc.printf("enteredpmodes"); |
sanjeet25 | 0:1f328e1c709f | 344 | while(1) { |
sanjeet25 | 0:1f328e1c709f | 345 | //if(pc.readable()) { |
sanjeet25 | 0:1f328e1c709f | 346 | Thread::wait(0x02); |
sanjeet25 | 0:1f328e1c709f | 347 | mutex.lock(); |
sanjeet25 | 0:1f328e1c709f | 348 | //key_input = pc.getc(); |
sanjeet25 | 0:1f328e1c709f | 349 | if((key_input=='n'||key_input=='N')&&!changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 350 | mode = Normal; |
sanjeet25 | 0:1f328e1c709f | 351 | pc.printf("Normal"); |
sanjeet25 | 0:1f328e1c709f | 352 | LRI=normalModeLRI; |
sanjeet25 | 0:1f328e1c709f | 353 | URI=normalModeURI; |
sanjeet25 | 0:1f328e1c709f | 354 | // (*Pace).signal_set(0x01); |
sanjeet25 | 0:1f328e1c709f | 355 | //resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 356 | modeset=0; |
sanjeet25 | 0:1f328e1c709f | 357 | } else if((key_input=='s'||key_input=='S')&&!changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 358 | mode=Sleep; |
sanjeet25 | 0:1f328e1c709f | 359 | pc.printf("Sleep"); |
sanjeet25 | 0:1f328e1c709f | 360 | modeset=1; |
sanjeet25 | 0:1f328e1c709f | 361 | LRI=sleepModeLRI; |
sanjeet25 | 0:1f328e1c709f | 362 | URI=sleepModeURI; |
sanjeet25 | 0:1f328e1c709f | 363 | // (*Pace).signal_set(0x01); |
sanjeet25 | 0:1f328e1c709f | 364 | //resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 365 | } else if((key_input=='e'||key_input=='E')&&!changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 366 | mode=Sports; |
sanjeet25 | 0:1f328e1c709f | 367 | pc.printf("Exercise"); |
sanjeet25 | 0:1f328e1c709f | 368 | modeset=2; |
sanjeet25 | 0:1f328e1c709f | 369 | LRI=sportsModeLRI; |
sanjeet25 | 0:1f328e1c709f | 370 | URI=sportsModeURI; |
sanjeet25 | 0:1f328e1c709f | 371 | // (*Pace).signal_set(0x01); |
sanjeet25 | 0:1f328e1c709f | 372 | //resetTimer0(); |
sanjeet25 | 0:1f328e1c709f | 373 | } else if((key_input=='m'||key_input=='M')&&!changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 374 | mode=Manual; |
sanjeet25 | 0:1f328e1c709f | 375 | modeset=3; |
sanjeet25 | 0:1f328e1c709f | 376 | LRI=manualModeLRI; |
sanjeet25 | 0:1f328e1c709f | 377 | URI=manualModeURI; |
sanjeet25 | 0:1f328e1c709f | 378 | aPace=true; |
sanjeet25 | 0:1f328e1c709f | 379 | //(*Pace).signal_set(0x02); |
sanjeet25 | 0:1f328e1c709f | 380 | pc.printf("Manual"); |
sanjeet25 | 0:1f328e1c709f | 381 | } else if((key_input=='v'||key_input=='V')&& !changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 382 | if(mode==Manual) { |
sanjeet25 | 0:1f328e1c709f | 383 | mode=Manual; |
sanjeet25 | 0:1f328e1c709f | 384 | pc.printf("Ventricular"); |
sanjeet25 | 0:1f328e1c709f | 385 | // AorVPacesend(); |
sanjeet25 | 0:1f328e1c709f | 386 | aPace=false; |
sanjeet25 | 0:1f328e1c709f | 387 | (*aorv).signal_set(0x01); |
sanjeet25 | 0:1f328e1c709f | 388 | } |
sanjeet25 | 0:1f328e1c709f | 389 | } else if((key_input=='a'||key_input=='A')&&!changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 390 | if(mode==Manual) { |
sanjeet25 | 0:1f328e1c709f | 391 | mode=Manual; |
sanjeet25 | 0:1f328e1c709f | 392 | //AorVPacesend(); |
sanjeet25 | 0:1f328e1c709f | 393 | pc.printf("Atrial"); |
sanjeet25 | 0:1f328e1c709f | 394 | aPace=true; |
sanjeet25 | 0:1f328e1c709f | 395 | (*aorv).signal_set(0x01); |
sanjeet25 | 0:1f328e1c709f | 396 | } |
sanjeet25 | 0:1f328e1c709f | 397 | } else if((key_input=='o'||key_input=='O')&&!changePacemakerInterval) { |
sanjeet25 | 0:1f328e1c709f | 398 | int a = 10 + rand() % 80; |
sanjeet25 | 0:1f328e1c709f | 399 | mode=Observer; |
sanjeet25 | 0:1f328e1c709f | 400 | pc.printf("Observer and %u",a); |
sanjeet25 | 0:1f328e1c709f | 401 | pacemakerInterval =a; |
sanjeet25 | 0:1f328e1c709f | 402 | } |
sanjeet25 | 0:1f328e1c709f | 403 | mutex.unlock(); |
sanjeet25 | 0:1f328e1c709f | 404 | |
sanjeet25 | 0:1f328e1c709f | 405 | //} |
sanjeet25 | 0:1f328e1c709f | 406 | } |
sanjeet25 | 0:1f328e1c709f | 407 | } |
sanjeet25 | 0:1f328e1c709f | 408 | |
sanjeet25 | 0:1f328e1c709f | 409 | void Rx_interrupt() |
sanjeet25 | 0:1f328e1c709f | 410 | { |
sanjeet25 | 0:1f328e1c709f | 411 | if(pc.readable()) |
sanjeet25 | 0:1f328e1c709f | 412 | { |
sanjeet25 | 0:1f328e1c709f | 413 | key_input=LPC_UART0->RBR; //read uart buffer data and clear the interrupt flag |
sanjeet25 | 0:1f328e1c709f | 414 | (*pmode).signal_set(0x02); //initiate the serial thread to change the state of the timer |
sanjeet25 | 0:1f328e1c709f | 415 | } |
sanjeet25 | 0:1f328e1c709f | 416 | } |
sanjeet25 | 0:1f328e1c709f | 417 | |
sanjeet25 | 0:1f328e1c709f | 418 | int main () |
sanjeet25 | 0:1f328e1c709f | 419 | { |
sanjeet25 | 0:1f328e1c709f | 420 | pc.baud(9600); |
sanjeet25 | 0:1f328e1c709f | 421 | pc.attach(&Rx_interrupt, Serial::RxIrq); |
sanjeet25 | 0:1f328e1c709f | 422 | VSignal.rise(&VSignalreceive); |
sanjeet25 | 0:1f328e1c709f | 423 | ASignal.rise(&ASignalreceive); |
sanjeet25 | 0:1f328e1c709f | 424 | timer0_init(); |
sanjeet25 | 0:1f328e1c709f | 425 | timer1_init(); |
sanjeet25 | 0:1f328e1c709f | 426 | Thread patrial(PacemakerAtrial); |
sanjeet25 | 0:1f328e1c709f | 427 | pa=&patrial; |
sanjeet25 | 0:1f328e1c709f | 428 | Thread pventrical(PacemakerVentricalEvent); |
sanjeet25 | 0:1f328e1c709f | 429 | pv=&pventrical; |
sanjeet25 | 0:1f328e1c709f | 430 | Thread pacesend(PacemakerSend); |
sanjeet25 | 0:1f328e1c709f | 431 | psend=&pacesend; |
sanjeet25 | 0:1f328e1c709f | 432 | Thread pmodes(PacemakerModes); |
sanjeet25 | 0:1f328e1c709f | 433 | pmode=&pmodes; |
sanjeet25 | 0:1f328e1c709f | 434 | Thread aorvpacesend(AorVPacesend); |
sanjeet25 | 0:1f328e1c709f | 435 | aorv=&aorvpacesend; |
sanjeet25 | 0:1f328e1c709f | 436 | //Thread pdisplay(PacemakerDisplay); |
sanjeet25 | 0:1f328e1c709f | 437 | |
sanjeet25 | 0:1f328e1c709f | 438 | |
sanjeet25 | 0:1f328e1c709f | 439 | while(1) { |
sanjeet25 | 0:1f328e1c709f | 440 | } |
sanjeet25 | 0:1f328e1c709f | 441 | } |