Part of the Pacemaker Project; this models the Pacemaker.

Dependencies:   mbed TextLCD mbed-rtos

Revision:
8:5924b2048a27
Child:
20:dc272bfaa276
Child:
22:365d51eb3783
diff -r af6c040f0421 -r 5924b2048a27 PMTest.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PMTest.cpp	Mon Nov 30 16:46:13 2015 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h"
+#include "LPC17xx.h"
+#include "TextLCD.h"
+#include "rtos.h"
+#include "Thread.h"
+
+DigitalOut vsense(p23);
+DigitalOut asense(p24);
+DigitalIn apace(p22):
+DigitalIn vpace(p21):
+
+int timer_count;
+int curr_test;
+
+int[][] testfunc;
+
+// hardware interrupt handler, adapted from code in piazza post by Dagaen
+extern "C" void TIMER0_IRQHandler (void)
+{
+if((LPC_TIM0->IR & 0x01) == 0x01)   // if MR0 interrupt, proceed
+    {
+    LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
+    timer_count++;                  //increment timer_count
+    }
+}
+ 
+// init the hardware interrupt (timer0), adapted same as above
+void timer0_init(int n)
+{
+    LPC_SC->PCONP |=1<1;            //timer0 power on
+    LPC_SC-> PCLKSEL0 |= 1 << 2;    // set timer clock to CCLCK nondivided (1 clock cycle = 1 increment)
+    LPC_TIM0->MR0 = n;          //100mhz clock cycle, 1 cycle = 10ns, 10ms = 10 000 000 ns = 1M cycles
+    LPC_TIM0->MCR = 3;              //interrupt and reset control
+                                    //3 = Interrupt & reset timer0 on match (111) sets all three bits
+    NVIC_EnableIRQ(TIMER0_IRQn);    //enable timer0 interrupt
+}
+
+// interrupt function
+void interrupt_and_run_test(){
+    // zero timer, set for 1ms interrupt
+    timer0_init(100000)
+    
+    // wait for atrial pulse
+    while(apace != 1}{}
+    
+    // check if timer was within event
+    
+    if(timer_count < testfunc[curr_test][0]){
+        printf("ATRIAL PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n");
+    }
+    
+    // send vsense
+    
+    while(timer_count < testfunc[curr_test][1]){};
+    vpace = 1;
+    
+    // send asense
+    while(timer_count < testfunc[curr_test][2]){};
+    apace = 1;
+    
+    // check if timer was in event
+
+    // wait for vpace
+    
+    // wait for atrial pulse
+    while(vpace != 1}{}
+    
+    // check if timer was within event
+    
+    if(timer_count < testfunc[curr_test][0]){
+        printf("VENT PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n");
+    }
+    
+    
+    
+    
+