Ethernetwebsoc
Dependencies: C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip
mbed-rtos/rtos/Queue.h@0:0ed2a7c7190c, 2013-05-31 (annotated)
- Committer:
- GordonSin
- Date:
- Fri May 31 04:09:54 2013 +0000
- Revision:
- 0:0ed2a7c7190c
31/5/2013;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GordonSin | 0:0ed2a7c7190c | 1 | /* Copyright (c) 2012 mbed.org */ |
GordonSin | 0:0ed2a7c7190c | 2 | #ifndef QUEUE_H |
GordonSin | 0:0ed2a7c7190c | 3 | #define QUEUE_H |
GordonSin | 0:0ed2a7c7190c | 4 | |
GordonSin | 0:0ed2a7c7190c | 5 | #include <stdint.h> |
GordonSin | 0:0ed2a7c7190c | 6 | #include <string.h> |
GordonSin | 0:0ed2a7c7190c | 7 | |
GordonSin | 0:0ed2a7c7190c | 8 | #include "cmsis_os.h" |
GordonSin | 0:0ed2a7c7190c | 9 | #include "error.h" |
GordonSin | 0:0ed2a7c7190c | 10 | |
GordonSin | 0:0ed2a7c7190c | 11 | namespace rtos { |
GordonSin | 0:0ed2a7c7190c | 12 | |
GordonSin | 0:0ed2a7c7190c | 13 | /*! The Queue class allow to control, send, receive, or wait for messages. |
GordonSin | 0:0ed2a7c7190c | 14 | A message can be a integer or pointer value to a certain type T that is send |
GordonSin | 0:0ed2a7c7190c | 15 | to a thread or interrupt service routine. |
GordonSin | 0:0ed2a7c7190c | 16 | \tparam T data type of a single message element. |
GordonSin | 0:0ed2a7c7190c | 17 | \tparam queue_sz maximum number of messages in queue. |
GordonSin | 0:0ed2a7c7190c | 18 | */ |
GordonSin | 0:0ed2a7c7190c | 19 | template<typename T, uint32_t queue_sz> |
GordonSin | 0:0ed2a7c7190c | 20 | class Queue { |
GordonSin | 0:0ed2a7c7190c | 21 | public: |
GordonSin | 0:0ed2a7c7190c | 22 | /*! Create and initialise a message Queue. */ |
GordonSin | 0:0ed2a7c7190c | 23 | Queue() { |
GordonSin | 0:0ed2a7c7190c | 24 | #ifdef CMSIS_OS_RTX |
GordonSin | 0:0ed2a7c7190c | 25 | memset(_queue_q, 0, sizeof(_queue_q)); |
GordonSin | 0:0ed2a7c7190c | 26 | _queue_def.pool = _queue_q; |
GordonSin | 0:0ed2a7c7190c | 27 | _queue_def.queue_sz = queue_sz; |
GordonSin | 0:0ed2a7c7190c | 28 | #endif |
GordonSin | 0:0ed2a7c7190c | 29 | _queue_id = osMessageCreate(&_queue_def, NULL); |
GordonSin | 0:0ed2a7c7190c | 30 | if (_queue_id == NULL) { |
GordonSin | 0:0ed2a7c7190c | 31 | error("Error initialising the queue object\n"); |
GordonSin | 0:0ed2a7c7190c | 32 | } |
GordonSin | 0:0ed2a7c7190c | 33 | } |
GordonSin | 0:0ed2a7c7190c | 34 | |
GordonSin | 0:0ed2a7c7190c | 35 | /*! Put a message in a Queue. |
GordonSin | 0:0ed2a7c7190c | 36 | \param data message pointer. |
GordonSin | 0:0ed2a7c7190c | 37 | \param millisec timeout value or 0 in case of no time-out. (default: 0) |
GordonSin | 0:0ed2a7c7190c | 38 | \return status code that indicates the execution status of the function. |
GordonSin | 0:0ed2a7c7190c | 39 | */ |
GordonSin | 0:0ed2a7c7190c | 40 | osStatus put(T* data, uint32_t millisec=0) { |
GordonSin | 0:0ed2a7c7190c | 41 | return osMessagePut(_queue_id, (uint32_t)data, millisec); |
GordonSin | 0:0ed2a7c7190c | 42 | } |
GordonSin | 0:0ed2a7c7190c | 43 | |
GordonSin | 0:0ed2a7c7190c | 44 | /*! Get a message or Wait for a message from a Queue. |
GordonSin | 0:0ed2a7c7190c | 45 | \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
GordonSin | 0:0ed2a7c7190c | 46 | \return event information that includes the message and the status code. |
GordonSin | 0:0ed2a7c7190c | 47 | */ |
GordonSin | 0:0ed2a7c7190c | 48 | osEvent get(uint32_t millisec=osWaitForever) { |
GordonSin | 0:0ed2a7c7190c | 49 | return osMessageGet(_queue_id, millisec); |
GordonSin | 0:0ed2a7c7190c | 50 | } |
GordonSin | 0:0ed2a7c7190c | 51 | |
GordonSin | 0:0ed2a7c7190c | 52 | private: |
GordonSin | 0:0ed2a7c7190c | 53 | osMessageQId _queue_id; |
GordonSin | 0:0ed2a7c7190c | 54 | osMessageQDef_t _queue_def; |
GordonSin | 0:0ed2a7c7190c | 55 | #ifdef CMSIS_OS_RTX |
GordonSin | 0:0ed2a7c7190c | 56 | uint32_t _queue_q[4+(queue_sz)]; |
GordonSin | 0:0ed2a7c7190c | 57 | #endif |
GordonSin | 0:0ed2a7c7190c | 58 | }; |
GordonSin | 0:0ed2a7c7190c | 59 | |
GordonSin | 0:0ed2a7c7190c | 60 | } |
GordonSin | 0:0ed2a7c7190c | 61 | #endif |