-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos.h
135 lines (115 loc) · 5.17 KB
/
os.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
// filename **********OS.H***********
// Real Time Operating System for Labs 2 and 3
// Jonathan W. Valvano 2/20/17, [email protected]
// EE445M/EE380L.6
// You may use, edit, run or distribute this file
// You are free to change the syntax/organization of this file
// You are required to implement the spirit of this OS
#ifndef _OS_H_
#define _OS_H_
// NVIC Defines
#define NVIC_EN0_INT21 0x00200000 // Interrupt 21 enable
#define NVIC_EN1_INT35 0x00000008
#define NVIC_EN2_INT70 0x00000040
// Edit these depending on your clock
#define TIME_1MS 80000
#define TIME_2MS (2 * TIME_1MS)
#define TIME_500US (TIME_1MS / 2)
#define TIME_250US (TIME_1MS / 5)
// ******** OS_Init ************
// initialize operating system, disable interrupts until OS_Launch
// initialize OS controlled I/O: serial, ADC, systick, LaunchPad I/O and timers
// input: none
// output: none
void OS_Init(void);
//******** OS_Launch ***************
// start the scheduler, enable interrupts
// Inputs: number of 12.5ns clock cycles for each time slice
// you may select the units of this parameter
// Outputs: none (does not return)
// In Lab 2, you can ignore the theTimeSlice field
// In Lab 3, you should implement the user-defined TimeSlice field
// It is ok to limit the range of theTimeSlice to match the 24-bit SysTick
void OS_Launch(unsigned long theTimeSlice);
// ******** OS_Suspend ************
// suspend execution of currently running thread
// scheduler will choose another thread to execute
// Can be used to implement cooperative multitasking
// Same function as OS_Sleep(0)
// input: none
// output: none
void OS_Suspend(void);
//******** OS_AddThreads ***************
// Test function that adds three foregound threads to the scheduler
// Inputs: three pointers to a void/void foreground tasks
// Outputs: 1 if successful, 0 if this thread can not be added
int OS_AddThreads(void(*task0)(void), void(*task1)(void), void(*task2)(void));
//******** OS_AddThread ***************
// add a foregound thread to the scheduler
// Inputs: pointer to a void/void foreground task
// number of bytes allocated for its stack
// priority, 0 is highest, 5 is the lowest
// Outputs: 1 if successful, 0 if this thread can not be added
// stack size must be divisable by 8 (aligned to double word boundary)
int OS_AddThread(void(*task)(void),
unsigned long stackSize, unsigned long priority);
//******** OS_Id ***************
// returns the thread ID for the currently running thread
// Inputs: none
// Outputs: Thread ID, number greater than zero
unsigned long OS_Id(void);
// ******** OS_Sleep ************
// place this thread into a dormant state
// input: number of msec to sleep
// output: none
// You are free to select the time resolution for this function
// OS_Sleep(0) implements cooperative multitasking
void OS_Sleep(unsigned long sleepTime);
// ******** OS_Kill ************
// kill the currently running thread, release its TCB and stack
// input: none
// output: none
void OS_Kill(void);
//******** OS_AddPeriodicThread ***************
// add a background periodic task
// typically this function receives the highest priority
// Inputs: pointer to a void/void background function
// period given in system time units (12.5ns)
// priority 0 is the highest, 5 is the lowest
// Outputs: 1 if successful, 0 if this thread can not be added
int OS_AddPeriodicThread(void(*task)(void), unsigned long period, unsigned long priority);
// ******** OS_Time ************
// return the system time
// Inputs: none
// Outputs: time in 12.5ns units, 0 to 4294967295
// The time resolution should be less than or equal to 1us, and the precision 32 bits
// It is ok to change the resolution and precision of this function as long as
// this function and OS_TimeDifference have the same resolution and precision
unsigned long OS_Time(void);
// ******** OS_TimeDifference ************
// Calculates difference between two times
// Inputs: two times measured with OS_Time
// Outputs: time difference in 12.5ns units
// The time resolution should be less than or equal to 1us, and the precision at least 12 bits
// It is ok to change the resolution and precision of this function as long as
// this function and OS_Time have the same resolution and precision
unsigned long OS_TimeDifference(unsigned long start, unsigned long stop);
// ******** OS_ClearMsTime ************
// sets the system time to zero (from Lab 1)
// Inputs: none
// Outputs: none
// You are free to change how this works
void OS_ClearMsTime(void);
// ******** OS_MsTime ************
// reads the current time in msec (from Lab 1)
// Inputs: none
// Outputs: time in ms units
// You are free to select the time resolution for this function
// It is ok to make the resolution to match the first call to OS_AddPeriodicThread
unsigned long OS_MsTime(void);
void Scheduler(void);
void InitTimer1A(unsigned long period, uint32_t priority);
void InitTimer2A(unsigned long period);
void InitTimer3A(void);
void InitTimer4A(uint32_t period, uint32_t priority);
#endif