Roomba Tank
CSC 460 Project 3
os.h
Go to the documentation of this file.
1 #ifndef _OS_H_
2 #define _OS_H_
3 
4 #define MAXTHREAD 16
5 #define WORKSPACE 256
6 #define MAXMUTEX 8
7 #define MAXEVENT 8
8 #define MSECPERTICK 10
9 #define MINPRIORITY 10
12 #ifndef NULL
13 #define NULL 0
14 #endif
15 
16 #define Disable_Interrupt() asm volatile ("cli"::)
17 #define Enable_Interrupt() asm volatile ("sei"::)
18 
19 typedef void (*voidfuncptr) (void);
21 typedef unsigned int PID;
22 typedef unsigned int MUTEX;
23 typedef unsigned int PRIORITY;
24 typedef unsigned int EVENT;
25 typedef unsigned int TICK;
26 
30 typedef enum process_states {
31  DEAD = 0,
39 
43 typedef enum kernel_request_type {
44  NONE = 0,
58 
62 typedef enum mutex_state {
66 } MUTEX_STATE;
67 
72 typedef struct Mutex {
76  unsigned int lockCount;
77 } MTX;
78 
82 typedef enum event_state {
86 } EVENT_STATE;
87 
92 typedef struct Event {
95  PID p;
96 } EVT;
97 
103 typedef struct ProcessDescriptor {
105  unsigned char *sp; /* stack pointer into the "workSpace" */
106  unsigned char workSpace[WORKSPACE];
110  int arg;
111  voidfuncptr code; /* function to be executed as a task */
113  unsigned int response;
119  unsigned int suspended;
121 } PD;
122 
123 // void OS_Init(void); redefined as main()
124 void OS_Abort(void);
125 
126 PID Task_Create( void (*f)(void), PRIORITY py, int arg);
127 void Task_Terminate(void);
128 void Task_Next(void); // Same as yield
129 int Task_GetArg( PID p );
130 void Task_Suspend( PID p );
131 void Task_Resume( PID p );
132 
133 void Task_Sleep(TICK t); // sleep time is at least t*MSECPERTICK
134 
135 MUTEX Mutex_Init(void);
136 void Mutex_Lock(MUTEX m);
137 void Mutex_Unlock(MUTEX m);
138 
139 EVENT Event_Init(void);
140 void Event_Wait(EVENT e);
141 void Event_Signal(EVENT e);
142 
143 #endif /* _OS_H_ */
struct Mutex MTX
void Task_Sleep(TICK t)
Definition: os.c:779
Definition: os.h:44
Definition: os.h:54
mutex_state
Definition: os.h:62
Definition: os.h:37
void Event_Wait(EVENT e)
Definition: os.c:723
Definition: os.h:33
struct ProcessDescriptor PD
Definition: os.h:32
void OS_Abort(void)
Definition: os.c:667
PID pidAction
Definition: os.h:120
enum process_states PROCESS_STATES
EVENT e
Definition: os.h:93
Definition: os.h:47
enum mutex_state MUTEX_STATE
TICK wakeTick
Definition: os.h:115
enum kernel_request_type KERNEL_REQUEST_TYPE
void Task_Resume(PID p)
Definition: os.c:805
kernel_request_type
Definition: os.h:43
PRIORITY inheritedPy
Definition: os.h:109
Definition: os.h:46
PROCESS_STATES state
Definition: os.h:107
PID Task_Create(void(*f)(void), PRIORITY py, int arg)
Definition: os.c:747
int Task_GetArg(PID p)
Definition: os.c:829
MUTEX Mutex_Init(void)
Definition: os.c:674
unsigned int suspended
Definition: os.h:119
PRIORITY py
Definition: os.h:108
EVENT eWait
Definition: os.h:117
Definition: os.h:50
unsigned char * sp
Definition: os.h:105
unsigned int PID
Definition: os.h:21
EVENT Event_Init(void)
Definition: os.c:711
TICK wakeTickOverflow
Definition: os.h:114
Definition: os.h:52
Definition: os.h:48
MUTEX_STATE state
Definition: os.h:74
Definition: os.h:64
unsigned int MUTEX
Definition: os.h:22
Definition: os.h:63
unsigned int lockCount
Definition: os.h:76
MUTEX m
Definition: os.h:116
Definition: os.h:34
struct Event EVT
void Task_Suspend(PID p)
Definition: os.c:793
Definition: os.h:49
Definition: os.h:84
PID owner
Definition: os.h:75
PID p
Definition: os.h:95
unsigned int PRIORITY
Definition: os.h:23
void Task_Terminate(void)
Definition: os.c:817
process_states
Definition: os.h:30
Definition: os.h:65
unsigned int response
Definition: os.h:113
Definition: os.h:45
unsigned int TICK
Definition: os.h:25
EVENT eSend
Definition: os.h:118
Definition: os.h:85
void(* voidfuncptr)(void)
Definition: os.h:19
enum event_state EVENT_STATE
EVENT_STATE state
Definition: os.h:94
Definition: os.h:31
void Mutex_Lock(MUTEX m)
Definition: os.c:686
KERNEL_REQUEST_TYPE request
Definition: os.h:112
#define WORKSPACE
Definition: os.h:5
voidfuncptr code
Definition: os.h:111
unsigned int EVENT
Definition: os.h:24
Definition: os.h:92
void Event_Signal(EVENT e)
Definition: os.c:735
Definition: os.h:55
MUTEX m
Definition: os.h:73
Definition: os.h:51
void Mutex_Unlock(MUTEX m)
Definition: os.c:699
Definition: os.h:83
event_state
Definition: os.h:82
Definition: os.h:72
void Task_Next(void)
Definition: os.c:768