-
Notifications
You must be signed in to change notification settings - Fork 4
/
rtx.h
236 lines (185 loc) · 4.95 KB
/
rtx.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#ifndef RTX_H
#define RTX_H
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include <ucontext.h>
#include "kbcrt.h"
// *** CONSTANTS ***
#define SIZE 2048
#define STACKSIZE 50000 // size of stack pointer
#define TOTAL_NUM_PROC 5 //total number of processes, will change
#define TOTAL_NUM_IPROC 3 //total number of i-processes
#define TIMERIPROCPID 2
#define ON 1
#define OFF 0
// *** STRUCTS ***
struct msgenv {
struct msgenv *p; //pointer to the next env in the queue this env resides in
int sender_id;
int target_id;
int msg_type; //type and text are char pointers, which are essentially arrays<- WRONG NOW
char* msg_text; //we can call a location of the pointer and it will work like an array
};
typedef struct msgenv msg_env;
struct envQ{
msg_env* head;
msg_env* tail;
};
typedef struct envQ env_Q;
struct pcb {
struct pcb *p; // pointer to next PCB in the queue that this PCB resides in
int state;
int pid;
int priority;
//void* PC;
//char *SP;
ucontext_t uc;
env_Q *receive_msg_Q;
//jmp_buf pcb_buf;
int process_type;
//int atom;
};
typedef struct pcb PCB; //use PCB
struct pcbq{
PCB* head;
PCB* tail;
};
typedef struct pcbq PCB_Q;
struct clock{
int ss;
int mm;
int hh;
};
typedef struct clock clk;
struct messageTrace {
int sender_id;
int target_id;
int msg_type;
clk timestamp;
};
typedef struct messageTrace msg_trace;
struct init_table {
int pid;
int priority;
//int stack_size;
int process_type;
//void* address;
};
typedef struct init_table init_table;
// *** FUNCTION DECLARATIONS ***
void cleanup();
// PROCESSES
void kbd_iproc(int sigval);
void crt_iproc(int sigval);
void timer_iproc(int sigval);
void ProcessA();
void ProcessB();
void ProcessC();
void CCI();
void null_process();
// PRIMITIVES
int PCB_ENQ(PCB* r, PCB_Q* queue);
PCB* PCB_DEQ(PCB_Q* queue);
PCB *PCB_REMOVE(PCB_Q *q, int id);
int env_ENQ(msg_env* e, env_Q* queue);
msg_env* env_DEQ(env_Q *queue);
msg_env *env_REMOVE(env_Q *q, int senderid);
int send_message (int dest_id, msg_env* e);
int k_send_message (int dest_id, msg_env* e);
msg_env* receive_message();
msg_env* k_receive_message();
int send_console_chars(msg_env* env);
int k_send_console_chars(msg_env* env);
int get_console_chars(msg_env* env);
int k_get_console_chars(msg_env* env);
void terminate(int signal);
int get_trace_buffers(msg_env* env);
int k_get_trace_buffers(msg_env* env);
int change_priority (int new_priority, int target_process_id);
int k_change_priority (int new_priority, int target_process_id);
msg_env *k_request_msg_env();
msg_env *request_msg_env();
int k_release_msg_env(msg_env *env);
int release_msg_env(msg_env *env);
int request_process_status(msg_env *env);
int k_request_process_status(msg_env *env);
void release_processor();
void k_release_processor();
int request_delay(int time_delay, int wakeup_code, msg_env *m);
int k_request_delay(int time_delay, int wakeup_code, msg_env *m);
void process_switch();
void context_switch(jmp_buf previous, jmp_buf next);
void atomic_off();
void atomic_on();
void atomic(int a);
void clock_increment(clk* clock, int system_or_wall);
int clock_set(clk* clock, int hours, int minutes, int seconds);
int clock_out(clk* clock);
PCB* convert_PID(int PID);
PCB_Q* convert_priority(int pri);
void ClockTest(clk *clock);
// INITIALIZATION FUNCTIONS
PCB_Q* create_Q( );
env_Q* create_env_Q( );
int init_clocks();
int init_queues( );
int init_msg_trace();
int init_env( );
int init_processes( );
int init_i_processes( );
void kb_crt_start();
void begin_RTX( );
// *** VARIABLES ***
PCB* pointer_2_PCB[TOTAL_NUM_PROC + TOTAL_NUM_IPROC]; //array of pointers to processes
PCB_Q* pointer_2_RPQ[4]; //array of pointers to ready process queues
PCB* curr_process;
clk* systemclock;
clk* wallclock; //Global Clock Variables
int wallClockOut;
msg_trace send_trace[16]; //went with arrays instead of queues
msg_trace receive_trace[16];
int send_start; // indeces for the arrays
int send_end;
int receive_start;
int receive_end;
int send_counter;
int receive_counter; //the only way I can think of setting up circular array
int Atom;
static int pulse_counter; //Dummy Pulse Counter
int alarmstatus;
ucontext_t mainuc;
// QUEUES
PCB_Q* ready_q_priority0;
PCB_Q* ready_q_priority1;
PCB_Q* ready_q_priority2;
PCB_Q* ready_q_priority3;
env_Q* sleep_Q;
PCB_Q* blocked_on_envelope;
PCB_Q* blocked_on_receive;
env_Q* envelope_q;
// STATES
#define RUNNING 0
#define READY 1
#define BLK_ON_ENV 2
#define BLK_ON_RCV 3
#define SLEEP 4
// Message Type
#define CONSOLE_INPUT 0
#define DISPLAY_ACK 1
#define COUNT_REPORT 2
#define NO_TYPE 3
#define WAKEUP 4
#define TRACE_BUFFER 5
#define PROCESS_STATUS 6
#endif