AKOS  v1.0.0
Documentation
Loading...
Searching...
No Matches
thread.h File Reference

Thread scheduling and thread messaging APIs. More...

#include <stdint.h>
#include <stddef.h>
#include "config.h"
#include "message.h"
Include dependency graph for thread.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  thread_t
 Static thread descriptor used during thread table registration. More...

Macros

#define AKOS_THREAD_DEFINE(_name, _id, _entry, _arg, _prio, _queue_size, _stack_size)

Typedefs

typedef struct thread_tcb * thread_handle_t
typedef void(* thread_func_t) (void *p_arg)
 Thread entry function signature.
typedef uint8_t thread_id_t
 Numeric thread identifier type.

Enumerations

enum  thread_state_t {
  THREAD_STATE_RUNNING = 0 , THREAD_STATE_READY , THREAD_STATE_DELAYED , THREAD_STATE_SUSPENDED ,
  THREAD_STATE_SUSPENDED_ON_MSG , THREAD_STATE_DELAYED_ON_MSG
}
 Runtime state of a thread control block. More...

Functions

uint32_t akos_thread_get_tick (void)
 Get current system tick.
void akos_thread_register_static_threads (void)
 Create all statically defined threads and kernel internal threads.
uint8_t akos_thread_get_app_thread_count (void)
 Get number of application threads defined via AKOS_THREAD_DEFINE.
uint8_t akos_thread_get_idle_thread_id (void)
 Get the runtime thread ID assigned to the idle thread.
uint8_t akos_thread_get_timer_thread_id (void)
 Get the runtime thread ID assigned to the timer thread.
uint8_t akos_thread_increment_tick (void)
 Tick handler routine called from SysTick.
void akos_thread_delay (const uint32_t tick_to_delay)
 Delay current thread by specified ticks.
void akos_thread_start (void)
 Start scheduler state.
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.
void akos_thread_post_msg_pure (uint8_t des_thread_id, int32_t sig)
 Post pure signal message to destination thread.
msg_t * akos_thread_wait_for_msg (uint32_t time_out)
 Wait for message from current thread queue.

Detailed Description

Thread scheduling and thread messaging APIs.

Author
Snoopy3921 - AK Foundation
Date
2026/05/08

Definition in file thread.h.

Macro Definition Documentation

◆ AKOS_THREAD_DEFINE

#define AKOS_THREAD_DEFINE ( _name,
_id,
_entry,
_arg,
_prio,
_queue_size,
_stack_size )
Value:
const thread_t _name __attribute__((used, section("task_desc"))) = { \
.id = (thread_id_t)(_id), \
.pf_thread = (thread_func_t)(_entry), \
.p_arg = (void *)(_arg), \
.prio = (uint8_t)(_prio), \
.queue_size = (size_t)(_queue_size), \
.stack_size = (size_t)(_stack_size), \
}
void(* thread_func_t)(void *p_arg)
Thread entry function signature.
Definition thread.h:59
uint8_t thread_id_t
Numeric thread identifier type.
Definition thread.h:65

Definition at line 27 of file thread.h.

Typedef Documentation

◆ thread_func_t

typedef void(* thread_func_t) (void *p_arg)

Thread entry function signature.

Parameters
p_argUser-provided thread argument.

Definition at line 59 of file thread.h.

◆ thread_handle_t

typedef struct thread_tcb* thread_handle_t

Opaque pointer to internal thread control block.

Definition at line 51 of file thread.h.

◆ thread_id_t

typedef uint8_t thread_id_t

Numeric thread identifier type.

Definition at line 65 of file thread.h.

Enumeration Type Documentation

◆ thread_state_t

Runtime state of a thread control block.

Enumerator
THREAD_STATE_RUNNING 

Currently executing thread.

THREAD_STATE_READY 

Ready to run, waiting for CPU.

THREAD_STATE_DELAYED 

Blocked until tick timeout expires.

THREAD_STATE_SUSPENDED 

Suspended explicitly by kernel/app logic.

THREAD_STATE_SUSPENDED_ON_MSG 

Waiting for message without timeout.

THREAD_STATE_DELAYED_ON_MSG 

Waiting for message with timeout.

Definition at line 41 of file thread.h.

Function Documentation

◆ akos_thread_delay()

void akos_thread_delay ( const uint32_t tick_to_delay)

Delay current thread by specified ticks.

Parameters
tick_to_delayDelay duration in ticks.

Delay current thread by specified ticks.

Parameters
tick_to_delayDelay in ticks.

Definition at line 541 of file thread.c.

◆ akos_thread_get_app_thread_count()

uint8_t akos_thread_get_app_thread_count ( void )

Get number of application threads defined via AKOS_THREAD_DEFINE.

Returns
Number of app threads linked into the image. App IDs are 0..count-1.

Definition at line 69 of file thread.c.

◆ akos_thread_get_idle_thread_id()

uint8_t akos_thread_get_idle_thread_id ( void )

Get the runtime thread ID assigned to the idle thread.

Returns
Idle thread ID.

Definition at line 74 of file thread.c.

◆ akos_thread_get_tick()

uint32_t akos_thread_get_tick ( void )

Get current system tick.

Returns
Tick counter.

Get current system tick.

Returns
Current tick value.

Definition at line 64 of file thread.c.

◆ akos_thread_get_timer_thread_id()

uint8_t akos_thread_get_timer_thread_id ( void )

Get the runtime thread ID assigned to the timer thread.

Returns
Timer thread ID.

Definition at line 79 of file thread.c.

◆ akos_thread_increment_tick()

uint8_t akos_thread_increment_tick ( void )

Tick handler routine called from SysTick.

Returns
OS_TRUE if context switch is needed, otherwise OS_FALSE.

Tick handler routine called from SysTick.

Returns
OS_TRUE if context switch is needed, otherwise OS_FALSE.

Definition at line 471 of file thread.c.

◆ akos_thread_post_msg_dynamic()

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.

Parameters
des_thread_idDestination thread ID.
sigMessage signal.
p_contentPayload pointer.
msg_sizePayload size in bytes.

Post dynamic message to destination thread.

Parameters
des_thread_idDestination thread ID.
sigMessage signal.
p_contentPayload pointer.
msg_sizePayload size in bytes.

Definition at line 571 of file thread.c.

◆ akos_thread_post_msg_pure()

void akos_thread_post_msg_pure ( uint8_t des_thread_id,
int32_t sig )

Post pure signal message to destination thread.

Parameters
des_thread_idDestination thread ID.
sigMessage signal.

Post pure signal message to destination thread.

Parameters
des_thread_idDestination thread ID.
sigMessage signal.

Definition at line 654 of file thread.c.

◆ akos_thread_register_static_threads()

void akos_thread_register_static_threads ( void )

Create all statically defined threads and kernel internal threads.

Create all statically defined threads and kernel internal threads.

Definition at line 402 of file thread.c.

◆ akos_thread_start()

void akos_thread_start ( void )

Start scheduler state.

Start scheduler state.

Definition at line 555 of file thread.c.

◆ akos_thread_wait_for_msg()

msg_t * akos_thread_wait_for_msg ( uint32_t time_out)

Wait for message from current thread queue.

Parameters
time_outTimeout in ticks. Use OS_CFG_DELAY_MAX for infinite wait.
Returns
Message pointer, or NULL on timeout.

Wait for message from current thread queue.

Parameters
time_outTimeout in ticks. Use OS_CFG_DELAY_MAX for infinite wait.
Returns
Message pointer, or NULL on timeout.

Definition at line 735 of file thread.c.