For robots and stuff
Radio/Radio.cpp@1:05a48c038381, 2014-12-28 (annotated)
- Committer:
- jjones646
- Date:
- Sun Dec 28 06:28:42 2014 +0000
- Revision:
- 1:05a48c038381
- Parent:
- Wireless/Radio/Radio.cpp@0:c5afea7b9057
- Child:
- 2:c42a035d71ed
updating;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 0:c5afea7b9057 | 1 | #include "Radio.h" |
jjones646 | 0:c5afea7b9057 | 2 | |
jjones646 | 0:c5afea7b9057 | 3 | Radio::Radio() : |
jjones646 | 0:c5afea7b9057 | 4 | _tx_led(NC), |
jjones646 | 0:c5afea7b9057 | 5 | _rx_led(NC), |
jjones646 | 0:c5afea7b9057 | 6 | _receive_thread(&Radio::receive_thread, this, osPriorityLow, 0), |
jjones646 | 0:c5afea7b9057 | 7 | _transmit_thread(&Radio::transmit_thread, this, osPriorityLow, 0), |
jjones646 | 0:c5afea7b9057 | 8 | _tx_led_thread(&Radio::led_tick, &_tx_led, osPriorityLow, 0), |
jjones646 | 0:c5afea7b9057 | 9 | _rx_led_thread(&Radio::led_tick, &_rx_led, osPriorityLow, 0) |
jjones646 | 0:c5afea7b9057 | 10 | { |
jjones646 | 0:c5afea7b9057 | 11 | _channel = 1; |
jjones646 | 0:c5afea7b9057 | 12 | _addr = 0; |
jjones646 | 0:c5afea7b9057 | 13 | _freq = 0; |
jjones646 | 0:c5afea7b9057 | 14 | _need_ack = false; |
jjones646 | 0:c5afea7b9057 | 15 | } |
jjones646 | 0:c5afea7b9057 | 16 | |
jjones646 | 0:c5afea7b9057 | 17 | Radio::Radio(PinName tx_led, PinName rx_led) : |
jjones646 | 0:c5afea7b9057 | 18 | _tx_led(tx_led), |
jjones646 | 0:c5afea7b9057 | 19 | _rx_led(rx_led), |
jjones646 | 0:c5afea7b9057 | 20 | _receive_thread(&Radio::receive_thread, this, osPriorityRealtime, 2048), |
jjones646 | 0:c5afea7b9057 | 21 | _transmit_thread(&Radio::transmit_thread, this, osPriorityNormal, 1024), |
jjones646 | 0:c5afea7b9057 | 22 | _tx_led_thread(&Radio::led_tick, &_tx_led, osPriorityLow, 128), |
jjones646 | 0:c5afea7b9057 | 23 | _rx_led_thread(&Radio::led_tick, &_rx_led, osPriorityLow, 128) |
jjones646 | 0:c5afea7b9057 | 24 | { |
jjones646 | 0:c5afea7b9057 | 25 | _channel = 1; |
jjones646 | 0:c5afea7b9057 | 26 | _addr = 0; |
jjones646 | 0:c5afea7b9057 | 27 | _freq = 0; |
jjones646 | 0:c5afea7b9057 | 28 | _need_ack = false; |
jjones646 | 0:c5afea7b9057 | 29 | } |
jjones646 | 0:c5afea7b9057 | 30 | |
jjones646 | 0:c5afea7b9057 | 31 | bool Radio::send(const RTP_t& packet) |
jjones646 | 0:c5afea7b9057 | 32 | { |
jjones646 | 0:c5afea7b9057 | 33 | _need_ack = packet.ack; |
jjones646 | 0:c5afea7b9057 | 34 | while (_need_ack) { |
jjones646 | 0:c5afea7b9057 | 35 | this->put_pck(packet.payload, packet.size); |
jjones646 | 0:c5afea7b9057 | 36 | } |
jjones646 | 0:c5afea7b9057 | 37 | |
jjones646 | 0:c5afea7b9057 | 38 | } |
jjones646 | 0:c5afea7b9057 | 39 | |
jjones646 | 0:c5afea7b9057 | 40 | void Radio::mailbox(const Mail<RTP_t, 6>& mail_ptr) |
jjones646 | 0:c5afea7b9057 | 41 | { |
jjones646 | 0:c5afea7b9057 | 42 | _rx_data = mail_ptr; |
jjones646 | 0:c5afea7b9057 | 43 | } |
jjones646 | 0:c5afea7b9057 | 44 | |
jjones646 | 0:c5afea7b9057 | 45 | // INTERRUPT ROUTINES |
jjones646 | 0:c5afea7b9057 | 46 | void Radio::isr_receive(void) |
jjones646 | 0:c5afea7b9057 | 47 | { |
jjones646 | 0:c5afea7b9057 | 48 | _receive_thread.signal_set(NEW_DATA); |
jjones646 | 0:c5afea7b9057 | 49 | } |
jjones646 | 0:c5afea7b9057 | 50 | |
jjones646 | 0:c5afea7b9057 | 51 | void Radio::led_tick(void const *arg) |
jjones646 | 0:c5afea7b9057 | 52 | { |
jjones646 | 0:c5afea7b9057 | 53 | DigitalOut *led = (DigitalOut*)arg; |
jjones646 | 0:c5afea7b9057 | 54 | |
jjones646 | 0:c5afea7b9057 | 55 | while(1) { |
jjones646 | 0:c5afea7b9057 | 56 | // wait for signal to be set before doing anything |
jjones646 | 0:c5afea7b9057 | 57 | osSignalWait(SET_LED_TICK, osWaitForever); |
jjones646 | 0:c5afea7b9057 | 58 | |
jjones646 | 0:c5afea7b9057 | 59 | // blink the led once |
jjones646 | 0:c5afea7b9057 | 60 | *led = 1; |
jjones646 | 0:c5afea7b9057 | 61 | Thread::wait(10); // ms |
jjones646 | 0:c5afea7b9057 | 62 | *led = 0; |
jjones646 | 0:c5afea7b9057 | 63 | Thread::wait(60); |
jjones646 | 0:c5afea7b9057 | 64 | } |
jjones646 | 0:c5afea7b9057 | 65 | } |