|
Nil RTOS
|
Classes | |
| struct | nil_system_t |
| System data structure. More... | |
| struct | nil_thread |
| Structure representing a thread. More... | |
| struct | nil_thread_cfg |
| Structure representing a thread static configuration. More... | |
| struct | semaphore_t |
| Type of a structure representing a counting semaphore. More... | |
Macros | |
| #define | NIL_DBG_ENABLED FALSE |
| System timer resolution in Hz. More... | |
Typedefs | |
| typedef struct port_intctx | intctx_t |
| Type of internal context structure. | |
| typedef void(* | tfunc_t )(void *) |
| Thread function. | |
| typedef struct nil_thread_cfg | thread_config_t |
| Type of a structure representing a thread static configuration. | |
| typedef thread_t * | thread_ref_t |
| Type of a thread reference. | |
| typedef struct nil_thread | thread_t |
| Type of a structure representing a thread. | |
Functions | |
| msg_t | nilSchGoSleepTimeoutS (tstate_t newstate, systime_t timeout) |
| Puts the current thread to sleep into the specified state with timeout specification. More... | |
| thread_ref_t | nilSchReadyI (thread_ref_t tr, msg_t msg) |
| Makes the specified thread ready for execution. More... | |
| void | nilSchRescheduleS () |
| Reschedules. More... | |
| void | nilSemReset (semaphore_t *sp, cnt_t n) |
| Performs a reset operation on the semaphore. More... | |
| void | nilSemResetI (semaphore_t *sp, cnt_t n) |
| Performs a reset operation on the semaphore. More... | |
| void | nilSemSignal (semaphore_t *sp) |
| Performs a signal operation on a semaphore. More... | |
| void | nilSemSignalI (semaphore_t *sp) |
| Performs a signal operation on a semaphore. More... | |
| msg_t | nilSemWaitTimeout (semaphore_t *sp, systime_t timeout) |
| Performs a wait operation on a semaphore with timeout specification. More... | |
| msg_t | nilSemWaitTimeoutS (semaphore_t *sp, systime_t timeout) |
| Performs a wait operation on a semaphore with timeout specification. More... | |
| void | nilSysInit (void) |
| Initializes the kernel. More... | |
| void | nilSysTimerHandlerI (void) |
| Time management handler. More... | |
| void | nilThdResumeI (thread_ref_t *trp, msg_t msg) |
| Wakes up a thread waiting on a thread reference object. More... | |
| void | nilThdSleep (systime_t time) |
| Suspends the invoking thread for the specified time. More... | |
| void | nilThdSleepUntil (systime_t time) |
| Suspends the invoking thread until the system time arrives to the specified value. More... | |
| msg_t | nilThdSuspendTimeoutS (thread_ref_t *trp, systime_t timeout) |
| Sends the current thread sleeping and sets a reference variable. More... | |
| systime_t | nilTimeNow (void) |
| Current system time. More... | |
| bool | nilTimeNowIsWithin (systime_t start, systime_t end) |
| Checks if the current system time is within the specified time window. More... | |
Variables | |
| nil_system_t | nil |
| System variables. | |
| nil_system_t | nil |
| System variables. | |
| const thread_config_t | nil_thd_configs [] |
| const uint8_t | nil_thd_count |
Nil RTOS identification | |
| #define | _NIL_ |
| Nil RTOS identification. | |
| #define | NIL_KERNEL_VERSION "0.0.1" |
| Kernel version string. | |
| #define | NIL_KERNEL_MAJOR 0 |
| Version major number. | |
| #define | NIL_KERNEL_MINOR 0 |
| Version minor number. | |
| #define | NIL_KERNEL_PATCH 1 |
| Version patch number. | |
Common constants | |
| #define | FALSE 0 |
| Generic 'false' boolean constant. | |
| #define | TRUE !FALSE |
| Generic 'true' boolean constant. | |
Wakeup status codes | |
| #define | NIL_MSG_OK 0 |
| Normal wakeup message. | |
| #define | NIL_MSG_TMO -1 |
| Wake-up caused by a timeout condition. | |
| #define | NIL_MSG_RST -2 |
| Wake-up caused by a reset condition. | |
Special time constants | |
| #define | TIME_IMMEDIATE ((systime_t)-1) |
| Zero time specification for some functions with a timeout specification. More... | |
| #define | TIME_INFINITE ((systime_t)0) |
| Infinite time specification for all functions with a timeout specification. | |
Thread state related macros | |
| #define | NIL_THD_READY 0 |
| Thread ready or executing. | |
| #define | NIL_THD_SLEEPING 1 |
| Thread sleeping. | |
| #define | NIL_THD_SUSP 2 |
| Thread suspended. | |
| #define | NIL_THD_WTSEM 3 |
| Thread waiting on semaphore. | |
| #define | NIL_THD_IS_READY(tr) ((tr)->state == NIL_THD_READY) |
| #define | NIL_THD_IS_SLEEPING(tr) ((tr)->state == NIL_THD_SLEEPING) |
| #define | NIL_THD_IS_SUSP(tr) ((tr)->state == NIL_THD_SUSP) |
| #define | NIL_THD_IS_WTSEM(tr) ((tr)->state == NIL_THD_WTSEM) |
Threads tables definition macros | |
| #define | NIL_THREADS_TABLE_BEGIN() const thread_config_t nil_thd_configs[] = { |
| Start of user threads table. | |
| #define | NIL_THREADS_TABLE_ENTRY(name, funcp, arg, wap, size) {name, funcp, arg, wap, size}, |
| Entry of user threads table. | |
| #define | NIL_THREADS_TABLE_END() |
| End of user threads table. | |
Macro Functions | |
| #define | nilSysHalt() port_halt() |
| System halt state. | |
| #define | nilSysDisable() port_disable() |
| Enters the kernel lock mode. More... | |
| #define | nilSysEnable() port_enable() |
| Enters the kernel lock mode. More... | |
| #define | nilSysLock() port_lock() |
| Enters the kernel lock mode. More... | |
| #define | nilSysUnlock() port_unlock() |
| Leaves the kernel lock mode. More... | |
| #define | nilSysLockFromISR() port_lock_from_isr() |
| Enters the kernel lock mode from within an interrupt handler. More... | |
| #define | nilSysUnlockFromISR() port_unlock_from_isr() |
| Leaves the kernel lock mode from within an interrupt handler. More... | |
| #define | nilThdSleepSeconds(sec) nilThdSleep(S2ST(sec)) |
| Delays the invoking thread for the specified number of seconds. More... | |
| #define | nilThdSleepMilliseconds(msec) nilThdSleep(MS2ST(msec)) |
| Delays the invoking thread for the specified number of milliseconds. More... | |
| #define | nilThdSleepMicroseconds(usec) nilThdSleep(US2ST(usec)) |
| Delays the invoking thread for the specified number of microseconds. More... | |
| #define | nilThdSleepS(timeout) nilSchGoSleepTimeoutS(NIL_THD_SLEEPING, timeout) |
| Suspends the invoking thread for the specified time. More... | |
| #define | nilThdSleepUntilS(time) nilSchGoSleepTimeoutS(NIL_THD_SLEEPING, (time) - nilTimeNowI()) |
| Suspends the invoking thread until the system time arrives to the specified value. More... | |
| #define | nilSemInit(sp, n) ((sp)->cnt = n) |
| Initializes a semaphore with the specified counter value. More... | |
| #define | nilSemWait(sp) nilSemWaitTimeout(sp, TIME_INFINITE) |
| Performs a wait operation on a semaphore. More... | |
| #define | nilSemWaitS(sp) nilSemWaitTimeoutS(sp, TIME_INFINITE) |
| Performs a wait operation on a semaphore. More... | |
| #define | nilTimeNowI() (nil.systime) |
| Current system time. More... | |
| #define | nilTimeIsWithin(time, start, end) |
| Checks if the specified time is within the specified time window. More... | |
Threads abstraction macros | |
| #define | NIL_THREAD(tname, arg) PORT_THREAD(tname, arg) |
| Thread declaration macro. More... | |
| #define | nilDbgAssert(c, m, r) {(void)(c);} |
ISRs abstraction macros | |
| #define | NIL_IRQ_PROLOGUE() PORT_IRQ_PROLOGUE() |
| IRQ handler enter code. More... | |
| #define | NIL_IRQ_EPILOGUE() PORT_IRQ_EPILOGUE() |
| IRQ handler exit code. More... | |
| #define | NIL_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id) |
| Standard normal IRQ handler declaration. More... | |
Fast ISRs abstraction macros | |
| #define | NIL_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id) |
| Standard fast IRQ handler declaration. More... | |
Time conversion utilities | |
| #define | S2ST(sec) ((systime_t)((sec) * NIL_CFG_FREQUENCY)) |
| Seconds to system ticks. More... | |
| #define | MS2ST(msec) |
| Milliseconds to system ticks. More... | |
| #define | US2ST(usec) |
| Microseconds to system ticks. More... | |
Nil RTOS services.
| #define MS2ST | ( | msec | ) |
Milliseconds to system ticks.
Converts from milliseconds to system ticks number.
| [in] | msec | number of milliseconds |
| #define NIL_DBG_ENABLED FALSE |
System timer resolution in Hz.
Time delta constant for the tick-less mode.
User fields added to the end of the thread_t structure.
| #define NIL_FAST_IRQ_HANDLER | ( | id | ) | PORT_FAST_IRQ_HANDLER(id) |
Standard fast IRQ handler declaration.
id can be a function name or a vector number depending on the port implementation. | #define NIL_IRQ_EPILOGUE | ( | ) | PORT_IRQ_EPILOGUE() |
IRQ handler exit code.
| #define NIL_IRQ_HANDLER | ( | id | ) | PORT_IRQ_HANDLER(id) |
Standard normal IRQ handler declaration.
id can be a function name or a vector number depending on the port implementation.| #define NIL_IRQ_PROLOGUE | ( | ) | PORT_IRQ_PROLOGUE() |
IRQ handler enter code.
| #define NIL_THREAD | ( | tname, | |
| arg | |||
| ) | PORT_THREAD(tname, arg) |
Thread declaration macro.
| #define nilSemInit | ( | sp, | |
| n | |||
| ) | ((sp)->cnt = n) |
Initializes a semaphore with the specified counter value.
| [out] | sp | pointer to a semaphore_t structure |
| [in] | n | initial value of the semaphore counter. Must be non-negative. |
| #define nilSemWait | ( | sp | ) | nilSemWaitTimeout(sp, TIME_INFINITE) |
Performs a wait operation on a semaphore.
| [in] | sp | pointer to a semaphore_t structure |
| NIL_MSG_OK | if the thread has not stopped on the semaphore or the semaphore has been signaled. |
| NIL_MSG_RST | if the semaphore has been reset using nilSemReset(). |
| #define nilSemWaitS | ( | sp | ) | nilSemWaitTimeoutS(sp, TIME_INFINITE) |
Performs a wait operation on a semaphore.
| [in] | sp | pointer to a semaphore_t structure |
| NIL_MSG_OK | if the thread has not stopped on the semaphore or the semaphore has been signaled. |
| NIL_MSG_RST | if the semaphore has been reset using nilSemReset(). |
| #define nilSysDisable | ( | ) | port_disable() |
Enters the kernel lock mode.
| #define nilSysEnable | ( | ) | port_enable() |
Enters the kernel lock mode.
| #define nilSysLock | ( | ) | port_lock() |
Enters the kernel lock mode.
| #define nilSysLockFromISR | ( | ) | port_lock_from_isr() |
Enters the kernel lock mode from within an interrupt handler.
| #define nilSysUnlock | ( | ) | port_unlock() |
Leaves the kernel lock mode.
| #define nilSysUnlockFromISR | ( | ) | port_unlock_from_isr() |
Leaves the kernel lock mode from within an interrupt handler.
| #define nilThdSleepMicroseconds | ( | usec | ) | nilThdSleep(US2ST(usec)) |
Delays the invoking thread for the specified number of microseconds.
| [in] | usec | time in microseconds, must be different from zero |
| #define nilThdSleepMilliseconds | ( | msec | ) | nilThdSleep(MS2ST(msec)) |
Delays the invoking thread for the specified number of milliseconds.
| [in] | msec | time in milliseconds, must be different from zero |
| #define nilThdSleepS | ( | timeout | ) | nilSchGoSleepTimeoutS(NIL_THD_SLEEPING, timeout) |
Suspends the invoking thread for the specified time.
| [in] | timeout | the delay in system ticks |
| #define nilThdSleepSeconds | ( | sec | ) | nilThdSleep(S2ST(sec)) |
Delays the invoking thread for the specified number of seconds.
| [in] | sec | time in seconds, must be different from zero |
| #define nilThdSleepUntilS | ( | time | ) | nilSchGoSleepTimeoutS(NIL_THD_SLEEPING, (time) - nilTimeNowI()) |
Suspends the invoking thread until the system time arrives to the specified value.
| [in] | time | absolute system time |
| #define nilTimeIsWithin | ( | time, | |
| start, | |||
| end | |||
| ) |
Checks if the specified time is within the specified time window.
| [in] | time | the time to be verified |
| [in] | start | the start of the time window (inclusive) |
| [in] | end | the end of the time window (non inclusive) |
| true | current time within the specified time window. |
| false | current time not within the specified time window. |
| #define nilTimeNowI | ( | ) | (nil.systime) |
Current system time.
Returns the number of system ticks since the nilSysInit() invocation.
nilThdSleepUntil().| #define S2ST | ( | sec | ) | ((systime_t)((sec) * NIL_CFG_FREQUENCY)) |
Seconds to system ticks.
Converts from seconds to system ticks number.
| [in] | sec | number of seconds |
| #define TIME_IMMEDIATE ((systime_t)-1) |
Zero time specification for some functions with a timeout specification.
TIME_IMMEDIATE as timeout parameter, see the specific function documentation. | #define US2ST | ( | usec | ) |
Microseconds to system ticks.
Converts from microseconds to system ticks number.
| [in] | usec | number of microseconds |
Puts the current thread to sleep into the specified state with timeout specification.
The thread goes into a sleeping state, if it is not awakened explicitly within the specified system time then it is forcibly awakened with a NIL_MSG_TMO low level message.
| [in] | newstate | the new thread state or a semaphore pointer |
| [in] | timeout | the number of ticks before the operation timeouts. the following special values are allowed:
|
| NIL_MSG_TMO | if a timeout occurred. |
| thread_ref_t nilSchReadyI | ( | thread_ref_t | tr, |
| msg_t | msg | ||
| ) |
Makes the specified thread ready for execution.
| [in] | tr | reference to the thread_t object |
| [in] | msg | the wakeup message |
| void nilSchRescheduleS | ( | ) |
Reschedules.
| void nilSemReset | ( | semaphore_t * | sp, |
| cnt_t | n | ||
| ) |
Performs a reset operation on the semaphore.
| [in] | sp | pointer to a semaphore_t structure |
| [in] | n | the new value of the semaphore counter. The value must be non-negative. |
| void nilSemResetI | ( | semaphore_t * | sp, |
| cnt_t | n | ||
| ) |
Performs a reset operation on the semaphore.
| [in] | sp | pointer to a semaphore_t structure |
| [in] | n | the new value of the semaphore counter. The value must be non-negative. |
| void nilSemSignal | ( | semaphore_t * | sp | ) |
Performs a signal operation on a semaphore.
| [in] | sp | pointer to a semaphore_t structure |
| void nilSemSignalI | ( | semaphore_t * | sp | ) |
Performs a signal operation on a semaphore.
| [in] | sp | pointer to a semaphore_t structure |
| msg_t nilSemWaitTimeout | ( | semaphore_t * | sp, |
| systime_t | timeout | ||
| ) |
Performs a wait operation on a semaphore with timeout specification.
| [in] | sp | pointer to a semaphore_t structure |
| [in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
| NIL_MSG_OK | if the thread has not stopped on the semaphore or the semaphore has been signaled. |
| NIL_MSG_RST | if the semaphore has been reset using nilSemReset(). |
| NIL_MSG_TMO | if the semaphore has not been signaled or reset within the specified timeout. |
| msg_t nilSemWaitTimeoutS | ( | semaphore_t * | sp, |
| systime_t | timeout | ||
| ) |
Performs a wait operation on a semaphore with timeout specification.
| [in] | sp | pointer to a semaphore_t structure |
| [in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
| NIL_MSG_OK | if the thread has not stopped on the semaphore or the semaphore has been signaled. |
| NIL_MSG_RST | if the semaphore has been reset using nilSemReset(). |
| NIL_MSG_TMO | if the semaphore has not been signaled or reset within the specified timeout. |
| void nilSysInit | ( | void | ) |
Initializes the kernel.
Initializes the kernel structures, the current instructions flow becomes the idle thread upon return. The idle thread must not invoke any kernel primitive able to change state to not runnable.
| void nilSysTimerHandlerI | ( | void | ) |
Time management handler.
| void nilThdResumeI | ( | thread_ref_t * | trp, |
| msg_t | msg | ||
| ) |
Wakes up a thread waiting on a thread reference object.
| [in] | trp | a pointer to a thread reference object |
| [in] | msg | the message code |
| void nilThdSleep | ( | systime_t | time | ) |
Suspends the invoking thread for the specified time.
| [in] | time | the delay in system ticks |
| void nilThdSleepUntil | ( | systime_t | time | ) |
Suspends the invoking thread until the system time arrives to the specified value.
| [in] | time | absolute system time |
| msg_t nilThdSuspendTimeoutS | ( | thread_ref_t * | trp, |
| systime_t | timeout | ||
| ) |
Sends the current thread sleeping and sets a reference variable.
| [in] | trp | a pointer to a thread reference object |
| [in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
| systime_t nilTimeNow | ( | void | ) |
Current system time.
Returns the number of system ticks since the nilSysInit() invocation.
nilThdSleepUntil().Checks if the current system time is within the specified time window.
| [in] | start | the start of the time window (inclusive) |
| [in] | end | the end of the time window (non inclusive) |
| true | current time within the specified time window. |
| false | current time not within the specified time window. |
1.8.6