#ifndef _CONTEXT_H_ #define _CONTEXT_H_ #include #include "rtos/spinlock.h" struct register_context { uint32_t r0; uint32_t r1; uint32_t pc; uint32_t cpsr; uint32_t r2; uint32_t r3; uint32_t r4; uint32_t r5; uint32_t r6; uint32_t r7; uint32_t r8; uint32_t r9; uint32_t r10; uint32_t r11; uint32_t r12; uint32_t sp; uint32_t r14; }; enum ctx_state { CONTEXT_NULL = 0, CONTEXT_RUNNING = 1, CONTEXT_READY = 2, CONTEXT_INTERRUPTED = 3, CONTEXT_SLEEP = 4, CONTEXT_SLEEP_QUEUE = 5, }; struct context { /* regs *MUST* be first in struct! */ struct register_context regs; void *stack; uint8_t state; uint8_t priority; /* next pointers for run & sleep queues */ struct context *run_queue; struct context *sleep_queue; }; extern struct context *current_context; void isr_context_yield(void); void context_yield(void); uint8_t isr_context_wait(struct spinlock *lock); uint8_t context_wait(struct spinlock *lock); uint8_t context_wait_queue(struct spinlock *lock, struct context **queue); uint8_t context_wait_pri_queue(struct spinlock *lock, struct context **queue); void isr_context_signal(struct context *c); void context_signal(struct context *c); uint32_t context_signal_queue(struct context **queue); void isr_context_interrupt(struct context *c); void context_interrupt(struct context *c); uint32_t context_interrupt_queue(struct context *c, struct context **queue); struct context * create_ctx(uint32_t stacksize, uint8_t priority, void (* code)(void *arg), void *arg); void init_context(void); #endif /* _CONTEXT_H_ */