26 #include "rtos/mbed_rtos_types.h" 27 #include "rtos/internal/mbed_rtos1_types.h" 28 #include "rtos/internal/mbed_rtos_storage.h" 29 #include "rtos/Kernel.h" 30 #include "platform/mbed_error.h" 31 #include "platform/NonCopyable.h" 32 #include "platform/mbed_assert.h" 34 #if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) 65 template<
typename T, u
int32_t queue_sz>
75 osMessageQueueAttr_t attr = { 0 };
76 attr.mq_mem = _queue_mem;
77 attr.mq_size =
sizeof(_queue_mem);
78 attr.cb_mem = &_obj_mem;
79 attr.cb_size =
sizeof(_obj_mem);
80 _id = osMessageQueueNew(queue_sz,
sizeof(T *), &attr);
90 osMessageQueueDelete(_id);
101 return osMessageQueueGetCount(_id) == 0;
112 return osMessageQueueGetSpace(_id) == 0;
123 return osMessageQueueGetCount(_id);
144 return try_put_for(Kernel::Clock::duration_u32::zero(), data, prio);
175 bool try_put_for(Kernel::Clock::duration_u32 rel_time, T *data, uint8_t prio = 0)
177 osStatus status = osMessageQueuePut(_id, &data, prio, rel_time.count());
178 return status == osOK;
218 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Replaced with try_put and try_put_for. In future put will be an untimed blocking call.")
219 osStatus
put(T *data, uint32_t millisec = 0, uint8_t prio = 0)
221 return osMessageQueuePut(_id, &data, prio, millisec);
239 return try_get_for(Kernel::Clock::duration_u32::zero(), data_out);
269 bool try_get_for(Kernel::Clock::duration_u32 rel_time, T **data_out)
271 osStatus status = osMessageQueueGet(_id, data_out,
nullptr, rel_time.count());
272 return status == osOK;
310 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Replaced with try_get and try_get_for. In future get will be an untimed blocking call.")
311 osEvent
get(uint32_t millisec = osWaitForever)
315 osStatus_t res = osMessageQueueGet(_id, &data,
nullptr, millisec);
319 event.status = (osStatus)osEventMessage;
320 event.value.p = data;
322 case osErrorResource:
326 event.status = (osStatus)osEventTimeout;
328 case osErrorParameter:
330 event.status = osErrorParameter;
333 event.def.message_id = _id;
338 osMessageQueueId_t _id;
339 char _queue_mem[queue_sz * (
sizeof(T *) +
sizeof(mbed_rtos_storage_message_t))];
340 mbed_rtos_storage_msg_queue_t _obj_mem;
bool full() const
Check if the queue is full.
~Queue()
Queue destructor.
The Queue class represents a collection of objects that are stored first by order of priority...
Prevents generation of copy constructor and copy assignment operator in derived classes.
bool try_get_for(Kernel::Clock::duration_u32 rel_time, T **data_out)
Get a message or wait for a message from the queue.
osEvent get(uint32_t millisec=osWaitForever)
Get a message or wait for a message from the queue.
bool try_get(T **data_out)
Get a message from the queue.
bool try_put(T *data, uint8_t prio=0)
Inserts the given element to the end of the queue.
bool try_put_for(Kernel::Clock::duration_u32 rel_time, T *data, uint8_t prio=0)
Inserts the given element to the end of the queue.
Queue()
Create and initialize a message Queue of objects of the parameterized type T and maximum capacity spe...
bool empty() const
Check if the queue is empty.
uint32_t count() const
Get number of queued messages in the queue.
osStatus put(T *data, uint32_t millisec=0, uint8_t prio=0)
Inserts the given element to the end of the queue.