APP 4

Dependencies:   mbed CRC16 mbed-rtos

Revision:
3:3ffa14e75b8a
Parent:
2:1250280a511b
Child:
6:3181f546e812
Child:
7:733d500dbe5c
--- a/APP.cpp	Sat Feb 20 19:25:57 2016 +0000
+++ b/APP.cpp	Sat Feb 20 20:44:35 2016 +0000
@@ -1,34 +1,33 @@
 #include "APP.h"
+#include "Manchester.h"
 
 Serial pc(USBTX, USBRX);
 
-int state = 0;
-float tempsHaut = 0.4;
-float tempsBas = 0.1;
+bool messageReady = false;
+bitset<2 * FRAMESIZE> message;
+int counter = 0;
 
 int benchmark(void (*function) (void))
 {
-    int counter = LPC_TIM2->TC;
+    int count = LPC_TIM2->TC;
     function();
-    return LPC_TIM2->TC - counter;
+    return LPC_TIM2->TC - count;
 }
 
 extern "C" void TIMER2_IRQHandler()
 {
     if ((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
     {
-        if (state == 0)
+        LPC_TIM2->IR |= 1 << 0;        // Clear MR0 interrupt flag
+        
+        if (messageReady)
         {
-            state = 1;
-            LPC_TIM2->MR0 = (int) CLOCKS_TO_SECOND * tempsHaut;
+            LPC_TIM2->EMR = ((message[counter++] + 1) << 4);
         }
-        else if (state == 1)
+        else
         {
-            state = 0;
-            LPC_TIM2->MR0 = (int) CLOCKS_TO_SECOND * tempsBas;
+            LPC_TIM2->EMR = (1 << 4);   // output 0
         }
-
-        LPC_TIM2->IR |= 1 << 0;        // Clear MR0 interrupt flag
     }
 }
  
@@ -36,11 +35,9 @@
 {
     LPC_SC->PCLKSEL1 |= (1 << 12);     // pclk = cclk timer2
     LPC_SC->PCONP |= (1 << 22);        // timer2 power on
-    LPC_TIM2->MR0 = 9600000;           // 100 msec
-    LPC_TIM2->MCR = 1;                 // interrupt and reset control
-                                       // 3 = Interrupt & reset timer2 on match
-                                       // 1 = Interrupt only, no reset of timer0
-    LPC_TIM2->EMR = (3 << 4);          // EMC0 = 11 (Toogle)
+    LPC_TIM2->MR0 = 9600000;           // 100 ms
+    LPC_TIM2->MCR = 3;                 // interrupt and reset control
+                                       // Interrupt & reset timer2 on match
     NVIC_EnableIRQ(TIMER2_IRQn);       // enable timer2 interrupt
     LPC_TIM2->TCR = 1;                 // enable Timer2
 }
@@ -50,8 +47,8 @@
     LPC_PINCON->PINSEL0 |= (3 << 12);  // P0.6 = MAT2.0
 
     initTimer();
-    
-    while(1)
+
+    while (true)
     {
         wait(1.0);
     }