For robots and stuff
Revision 2:c42a035d71ed, committed 2014-12-31
- Comitter:
- jjones646
- Date:
- Wed Dec 31 22:16:01 2014 +0000
- Parent:
- 1:05a48c038381
- Commit message:
- adding dummy cc1101 support
Changed in this revision
diff -r 05a48c038381 -r c42a035d71ed CC1101/CC1101-Threads.cpp --- a/CC1101/CC1101-Threads.cpp Sun Dec 28 06:28:42 2014 +0000 +++ b/CC1101/CC1101-Threads.cpp Wed Dec 31 22:16:01 2014 +0000 @@ -46,12 +46,16 @@ osSignalWait(START_THREAD, osWaitForever); while(1) { - osEvent evt = instance->_tx_data.get(); + + osSignalWait(START_THREAD, osWaitForever); + + /* osEvent evt = instance->_tx_data.get(); if (evt.status == osEventMail) { RTP_t *mail = (RTP_t*)evt.value.p; instance->put_pck(mail->payload, mail->size); // send the packet over air } + */ } } @@ -64,6 +68,11 @@ // receiving operations while(1) { + + osSignalWait(START_THREAD, osWaitForever); + + + /* osSignalWait(NEW_DATA, osWaitForever); // set the limit for max bytes to put in the buffer every time @@ -81,18 +90,19 @@ instance->_rx_data.put(data); // send the data over the serial connection -#if DEBUG_MODE > 0 + #if DEBUG_MODE > 0 std::printf(" ==============\r\n"); for (int i=0; i < rxlength; i++) { std::printf(" | 0x%02X |\r\n", instance->buffer[i]); } std::printf(" ==============\r\n"); -#endif + #endif } } else { std::printf("Receiving packet failure\r\n"); } instance->_spi->frequency(5000000); + */ } } \ No newline at end of file
diff -r 05a48c038381 -r c42a035d71ed CC1101/CC1101.cpp --- a/CC1101/CC1101.cpp Sun Dec 28 06:28:42 2014 +0000 +++ b/CC1101/CC1101.cpp Wed Dec 31 22:16:01 2014 +0000 @@ -11,7 +11,7 @@ { }; CC1101::CC1101(PinName mosi, PinName miso, PinName clk, PinName csn, PinName tx_led, PinName rx_led, PinName interpt, unsigned int xosc) : - Radio(_tx_led, _rx_led), + Radio(tx_led, rx_led), _crystal_freq(xosc) { setup_spi(mosi, miso, clk); @@ -72,6 +72,11 @@ } */ +void CC1101::isr_receive(void) +{ + // do nothing +} + // Configuration method that is called from the constructors void CC1101::setup_chip() @@ -124,8 +129,8 @@ _modem.sync_mode = SYNC_HIGH_ALLOW_TWO; _modem.preamble_bytes = PREAM_FOUR; - _send_count = 1; - _receive_count = 0; + //_send_count = 1; + //_receive_count = 0; // the values assigned here are used for the frequency synthesizer control assign_if_freq(_316KHZ_); @@ -152,8 +157,14 @@ fprintf(fp, "FATAL ERROR: CC1101 Version Error\n"); fclose(fp); #endif - // send message over serial port and kill mbed - error( + + // flip the error led ON + _err_led = !_err_led; + + _has_error = true; + + // send message over serial port + std::printf( "[FATAL ERROR]\r\n" " Wrong version number returned from chip's 'VERSION' register (Addr: 0x%02X)\r\n" "\r\n" @@ -168,7 +179,7 @@ } -void powerUp(void) +void CC1101::powerUp(void) { #if DEBUG_MODE > 0 std::printf("[CC1101 RADIO TRANSCEIVER INITILIZATION]\r\n"); @@ -945,7 +956,7 @@ std::printf(" LQI: %u\r\n", _lqi); #endif - if (_p_count%5 == 0) { + if (_p_count++%5 == 0) { //calibrate the frequency synthesizer calibrate(); } @@ -955,7 +966,7 @@ return 1; } else { - *length = size; + *length = rx_size; } }
diff -r 05a48c038381 -r c42a035d71ed CC1101/CC1101.h --- a/CC1101/CC1101.h Sun Dec 28 06:28:42 2014 +0000 +++ b/CC1101/CC1101.h Wed Dec 31 22:16:01 2014 +0000 @@ -209,7 +209,7 @@ * @param *txBuffer Pointer to a buffer containing the data that are going to be transmitted * @param size The size of the txBuffer */ - virtual void put_pck(uint8_t*, uint8_t, bool = false); + virtual void put_pck(uint8_t*, uint8_t); /** @@ -243,13 +243,13 @@ void tx_mode(void); - + void idle(void); virtual void powerUp(void); protected: - + DigitalOut *_csn; /* DigitalOut _tx_led; @@ -262,9 +262,9 @@ void calibrate(); private: - + //static void threadStarter(void const*); - + /* static void led_tick(void const*); @@ -274,13 +274,13 @@ */ void rssi(uint8_t); -/* - Thread _receive_thread; - Thread _transmit_thread; - Thread _tx_led_thread; - Thread _rx_led_thread; - //Thread _serial_thread; - */ + /* + Thread _receive_thread; + Thread _transmit_thread; + Thread _tx_led_thread; + Thread _rx_led_thread; + //Thread _serial_thread; + */ void setup_spi(PinName = NC, PinName = NC, PinName = NC); void setup_pins(PinName = NC, PinName = NC); @@ -296,7 +296,7 @@ void assign_freq_offset(uint8_t); // ISR routine for new radio data received over the air - // void isr_receive(void); + void isr_receive(void); void power_on_reset(void); void put_rf_settings(void); void compute_freq(void); @@ -323,7 +323,7 @@ PinName _so; PinName _si; PinName _sck; - + // Variables used to calculate RSSI uint8_t rssi_dec; int16_t rssi_dBm;
diff -r 05a48c038381 -r c42a035d71ed Radio/Radio.cpp --- a/Radio/Radio.cpp Sun Dec 28 06:28:42 2014 +0000 +++ b/Radio/Radio.cpp Wed Dec 31 22:16:01 2014 +0000 @@ -3,6 +3,7 @@ Radio::Radio() : _tx_led(NC), _rx_led(NC), + _err_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), @@ -12,11 +13,14 @@ _addr = 0; _freq = 0; _need_ack = false; + _p_count = 0; + _has_error = false; } Radio::Radio(PinName tx_led, PinName rx_led) : _tx_led(tx_led), _rx_led(rx_led), + _err_led(p29), _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), @@ -26,6 +30,14 @@ _addr = 0; _freq = 0; _need_ack = false; + _p_count = 0; + _tx_led = 1; + _rx_led = 1; + + // always off initially + _err_led = 1; + + _has_error = false; } bool Radio::send(const RTP_t& packet) @@ -37,11 +49,6 @@ } -void Radio::mailbox(const Mail<RTP_t, 6>& mail_ptr) -{ - _rx_data = mail_ptr; -} - // INTERRUPT ROUTINES void Radio::isr_receive(void) { @@ -51,15 +58,22 @@ void Radio::led_tick(void const *arg) { DigitalOut *led = (DigitalOut*)arg; + + // initial LED state to OFF + *led = 1; while(1) { // wait for signal to be set before doing anything osSignalWait(SET_LED_TICK, osWaitForever); // blink the led once - *led = 1; + *led = !*led; Thread::wait(10); // ms - *led = 0; + *led = !*led; Thread::wait(60); } -} \ No newline at end of file +} + +bool Radio::hasError(void){ + return _has_error; + } \ No newline at end of file
diff -r 05a48c038381 -r c42a035d71ed Radio/Radio.h --- a/Radio/Radio.h Sun Dec 28 06:28:42 2014 +0000 +++ b/Radio/Radio.h Wed Dec 31 22:16:01 2014 +0000 @@ -1,8 +1,6 @@ #ifndef RADIO_H #define RADIO_H -#if 0 - #include "mbed.h" #include "rtos.h" @@ -46,8 +44,8 @@ } virtual void powerUp(void) = 0; - - void mailbox(const Mail<RTP_t, 6>*); + + bool hasError(void); protected: virtual void put_pck(uint8_t*, uint8_t) = 0; @@ -56,31 +54,35 @@ static const int BUFFER_SIZE = 70; uint8_t buffer[BUFFER_SIZE]; - Mail<RTP_t, 6> _rx_data; - Mail<RTP_t, 5> _tx_data; - bool _need_ack; uint8_t _channel; uint32_t _freq; uint8_t _addr; int8_t _rssi; + uint8_t _p_count; + static void transmit_thread(void const*); static void receive_thread(void const*); -SPI *_spi; - -private: - void isr_receive(void); - InterruptIn *_rx_int; - DigitalOut _tx_led; - DigitalOut _rx_led; - static void led_tick(void const*); + SPI *_spi; Thread _receive_thread; Thread _transmit_thread; Thread _tx_led_thread; Thread _rx_led_thread; + + InterruptIn *_rx_int; + + DigitalOut _err_led; + + bool _has_error; + +private: + void isr_receive(void); + + DigitalOut _tx_led; + DigitalOut _rx_led; + static void led_tick(void const*); }; -#endif // RADIO_H -#endif \ No newline at end of file +#endif // RADIO_H \ No newline at end of file