|
BRISCITS
0.1
RISC "Real-Time" Scheduler
|
#include <cpu.h>#include <stdint.h>#include <stddef.h>#include <stdbool.h>Go to the source code of this file.
Data Structures | |
| struct | brisc_thread |
Macros | |
| #define | BRISC_THREAD_MAX 8 |
| #define | BRISC_THREAD_NAME_MAX 8 |
| #define | BRISC_THREAD_PRIO_INVALID (-1) |
| #define | BRISC_THREAD_PRIO_SUSPEND (0) |
| #define | BRISC_THREAD_PRIO_MIN (1) |
| #define | BRISC_THREAD_PRIO_MAX (127) |
| #define | brisc_systick_t uint32_t |
| #define | b_int_enabled() cpu_int_enabled() |
| #define | b_int_enable() cpu_int_enable() |
| #define | b_int_disable() cpu_int_disable() |
| #define | b_int_set(s) cpu_int_set((s)) |
| #define | b_atomic_acquire(s) cpu_atomic_acquire((s)) |
| #define | b_atomic_release(s) cpu_atomic_release((s)) |
| #define | b_wfi() cpu_wfi(); |
| #define | b_thread_block_while(cond) while((cond)) b_thread_yield() |
| Block while a condition exists. More... | |
| #define | b_thread_prio_clear() (brisc_scheduler_state.prio = 0) |
| Clears the current thread's priority, effective causing the thread to yield the remainder of it's slices upon the next scheduler run. More... | |
Functions | |
| struct brisc_thread | __attribute__ ((aligned(8))) |
| 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... | |
| 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... | |
| 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_stop (int id) |
| Stop a thread. The thread remains active in the run queue, yet receives no run time. 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... | |
| 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) |
| void | b_thread_yield (void) |
| Yield the remainder of the current thread's time slice(s). More... | |
| brisc_systick_t | b_thread_systick (void) |
| volatile brisc_thread_t * | b_thread_current (void) |
| 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... | |
Variables | |
| char | name [BRISC_THREAD_NAME_MAX+1] |
| int8_t | prio |
| cpu_state_t * | cpu_state |
| #define b_atomic_acquire | ( | s | ) | cpu_atomic_acquire((s)) |
Atomic acquire a lock
Definition at line 174 of file brisc_thread.h.
| #define b_atomic_release | ( | s | ) | cpu_atomic_release((s)) |
Atomic release a lock
Definition at line 175 of file brisc_thread.h.
| #define b_int_disable | ( | ) | cpu_int_disable() |
CPU global interrupt disable
Definition at line 171 of file brisc_thread.h.
| #define b_int_enable | ( | ) | cpu_int_enable() |
CPU global interrupt enable
Definition at line 170 of file brisc_thread.h.
| #define b_int_enabled | ( | ) | cpu_int_enabled() |
Definition at line 169 of file brisc_thread.h.
| #define b_int_set | ( | s | ) | cpu_int_set((s)) |
CPU global set state
Definition at line 172 of file brisc_thread.h.
| #define b_thread_block_while | ( | cond | ) | while((cond)) b_thread_yield() |
Block while a condition exists.
| cond | An expression that can resolve to a bool. |
Definition at line 183 of file brisc_thread.h.
| #define b_thread_prio_clear | ( | ) | (brisc_scheduler_state.prio = 0) |
Clears the current thread's priority, effective causing the thread to yield the remainder of it's slices upon the next scheduler run.
Definition at line 189 of file brisc_thread.h.
| #define b_wfi | ( | ) | cpu_wfi(); |
CPU wait for interrupt
Definition at line 177 of file brisc_thread.h.
| #define brisc_systick_t uint32_t |
Definition at line 160 of file brisc_thread.h.
| #define BRISC_THREAD_MAX 8 |
Maximum number of threads
Definition at line 148 of file brisc_thread.h.
| #define BRISC_THREAD_NAME_MAX 8 |
Maximum characters in the name of a thread
Definition at line 152 of file brisc_thread.h.
| #define BRISC_THREAD_PRIO_INVALID (-1) |
Thread is invalid (initial state)
Definition at line 155 of file brisc_thread.h.
| #define BRISC_THREAD_PRIO_MAX (127) |
Maximum thread priority
Definition at line 158 of file brisc_thread.h.
| #define BRISC_THREAD_PRIO_MIN (1) |
Minimum thread priority
Definition at line 157 of file brisc_thread.h.
| #define BRISC_THREAD_PRIO_SUSPEND (0) |
Thread is active, but suspended
Definition at line 156 of file brisc_thread.h.
| struct brisc_thread __attribute__ | ( | (aligned(8)) | ) |
| 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.
| name | A human readable name for the thread. |
| thread_fn | A pointer to the entry point of the thread function. |
| arg | This pointer will be passed as a parameter to the thread function. |
| stack | Pointer to the base of the thread's program stack space on an even cpu_reg_t word boundary. |
| n_stack_words | The number of cpu_reg_t words contained in the stack space. |
Definition at line 98 of file brisc_thread.c.
| volatile brisc_thread_t* b_thread_current | ( | void | ) |
| 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.
| name | An 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 | ) |
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.
| id | The thread handle. |
| prio | The thread priority -1 .. 127 |
Definition at line 132 of file brisc_thread.c.
| void b_thread_set_systick_fn | ( | void(*)(void) | systick_fn | ) |
| void b_thread_set_yield_fn | ( | void(*)(void) | yield_fn | ) |
| 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().
| id | Thread 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.
| id | Thread descriptor. |
Definition at line 67 of file brisc_thread.c.
| brisc_systick_t b_thread_systick | ( | void | ) |
| void b_thread_unlock | ( | void | ) |
| 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.
| cpu_state_t* cpu_state |
Definition at line 90 of file brisc_thread.h.
| char name[BRISC_THREAD_NAME_MAX+1] |
Definition at line 88 of file brisc_thread.h.
| int8_t prio |
Definition at line 89 of file brisc_thread.h.
1.8.11