sam7fc/include/rtos/context.h

71 lines
1.5 KiB
C
Raw Normal View History

2008-02-23 00:25:31 +01:00
#ifndef _CONTEXT_H_
#define _CONTEXT_H_
#include <stdint.h>
#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,
2008-02-23 00:25:31 +01:00
};
struct context {
/* regs *MUST* be first in struct! */
struct register_context regs;
2008-02-29 15:33:56 +01:00
void *stack;
uint8_t state;
2008-02-23 00:25:31 +01:00
uint8_t priority;
/* next pointers for run & sleep queues */
struct context *run_queue;
struct context *sleep_queue;
2008-02-23 00:25:31 +01:00
};
extern struct context *current_context;
2008-02-25 18:16:42 +01:00
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);
2008-02-23 00:25:31 +01:00
uint32_t context_signal_queue(struct context **queue);
void isr_context_interrupt(struct context *c);
void context_interrupt(struct context *c);
2008-02-23 00:25:31 +01:00
uint32_t context_interrupt_queue(struct context *c, struct context **queue);
2008-02-25 18:16:42 +01:00
struct context * create_ctx(uint32_t stacksize, uint8_t priority, void (* code)(void *arg), void *arg);
void init_context(void);
2008-02-23 00:25:31 +01:00
#endif /* _CONTEXT_H_ */