Problematique

Dependencies:   mbed mbed-rtos

Revision:
1:261bb31628e8
Parent:
0:dc7095ab4963
Child:
2:db7c8378b324
--- a/main.cpp	Sun Feb 09 19:02:50 2014 +0000
+++ b/main.cpp	Mon Feb 10 15:47:25 2014 +0000
@@ -1,4 +1,6 @@
 #include "mbed.h"
+#include "rtos.h"
+#include <bitset>
 
 Serial pc(USBTX, USBRX);
 
@@ -16,7 +18,7 @@
 
 void sendTrame(bool *trame)
 {
-    for (int a = 0; a < 16; a++)
+    for (int a = 0; a < 5; a++)
     {
         if (trame[a])
         {
@@ -35,6 +37,12 @@
         
         LPC_PWM1->IR = 0xFF;
     }
+    
+    LPC_PWM1->TCR = 0x0;
+}
+
+void send(void const *args) {
+    sendTrame(Trame);
 }
 
 void initialize()
@@ -49,15 +57,16 @@
     LPC_PINCON->PINSEL4 |= (1 << 2);  // Pin 25 PWM
 
     //Initialize Timer2 for capture
-    NVIC_SetVector(TIMER2_IRQn, uint32_t(readTrame));
+    NVIC_SetVector(TIMER2_IRQn, (uint32_t)&readTrame);
+    NVIC_EnableIRQ(TIMER2_IRQn);
 
     LPC_TIM2->TC = 0;           // Initialize Time Counter
     LPC_TIM2->PC = 0;           // Initialize Prescale Counter
     LPC_TIM2->PR = 0;           // Initialize Prescale Register
     LPC_TIM2->TCR |= (1 << 1);  // Reset Timer Control Register
     LPC_TIM2->IR = 0xFF;        // Reset Interrupt Register
-    LPC_TIM2->CCR |= (1 << 5) | (1 << 4) | (1 << 3);      // Initialize Capture Control Register
-    LPC_TIM2->CTCR |= (1 << 2) | (1 << 0);                // TC is incremented on rising edge
+    LPC_TIM2->CCR |=  (1 << 5) | (1 << 4) | (1 << 3);   // Initialize Capture Control Register
+    LPC_TIM2->CTCR |= (1 << 0); // TC is incremented on rising edge
 
     LPC_TIM2->TCR = 0x01;       // Start Timer Control Register
     
@@ -69,14 +78,28 @@
     LPC_PWM1->LER |= (1 << 2) | (1 << 1);   // Initialize Latch Enable Register
     LPC_PWM1->TCR |= (1 << 0);              // Enable counter
     
-    LPC_PWM1->IR = 0xFF; // Reset Interrupt Register
+    LPC_PWM1->IR = 0xFF; // Reset Interrupt Registe
 }
 
 int main()
 {
     initialize();
     
-    sendTrame(Trame);
+    Thread thread1(send);
+    //thread1.set_priority(osPriorityHigh);
     
-    while(true);
+    while(true) {
+        while (LPC_TIM2->IR != 0x0);
+        pc.printf("borne 1\n\r");
+        
+        LPC_TIM2->IR = 0xFF;
+        pc.printf("borne 2\n\r");
+        NVIC_EnableIRQ(TIMER2_IRQn);
+        pc.printf("borne 3\n\r");
+        NVIC_DisableIRQ(TIMER2_IRQn);
+        pc.printf("borne 4\n\r");
+        //NVIC_DisableIRQ(TIMER2_IRQn);
+        
+        pc.printf("borne 5\n\r");
+    }
 }