Jonathan Jones
/
Radios
Radio Structures in OOP
Diff: modules/CommLink/CommLink.cpp
- Revision:
- 5:146523a0d1f4
- Parent:
- 4:989d51f3e6ef
- Child:
- 6:4a3dbfbc30f1
--- a/modules/CommLink/CommLink.cpp Sat Jan 03 11:04:31 2015 +0000 +++ b/modules/CommLink/CommLink.cpp Wed Jan 14 17:46:44 2015 +0000 @@ -70,7 +70,7 @@ { 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); + _spi = new SPI(_mosi_pin, _miso_pin, _sck_pin); // DON'T FORGET TO DELETE IN DERIVED CLASS _spi->format(8,0); _spi->frequency(5000000); } @@ -79,15 +79,15 @@ void CommLink::setup_cs(void) { if (_cs_pin != NC) { - _cs = new DigitalOut(_cs_pin); + _cs = new DigitalOut(_cs_pin); // DON'T FORGET TO DELETE IN DERIVED CLASS } } void CommLink::setup_interrupt(void) { if (_int_pin != NC) { - _int_in = new InterruptIn(_int_pin); - //_int_in->mode(PullDown); + _int_in = new InterruptIn(_int_pin); // DON'T FORGET TO DELETE IN DERIVED CLASS + _int_in->mode(PullDown); } } @@ -101,22 +101,26 @@ // Only continue past this point once the hardware link is initialized osSignalWait(COMM_LINK_SIGNAL_START_THREAD, osWaitForever); + 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 // ================= + osSignalWait(COMM_LINK_SIGNAL_TX_TRIGGER, osWaitForever); // [] - 2 - Copy the packet from the CommModule txQueue into the CommLink txQueue // ================= - void * osMailAlloc (osMailQId queue_id, uint32_t millisec); + //void * osMailAlloc (osMailQId queue_id, uint32_t millisec); // [] - 3 - Call the method for sending the packet over a hardware communication link // ================= - uint8_t temp[20] = { 0 }; - inst->sendData(temp, 20); // [] - 4 - Blink the TX LED for the hardware link // ================= - + tx_led = 1; + osDelay(60); + tx_led = 0; + osDelay(20); } } @@ -132,11 +136,14 @@ // Set the function to call on an interrupt trigger inst->_int_in->rise(inst, &CommLink::ISR); + DigitalOut rx_led(LED2, 0); + while(1) { // [X] - 1 - Wait until new data has arrived // ================= - osSignalWait(COMM_LINK_SIGNAL_INTERRUPT_TRIGGER, osWaitForever); - + 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; @@ -144,17 +151,22 @@ //uint8_t *buf_ptr = p.data; inst->getData(p.data, &rec_bytes); - - p.port = p.data[0] & 0xF0; + //p.port = p.data[0] & 0xF0; + p.port = 8; p.subclass = p.data[0] & 0x0F; - // [] - 3 - Write the data to the CommModule object's rxQueue + + // [X] - 3 - Write the data to the CommModule object's rxQueue // ================= - //_comm_module->receive(p); + inst->_comm_module_ptr->receive(p); - // [] - 4 - Blink the RX LED for the hardware link + // [~] - 4 - Blink the RX LED for the hardware link // ================= + rx_led = 1; + osDelay(100); + rx_led = 0; + //osDelay(20); } } @@ -180,20 +192,20 @@ 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 OVERRIDEN BASE CLASS IMPLEMENTATIONS OF THIS CLASS METHOD +// 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_INTERRUPT_TRIGGER); + osSignalSet(_rxID , COMM_LINK_SIGNAL_RX_TRIGGER); } void CommLink::toggle_cs(void) @@ -204,4 +216,15 @@ void CommLink::triggerReceive(void) { CommLink::ISR(); +} + +void CommLink::triggerTransmit(void) +{ + osSignalSet(_txID , COMM_LINK_SIGNAL_TX_TRIGGER); +} + +void CommLink::setCommModule(CommModule& com) +{ + _comm_module_ptr = &com; + osSignalSet(_rxID , COMM_LINK_SIGNAL_MODULE_LINKED); } \ No newline at end of file