APP 4

Dependencies:   mbed CRC16 mbed-rtos

Revision:
22:b855dbf3a8c1
Parent:
20:f0932bfe09ed
--- a/APP.cpp	Tue Feb 23 00:22:49 2016 +0000
+++ b/APP.cpp	Tue Feb 23 03:52:19 2016 +0000
@@ -18,11 +18,15 @@
 unsigned int period = 0;
 unsigned int currentClocks = 0;
 bool periodCalculated = false;
-bool firstBit = true;
-bool value = false;
 MEF mef;
 STATES mefSTATE;
 int payloadSize = 0;
+bool swag = false;
+bool asdf = false;
+int messageLength = 4;
+bool buffer[16];
+int bufferCounter = 0;
+bool firstBit = true;
 
 int benchmark(void (*function) (void))
 {
@@ -35,7 +39,6 @@
 {
     if ((LPC_TIM1->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
     {
-        LPC_TIM1->IR |= 1 << 0;        // Clear MR0 interrupt flag
         clockTick = !clockTick;
         out = encode(message[counter], clockTick);
 
@@ -44,10 +47,12 @@
             counter++;
         }
 
-        if (counter >= FRAMESIZE)
+        if (counter >= 56+messageLength*8)
         {
-            LPC_TIM1->MR0 = 1000000000;
+            counter = 0;
         }
+        
+        LPC_TIM1->IR |= 1 << 0;        // Clear MR0 interrupt flag
     }
 }
 
@@ -65,6 +70,8 @@
     
     if (firstBit)
     {
+        swag = true;
+        asdf = !inputValue;
         mef.ReceiveBit(!inputValue);
         firstBit = false;
     }
@@ -74,6 +81,8 @@
         if (clocks >= period*1.5 || (currentClocks + clocks) >= period*1.5)
         {
             currentClocks = 0;
+            swag = true;
+            asdf = !inputValue;
             mef.ReceiveBit(!inputValue);
         }
         else
@@ -92,7 +101,7 @@
     //Timer 1 (match)
     LPC_SC->PCLKSEL0 |= (1 << 4);           // pclk = cclk timer1
     LPC_SC->PCONP |= (1 << 2);              // timer1 power on
-    LPC_TIM1->MR0 = CLOCKS_TO_SECOND / 1000;  // 100 ms
+    LPC_TIM1->MR0 = CLOCKS_TO_SECOND / 100;  // 100 ms
     LPC_TIM1->MCR = 3;                      // interrupt and reset control
                                             // Interrupt & reset timer on match
     LPC_TIM1->EMR = (3 << 4);
@@ -115,7 +124,7 @@
 
 int main()
 {
-    message = buildFrame(convertToBits("BLUBLUBLUBLUBLU", 17), 17);    
+    message = buildFrame(convertToBits("BLUB", messageLength), messageLength);    
 
     LPC_PINCON->PINSEL0 |= (3 << 8);   // P0.4 = CAP2.0
     initTimers();
@@ -150,6 +159,12 @@
             pc.printf("%i\r\n", debugMessage);
             debugMessageReady = false;
         }
+        
+        if (swag)
+        {
+            pc.printf("%i ", asdf);
+            swag = false;
+        }
     }
 }
 
@@ -168,6 +183,8 @@
 void _decodeError()
 {
     frameDropped = true;
+    periodCalculated = false;
+    period = 0;
 }
 
 void _updateState(STATES state)