For robots and stuff
Wireless/Radio/Radio.cpp
- Committer:
- jjones646
- Date:
- 2014-12-28
- Revision:
- 0:c5afea7b9057
File content as of revision 0:c5afea7b9057:
#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); } }