Jonathan Jones
/
Radios
Radio Structures in OOP
Diff: modules/CommLink/CommLink.cpp
- Revision:
- 6:4a3dbfbc30f1
- Parent:
- 5:146523a0d1f4
--- a/modules/CommLink/CommLink.cpp Wed Jan 14 17:46:44 2015 +0000 +++ b/modules/CommLink/CommLink.cpp Thu Jan 15 07:15:33 2015 +0000 @@ -10,8 +10,6 @@ // Default constructor CommLink::CommLink() { - setup_pins(); - setup(); } CommLink::CommLink(PinName mosi, PinName miso, PinName sck, PinName cs, PinName int_pin) : @@ -35,22 +33,13 @@ setup_cs(); setup_interrupt(); - - // [X] - 2.1 - Define the TX & RX queues. + // [X] - 2 - Define the thread tasks for controlling the data queues // ================= - // The size allocations for each queue are dependent upon what interface that communication is occuring on (radio/serial/usb/etc.) - - // [X] - 2.2 - Create small TX & RX queues. - // ================= - - - // [X] - 3.1 - define the thread tasks for controlling the data queues - // ================= - // Outline the thread definitions define_thread(_txDef, &CommLink::txThread); define_thread(_rxDef, &CommLink::rxThread); - // [X] - 3.2 - Create the threads and pass them a pointer to the created object + // [X] - 3 - Create the threads and pass them a pointer to the created object + // ================= _txID = osThreadCreate(&_txDef, (void*)this); _rxID = osThreadCreate(&_rxDef, (void*)this); } @@ -69,7 +58,6 @@ void CommLink::setup_spi(void) { if (_mosi_pin != NC & _miso_pin != NC & _sck_pin != NC) { - // Setup the spi for 8 bit data, high steady state clock, second edge capture _spi = new SPI(_mosi_pin, _miso_pin, _sck_pin); // DON'T FORGET TO DELETE IN DERIVED CLASS _spi->format(8,0); _spi->frequency(5000000); @@ -104,7 +92,7 @@ DigitalOut tx_led(LED1, 1); while(1) { - // [] - 1 - Wait until the CommModule class sends a signal to begin operation on new data being placed in its txQueue + // [X] - 1 - Wait until the CommModule class sends a signal to begin operation on new data being placed in its txQueue // ================= osSignalWait(COMM_LINK_SIGNAL_TX_TRIGGER, osWaitForever); @@ -136,20 +124,19 @@ // Set the function to call on an interrupt trigger inst->_int_in->rise(inst, &CommLink::ISR); - DigitalOut rx_led(LED2, 0); + DigitalOut rx_led(LED2, 1); while(1) { - // [X] - 1 - Wait until new data has arrived + // [X] - 1 - Wait until new data has arrived - this is interrupt triggered by CommLink::ISR() // ================= - LOG("WAITING FOR TRIGGER"); osSignalWait(COMM_LINK_SIGNAL_RX_TRIGGER, osWaitForever); - LOG("TRIGGERED"); + + // [X] - 2 - Get the received data from the external chip // ================= uint8_t rec_bytes = COMM_LINK_BUFFER_SIZE; RTP_t p; - //uint8_t *buf_ptr = p.data; inst->getData(p.data, &rec_bytes); //p.port = p.data[0] & 0xF0; p.port = 8; @@ -158,7 +145,7 @@ // [X] - 3 - Write the data to the CommModule object's rxQueue // ================= - inst->_comm_module_ptr->receive(p); + inst->_comm_module->receive(p); // [~] - 4 - Blink the RX LED for the hardware link @@ -179,52 +166,27 @@ } -void CommLink::write_tx_queue(RTP_t *p) +void CommLink::sendPacket(RTP_t *p) { - // [] - 1 - Write the data to the RX queue - // ================= - - // [] - 2 - Signal the TX thread of new data - // ================= - + sendData(p->raw, p->data_size+1); } -void CommLink::sendPacket(RTP_t *p) -{ - sendData(p->data, sizeof(p->data)); -} - - - -void CommLink::receivePacket(RTP_t *p) -{ - -} - // Interrupt Service Routine - KEEP OPERATIONS TO ABOSOLUTE MINIMUM HERE AND IN ANY OVERRIDEN BASE CLASS IMPLEMENTATIONS OF THIS CLASS METHOD void CommLink::ISR(void) { osSignalSet(_rxID , COMM_LINK_SIGNAL_RX_TRIGGER); } + void CommLink::toggle_cs(void) { *_cs = !*_cs; } -void CommLink::triggerReceive(void) -{ - CommLink::ISR(); -} -void CommLink::triggerTransmit(void) +void CommLink::setModule(CommModule& com) { - osSignalSet(_txID , COMM_LINK_SIGNAL_TX_TRIGGER); -} - -void CommLink::setCommModule(CommModule& com) -{ - _comm_module_ptr = &com; + _comm_module = &com; osSignalSet(_rxID , COMM_LINK_SIGNAL_MODULE_LINKED); } \ No newline at end of file