BRISCITS  0.1
RISC "Real-Time" Scheduler
Functions
brisc_thread.c File Reference
#include <brisc_thread.h>
#include <brisc_sched.h>
#include <string.h>

Go to the source code of this file.

Functions

int b_thread_init (const char *name)
 Called by the "main()" thread, initializes briscits and inserts an entry in the thread table for the "main()" thread. More...
 
void b_thread_set_systick_fn (void(*systick_fn)(void))
 Insert a callback on systick interrupt. More...
 
void b_thread_set_yield_fn (void(*yield_fn)(void))
 Insert a callback on yield interrupt. More...
 
brisc_systick_t b_thread_systick (void)
 
void b_thread_stop (int id)
 Stop a thread. The thread remains active in the run queue, yet receives no run time. More...
 
void b_thread_start (int id)
 Start a thread with the default priority of BRISC_THREAD_PRIO_MIN. TO start thread with other priority, start thread using b_thread_set_prio(). More...
 
void b_thread_lock (void)
 Lock the scheduler such that the current thread will nut yield until thread_unlock() is called. More...
 
void b_thread_unlock (void)
 Unlock the current thread (see thread_lock()) More...
 
void b_thread_yield (void)
 Yield the remainder of the current thread's time slice(s). More...
 
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. More...
 
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 of contiguous time slices the thread is allowed to get. More...
 
int8_t b_thread_priority (int id)
 
volatile brisc_thread_t * b_thread_current (void)
 

Function Documentation

int b_thread_create ( const char *  name,
void(*)(void *)  thread_fn,
void *  arg,
cpu_reg_t *  stack,
size_t  n_stack_words 
)

Allocate a new thread in the run queue.


Parameters
nameA human readable name for the thread.
thread_fnA pointer to the entry point of the thread function.
argThis pointer will be passed as a parameter to the thread function.
stackPointer to the base of the thread's program stack space on an even cpu_reg_t word boundary.
n_stack_wordsThe number of cpu_reg_t words contained in the stack space.
Returns
a valid thread descriptor >= 0, or < 0 on failure (not enogh thread slots BRISC_THREAD_MAX).

Definition at line 98 of file brisc_thread.c.

volatile brisc_thread_t* b_thread_current ( void  )

Returns
a pointer to the current thread context.

Definition at line 167 of file brisc_thread.c.

int b_thread_init ( const char *  name)

Called by the "main()" thread, initializes briscits and inserts an entry in the thread table for the "main()" thread.


Parameters
nameAn ASCII name for the thread (ex. "main").

Definition at line 41 of file brisc_thread.c.

void b_thread_lock ( void  )

Lock the scheduler such that the current thread will nut yield until thread_unlock() is called.


Definition at line 77 of file brisc_thread.c.

int8_t b_thread_priority ( int  id)

Returns
Given a thread descriptor, return the corresponding thread prority or return BRISC_THREAD_PRIO_INVALID if descriptor is invalid.

Definition at line 143 of file brisc_thread.c.

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 of contiguous time slices the thread is allowed to get.


Parameters
idThe thread handle.
prioThe thread priority -1 .. 127
Returns
< 0 on failure

Definition at line 132 of file brisc_thread.c.

void b_thread_set_systick_fn ( void(*)(void)  systick_fn)

Insert a callback on systick interrupt.


Definition at line 51 of file brisc_thread.c.

void b_thread_set_yield_fn ( void(*)(void)  yield_fn)

Insert a callback on yield interrupt.


Definition at line 56 of file brisc_thread.c.

void b_thread_start ( int  id)

Start a thread with the default priority of BRISC_THREAD_PRIO_MIN. TO start thread with other priority, start thread using b_thread_set_prio().


Parameters
idThread descriptor.

Definition at line 72 of file brisc_thread.c.

void b_thread_stop ( int  id)

Stop a thread. The thread remains active in the run queue, yet receives no run time.


Parameters
idThread descriptor.

Definition at line 67 of file brisc_thread.c.

brisc_systick_t b_thread_systick ( void  )

Returns
the value of the systick counter.

Definition at line 62 of file brisc_thread.c.

void b_thread_unlock ( void  )

Unlock the current thread (see thread_lock())


Definition at line 82 of file brisc_thread.c.

void b_thread_yield ( void  )

Yield the remainder of the current thread's time slice(s).


Definition at line 87 of file brisc_thread.c.