-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.h
138 lines (106 loc) · 3.02 KB
/
kernel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef KERNEL_H
#define KERNEL_H
// Debug option
// #define _DEBUG
/*********************************************************/
/** Global variabels and definitions */
/*********************************************************/
#include <stdlib.h>
#ifdef texas_dsp
#define CONTEXT_SIZE (34 - 2)
#else
#define CONTEXT_SIZE 13
#define STACK_SIZE 100
#endif
#define TRUE 1
#define FALSE !TRUE
#define RUNNING 1
#define INIT !RUNNING
#define FAIL 0
#define SUCCESS 1
#define OK 1
#define DEADLINE_REACHED 0
#define NOT_EMPTY 0
#define SENDER +1
#define RECEIVER -1
typedef int exception;
typedef int bool;
typedef unsigned int uint;
typedef int action;
struct l_obj; // Forward declaration
// Task Control Block, TCB
#ifdef texas_dsp
typedef struct {
void (*PC)();
uint *SP;
uint Context[CONTEXT_SIZE];
uint StackSeg[STACK_SIZE];
uint DeadLine;
} TCB;
#else
typedef struct {
uint Context[CONTEXT_SIZE];
uint *SP;
void (*PC)();
uint SPSR;
uint StackSeg[STACK_SIZE];
uint DeadLine;
} TCB;
#endif
// Message items
typedef struct msgobj {
char *pData;
exception Status;
struct l_obj *pBlock;
struct msgobj *pPrevious;
struct msgobj *pNext;
} msg;
// Mailbox structure
typedef struct {
msg *pHead;
msg *pTail;
int nDataSize;
int nMaxMessages;
int nMessages;
int nBlockedMsg;
} mailbox;
// Generic list item
typedef struct l_obj {
TCB *pTask;
uint nTCnt;
msg *pMessage;
struct l_obj *pPrevious;
struct l_obj *pNext;
} listobj;
// Generic list
typedef struct {
listobj *pHead;
listobj *pTail;
} list;
// Function prototypes
// Task administration
int init_kernel(void);
exception create_task(void (*body)(), uint d);
void terminate(void);
void run(void);
// Communication
mailbox* create_mailbox( uint nMessages, uint nDataSize );
int no_messages( mailbox* mBox );
exception send_wait( mailbox* mBox, void* pData );
exception receive_wait( mailbox* mBox, void* pData );
exception send_no_wait( mailbox* mBox, void* pData );
int receive_no_wait( mailbox* mBox, void* pData );
// Timing
exception wait(uint nTicks);
void set_ticks( uint no_of_ticks );
uint ticks(void );
uint deadline(void);
void set_deadline(uint nNew);
//Interrupt
extern void isr_off(void);
extern void isr_on(void);
// Stores DSP registers in TCB pointed to by Running
extern void SaveContext(void);
// Restores DSP registers from TCB pointed to by Running
extern void LoadContext(void);
#endif