AKOS  v1.0.0
Documentation
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/****************************************************************************/
12
13#ifndef THREAD_H
14#define THREAD_H
15
16#ifdef __cplusplus
17extern "C"
18{
19#endif
20
21#include <stdint.h>
22#include <stddef.h>
23#include "config.h"
24
25#include "message.h"
26
27#if (OS_CFG_USE_SHELL != 0u)
28#define AKOS_THREAD_NAME_INIT(_name) .name = #_name,
29#else
30#define AKOS_THREAD_NAME_INIT(_name)
31#endif
32
33#define AKOS_THREAD_DEFINE(_name, _id, _entry, _arg, _prio, _queue_size, _stack_size) \
34 const thread_t _name __attribute__((used, section("task_desc"))) = { \
35 AKOS_THREAD_NAME_INIT(_name) \
36 .id = (thread_id_t)(_id), \
37 .pf_thread = (thread_func_t)(_entry), \
38 .p_arg = (void *)(_arg), \
39 .prio = (uint8_t)(_prio), \
40 .queue_size = (size_t)(_queue_size), \
41 .stack_size = (size_t)(_stack_size), \
42 }
43
57
58 typedef struct thread_tcb *thread_handle_t;
59 typedef struct thread thread_t;
60
66 typedef void (*thread_func_t)(void *p_arg);
67
72 typedef uint8_t thread_id_t;
73
74 typedef struct
75 {
76#if (OS_CFG_USE_SHELL != 0u)
77 const char *name;
78#endif
79 thread_id_t id;
80 uint8_t prio;
81 uint32_t run_ticks;
83
88 struct thread
89 {
90#if (OS_CFG_USE_SHELL != 0u)
91 const char *name;
92#endif
95 void *p_arg;
96 uint8_t prio;
97 size_t queue_size;
98 size_t stack_size;
99 };
100
105 uint32_t akos_thread_get_tick(void);
106
111
117
122 uint8_t akos_thread_get_idle_thread_id(void);
123
129
135
140 uint8_t akos_thread_increment_tick(void);
141
146 void akos_thread_delay(const uint32_t tick_to_delay);
147
151 void akos_thread_start(void);
152
160 void akos_thread_post_msg_dynamic(uint8_t des_thread_id, int32_t sig, void *p_content, uint8_t msg_size);
161
167 void akos_thread_post_msg_pure(uint8_t des_thread_id, int32_t sig);
168
174 msg_t *akos_thread_wait_for_msg(uint32_t time_out);
175
181 void akos_thread_get_runtime_totals(uint32_t *p_idle_ticks, uint32_t *p_total_ticks);
182
187 uint8_t akos_thread_get_runtime_count(void);
188
194 void akos_thread_get_runtime_snapshot(uint8_t index, thread_runtime_snapshot_t *p_snapshot);
195
196#ifdef __cplusplus
197}
198#endif
199#endif /* THREAD_H */
Build-time configuration macros for AK-mOS.
Message object and message queue APIs.
Static thread descriptor used during thread table registration.
Definition thread.h:89
size_t queue_size
Definition thread.h:97
size_t stack_size
Definition thread.h:98
thread_id_t id
Definition thread.h:93
thread_func_t pf_thread
Definition thread.h:94
void * p_arg
Definition thread.h:95
uint8_t prio
Definition thread.h:96
msg_t * akos_thread_wait_for_msg(uint32_t time_out)
Wait for message from current thread queue.
Definition thread.c:937
uint8_t akos_thread_get_timer_thread_id(void)
Get the runtime thread ID assigned to the timer thread.
Definition thread.c:86
void akos_thread_register_static_threads(void)
Create all statically defined threads and kernel internal threads.
Definition thread.c:455
uint8_t akos_thread_get_runtime_count(void)
Get number of runtime thread slots, including internal threads.
Definition thread.c:702
uint32_t akos_thread_get_tick(void)
Get current system tick.
Definition thread.c:66
void akos_thread_start(void)
Start scheduler state.
Definition thread.c:650
uint8_t akos_thread_increment_tick(void)
Tick handler routine called from SysTick.
Definition thread.c:560
uint8_t akos_thread_get_app_thread_count(void)
Get number of application threads defined via AKOS_THREAD_DEFINE.
Definition thread.c:71
void(* thread_func_t)(void *p_arg)
Thread entry function signature.
Definition thread.h:66
void akos_thread_get_runtime_totals(uint32_t *p_idle_ticks, uint32_t *p_total_ticks)
Snapshot accumulated runtime counters.
Definition thread.c:665
void akos_thread_delay(const uint32_t tick_to_delay)
Delay current thread by specified ticks.
Definition thread.c:636
void akos_thread_post_msg_dynamic(uint8_t des_thread_id, int32_t sig, void *p_content, uint8_t msg_size)
Post dynamic message to destination thread.
Definition thread.c:761
uint8_t akos_thread_get_shell_thread_id(void)
Get the runtime thread ID assigned to the shell thread.
Definition thread.c:81
thread_state_t
Runtime state of a thread control block.
Definition thread.h:49
@ THREAD_STATE_READY
Definition thread.h:51
@ THREAD_STATE_DELAYED
Definition thread.h:52
@ THREAD_STATE_RUNNING
Definition thread.h:50
@ THREAD_STATE_DELAYED_ON_MSG
Definition thread.h:55
@ THREAD_STATE_SUSPENDED
Definition thread.h:53
@ THREAD_STATE_SUSPENDED_ON_MSG
Definition thread.h:54
uint8_t akos_thread_get_idle_thread_id(void)
Get the runtime thread ID assigned to the idle thread.
Definition thread.c:76
uint8_t thread_id_t
Numeric thread identifier type.
Definition thread.h:72
void akos_thread_post_msg_pure(uint8_t des_thread_id, int32_t sig)
Post pure signal message to destination thread.
Definition thread.c:850
void akos_thread_get_runtime_snapshot(uint8_t index, thread_runtime_snapshot_t *p_snapshot)
Snapshot one runtime thread slot by index.
Definition thread.c:707
struct thread_tcb * thread_handle_t
Definition thread.h:58