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.c File Reference

SuperTinyKernel RTOS via Infineon abstraction-rtos API example program. More...

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "cyabs_rtos.h"
#include "cyabs_rtos_stk.h"
#include "RTE_Components.h"
#include "stk_config.h"
Include dependency graph for blinky_c-cyabs_rtos/example.c:

Go to the source code of this file.

Classes

struct  phases_t

Macros

#define STACK_SIZE   1024U /* bytes, per thread (>= CY_RTOS_MIN_STACK_SIZE) */
#define APP_PRIORITY   CY_RTOS_PRIORITY_NORMAL /* all threads share one priority */
#define FLAG_PHASE_A   0x0001UL /* wake-up bit of thread phaseA */
#define FLAG_PHASE_B   0x0002UL /* wake-up bit of thread phaseB */
#define FLAG_PHASE_C   0x0004UL /* wake-up bit of thread phaseC */
#define FLAG_PHASE_D   0x0008UL /* wake-up bit of thread phaseD */
#define FLAG_CLOCK   0x0100UL /* wake-up bit of thread clock */
#define APP_CHECK(call)
#define STACK_DECL(name)

Functions

static uint8_t stack_app_main[1024U] __attribute__ ((aligned(16)))
void Switch_On (unsigned char led)
void Switch_Off (unsigned char led)
static void wait_flag (uint32_t flag)
void signal_func (uint32_t next_flag)
void phaseA (cy_thread_arg_t argument)
void phaseB (cy_thread_arg_t argument)
void phaseC (cy_thread_arg_t argument)
void phaseD (cy_thread_arg_t argument)
void clock_thread (cy_thread_arg_t argument)
void app_main (cy_thread_arg_t argument)
static void app_init (void)
void app_run ()

Variables

cy_thread_t tid_app_main
cy_thread_t tid_phaseA
cy_thread_t tid_phaseB
cy_thread_t tid_phaseC
cy_thread_t tid_phaseD
cy_thread_t tid_clock
cy_event_t g_flags
struct phases_t g_phases

Detailed Description

SuperTinyKernel RTOS via Infineon abstraction-rtos API example program.

Definition in file blinky_c-cyabs_rtos/example.c.

Macro Definition Documentation

◆ APP_CHECK

#define APP_CHECK ( call)
Value:
do { if ((call) != CY_RSLT_SUCCESS) { for (;;) {} } } while (0)
Examples
blinky_c-cyabs_rtos/example.c.

Definition at line 50 of file blinky_c-cyabs_rtos/example.c.

Referenced by app_init(), and app_main().

◆ APP_PRIORITY

#define APP_PRIORITY   CY_RTOS_PRIORITY_NORMAL /* all threads share one priority */

◆ FLAG_CLOCK

#define FLAG_CLOCK   0x0100UL /* wake-up bit of thread clock */

◆ FLAG_PHASE_A

#define FLAG_PHASE_A   0x0001UL /* wake-up bit of thread phaseA */

◆ FLAG_PHASE_B

#define FLAG_PHASE_B   0x0002UL /* wake-up bit of thread phaseB */

◆ FLAG_PHASE_C

#define FLAG_PHASE_C   0x0004UL /* wake-up bit of thread phaseC */

◆ FLAG_PHASE_D

#define FLAG_PHASE_D   0x0008UL /* wake-up bit of thread phaseD */

◆ STACK_DECL

#define STACK_DECL ( name)
Value:
static uint8_t name[STACK_SIZE] __attribute__((aligned(16)))
static uint8_t stack_app_main[1024U] __attribute__((aligned(16)))
#define STACK_SIZE
Examples
blinky_c-cyabs_rtos/example.c.

Definition at line 63 of file blinky_c-cyabs_rtos/example.c.

◆ STACK_SIZE

Function Documentation

◆ __attribute__()

uint8_t stack_app_main[1024U] __attribute__ ( (aligned(16)) )
static

◆ app_init()

void app_init ( void )
static
Examples
blinky_c-cyabs_rtos/example.c.

Definition at line 215 of file blinky_c-cyabs_rtos/example.c.

215 {
217
218 /* Create application main thread */
221}
cy_rslt_t cy_rtos_event_init(cy_event_t *event)
cy_rslt_t cy_rtos_thread_create(cy_thread_t *thread, cy_thread_entry_fn_t entry_function, const char *name, void *stack, uint32_t stack_size, cy_thread_priority_t priority, cy_thread_arg_t arg)
void app_main(void *argument)
cy_event_t g_flags
#define APP_PRIORITY
cy_thread_t tid_app_main
#define APP_CHECK(call)
static ULONG stack_app_main[1024U/sizeof(ULONG)]

References APP_CHECK, app_main(), APP_PRIORITY, cy_rtos_event_init(), cy_rtos_thread_create(), g_flags, stack_app_main, STACK_SIZE, and tid_app_main.

Referenced by app_run(), and cy_rtos_stk_kernel_enter().

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

◆ app_main()

void app_main ( cy_thread_arg_t argument)

Definition at line 189 of file blinky_c-cyabs_rtos/example.c.

189 {
190 (void)argument;
191
202
203 cy_rtos_event_setbits(&g_flags, FLAG_PHASE_A); /* set signal to phaseA thread */
204
205 /* sleep forever (osWaitForever): nobody sends a notification to this thread */
207}
#define CY_RTOS_NEVER_TIMEOUT
Definition cyabs_rtos.h:77
cy_rslt_t cy_rtos_event_setbits(const cy_event_t *event, uint32_t bits)
cy_rslt_t cy_rtos_thread_wait_notification(cy_time_t timeout_ms)
void phaseD(void *argument)
osThreadId_t tid_phaseC
void phaseA(void *argument)
osThreadId_t tid_phaseB
void phaseC(void *argument)
osThreadId_t tid_clock
osThreadId_t tid_phaseD
void phaseB(void *argument)
osThreadId_t tid_phaseA
void clock_thread(cy_thread_arg_t argument)
#define FLAG_PHASE_A
static ULONG stack_phaseC[1024U/sizeof(ULONG)]
static ULONG stack_clock[1024U/sizeof(ULONG)]
static ULONG stack_phaseB[1024U/sizeof(ULONG)]
static ULONG stack_phaseD[1024U/sizeof(ULONG)]
static ULONG stack_phaseA[1024U/sizeof(ULONG)]

References APP_CHECK, APP_PRIORITY, clock_thread(), cy_rtos_event_setbits(), CY_RTOS_NEVER_TIMEOUT, cy_rtos_thread_create(), cy_rtos_thread_wait_notification(), FLAG_PHASE_A, g_flags, phaseA(), phaseB(), phaseC(), phaseD(), stack_clock, stack_phaseA, stack_phaseB, stack_phaseC, stack_phaseD, STACK_SIZE, tid_clock, tid_phaseA, tid_phaseB, tid_phaseC, and tid_phaseD.

Here is the call graph for this function:

◆ app_run()

void app_run ( )

Definition at line 224 of file blinky_c-cyabs_rtos/example.c.

228{
229 // System Initialization
230 SystemCoreClockUpdate();
231
232 // Init LEDs
233 Led_InitAll(false);
234
235 // ...
236
237 (void)cy_rtos_stk_kernel_enter(app_init); // Start STK kernel (does not return)
238
239 while(1);
240}
void Led_InitAll(bool state)
Definition c_wrapper.cpp:27
cy_rslt_t cy_rtos_stk_kernel_enter(void(*app_init)(void))
static void app_init(void)

References app_init(), cy_rtos_stk_kernel_enter(), and Led_InitAll().

Here is the call graph for this function:

◆ clock_thread()

void clock_thread ( cy_thread_arg_t argument)
Examples
blinky_c-cyabs_rtos/example.c, and blinky_c-threadx/example.c.

Definition at line 178 of file blinky_c-cyabs_rtos/example.c.

178 {
179 (void)argument;
180 for (;;) {
181 wait_flag(FLAG_CLOCK); /* wait for an event flag */
182 cy_rtos_delay_milliseconds(80); /* delay 80ms */
183 }
184}
cy_rslt_t cy_rtos_delay_milliseconds(cy_time_t num_ms)
static void wait_flag(uint32_t flag)
#define FLAG_CLOCK

References cy_rtos_delay_milliseconds(), FLAG_CLOCK, and wait_flag().

Referenced by app_main(), and app_main().

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

◆ phaseA()

void phaseA ( cy_thread_arg_t argument)

Definition at line 118 of file blinky_c-cyabs_rtos/example.c.

118 {
119 (void)argument;
120 for (;;) {
121 wait_flag(FLAG_PHASE_A); /* wait for an event flag */
122 Switch_On(0);
123 g_phases.phaseA = 1;
124 signal_func(FLAG_PHASE_B); /* call common signal function */
125 g_phases.phaseA = 0;
126 Switch_Off(0);
127 }
128}
void Switch_Off(unsigned char led)
void Switch_On(unsigned char led)
struct phases_t g_phases
void signal_func(osThreadId_t tid)
#define FLAG_PHASE_B

References FLAG_PHASE_A, FLAG_PHASE_B, g_phases, signal_func(), Switch_Off(), Switch_On(), and wait_flag().

Here is the call graph for this function:

◆ phaseB()

void phaseB ( cy_thread_arg_t argument)

Definition at line 133 of file blinky_c-cyabs_rtos/example.c.

133 {
134 (void)argument;
135 for (;;) {
136 wait_flag(FLAG_PHASE_B); /* wait for an event flag */
137 Switch_On(1);
138 g_phases.phaseB = 1;
139 signal_func(FLAG_PHASE_C); /* call common signal function */
140 g_phases.phaseB = 0;
141 Switch_Off(1);
142 }
143}
#define FLAG_PHASE_C

References FLAG_PHASE_B, FLAG_PHASE_C, g_phases, signal_func(), Switch_Off(), Switch_On(), and wait_flag().

Here is the call graph for this function:

◆ phaseC()

void phaseC ( cy_thread_arg_t argument)

Definition at line 148 of file blinky_c-cyabs_rtos/example.c.

148 {
149 (void)argument;
150 for (;;) {
151 wait_flag(FLAG_PHASE_C); /* wait for an event flag */
152 Switch_On(2);
153 g_phases.phaseC = 1;
154 signal_func(FLAG_PHASE_D); /* call common signal function */
155 g_phases.phaseC = 0;
156 Switch_Off(2);
157 }
158}
#define FLAG_PHASE_D

References FLAG_PHASE_C, FLAG_PHASE_D, g_phases, signal_func(), Switch_Off(), Switch_On(), and wait_flag().

Here is the call graph for this function:

◆ phaseD()

void phaseD ( cy_thread_arg_t argument)

Definition at line 163 of file blinky_c-cyabs_rtos/example.c.

163 {
164 (void)argument;
165 for (;;) {
166 wait_flag(FLAG_PHASE_D); /* wait for an event flag */
167 Switch_On(3);
168 g_phases.phaseD = 1;
169 signal_func(FLAG_PHASE_A); /* call common signal function */
170 g_phases.phaseD = 0;
171 Switch_Off(3);
172 }
173}

References FLAG_PHASE_A, FLAG_PHASE_D, g_phases, signal_func(), Switch_Off(), Switch_On(), and wait_flag().

Here is the call graph for this function:

◆ signal_func()

void signal_func ( uint32_t next_flag)

Definition at line 106 of file blinky_c-cyabs_rtos/example.c.

106 {
107 cy_rtos_event_setbits(&g_flags, FLAG_CLOCK); /* set signal to clock thread */
108 cy_rtos_delay_milliseconds(500); /* delay 500ms */
109 cy_rtos_event_setbits(&g_flags, FLAG_CLOCK); /* set signal to clock thread */
110 cy_rtos_delay_milliseconds(500); /* delay 500ms */
111 cy_rtos_event_setbits(&g_flags, next_flag); /* set signal to next thread */
112 cy_rtos_delay_milliseconds(500); /* delay 500ms */
113}

References cy_rtos_delay_milliseconds(), cy_rtos_event_setbits(), FLAG_CLOCK, and g_flags.

Here is the call graph for this function:

◆ Switch_Off()

void Switch_Off ( unsigned char led)

Definition at line 89 of file blinky_c-cyabs_rtos/example.c.

89 {
90 //printf("LED Off: #%d\n", led);
91 Led_Set((LedId)led, false);
92}
void Led_Set(LedId led, bool state)
Definition c_wrapper.cpp:22
LedId
Definition led.h:16

References Led_Set().

Here is the call graph for this function:

◆ Switch_On()

void Switch_On ( unsigned char led)

Definition at line 81 of file blinky_c-cyabs_rtos/example.c.

81 {
82 //printf("LED On: #%d\n", led);
83 Led_Set((LedId)led, true);
84}

References Led_Set().

Here is the call graph for this function:

◆ wait_flag()

void wait_flag ( uint32_t flag)
static
Examples
blinky_c-cyabs_rtos/example.c, and blinky_c-threadx/example.c.

Definition at line 97 of file blinky_c-cyabs_rtos/example.c.

97 {
98 uint32_t bits = flag; /* in: bits to wait for, out: flags */
99 (void)cy_rtos_event_waitbits(&g_flags, &bits, true /* clear */, false /* any */,
101}
cy_rslt_t cy_rtos_event_waitbits(const cy_event_t *event, uint32_t *bits, bool clear, bool all, cy_time_t timeout_ms)

References cy_rtos_event_waitbits(), CY_RTOS_NEVER_TIMEOUT, and g_flags.

Referenced by clock_thread(), clock_thread(), phaseA(), phaseA(), phaseB(), phaseB(), phaseC(), phaseC(), phaseD(), and phaseD().

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

Variable Documentation

◆ g_flags

◆ g_phases

struct phases_t g_phases

◆ tid_app_main

◆ tid_clock

cy_thread_t tid_clock

Definition at line 58 of file blinky_c-cyabs_rtos/example.c.

◆ tid_phaseA

cy_thread_t tid_phaseA

Definition at line 54 of file blinky_c-cyabs_rtos/example.c.

◆ tid_phaseB

cy_thread_t tid_phaseB

Definition at line 55 of file blinky_c-cyabs_rtos/example.c.

◆ tid_phaseC

cy_thread_t tid_phaseC

Definition at line 56 of file blinky_c-cyabs_rtos/example.c.

◆ tid_phaseD

cy_thread_t tid_phaseD

Definition at line 57 of file blinky_c-cyabs_rtos/example.c.