For robots and stuff

Dependents:   Base Station

Revision:
1:05a48c038381
Parent:
0:c5afea7b9057
Child:
2:c42a035d71ed
diff -r c5afea7b9057 -r 05a48c038381 Radio/Radio.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Radio/Radio.cpp	Sun Dec 28 06:28:42 2014 +0000
@@ -0,0 +1,65 @@
+#include "Radio.h"
+
+Radio::Radio() :
+    _tx_led(NC),
+    _rx_led(NC),
+    _receive_thread(&Radio::receive_thread, this, osPriorityLow, 0),
+    _transmit_thread(&Radio::transmit_thread, this, osPriorityLow, 0),
+    _tx_led_thread(&Radio::led_tick, &_tx_led, osPriorityLow, 0),
+    _rx_led_thread(&Radio::led_tick, &_rx_led, osPriorityLow, 0)
+{
+    _channel = 1;
+    _addr = 0;
+    _freq = 0;
+    _need_ack = false;
+}
+
+Radio::Radio(PinName tx_led, PinName rx_led) :
+    _tx_led(tx_led),
+    _rx_led(rx_led),
+    _receive_thread(&Radio::receive_thread, this, osPriorityRealtime, 2048),
+    _transmit_thread(&Radio::transmit_thread, this, osPriorityNormal, 1024),
+    _tx_led_thread(&Radio::led_tick, &_tx_led, osPriorityLow, 128),
+    _rx_led_thread(&Radio::led_tick, &_rx_led, osPriorityLow, 128)
+{
+    _channel = 1;
+    _addr = 0;
+    _freq = 0;
+    _need_ack = false;
+}
+
+bool Radio::send(const RTP_t& packet)
+{
+    _need_ack = packet.ack;
+    while (_need_ack) {
+        this->put_pck(packet.payload, packet.size);
+    }
+
+}
+
+void Radio::mailbox(const Mail<RTP_t, 6>& mail_ptr)
+{
+    _rx_data = mail_ptr;
+}
+
+// INTERRUPT ROUTINES
+void Radio::isr_receive(void)
+{
+    _receive_thread.signal_set(NEW_DATA);
+}
+
+void Radio::led_tick(void const *arg)
+{
+    DigitalOut *led = (DigitalOut*)arg;
+
+    while(1) {
+        // wait for signal to be set before doing anything
+        osSignalWait(SET_LED_TICK, osWaitForever);
+
+        // blink the led once
+        *led = 1;
+        Thread::wait(10);   // ms
+        *led = 0;
+        Thread::wait(60);
+    }
+}
\ No newline at end of file