Jonathan Jones
/
Radios
Radio Structures in OOP
modules/CommLink/CommLink.cpp@2:7d523bdd2f50, 2014-12-28 (annotated)
- Committer:
- jjones646
- Date:
- Sun Dec 28 06:05:17 2014 +0000
- Revision:
- 2:7d523bdd2f50
- Child:
- 3:dc7e9c6bc26c
outlining communication implementations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 2:7d523bdd2f50 | 1 | #include "CommLink.h" |
jjones646 | 2:7d523bdd2f50 | 2 | |
jjones646 | 2:7d523bdd2f50 | 3 | // Set the class's constants for streamlined use in other areas of the code |
jjones646 | 2:7d523bdd2f50 | 4 | const int CommLink::TX_QUEUE_SIZE = COMM_LINK_TX_QUEUE_SIZE; |
jjones646 | 2:7d523bdd2f50 | 5 | const int CommLink::RX_QUEUE_SIZE = COMM_LINK_RX_QUEUE_SIZE; |
jjones646 | 2:7d523bdd2f50 | 6 | |
jjones646 | 2:7d523bdd2f50 | 7 | // Default constructor |
jjones646 | 2:7d523bdd2f50 | 8 | CommLink::CommLink() |
jjones646 | 2:7d523bdd2f50 | 9 | { |
jjones646 | 2:7d523bdd2f50 | 10 | /* |
jjones646 | 2:7d523bdd2f50 | 11 | { |
jjones646 | 2:7d523bdd2f50 | 12 | // [] - 1 - Initialize the hardware for communication |
jjones646 | 2:7d523bdd2f50 | 13 | |
jjones646 | 2:7d523bdd2f50 | 14 | // [] - 2 - Create small tx & rx queues |
jjones646 | 2:7d523bdd2f50 | 15 | // The size allocations for each queue are dependent upon what interface that communication is occuring on (radio/serial/usb/etc.) |
jjones646 | 2:7d523bdd2f50 | 16 | |
jjones646 | 2:7d523bdd2f50 | 17 | // [] - 3 - Create and start thread operations for handeling data exchanges from the queues |
jjones646 | 2:7d523bdd2f50 | 18 | } |
jjones646 | 2:7d523bdd2f50 | 19 | */ |
jjones646 | 2:7d523bdd2f50 | 20 | |
jjones646 | 2:7d523bdd2f50 | 21 | // Disable interface by default |
jjones646 | 2:7d523bdd2f50 | 22 | _enabled = false; |
jjones646 | 2:7d523bdd2f50 | 23 | |
jjones646 | 2:7d523bdd2f50 | 24 | // Define the data queues [THESE ARE MACROS] |
jjones646 | 2:7d523bdd2f50 | 25 | osMailQDef(_txQueue, COMM_LINK_TX_QUEUE_SIZE, RTP_t); |
jjones646 | 2:7d523bdd2f50 | 26 | osMailQDef(_rxQueue, COMM_LINK_RX_QUEUE_SIZE, RTP_t); |
jjones646 | 2:7d523bdd2f50 | 27 | //osMailQId _rxQueue__; |
jjones646 | 2:7d523bdd2f50 | 28 | //osMailQId _txQueue__; |
jjones646 | 2:7d523bdd2f50 | 29 | |
jjones646 | 2:7d523bdd2f50 | 30 | // [THIS CURRENTLY CAUSES AN MBED RUNTIME ERROR] |
jjones646 | 2:7d523bdd2f50 | 31 | // Create the data queues |
jjones646 | 2:7d523bdd2f50 | 32 | //_txQueue = osMailCreate(osMailQ(_txQueue), NULL); |
jjones646 | 2:7d523bdd2f50 | 33 | //_rxQueue = osMailCreate(osMailQ(_rxQueue), NULL); |
jjones646 | 2:7d523bdd2f50 | 34 | |
jjones646 | 2:7d523bdd2f50 | 35 | // Outline the thread definitions |
jjones646 | 2:7d523bdd2f50 | 36 | define_thread(_txDef, &CommLink::txThread); |
jjones646 | 2:7d523bdd2f50 | 37 | define_thread(_rxDef, &CommLink::rxThread); |
jjones646 | 2:7d523bdd2f50 | 38 | |
jjones646 | 2:7d523bdd2f50 | 39 | // Create the thread and pass it a pointer to the created object |
jjones646 | 2:7d523bdd2f50 | 40 | _txID = osThreadCreate(&_txDef, (void*)this); |
jjones646 | 2:7d523bdd2f50 | 41 | _rxID = osThreadCreate(&_rxDef, (void*)this); |
jjones646 | 2:7d523bdd2f50 | 42 | } |
jjones646 | 2:7d523bdd2f50 | 43 | |
jjones646 | 2:7d523bdd2f50 | 44 | // Deconstructor |
jjones646 | 2:7d523bdd2f50 | 45 | CommLink::~CommLink() |
jjones646 | 2:7d523bdd2f50 | 46 | { |
jjones646 | 2:7d523bdd2f50 | 47 | |
jjones646 | 2:7d523bdd2f50 | 48 | } |
jjones646 | 2:7d523bdd2f50 | 49 | |
jjones646 | 2:7d523bdd2f50 | 50 | // Task operations for sending data over the hardware link when a new item is placed in the queue |
jjones646 | 2:7d523bdd2f50 | 51 | void CommLink::txThread(void const *arg) |
jjones646 | 2:7d523bdd2f50 | 52 | { |
jjones646 | 2:7d523bdd2f50 | 53 | CommLink *inst = (CommLink*)arg; |
jjones646 | 2:7d523bdd2f50 | 54 | |
jjones646 | 2:7d523bdd2f50 | 55 | // Only continue past this point once at least one (1) hardware link is initialized |
jjones646 | 2:7d523bdd2f50 | 56 | |
jjones646 | 2:7d523bdd2f50 | 57 | while(1) { |
jjones646 | 2:7d523bdd2f50 | 58 | // [] - 1 - Wait until the CommModule class sends a signal to begin operation on new data being placed in its txQueue |
jjones646 | 2:7d523bdd2f50 | 59 | |
jjones646 | 2:7d523bdd2f50 | 60 | // [] - 2 - Copy the packet from the CommModule txQueue into the CommLink txQueue |
jjones646 | 2:7d523bdd2f50 | 61 | |
jjones646 | 2:7d523bdd2f50 | 62 | // [] - 3 - Call the method for sending the packet over a hardware communication link |
jjones646 | 2:7d523bdd2f50 | 63 | // This should be done with the pure virtual method 1sendPacket(RTP_t* p)1 |
jjones646 | 2:7d523bdd2f50 | 64 | |
jjones646 | 2:7d523bdd2f50 | 65 | // 3 - Blink the TX LED for the hardware link |
jjones646 | 2:7d523bdd2f50 | 66 | } |
jjones646 | 2:7d523bdd2f50 | 67 | } |
jjones646 | 2:7d523bdd2f50 | 68 | |
jjones646 | 2:7d523bdd2f50 | 69 | // Task operations for placing received data into the received data queue |
jjones646 | 2:7d523bdd2f50 | 70 | void CommLink::rxThread(void const *arg) |
jjones646 | 2:7d523bdd2f50 | 71 | { |
jjones646 | 2:7d523bdd2f50 | 72 | CommLink *inst = (CommLink*)arg; |
jjones646 | 2:7d523bdd2f50 | 73 | |
jjones646 | 2:7d523bdd2f50 | 74 | // Only continue past this point once at least one (1) hardware link is initialized |
jjones646 | 2:7d523bdd2f50 | 75 | |
jjones646 | 2:7d523bdd2f50 | 76 | while(1) { |
jjones646 | 2:7d523bdd2f50 | 77 | // [] - 1 - Wait until new data is placed in the rxQueue before beginning any operations (the derived classes from CommLink are responsible for properly signaling when new data is present) |
jjones646 | 2:7d523bdd2f50 | 78 | |
jjones646 | 2:7d523bdd2f50 | 79 | // [] - 2 - Read the packet from the rxQueue and pass it to the CommModule class's rxQueue |
jjones646 | 2:7d523bdd2f50 | 80 | |
jjones646 | 2:7d523bdd2f50 | 81 | // [] - 3 - Signal to the CommModule class that a new packet has been received (this will begin operations for its rxThread) |
jjones646 | 2:7d523bdd2f50 | 82 | |
jjones646 | 2:7d523bdd2f50 | 83 | // [] - 4 - Blink the RX LED for the hardware link |
jjones646 | 2:7d523bdd2f50 | 84 | } |
jjones646 | 2:7d523bdd2f50 | 85 | } |
jjones646 | 2:7d523bdd2f50 | 86 | |
jjones646 | 2:7d523bdd2f50 | 87 | // Will enable/disable the currently active hardware communication link to ensure only one (1) perheripial is communicating at any given time |
jjones646 | 2:7d523bdd2f50 | 88 | // A static member variable might help here for tracking the active hardware communication links |
jjones646 | 2:7d523bdd2f50 | 89 | uint32_t CommLink::enable(bool en) |
jjones646 | 2:7d523bdd2f50 | 90 | { |
jjones646 | 2:7d523bdd2f50 | 91 | this->_enabled = en; |
jjones646 | 2:7d523bdd2f50 | 92 | return 1; |
jjones646 | 2:7d523bdd2f50 | 93 | } |