Jonathan Jones
/
Radios
Radio Structures in OOP
modules/CommModule/CommModule.h@3:dc7e9c6bc26c, 2015-01-03 (annotated)
- Committer:
- jjones646
- Date:
- Sat Jan 03 04:35:32 2015 +0000
- Revision:
- 3:dc7e9c6bc26c
- Parent:
- 2:7d523bdd2f50
- Child:
- 4:989d51f3e6ef
updating with threaded tasks for communication classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 2:7d523bdd2f50 | 1 | #ifndef COMMUNICATION_MODULE_H |
jjones646 | 2:7d523bdd2f50 | 2 | #define COMMUNICATION_MODULE_H |
jjones646 | 2:7d523bdd2f50 | 3 | |
jjones646 | 2:7d523bdd2f50 | 4 | #include "mbed.h" |
jjones646 | 2:7d523bdd2f50 | 5 | #include "cmsis_os.h" |
jjones646 | 2:7d523bdd2f50 | 6 | #include "RTP.h" |
jjones646 | 2:7d523bdd2f50 | 7 | #include "ThreadHelper.h" |
jjones646 | 3:dc7e9c6bc26c | 8 | #include "MailHelper.h" |
jjones646 | 3:dc7e9c6bc26c | 9 | #include "Logger.h" |
jjones646 | 3:dc7e9c6bc26c | 10 | #include "FunctionPointerRJ.h" |
jjones646 | 2:7d523bdd2f50 | 11 | |
jjones646 | 3:dc7e9c6bc26c | 12 | #include <algorithm> // std::binary_search, std::sort |
jjones646 | 3:dc7e9c6bc26c | 13 | #include <vector> |
jjones646 | 3:dc7e9c6bc26c | 14 | |
jjones646 | 3:dc7e9c6bc26c | 15 | #define COMM_MODULE_TX_QUEUE_SIZE 20 |
jjones646 | 3:dc7e9c6bc26c | 16 | #define COMM_MODULE_RX_QUEUE_SIZE 4 |
jjones646 | 3:dc7e9c6bc26c | 17 | #define COMM_MODULE_NBR_PORTS 15 |
jjones646 | 3:dc7e9c6bc26c | 18 | #define COMM_MODULE_SIGNAL_START_THREAD 0x01 |
jjones646 | 3:dc7e9c6bc26c | 19 | |
jjones646 | 3:dc7e9c6bc26c | 20 | class CommLink; |
jjones646 | 2:7d523bdd2f50 | 21 | |
jjones646 | 2:7d523bdd2f50 | 22 | // Base class for a communication module |
jjones646 | 2:7d523bdd2f50 | 23 | class CommModule |
jjones646 | 2:7d523bdd2f50 | 24 | { |
jjones646 | 2:7d523bdd2f50 | 25 | public: |
jjones646 | 2:7d523bdd2f50 | 26 | // Default Constructor |
jjones646 | 2:7d523bdd2f50 | 27 | CommModule(); |
jjones646 | 2:7d523bdd2f50 | 28 | |
jjones646 | 2:7d523bdd2f50 | 29 | // Deconstructor |
jjones646 | 3:dc7e9c6bc26c | 30 | virtual ~CommModule(); |
jjones646 | 3:dc7e9c6bc26c | 31 | |
jjones646 | 2:7d523bdd2f50 | 32 | // Class constants - set in CommModule.cpp |
jjones646 | 2:7d523bdd2f50 | 33 | static const int NBR_PORTS; |
jjones646 | 2:7d523bdd2f50 | 34 | static const int TX_QUEUE_SIZE; |
jjones646 | 2:7d523bdd2f50 | 35 | static const int RX_QUEUE_SIZE; |
jjones646 | 2:7d523bdd2f50 | 36 | |
jjones646 | 3:dc7e9c6bc26c | 37 | // Open a socket connection for communicating. |
jjones646 | 3:dc7e9c6bc26c | 38 | template <typename T> |
jjones646 | 3:dc7e9c6bc26c | 39 | void TxHandler(T*, void(T::*)(RTP_t*), uint8_t); |
jjones646 | 2:7d523bdd2f50 | 40 | |
jjones646 | 3:dc7e9c6bc26c | 41 | void TxHandler(void(*)(RTP_t*), uint8_t); |
jjones646 | 2:7d523bdd2f50 | 42 | |
jjones646 | 3:dc7e9c6bc26c | 43 | void openSocket(CommLink*, uint8_t, void(*)(void const*)); |
jjones646 | 3:dc7e9c6bc26c | 44 | |
jjones646 | 2:7d523bdd2f50 | 45 | // Send a RTP packet. The details of exactly how the packet will be sent are determined from the RTP packet's port and subclass values |
jjones646 | 2:7d523bdd2f50 | 46 | void send(RTP_t&); |
jjones646 | 3:dc7e9c6bc26c | 47 | |
jjones646 | 3:dc7e9c6bc26c | 48 | void receive(RTP_t&); |
jjones646 | 2:7d523bdd2f50 | 49 | |
jjones646 | 2:7d523bdd2f50 | 50 | protected: |
jjones646 | 3:dc7e9c6bc26c | 51 | // NOP function for keeping a oommunication link active |
jjones646 | 3:dc7e9c6bc26c | 52 | void nopFunc(void); |
jjones646 | 3:dc7e9c6bc26c | 53 | |
jjones646 | 3:dc7e9c6bc26c | 54 | // Memory Queue IDs |
jjones646 | 2:7d523bdd2f50 | 55 | osMailQId _txQueue; |
jjones646 | 2:7d523bdd2f50 | 56 | osMailQId _rxQueue; |
jjones646 | 2:7d523bdd2f50 | 57 | |
jjones646 | 3:dc7e9c6bc26c | 58 | // Thread IDs |
jjones646 | 3:dc7e9c6bc26c | 59 | osThreadId _txID; |
jjones646 | 3:dc7e9c6bc26c | 60 | osThreadId _rxID; |
jjones646 | 2:7d523bdd2f50 | 61 | |
jjones646 | 3:dc7e9c6bc26c | 62 | std::vector<uint8_t> *_open_ports; |
jjones646 | 3:dc7e9c6bc26c | 63 | |
jjones646 | 2:7d523bdd2f50 | 64 | private: |
jjones646 | 2:7d523bdd2f50 | 65 | // Used to help define the class's threads in the constructor |
jjones646 | 2:7d523bdd2f50 | 66 | friend void define_thread(osThreadDef_t&, void(*task)(void const *arg), osPriority, uint32_t, unsigned char*); |
jjones646 | 3:dc7e9c6bc26c | 67 | |
jjones646 | 3:dc7e9c6bc26c | 68 | MailHelper<RTP_t, COMM_MODULE_TX_QUEUE_SIZE> _txQueueHelper; |
jjones646 | 3:dc7e9c6bc26c | 69 | MailHelper<RTP_t, COMM_MODULE_RX_QUEUE_SIZE> _rxQueueHelper; |
jjones646 | 2:7d523bdd2f50 | 70 | |
jjones646 | 2:7d523bdd2f50 | 71 | // The working threads for handeling rx and tx data queues |
jjones646 | 2:7d523bdd2f50 | 72 | static void txThread(void const*); |
jjones646 | 2:7d523bdd2f50 | 73 | static void rxThread(void const*); |
jjones646 | 2:7d523bdd2f50 | 74 | |
jjones646 | 3:dc7e9c6bc26c | 75 | // Thread and Mail defintion data structures |
jjones646 | 2:7d523bdd2f50 | 76 | osThreadDef_t _txDef; |
jjones646 | 2:7d523bdd2f50 | 77 | osThreadDef_t _rxDef; |
jjones646 | 3:dc7e9c6bc26c | 78 | osMailQDef_t _txQDef; |
jjones646 | 3:dc7e9c6bc26c | 79 | osMailQDef_t _rxQDef; |
jjones646 | 2:7d523bdd2f50 | 80 | |
jjones646 | 3:dc7e9c6bc26c | 81 | CommLink *_link[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 82 | |
jjones646 | 3:dc7e9c6bc26c | 83 | FunctionPointerRJ _rx_handles[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 84 | FunctionPointerRJ _tx_handles[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 85 | |
jjones646 | 3:dc7e9c6bc26c | 86 | static bool isReady; |
jjones646 | 3:dc7e9c6bc26c | 87 | |
jjones646 | 3:dc7e9c6bc26c | 88 | void ready(void); |
jjones646 | 3:dc7e9c6bc26c | 89 | |
jjones646 | 2:7d523bdd2f50 | 90 | // Ignore for now |
jjones646 | 2:7d523bdd2f50 | 91 | // bool _dynamic_stack; |
jjones646 | 3:dc7e9c6bc26c | 92 | |
jjones646 | 2:7d523bdd2f50 | 93 | }; |
jjones646 | 2:7d523bdd2f50 | 94 | |
jjones646 | 2:7d523bdd2f50 | 95 | #endif // COMMUNICATION_MODULE_H |