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
example.cpp File Reference

Blinky with a control task and LED tasks communicating over pipes and an event. More...

#include <stk.h>
#include "example.h"
#include <sync/stk_sync_pipe.h>
#include <sync/stk_sync_event.h>
Include dependency graph for blinky_mc/example.cpp:

Go to the source code of this file.

Classes

class  LedTask< _Priority, _AccessMode >
class  CtrlTask< _AccessMode >

Enumerations

enum  LedState : uint8_t {
  LED_OFF = 0 ,
  LED_ON = 1
}
enum  { TASK_STACK_SIZE = 256 }

Functions

void StartCore0 ()
void StartCore1 ()
void RunExample ()

Variables

static stk::sync::PipeT< LedState, 1 > g_PipeOff
static stk::sync::PipeT< LedState, 1 > g_PipeOn
static stk::sync::Event g_WakeCtrl

Detailed Description

Blinky with a control task and LED tasks communicating over pipes and an event.

Definition in file blinky_mc/example.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TASK_STACK_SIZE 

Definition at line 84 of file blinky_mc/example.cpp.

84{ TASK_STACK_SIZE = 256 };
#define TASK_STACK_SIZE

◆ LedState

enum LedState : uint8_t
Enumerator
LED_OFF 
LED_ON 
Examples
blinky_mc/example.cpp, sync/example.cpp, and sync_c/example.c.

Definition at line 30 of file blinky_mc/example.cpp.

31{
32 LED_OFF = 0,
33 LED_ON = 1
34};

Function Documentation

◆ RunExample()

void RunExample ( void )

Definition at line 170 of file blinky_mc/example.cpp.

171{
172 Led::InitAll(false);
173
174 // start on the main core (0) in the last step as it will be the last blocking call of RunExample
177
178 // shall not reach here after Start() was called
179 STK_ASSERT(false);
180}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532
static void Start(uint8_t cpu_id, void(*entry_func)(void))
Definition cpu.cpp:24
static void InitAll(bool init_state)
Definition led.h:40
void StartCore1()
void StartCore0()

References bsp::Led::InitAll(), bsp::Cpu::Start(), StartCore0(), StartCore1(), and STK_ASSERT.

Here is the call graph for this function:

◆ StartCore0()

void StartCore0 ( )
Examples
blinky_mc/example.cpp, sync/example.cpp, and sync_c/example.c.

Definition at line 120 of file blinky_mc/example.cpp.

121{
122 using namespace stk;
123
124 // allocate scheduling kernel for 1 thread (tasks) with Round-robin scheduling strategy
126
127 // these are secure/trusted tasks which are allowed to access hardware safely
128 static LedTask<ACCESS_PRIVILEGED> secure_hw_task0(LED_OFF, g_PipeOff);
129 static LedTask<ACCESS_PRIVILEGED> secure_hw_task1(LED_ON, g_PipeOn);
130
131 // init scheduling kernel
132 kernel.Initialize();
133
134 // register threads (tasks)
135 kernel.AddTask(&secure_hw_task0);
136 kernel.AddTask(&secure_hw_task1);
137
138 // start scheduler (it will start threads added by AddTask), execution in main() will be blocked on this line
139 kernel.Start();
140
141 // shall not reach here after Start() was called
142 STK_ASSERT(false);
143}
Namespace of STK package.
Concrete implementation of IKernel.
Definition stk.h:102
void Start() override
Start the scheduler. This call does not return until all tasks have exited (KERNEL_DYNAMIC mode) or i...
Definition stk.h:1999
EAddResult AddTask(ITask *user_task) override
Register task for a soft real-time (SRT) scheduling.
Definition stk.h:1465
void Initialize(uint32_t resolution_us=PERIODICITY_DEFAULT) override
Initialize kernel.
Definition stk.h:1425
static stk::sync::PipeT< LedState, 1 > g_PipeOn
static stk::sync::PipeT< LedState, 1 > g_PipeOff

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::AddTask(), g_PipeOff, g_PipeOn, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::Initialize(), LED_OFF, LED_ON, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::Start(), and STK_ASSERT.

Referenced by RunExample().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartCore1()

void StartCore1 ( )
Examples
blinky_mc/example.cpp, sync/example.cpp, and sync_c/example.c.

Definition at line 145 of file blinky_mc/example.cpp.

146{
147 using namespace stk;
148
149 // allocate scheduling kernel for 1 thread (tasks) with Round-robin scheduling strategy
150 static Kernel<KERNEL_STATIC | KERNEL_SYNC | (STK_TICKLESS_IDLE ? KERNEL_TICKLESS : 0), 1,
152
153 // if MCU supports (for example Cortex-M7/M33), ACCESS_USER does not allow an access to a hardware directly,
154 // therefore you can process in this thread/task an insecure context or data
155 static CtrlTask<ACCESS_USER> unsecure_task;
156
157 // init scheduling kernel
158 kernel.Initialize();
159
160 // register threads (tasks)
161 kernel.AddTask(&unsecure_task);
162
163 // start scheduler (it will start threads added by AddTask), execution in main() will be blocked on this line
164 kernel.Start();
165
166 // shall not reach here after Start() was called
167 STK_ASSERT(false);
168}
PlatformArmCortexM PlatformDefault
Default platform implementation.
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
Definition stk_common.h:51
@ KERNEL_SYNC
Synchronization support (see Event).
Definition stk_common.h:50
@ KERNEL_STATIC
All tasks are static and can not exit.
Definition stk_common.h:47
SwitchStrategyRoundRobinT< false > SwitchStrategyRoundRobin
Shorthand alias for SwitchStrategyRoundRobinT<>.

References stk::KERNEL_STATIC, stk::KERNEL_SYNC, stk::KERNEL_TICKLESS, and STK_ASSERT.

Referenced by RunExample().

Here is the caller graph for this function:

Variable Documentation

◆ g_PipeOff

stk::sync::PipeT<LedState, 1> g_PipeOff
static
Examples
blinky_mc/example.cpp.

Definition at line 39 of file blinky_mc/example.cpp.

Referenced by CtrlTask< _AccessMode >::Run(), and StartCore0().

◆ g_PipeOn

stk::sync::PipeT<LedState, 1> g_PipeOn
static
Examples
blinky_mc/example.cpp.

Definition at line 40 of file blinky_mc/example.cpp.

Referenced by CtrlTask< _AccessMode >::Run(), and StartCore0().

◆ g_WakeCtrl

stk::sync::Event g_WakeCtrl
static
Examples
blinky_mc/example.cpp.

Definition at line 45 of file blinky_mc/example.cpp.

Referenced by CtrlTask< _AccessMode >::Run().