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: four LED tasks pass a baton to each other with stk::sync::EventFlags. More...

#include <stk.h>
#include <sync/stk_sync_eventflags.h>
#include "example.h"
Include dependency graph for blinky/example.cpp:

Go to the source code of this file.

Classes

class  MyTask< _AccessMode >

Enumerations

enum  { TASK_STACK_SIZE = 256 }

Functions

void RunExample ()

Variables

static const uint32_t FLAGS_ALL []
static stk::sync::EventFlags g_TaskFlags (FLAGS_ALL[LED_RED])
static stk::Ticks g_Timeline = 0

Detailed Description

Blinky: four LED tasks pass a baton to each other with stk::sync::EventFlags.

Definition in file blinky/example.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TASK_STACK_SIZE 

Definition at line 33 of file blinky/example.cpp.

33{ TASK_STACK_SIZE = 256 };
#define TASK_STACK_SIZE

Function Documentation

◆ RunExample()

void RunExample ( void )

Definition at line 98 of file blinky/example.cpp.

99{
100 using namespace stk;
101
102 Led::InitAll(false);
103
104 // operating in Static + Sync mode (EventFlags requires KERNEL_SYNC) and optionally tickless
105 const uint8_t KernelMode = KERNEL_STATIC | KERNEL_SYNC | (STK_TICKLESS_IDLE ? KERNEL_TICKLESS : 0);
106
107 // allocate scheduling kernel for 3 threads (tasks) with Round-Robin scheduling strategy
109
110 // note: using ACCESS_PRIVILEGED as Cortex-M3+ may not allow writing to GPIO from a less secure user thread
115
116 // init scheduling kernel
117 kernel.Initialize();
118
119 // register threads (tasks)
120 kernel.AddTask(&task1);
121 kernel.AddTask(&task2);
122 kernel.AddTask(&task3);
123 kernel.AddTask(&task4);
124
125 // start scheduler (it will start threads added by AddTask), execution in main() will be blocked on this line
126 kernel.Start();
127
128 // shall not reach here after Start() was called
129 STK_ASSERT(false);
130}
@ LED_ORANGE
Definition led.h:18
@ LED_GREEN
Definition led.h:17
@ LED_BLUE
Definition led.h:20
@ LED_RED
Definition led.h:19
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532
Namespace of STK package.
@ 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
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 void InitAll(bool init_state)
Definition led.h:40

References stk::Kernel< TMode, TSize, TStrategy, TPlatform >::AddTask(), bsp::Led::InitAll(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::Initialize(), stk::KERNEL_STATIC, stk::KERNEL_SYNC, stk::KERNEL_TICKLESS, LED_BLUE, LED_GREEN, LED_ORANGE, LED_RED, stk::Kernel< TMode, TSize, TStrategy, TPlatform >::Start(), and STK_ASSERT.

Here is the call graph for this function:

Variable Documentation

◆ FLAGS_ALL

const uint32_t FLAGS_ALL[]
static
Initial value:
= {
(1U << LED_RED),
(1U << LED_ORANGE),
(1U << LED_GREEN),
(1U << LED_BLUE)
}

Definition at line 37 of file blinky/example.cpp.

37 {
38 (1U << LED_RED),
39 (1U << LED_ORANGE),
40 (1U << LED_GREEN),
41 (1U << LED_BLUE)
42};

◆ g_TaskFlags

stk::sync::EventFlags g_TaskFlags(FLAGS_ALL[LED_RED]) ( FLAGS_ALL [LED_RED])
static

◆ g_Timeline

stk::Ticks g_Timeline = 0
static

Definition at line 48 of file blinky/example.cpp.