Skip to content

Commit 940614c

Browse files
authored
Merge pull request #5760 from bulislaw/rtc_isr_safe_doc
Add notes about ISR safety to RTOS doxygen
2 parents 2c6403e + ec681b6 commit 940614c

File tree

9 files changed

+184
-11
lines changed

9 files changed

+184
-11
lines changed

rtos/ConditionVariable.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ struct Waiter;
118118
*/
119119
class ConditionVariable : private mbed::NonCopyable<ConditionVariable> {
120120
public:
121-
/** Create and Initialize a ConditionVariable object */
121+
/** Create and Initialize a ConditionVariable object
122+
*
123+
* @note You may call this function from ISR context.
124+
*/
122125
ConditionVariable(Mutex &mutex);
123126

124127
/** Wait for a notification
@@ -142,6 +145,8 @@ class ConditionVariable : private mbed::NonCopyable<ConditionVariable> {
142145
*
143146
* mutex.unlock();
144147
* @endcode
148+
*
149+
* @note You cannot call this function from ISR context.
145150
*/
146151
void wait();
147152

@@ -176,21 +181,31 @@ class ConditionVariable : private mbed::NonCopyable<ConditionVariable> {
176181
*
177182
* mutex.unlock();
178183
* @endcode
184+
*
185+
* @note You cannot call this function from ISR context.
179186
*/
180187
bool wait_for(uint32_t millisec);
181188

182189
/** Notify one waiter on this condition variable that a condition changed.
183190
*
184191
* @note - The thread calling this function must be the owner of the ConditionVariable's mutex
192+
*
193+
* @note This function may be called from ISR context.
185194
*/
186195
void notify_one();
187196

188197
/** Notify all waiters on this condition variable that a condition changed.
189198
*
190199
* @note - The thread calling this function must be the owner of the ConditionVariable's mutex
200+
*
201+
* @note This function may be called from ISR context.
191202
*/
192203
void notify_all();
193204

205+
/** ConditionVariable destructor
206+
*
207+
* @note You may call this function from ISR context.
208+
*/
194209
~ConditionVariable();
195210

196211
protected:

rtos/EventFlags.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,40 @@ namespace rtos {
4646
*/
4747
class EventFlags : private mbed::NonCopyable<EventFlags> {
4848
public:
49-
/** Create and Initialize a EventFlags object */
49+
/** Create and Initialize an EventFlags object
50+
*
51+
* @note You cannot call this function from ISR context.
52+
*/
5053
EventFlags();
5154

5255
/** Create and Initialize a EventFlags object
5356
5457
@param name name to be used for this EventFlags. It has to stay allocated for the lifetime of the thread.
58+
59+
@note You cannot call this function from ISR context.
5560
*/
5661
EventFlags(const char *name);
5762

5863
/** Set the specified Event Flags.
5964
@param flags specifies the flags that shall be set.
6065
@return event flags after setting or error code if highest bit set (@a osFlagsError).
66+
67+
@note This function may be called from ISR context.
6168
*/
6269
uint32_t set(uint32_t flags);
6370

6471
/** Clear the specified Event Flags.
6572
@param flags specifies the flags that shall be cleared. (default: 0x7fffffff - all flags)
6673
@return event flags before clearing or error code if highest bit set (@a osFlagsError).
74+
75+
@note You may call this function from ISR context.
6776
*/
6877
uint32_t clear(uint32_t flags = 0x7fffffff);
6978

7079
/** Get the currently set Event Flags.
7180
@return set event flags.
81+
82+
@note You may call this function from ISR context.
7283
*/
7384
uint32_t get() const;
7485

@@ -77,6 +88,8 @@ class EventFlags : private mbed::NonCopyable<EventFlags> {
7788
@param timeout timeout value or 0 in case of no time-out. (default: osWaitForever)
7889
@param clear specifies wether to clear the flags after waiting for them. (default: true)
7990
@return event flags before clearing or error code if highest bit set (@a osFlagsError).
91+
92+
@note You may call this function from ISR context if the timeout parameter is set to 0.
8093
*/
8194
uint32_t wait_all(uint32_t flags = 0, uint32_t timeout = osWaitForever, bool clear = true);
8295

@@ -85,9 +98,15 @@ class EventFlags : private mbed::NonCopyable<EventFlags> {
8598
@param timeout timeout value or 0 in case of no time-out. (default: osWaitForever)
8699
@param clear specifies wether to clear the flags after waiting for them. (default: true)
87100
@return event flags before clearing or error code if highest bit set (@a osFlagsError).
101+
102+
@note This function may be called from ISR context if the timeout parameter is set to 0.
88103
*/
89104
uint32_t wait_any(uint32_t flags = 0, uint32_t timeout = osWaitForever, bool clear = true);
90105

106+
/** Event flags destructor
107+
108+
@note You cannot call this function from ISR context.
109+
*/
91110
~EventFlags();
92111

93112
private:

rtos/Mail.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ namespace rtos {
5555
template<typename T, uint32_t queue_sz>
5656
class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
5757
public:
58-
/** Create and Initialise Mail queue. */
58+
/** Create and Initialize Mail queue.
59+
*
60+
* @note You cannot call this function from ISR context.
61+
*/
5962
Mail() { };
6063

6164
/** Check if the mail queue is empty
6265
*
6366
* @return True if the mail queue is empty, false if not
67+
*
68+
* @note You may call this function from ISR context.
6469
*/
6570
bool empty() const {
6671
return _queue.empty();
@@ -69,6 +74,8 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
6974
/** Check if the mail queue is full
7075
*
7176
* @return True if the mail queue is full, false if not
77+
*
78+
* @note You may call this function from ISR context.
7279
*/
7380
bool full() const {
7481
return _queue.full();
@@ -77,6 +84,8 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
7784
/** Allocate a memory block of type T
7885
@param millisec timeout value or 0 in case of no time-out. (default: 0).
7986
@return pointer to memory block that can be filled with mail or NULL in case error.
87+
88+
@note You may call this function from ISR context if the millisec parameter is set to 0.
8089
*/
8190
T* alloc(uint32_t millisec=0) {
8291
return _pool.alloc();
@@ -85,6 +94,8 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
8594
/** Allocate a memory block of type T and set memory block to zero.
8695
@param millisec timeout value or 0 in case of no time-out. (default: 0).
8796
@return pointer to memory block that can be filled with mail or NULL in case error.
97+
98+
@note You may call this function from ISR context if the millisec parameter is set to 0.
8899
*/
89100
T* calloc(uint32_t millisec=0) {
90101
return _pool.calloc();
@@ -93,6 +104,8 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
93104
/** Put a mail in the queue.
94105
@param mptr memory block previously allocated with Mail::alloc or Mail::calloc.
95106
@return status code that indicates the execution status of the function.
107+
108+
@note You may call this function from ISR context.
96109
*/
97110
osStatus put(T *mptr) {
98111
return _queue.put(mptr);
@@ -101,6 +114,8 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
101114
/** Get a mail from a queue.
102115
@param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
103116
@return event that contains mail information or error code.
117+
118+
@note You may call this function from ISR context if the millisec parameter is set to 0.
104119
*/
105120
osEvent get(uint32_t millisec=osWaitForever) {
106121
osEvent evt = _queue.get(millisec);
@@ -113,6 +128,8 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
113128
/** Free a memory block from a mail.
114129
@param mptr pointer to the memory block that was obtained with Mail::get.
115130
@return status code that indicates the execution status of the function.
131+
132+
@note You may call this function from ISR context.
116133
*/
117134
osStatus free(T *mptr) {
118135
return _pool.free(mptr);

rtos/MemoryPool.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ template<typename T, uint32_t pool_sz>
5050
class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
5151
MBED_STATIC_ASSERT(pool_sz > 0, "Invalid memory pool size. Must be greater than 0.");
5252
public:
53-
/** Create and Initialize a memory pool. */
53+
/** Create and Initialize a memory pool.
54+
*
55+
* @note You cannot call this function from ISR context.
56+
*/
5457
MemoryPool() {
5558
memset(_pool_mem, 0, sizeof(_pool_mem));
5659
memset(&_obj_mem, 0, sizeof(_obj_mem));
@@ -63,20 +66,27 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
6366
MBED_ASSERT(_id);
6467
}
6568

66-
/** Destroy a memory pool */
69+
/** Destroy a memory pool
70+
*
71+
* @note You cannot call this function from ISR context.
72+
*/
6773
~MemoryPool() {
6874
osMemoryPoolDelete(_id);
6975
}
7076

7177
/** Allocate a memory block of type T from a memory pool.
7278
@return address of the allocated memory block or NULL in case of no memory available.
79+
80+
@note You may call this function from ISR context.
7381
*/
7482
T* alloc(void) {
7583
return (T*)osMemoryPoolAlloc(_id, 0);
7684
}
7785

7886
/** Allocate a memory block of type T from a memory pool and set memory block to zero.
7987
@return address of the allocated memory block or NULL in case of no memory available.
88+
89+
@note You may call this function from ISR context.
8090
*/
8191
T* calloc(void) {
8292
T *item = (T*)osMemoryPoolAlloc(_id, 0);
@@ -92,6 +102,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
92102
is NULL or invalid, or osErrorResource if given memory block is in an
93103
invalid memory pool state.
94104
105+
@note You may call this function from ISR context.
95106
*/
96107
osStatus free(T *block) {
97108
return osMemoryPoolFree(_id, (void*)block);

rtos/Mutex.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,26 @@ namespace rtos {
4040
/** The Mutex class is used to synchronize the execution of threads.
4141
This is for example used to protect access to a shared resource.
4242
43+
@note You cannot use member functions of this class in ISR context. If you require Mutex functionality within
44+
ISR handler, consider using @a Semaphore.
45+
4346
@note
4447
Memory considerations: The mutex control structures will be created on current thread's stack, both for the mbed OS
4548
and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
4649
*/
4750
class Mutex : private mbed::NonCopyable<Mutex> {
4851
public:
49-
/** Create and Initialize a Mutex object */
52+
/** Create and Initialize a Mutex object
53+
*
54+
* @note You cannot call this function from ISR context.
55+
*/
5056
Mutex();
5157

5258
/** Create and Initialize a Mutex object
5359
5460
@param name name to be used for this mutex. It has to stay allocated for the lifetime of the thread.
61+
62+
@note You cannot call this function from ISR context.
5563
*/
5664
Mutex(const char *name);
5765

@@ -63,11 +71,15 @@ class Mutex : private mbed::NonCopyable<Mutex> {
6371
@a osErrorParameter internal error.
6472
@a osErrorResource the mutex could not be obtained when no timeout was specified.
6573
@a osErrorISR this function cannot be called from the interrupt service routine.
74+
75+
@note You cannot call this function from ISR context.
6676
*/
6777
osStatus lock(uint32_t millisec=osWaitForever);
6878

6979
/** Try to lock the mutex, and return immediately
7080
@return true if the mutex was acquired, false otherwise.
81+
82+
@note This function cannot be called from ISR context.
7183
*/
7284
bool trylock();
7385

@@ -77,14 +89,22 @@ class Mutex : private mbed::NonCopyable<Mutex> {
7789
@a osErrorParameter internal error.
7890
@a osErrorResource the mutex was not locked or the current thread wasn't the owner.
7991
@a osErrorISR this function cannot be called from the interrupt service routine.
92+
93+
@note This function cannot be called from ISR context.
8094
*/
8195
osStatus unlock();
8296

8397
/** Get the owner the this mutex
8498
@return the current owner of this mutex.
99+
100+
@note You cannot call this function from ISR context.
85101
*/
86102
osThreadId get_owner();
87103

104+
/** Mutex destructor
105+
*
106+
* @note You cannot call this function from ISR context.
107+
*/
88108
~Mutex();
89109

90110
private:

rtos/Queue.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ namespace rtos {
5252
template<typename T, uint32_t queue_sz>
5353
class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
5454
public:
55-
/** Create and initialize a message Queue. */
55+
/** Create and initialize a message Queue.
56+
*
57+
* @note You cannot call this function from ISR context.
58+
*/
5659
Queue() {
5760
memset(&_obj_mem, 0, sizeof(_obj_mem));
5861
osMessageQueueAttr_t attr = { 0 };
@@ -63,14 +66,19 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
6366
_id = osMessageQueueNew(queue_sz, sizeof(T*), &attr);
6467
MBED_ASSERT(_id);
6568
}
66-
69+
/** Queue destructor
70+
*
71+
* @note You cannot call this function from ISR context.
72+
*/
6773
~Queue() {
6874
osMessageQueueDelete(_id);
6975
}
7076

7177
/** Check if the queue is empty
7278
*
7379
* @return True if the queue is empty, false if not
80+
*
81+
* @note You may call this function from ISR context.
7482
*/
7583
bool empty() const {
7684
return osMessageQueueGetCount(_id) == 0;
@@ -79,6 +87,8 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
7987
/** Check if the queue is full
8088
*
8189
* @return True if the queue is full, false if not
90+
*
91+
* @note You may call this function from ISR context.
8292
*/
8393
bool full() const {
8494
return osMessageQueueGetSpace(_id) == 0;
@@ -93,6 +103,8 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
93103
@a osErrorTimeout the message could not be put into the queue in the given time.
94104
@a osErrorResource not enough space in the queue.
95105
@a osErrorParameter internal error or non-zero timeout specified in an ISR.
106+
107+
@note You may call this function from ISR context if the millisec parameter is set to 0.
96108
*/
97109
osStatus put(T* data, uint32_t millisec=0, uint8_t prio=0) {
98110
return osMessageQueuePut(_id, &data, prio, millisec);
@@ -106,6 +118,8 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
106118
@a osOK no message is available in the queue and no timeout was specified.
107119
@a osEventTimeout no message has arrived during the given timeout period.
108120
@a osErrorParameter a parameter is invalid or outside of a permitted range.
121+
122+
@note You may call this function from ISR context if the millisec parameter is set to 0.
109123
*/
110124
osEvent get(uint32_t millisec=osWaitForever) {
111125
osEvent event;

0 commit comments

Comments
 (0)