Skip to content

Commit 924fecb

Browse files
committed
Expose new generic sync::Pipe class via C API.
Improve C API user manual.
1 parent 303e2d2 commit 924fecb

7 files changed

Lines changed: 1085 additions & 111 deletions

File tree

build/example/blinky_c/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define STACK_SIZE 256
1717

1818
static volatile uint8_t g_TaskSwitch = 0;
19-
static uint32_t g_Stack[STK_C_KERNEL_MAX_TASKS][STACK_SIZE] __stk_c_stack_attr;
19+
static uint32_t g_Stack[STK_C_KERNEL_MAX_TASKS][STACK_SIZE] __stk_c_stack;
2020

2121
static void InitLeds()
2222
{

build/example/project/eclipse/rpi/sync_c-rp2350w/.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
<type>2</type>
9696
<locationURI>virtual:/virtual</locationURI>
9797
</link>
98+
<link>
99+
<name>src/driver/c_wrapper.cpp</name>
100+
<type>1</type>
101+
<locationURI>PARENT-4-PROJECT_LOC/driver/c_wrapper.cpp</locationURI>
102+
</link>
98103
<link>
99104
<name>src/driver/cpu.h</name>
100105
<type>1</type>

build/example/sync_c/example.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,12 @@ typedef enum LedState {
4141
LED_ON
4242
} LedState;
4343

44-
// Memory containers for sync primitives (static allocation)
44+
// Pointers to synchronization primitives
4545
#if STK_EXAMPLE_USE_PIPE
46-
static stk_pipe_mem_t g_PipeMem;
4746
static stk_pipe_t *g_CtrlSignalPipe;
4847
#else
49-
static stk_event_mem_t g_EvRdyMem, g_EvOnMem, g_EvOffMem;
5048
static stk_event_t *g_EventReady, *g_EventSwitchOn, *g_EventSwitchOff;
5149
#endif
52-
53-
static stk_mutex_mem_t g_HwMtxMem;
5450
static stk_mutex_t *g_HwMutex;
5551

5652
// ─────────────────────────────────────────────────────────────────────────────
@@ -65,10 +61,8 @@ static void LedTask_Run(void *arg)
6561
while (true)
6662
{
6763
#if STK_EXAMPLE_USE_PIPE
68-
size_t pipe_val;
69-
if (!stk_pipe_read(g_CtrlSignalPipe, &pipe_val, 100))
64+
if (!stk_pipe_read(g_CtrlSignalPipe, &task_id, 100))
7065
continue;
71-
task_id = (LedState)pipe_val;
7266
#else
7367
switch (task_id)
7468
{
@@ -121,7 +115,8 @@ static void CtrlTask_Run(void *arg)
121115
task_start = stk_time_now_ms();
122116

123117
#if STK_EXAMPLE_USE_PIPE
124-
stk_pipe_write(g_CtrlSignalPipe, led_sw ? LED_ON : LED_OFF, STK_WAIT_INFINITE);
118+
LedState new_state = led_sw ? LED_ON : LED_OFF;
119+
stk_pipe_write(g_CtrlSignalPipe, &new_state, STK_WAIT_INFINITE);
125120
#else
126121
if (led_sw)
127122
stk_event_set(g_EventSwitchOn);
@@ -142,11 +137,21 @@ static void InitLeds()
142137

143138
static void InitSync()
144139
{
145-
// init Mutex
140+
// Memory containers for sync primitives (static allocation)
141+
static stk_mutex_mem_t g_HwMtxMem;
142+
#if STK_EXAMPLE_USE_PIPE
143+
static stk_pipe_mem_t g_PipeMem;
144+
static LedState s_PipeBuf[16] __stk_c_aligned;
145+
#else
146+
static stk_event_mem_t g_EvRdyMem, g_EvOnMem, g_EvOffMem;
147+
#endif
148+
146149
g_HwMutex = stk_mutex_create(&g_HwMtxMem, sizeof(g_HwMtxMem));
147150

148151
#if STK_EXAMPLE_USE_PIPE
149-
g_CtrlSignalPipe = stk_pipe_create(&g_PipeMem, sizeof(g_PipeMem));
152+
g_CtrlSignalPipe = stk_pipe_create(&g_PipeMem, sizeof(g_PipeMem),
153+
s_PipeBuf, sizeof(s_PipeBuf),
154+
16, sizeof(LedState));
150155
#else
151156
g_EventReady = stk_event_create(&g_EvRdyMem, sizeof(g_EvRdyMem), false);
152157
g_EventSwitchOn = stk_event_create(&g_EvOnMem, sizeof(g_EvOnMem), false);
@@ -156,11 +161,11 @@ static void InitSync()
156161

157162
#if STK_EXAMPLE_DUALCORE
158163

159-
static size_t g_StackCore0_T1[TASK_STACK_SIZE] __stk_c_stack_attr;
164+
static size_t g_StackCore0_T1[TASK_STACK_SIZE] __stk_c_stack;
160165
#if !STK_EXAMPLE_USE_PIPE
161-
static size_t g_StackCore0_T2[TASK_STACK_SIZE] __stk_c_stack_attr;
166+
static size_t g_StackCore0_T2[TASK_STACK_SIZE] __stk_c_stack;
162167
#endif
163-
static size_t g_StackCore1_T1[TASK_STACK_SIZE] __stk_c_stack_attr;
168+
static size_t g_StackCore1_T1[TASK_STACK_SIZE] __stk_c_stack;
164169

165170
void StartCore0()
166171
{

0 commit comments

Comments
 (0)