SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
Scheduler

Typedefs

typedef enum cy_scheduler_state cy_scheduler_state_t

Enumerations

enum  cy_scheduler_state {
  CY_SCHEDULER_STATE_NOT_STARTED ,
  CY_SCHEDULER_STATE_INACTIVE ,
  CY_SCHEDULER_STATE_LOCKED ,
  CY_SCHEDULER_STATE_READY ,
  CY_SCHEDULER_STATE_SUSPENDED ,
  CY_SCHEDULER_STATE_RUNNING ,
  CY_SCHEDULER_STATE_UNKNOWN
}
cy_rslt_t cy_rtos_scheduler_suspend (void)
cy_rslt_t cy_rtos_scheduler_resume (void)
cy_rslt_t cy_rtos_scheduler_get_state (cy_scheduler_state_t *state)

Detailed Description

APIs for working with Scheduler.

Typedef Documentation

◆ cy_scheduler_state_t

The state a scheduler can be in

Enumeration Type Documentation

◆ cy_scheduler_state

The state a scheduler can be in

Enumerator
CY_SCHEDULER_STATE_NOT_STARTED 

Scheduler has not started

CY_SCHEDULER_STATE_INACTIVE 

Scheduler is not ready yet

CY_SCHEDULER_STATE_LOCKED 

Scheduler is locked

CY_SCHEDULER_STATE_READY 

Scheduler is ready but not running

CY_SCHEDULER_STATE_SUSPENDED 

Scheduler has been suspended

CY_SCHEDULER_STATE_RUNNING 

Scheduler is currently running

CY_SCHEDULER_STATE_UNKNOWN 

An error occurred

Definition at line 145 of file cyabs_rtos.h.

146{
enum cy_scheduler_state cy_scheduler_state_t
@ CY_SCHEDULER_STATE_UNKNOWN
Definition cyabs_rtos.h:153
@ CY_SCHEDULER_STATE_RUNNING
Definition cyabs_rtos.h:152
@ CY_SCHEDULER_STATE_INACTIVE
Definition cyabs_rtos.h:148
@ CY_SCHEDULER_STATE_LOCKED
Definition cyabs_rtos.h:149
@ CY_SCHEDULER_STATE_NOT_STARTED
Definition cyabs_rtos.h:147
@ CY_SCHEDULER_STATE_SUSPENDED
Definition cyabs_rtos.h:151
@ CY_SCHEDULER_STATE_READY
Definition cyabs_rtos.h:150

Function Documentation

◆ cy_rtos_scheduler_get_state()

cy_rslt_t cy_rtos_scheduler_get_state ( cy_scheduler_state_t * state)

Gets the state the scheduler is currently in

This function is called to determine if the scheduler is running/suspend/not started.

Parameters
[out]stateReturns the state the scheduler is currently in
Returns
The status of the scheduler state check. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM].

Definition at line 814 of file cyabs_rtos_stk.cpp.

815{
816 if (state == nullptr)
817 {
818 return CY_RTOS_BAD_PARAM;
819 }
820
821 switch (KState())
822 {
825 *state = ((g_SuspendCount != 0U) ? CY_SCHEDULER_STATE_SUSPENDED : CY_SCHEDULER_STATE_NOT_STARTED);
826 break;
830 break;
832 default:
834 break;
835 }
836
837 return CY_RSLT_SUCCESS;
838}
#define CY_RTOS_BAD_PARAM
Definition cyabs_rtos.h:96
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
@ KSTATE_LOCKED
Running, but task switching is disabled with IKernelService::LockScheduler(). Ticks,...
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
@ KSTATE_READY
Ready to start, IKernel::Start() must be called.

References CY_RTOS_BAD_PARAM, CY_SCHEDULER_STATE_NOT_STARTED, CY_SCHEDULER_STATE_RUNNING, CY_SCHEDULER_STATE_SUSPENDED, stk::IKernel::KSTATE_INACTIVE, stk::IKernel::KSTATE_LOCKED, stk::IKernel::KSTATE_READY, stk::IKernel::KSTATE_RUNNING, and stk::IKernel::KSTATE_SUSPENDED.

◆ cy_rtos_scheduler_resume()

cy_rslt_t cy_rtos_scheduler_resume ( void )

Resume the scheduler

This function resumes the scheduler after it was suspended. If incorrectly called (called more times than cy_rtos_scheduler_suspend) it fails returning CY_RTOS_BAD_PARAM

Returns
The status of scheduler resume request. Same across all RTOS kernels [CY_RSLT_SUCCESS, CY_RTOS_BAD_PARAM].

Definition at line 799 of file cyabs_rtos_stk.cpp.

800{
801 if (g_SuspendCount == 0U)
802 {
803 return CY_RTOS_BAD_PARAM;
804 }
805
806 if ((--g_SuspendCount == 0U) && (KState() == stk::IKernel::KSTATE_LOCKED))
807 {
808 (void)stk::UnlockScheduler();
809 }
810
811 return CY_RSLT_SUCCESS;
812}
static ELockResult UnlockScheduler()
Enable task switching (equivalent of CMSIS-RTOS2 osKernelUnlock).
Definition stk_helper.h:611

References CY_RTOS_BAD_PARAM, stk::IKernel::KSTATE_LOCKED, and stk::UnlockScheduler().

Here is the call graph for this function:

◆ cy_rtos_scheduler_suspend()

cy_rslt_t cy_rtos_scheduler_suspend ( void )

Suspend the scheduler

This function suspends the scheduler and makes sure that the code executed after the call does not get interrupted by a task switch. Multiple suspend calls can be done making nesting possible granted that the same number of resume calls are made.

Note
API functions that have the potential to cause a context switch must not be called while the scheduler is suspended.
Returns
The status of scheduler suspend request. Same across all RTOS kernels [CY_RSLT_SUCCESS].
Specific for kernel:

< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())

< not allowed in this context (ISR, scheduler not running or locked, not a thread created by cy_rtos_thread_create())

Definition at line 774 of file cyabs_rtos_stk.cpp.

775{
776 if (InIsr())
777 {
778 return Fail(CY_RTOS_STK_ERR_CONTEXT);
779 }
780
781 const stk::IKernel::EKernelState st = KState();
782
783 // before Start() nothing is switched: only the nesting is recorded
785 {
787
788 if ((lr != stk::LOCK_WAS_UNLOCKED) && (lr != stk::LOCK_WAS_LOCKED))
789 {
790 return Fail(CY_RTOS_STK_ERR_CONTEXT);
791 }
792 }
793
794 ++g_SuspendCount;
795
796 return CY_RSLT_SUCCESS;
797}
#define CY_RTOS_STK_ERR_CONTEXT
static ELockResult LockScheduler()
Disable task switching (equivalent of CMSIS-RTOS2 osKernelLock). Ticks, timeouts and ISRs keep runnin...
Definition stk_helper.h:600
ELockResult
Result of IKernel::SetSchedulerLock(), IKernelService::LockScheduler(), UnlockScheduler() and Restore...
Definition stk_common.h:161
@ LOCK_WAS_UNLOCKED
LockScheduler/UnlockScheduler: previous state was unlocked. RestoreSchedulerLock: now unlocked.
Definition stk_common.h:164
@ LOCK_WAS_LOCKED
LockScheduler/UnlockScheduler: previous state was locked. RestoreSchedulerLock: now locked.
Definition stk_common.h:165
EKernelState
Kernel state.

References CY_RTOS_STK_ERR_CONTEXT, stk::IKernel::KSTATE_LOCKED, stk::IKernel::KSTATE_RUNNING, stk::LOCK_WAS_LOCKED, stk::LOCK_WAS_UNLOCKED, and stk::LockScheduler().

Here is the call graph for this function: