An OS_CRIT object is used to establish critical sections of code that can only be run by one task at a time. Tasks that try to claim a critical section which is currently claimed by another task will stop and wait for that task to release the critical section before continuing execution.
More...
#include <nbrtos.h>
Inherits OS_TASK_DLY_OBJ.
|
| | OS_CRIT () |
| | Create and initialize an OS_CRIT object.
|
| |
| uint8_t | Init () |
| | Initialize an OS_CRIT object to its default state.
|
| |
| uint8_t | LockAndEnter (uint32_t timeoutTicks=WAIT_FOREVER) |
| | Locks the current task to prevent task switching and claims the critical section.
|
| |
| uint8_t | Enter (TickTimeout &t) |
| | Request to Enter/Claim the critical section.
|
| |
| uint8_t | Enter (uint32_t timeoutTicks=WAIT_FOREVER) |
| | Request to Enter/Claim the critical section, with a time out parameter.
|
| |
| uint8_t | EnterNoWait () |
| | Request to Enter/Claim the critical section. Does not wait if a critical section is not available.
|
| |
| uint8_t | Leave () |
| | Release the critical section.
|
| |
| uint8_t | LeaveAndUnlock () |
| | Leave/release the critical section and unlock the task.
|
| |
| bool | UsedFromISR () |
| | Check if critical section UsedFromISR flag is set.
|
| |
| void | SetUseFromISR (bool enableFromISR) |
| | Set critical section UsedFromISR flag.
|
| |
| bool | OwnedByCurTask () |
| | Check if critical section owned by the current task.
|
| |
| uint32_t | CurDepth () |
| | Returns the critical section depth count.
|
| |
|
|
class | fifo_buffer_storage |
| |
| void | ForceReboot (bool fromIRQ=false) |
| | Forces the system hardware to perform a soft reset.
|
| |
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at a time. Tasks that try to claim a critical section which is currently claimed by another task will stop and wait for that task to release the critical section before continuing execution.
◆ OS_CRIT()
◆ CurDepth()
| uint32_t OS_CRIT::CurDepth |
( |
| ) |
|
|
inline |
Returns the critical section depth count.
- Returns
- Depth count value
◆ Enter() [1/2]
Request to Enter/Claim the critical section.
- Note
- You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
- Parameters
-
| t | The number of TickTimeout time ticks to wait for the critical section. A timeout of 0 (zero) waits forever. |
- Return values
-
| OS_NO_ERR | If we were successful in claiming the critical section or if our task owns it |
| OS_TIMEOUT | If we were unable to claim the section NBRTOS Error Codes |
- See also
- NBRTOS Error Codes, EnterNoWait(), Leave()
◆ Enter() [2/2]
| uint8_t OS_CRIT::Enter |
( |
uint32_t | timeoutTicks = WAIT_FOREVER | ) |
|
|
inline |
Request to Enter/Claim the critical section, with a time out parameter.
- Note
- You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
- Parameters
-
| timeoutTicks | The number of sytem TimeTicks to wait for the critical section. A timeout of 0 (zero) waits forever. |
- Return values
-
| OS_NO_ERR | If we were successful in claiming the critical section or if our task owns it |
| OS_TIMEOUT | If we were unable to claim the section NBRTOS Error Codes |
- See also
- NBRTOS Error Codes, EnterNoWait(), Leave()
◆ EnterNoWait()
| uint8_t OS_CRIT::EnterNoWait |
( |
| ) |
|
Request to Enter/Claim the critical section. Does not wait if a critical section is not available.
- Note
- You must call Leave() once for each successful Enter() call to release the critical section so that another task can run it.
- Return values
-
| OS_NO_ERR | If we were successful in claiming the critical section or if our task owns it |
| OS_TIMEOUT | If we were unable to claim the section NBRTOS Error Codes |
- See also
- NBRTOS Error Codes, Enter(), Leave()
◆ Init()
| uint8_t OS_CRIT::Init |
( |
| ) |
|
◆ Leave()
| uint8_t OS_CRIT::Leave |
( |
| ) |
|
Release the critical section.
- Note
- This function must be called once for each successful Enter() or EnterNoWait() call to release the critical section so another task can run it.
- Return values
-
| OS_NO_ERR | If we were successful in claiming the critical section or if our task owns it |
| OS_CRIT_ERR | If we are trying to release a critical section that we do not own NBRTOS Error Codes |
- See also
- NBRTOS Error Codes, Enter(), EnterNoWait()
◆ LeaveAndUnlock()
| uint8_t OS_CRIT::LeaveAndUnlock |
( |
| ) |
|
◆ LockAndEnter()
| uint8_t OS_CRIT::LockAndEnter |
( |
uint32_t | timeoutTicks = WAIT_FOREVER | ) |
|
Locks the current task to prevent task switching and claims the critical section.
- Note
- If it is unable to claim the critical section and times out, then the lock will be released. Otherwise LeaveAndUnlock() must be called once for each successful LockAndEnter() call to both unlock and release the critical section so that another task might run it.
- Parameters
-
| timeoutTicks | The number of TickTimeout time ticks to wait for the critical section. A timeout of 0 (zero) waits forever. |
- Return values
-
| OS_NO_ERR | If we were successful in claiming the critical section or if our task owns it |
| OS_TIMEOUT | If we were unable to claim the section |
- See also
- NBRTOS Error Codes, LeaveAndUnlock(), Enter()
◆ SetUseFromISR()
| void OS_CRIT::SetUseFromISR |
( |
bool | enableFromISR | ) |
|
|
inline |
Set critical section UsedFromISR flag.
- Parameters
-
| enableFromISR | Set true to set flag |
- See also
- UsedFromISR()
◆ UsedFromISR()
| bool OS_CRIT::UsedFromISR |
( |
| ) |
|
|
inline |
◆ ForceReboot
| void ForceReboot |
( |
bool | fromIRQ = false | ) |
|
|
friend |
Forces the system hardware to perform a soft reset.
This function triggers a complete system restart by directly commanding the hardware reset mechanisms. The reset is immediate and unconditional - all running processes are terminated, memory contents are cleared, and the system restarts from the boot sequence. This is equivalent to a power cycle but is performed through software control. The function never returns to the calling code as the system undergoes a complete restart.
- Parameters
-
| fromIRQ | Optional parameter indicating the reset context true: reset is being triggered from within an interrupt service routine or exception handler, which may require special handling procedures false: reset is being triggered from normal application code (default) |
- Note
- This function never returns - execution does not continue after this call. All unsaved data, network connections, and application state will be lost. File systems and persistent storage should be properly synchronized before calling. The fromIRQ parameter ensures proper reset handling when called from interrupt contexts. After reset, the system will restart from the beginning of the boot sequence. Use this function only when a complete system restart is absolutely necessary.
- Warning
- This function immediately terminates all system operations without cleanup. Ensure critical data is saved and network connections are properly closed before use.
- See also
- attribute((noreturn)) indicates this function never returns to the caller
The documentation for this struct was generated from the following file: