Test function for CThunk class

Dependencies:   CThunk mbed

Revision:
10:47bfaa986895
Parent:
8:ac4f1c813c8d
--- a/main.cpp	Wed Aug 20 14:38:26 2014 +0000
+++ b/main.cpp	Thu Aug 21 17:10:29 2014 +0000
@@ -1,5 +1,5 @@
 #include <mbed.h>
-#include <CThunk.h>
+#include <thunk.h>
 
 class CTest
 {
@@ -14,9 +14,11 @@
     void callback2(void* context);
 
 private:
-    DigitalOut m_led1, m_led2;
+    CThunkIRQ<CTest> m_irq;
+    DigitalOut m_led1, m_led2, m_led3;
 
     void callback1(void);
+    void callback_irq(void);
 
     uint32_t m_counter;
 };
@@ -24,12 +26,21 @@
 CTest::CTest(void)
     :pc(USBTX, USBRX),
     thunk(this, &CTest::callback1),
+    m_irq(this, TIMER0_IRQn, &CTest::callback_irq),
     m_led1(LED1),
-    m_led2(LED2)
+    m_led2(LED2),
+    m_led3(LED3)
 {
     m_counter = 0;
 
-    pc.baud(115200);    
+    pc.baud(115200);
+    
+    /* enable timer */
+    LPC_SC->PCONP |= 2;
+    LPC_TIM0->TCR = 2;
+    LPC_TIM0->MR0 = 2398000;
+    LPC_TIM0->MCR = 3;
+    LPC_TIM0->TCR = 1;
 }
 
 void CTest::callback1(void)
@@ -58,6 +69,18 @@
     pc.printf("callback2:   m_counter after : %i\n", m_counter);
 }
 
+void CTest::callback_irq(void)
+{
+    uint32_t reason = LPC_TIM0->IR;
+
+    /* verify reason */
+    if(reason & 1)
+        m_led3 = !m_led3;
+
+    /* acknowledge IRQ */
+    LPC_TIM0->IR = reason;
+}
+
 void CTest::hexdump(const void* data, int length)
 {
     int i;
@@ -100,7 +123,7 @@
     /* call entry point */
     entry();
 
-    /* turn both LED's on */
+    /* sit waiting for timer interrupts */
     while(1)
         __WFI();
 }