38 static int thread_new_id(
void );
39 static void thread_exit (
void );
92 static void thread_exit(
void )
98 int b_thread_create(
const char*
name,
void (*thread_fn)(
void*),
void* arg, cpu_reg_t* stack,
size_t n_stack_words )
100 int id = thread_new_id();
104 if ( thread_fn == NULL && stack == NULL )
111 uint8_t* stack_uint8 = (uint8_t*)stack;
114 cpu_state_t*
cpu_state = (cpu_state_t*) &stack_uint8 [ (n_stack_words*
sizeof(cpu_reg_t)) -
sizeof(cpu_state_t) ];
115 memset( cpu_state, 0,
sizeof(cpu_state_t) );
117 cpu_state->reg.x[CPU_A0_XREG] = (cpu_reg_t)arg;
118 cpu_state->reg.x[CPU_RA_XREG] = (cpu_reg_t)thread_exit;
119 cpu_state->reg.x[CPU_PC_XREG] = (cpu_reg_t)thread_fn;
120 cpu_set_initial_state(cpu_state);
154 static int thread_new_id(
void )
int b_thread_set_prio(int id, int8_t prio)
set a thread priority. < 0 is inactive, = 0 is active but suspended. > 0 indicates the maximum number...
char name[BRISC_THREAD_NAME_MAX+1]
void b_thread_lock(void)
Lock the scheduler such that the current thread will nut yield until thread_unlock() is called...
volatile brisc_thread_t * b_thread_current(void)
brisc_systick_t b_thread_systick(void)
void b_thread_set_systick_fn(void(*systick_fn)(void))
Insert a callback on systick interrupt.
void b_thread_start(int id)
Start a thread with the default priority of BRISC_THREAD_PRIO_MIN. TO start thread with other priorit...
#define BRISC_THREAD_NAME_MAX
#define BRISC_THREAD_PRIO_INVALID
volatile brisc_scheduler_t brisc_scheduler_state
void b_thread_stop(int id)
Stop a thread. The thread remains active in the run queue, yet receives no run time.
void b_thread_set_yield_fn(void(*yield_fn)(void))
Insert a callback on yield interrupt.
#define BRISC_THREAD_PRIO_MIN
void b_thread_yield(void)
Yield the remainder of the current thread's time slice(s).
#define BRISC_THREAD_PRIO_SUSPEND
int b_thread_create(const char *name, void(*thread_fn)(void *), void *arg, cpu_reg_t *stack, size_t n_stack_words)
Allocate a new thread in the run queue.
void b_thread_unlock(void)
Unlock the current thread (see thread_lock())
volatile brisc_thread_t * b_thread_state(uint8_t id)
int8_t b_thread_priority(int id)
int b_thread_init(const char *name)
Called by the "main()" thread, initializes briscits and inserts an entry in the thread table for the ...