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

Thread-local storage (TLS) and per-task semaphores. More...

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

Go to the source code of this file.

Classes

struct  MyTls
class  MyTask< _AccessMode >

Enumerations

enum  { TASK_STACK_SIZE = 256 }

Functions

static void SwitchOnLED ()
void RunExample ()

Variables

static stk::sync::Semaphore g_Sem0 (1)
static stk::sync::Semaphore g_Sem1 (0)
static stk::sync::Semaphore g_Sem2 (0)
static stk::sync::Semaphore g_Sem3 (0)
static stk::sync::Semaphore *const g_Sem [LED_MAX]
static stk::Ticks g_Timeline = 0

Detailed Description

Thread-local storage (TLS) and per-task semaphores.

Definition in file tls/example.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TASK_STACK_SIZE 

Definition at line 71 of file tls/example.cpp.

71{ TASK_STACK_SIZE = 256 };
#define TASK_STACK_SIZE

Function Documentation

◆ RunExample()

void RunExample ( void )

Definition at line 122 of file tls/example.cpp.

123{
124 using namespace stk;
125
126 Led::InitAll(false);
127
128 // allocate scheduling kernel for 4 threads (tasks) with Round-robin scheduling strategy
129 static Kernel<KERNEL_STATIC | KERNEL_SYNC | (STK_TICKLESS_IDLE ? KERNEL_TICKLESS : 0), 4,
131
132 // note: using ACCESS_PRIVILEGED as Cortex-M7 or Cortex-M33 may require privileged access to peripherals
137
138 // init scheduling kernel
139 kernel.Initialize();
140
141 // register threads (tasks)
142 kernel.AddTask(&task1);
143 kernel.AddTask(&task2);
144 kernel.AddTask(&task3);
145 kernel.AddTask(&task4);
146
147 // start scheduler (it will start threads added by AddTask), execution in main() will be blocked on this line
148 kernel.Start();
149
150 // shall not reach here after Start() was called
151 STK_ASSERT(false);
152}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532
Namespace of STK package.
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 > SwitchStrategyRR
Shorthand alias for SwitchStrategyRoundRobin.
Concrete implementation of IKernel.
Definition stk.h:102
static void InitAll(bool init_state)
Definition led.h:40

References bsp::Led::InitAll(), stk::KERNEL_STATIC, stk::KERNEL_SYNC, stk::KERNEL_TICKLESS, and STK_ASSERT.

Referenced by main().

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

◆ SwitchOnLED()

void SwitchOnLED ( )
static
Examples
/tls/example.cpp, and low_power/example.cpp.

Definition at line 59 of file tls/example.cpp.

60{
61 // for demonstration purpose we get task_id from our TLS and switch on corresponding LED
62 Led::Id led = stk::hw::GetTlsPtr<MyTls>()->led;
63
65}
LedId Id
Definition led.h:32
static void SwitchOnExclusive(Id led)
Definition led.h:48

References bsp::Led::SwitchOnExclusive().

Referenced by LedTask< _Priority, _AccessMode >::Run(), and MyTask< _AccessMode >::Run().

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

Variable Documentation

◆ g_Sem

stk::sync::Semaphore* const g_Sem[LED_MAX]
static
Initial value:
=
{
}
static stk::sync::Semaphore g_Sem1(0)
static stk::sync::Semaphore g_Sem3(0)
static stk::sync::Semaphore g_Sem2(0)
static stk::sync::Semaphore g_Sem0(1)
Examples
/tls/example.cpp.

Definition at line 44 of file tls/example.cpp.

45{
47};

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

◆ g_Sem0

stk::sync::Semaphore g_Sem0(1) ( 1 )
static
Examples
/tls/example.cpp.

◆ g_Sem1

stk::sync::Semaphore g_Sem1(0) ( 0 )
static
Examples
/tls/example.cpp.

◆ g_Sem2

stk::sync::Semaphore g_Sem2(0) ( 0 )
static
Examples
/tls/example.cpp.

◆ g_Sem3

stk::sync::Semaphore g_Sem3(0) ( 0 )
static
Examples
/tls/example.cpp.

◆ g_Timeline

stk::Ticks g_Timeline = 0
static