APP4 S5

Dependencies:   mbed-rtos mbed

Revision:
3:6ea97936f6fa
Parent:
2:fdb34827d964
Child:
4:728322e9e3eb
--- a/radio.cpp	Wed Oct 11 19:14:21 2017 +0000
+++ b/radio.cpp	Wed Oct 11 20:15:23 2017 +0000
@@ -2,12 +2,15 @@
 #include "radio.h"
 
 #include "mbed.h"
+#include "rtos.h"
 
 #include <LPC17xx.h>
 
 #define MESSAGE_BUFFER_SIZE 16
 
-#define INPUT_RADIO p5
+#define MANCHESTER_SPEED_OUT 250
+    
+#define INPUT_RADIO p18
 #define OUTPUT_RADIO p6
 
 radio_message_t out_messages[MESSAGE_BUFFER_SIZE];
@@ -18,18 +21,82 @@
 byte in_message_in;
 byte in_message_out;
 
-DigitalIn input(INPUT_RADIO);
+InterruptIn input(INPUT_RADIO);
+
+RtosTimer out_timer(radio_out, osTimerPeriodic, (void *)out_messages);
+
 DigitalOut output(OUTPUT_RADIO);
 
+DigitalOut in_debug_led(LED4);
+DigitalOut out_debug_led(LED3);
+
 // API functions
 void init_radio_system()
 {
-   setup_interrupt_in();
-    
+   setup_radio_in();   
+   setup_radio_out(); 
+   output = 0;
 }
 
 // Private functions
-void setup_interrupt_in()
+
+void in_rise()
+{
+    in_debug_led = 1;   
+}
+
+void in_fall()
+{
+    in_debug_led = 0;
+}
+
+void setup_radio_in()
+{
+    in_debug_led = 0;
+    
+    input.rise(&in_rise);
+    input.fall(&in_fall);   
+}
+
+
+void setup_radio_out()
 {
+    out_message_in = 0;
+    out_message_out = 0;
+        
+    out_debug_led = 0;    
     
+    //////////////////////////////////////////////////////
+    // Creation d'un message et insertion dans le buffer
+    radio_message_t* message = (out_messages + out_message_in);
+    
+    message->preambule = HEADER_DELIMITER;
+    message->start = HEADER_START;
+    message->options = HEADER_DELIMITER;
+    message->length = 0x2;
+    
+    message->data[0] = 0xF0;
+    message->data[1] = 0x0F;    
+    
+    // Ajouter calcul
+    message->control = 0xFF;
+    
+    message->end = FOOTER_END;
+    // On avance dans le buffer;
+    out_message_in++;
+    //////////////////////////////////////////////////////   
+    
+    out_timer.start(MANCHESTER_SPEED_OUT);       
 }
+
+
+void radio_out(void const *args)
+{
+    radio_message_t* message = (radio_message_t*)(out_messages + out_message_out);   
+    
+    #define OUTPUT_HIGH output = 1;
+    #define OUTPUT_LOW output = 0;
+    
+    out_debug_led = !out_debug_led;
+    output = !output;
+}