Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1670 pj 1
#include "kernel/kern.h"
2
#include "modules/intdrive.h"
3
#include "modules/rm.h"
4
#include "modules/cbs.h"
5
#include "modules/rr.h"
6
#include "modules/dummy.h"
7
 
8
#include "modules/sem.h"
9
#include "modules/hartport.h"
10
#include "hlp.h"
11
//#include "modules/srp.h"
12
//#include "modules/pi.h"
13
//#include "modules/npp.h"
14
 
15
#include <drivers/shark_linuxc26.h>
16
#include <drivers/shark_pci26.h>
17
#include <drivers/shark_input26.h>
18
#include <drivers/shark_keyb26.h>
19
#include <drivers/shark_fb26.h>
20
 
21
#include "ll/i386/x-dos.h"
22
 
23
#define FRAME_BUFFER_DEVICE 0
24
 
25
/*+ system tick in us +*/
26
#define TICK 1
27
 
28
/*+ RR tick in us +*/
29
#define RRTICK 10000
30
 
31
/*+ Interrupt Server +*/
32
#define INTDRIVE_Q 1000
33
#define INTDRIVE_T 10000
34
#define INTDRIVE_FLAG 0
35
 
36
void call_shutdown_task(void *arg);
37
int device_drivers_init();
38
int device_drivers_close();
39
void set_shutdown_task();
40
TASK shutdown_task_body(void *arg);
41
 
42
PID shutdown_task_PID = -1;
43
 
44
/* This is the buffer used by read_myfile */
45
char myfilebuf[1000];
46
 
47
/* This is the number of bytes read by read_myfile */
48
int myfilebuf_length;
49
 
50
void read_myfile()
51
{
52
  /* DOS file descriptor */
53
  DOS_FILE *f;
54
 
55
  /* Error code */
56
  int err;
57
 
58
  /* open the DOS file for reading  (you can specify only "r" or "w") */
59
  f = DOS_fopen("hlp.cfg","r");
60
 
61
  /* check for open errors */
62
  if (!f) {
63
    /* error!! */
64
    err = DOS_error();
65
 
66
    /* note that if you call DOS_error() here, it return 0!!! */
67
    myfilebuf_length = 0;
68
    return;
69
  }
70
 
71
  //  cprintf("pre fread\n");
72
  /* read up to 1000 chars */
73
  myfilebuf_length = DOS_fread(&myfilebuf,1,1000,f);
74
  // cprintf("post fread\n");
75
 
76
  /* check for errors */
77
  err = DOS_error();
78
 
79
  if (err) {
80
    cprintf("Error %d reading myfile.txt...\n", err);
81
    myfilebuf_length = 0;
82
    /* there is not return because I want to close the file! */
83
  }
84
 
85
  /* Close the file */
86
  DOS_fclose(f);
87
  cprintf("Read hlp.cfg...\n");
88
}
89
 
90
 
91
TIME __kernel_register_levels__(void *arg)
92
{
93
  struct multiboot_info *mb = (struct multiboot_info *)arg;
94
 
95
  INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
96
 
97
  read_myfile();
98
 
99
  //EDF_register_level(EDF_ENABLE_ALL);
100
  RM_register_level(RM_ENABLE_ALL);
101
  // HCBS_register_level(HCBS_ENABLE_ALL, 1);
102
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
103
  CBS_register_level(CBS_ENABLE_ALL, 1);
104
  dummy_register_level();
105
 
106
  HLP_register_module();
107
  //  SRP_register_module();
108
  //  PI_register_module();
109
  //  NPP_register_module();
110
  SEM_register_module();
111
 
112
  return TICK;
113
}
114
 
115
TASK __init__(void *arg)
116
{
117
  struct multiboot_info *mb = (struct multiboot_info *)arg;
118
 
119
  HARTPORT_init();
120
 
121
  /* Create the shutdown task. It will be activated at RUNLEVEL
122
     SHUTDOWN */
123
  set_shutdown_task();
124
 
125
  /* Init the drivers */
126
  device_drivers_init();
127
 
128
  /* Set the shutdown task activation */
129
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
130
 
131
  __call_main__(mb);
132
 
133
  return (void *)0;
134
}
135
 
136
void set_shutdown_task() {
137
 
138
  /* WARNING: the shutdown task is a background thread. It cannot execute
139
              if the system is overloaded */
140
  NRT_TASK_MODEL nrt;
141
 
142
  nrt_task_default_model(nrt);
143
  nrt_task_def_system(nrt);
144
 
145
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
146
  if (shutdown_task_PID == NIL) {
147
    sys_shutdown_message("Error: Cannot create shutdown task\n");
148
    sys_end();
149
  }
150
 
151
}
152
 
153
int device_drivers_init() {
154
 
155
  int res;
156
  KEYB_PARMS kparms = BASE_KEYB;
157
 
158
  LINUXC26_register_module();
159
 
160
  PCI26_init();
161
 
162
  INPUT26_init();
163
 
164
  keyb_def_ctrlC(kparms, NULL);
165
 
166
  KEYB26_init(&kparms);
167
 
168
  FB26_init();
169
 
170
  res = FB26_open(FRAME_BUFFER_DEVICE);
171
  if (res) {
172
    cprintf("Error: Cannot open graphical mode\n");
173
    KEYB26_close();
174
    INPUT26_close();
175
    sys_end();
176
  }
177
 
178
  FB26_use_grx(FRAME_BUFFER_DEVICE);
179
 
180
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
181
 
182
  return 0;
183
 
184
}
185
 
186
int device_drivers_close() {
187
 
188
  FB26_close(FRAME_BUFFER_DEVICE);
189
 
190
  KEYB26_close();
191
 
192
  INPUT26_close();
193
 
194
  return 0;
195
 
196
}
197
 
198
#define SHUTDOWN_TIMEOUT_SEC 3
199
 
200
void call_shutdown_task(void *arg)
201
{
202
  struct timespec t;
203
 
204
  sys_gettime(&t);
205
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
206
 
207
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
208
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
209
 
210
  task_activate(shutdown_task_PID);
211
}
212
 
213
TASK shutdown_task_body(void *arg) {
214
 
215
  device_drivers_close();
216
 
217
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
218
 
219
  sys_abort_shutdown(0);
220
 
221
  return NULL;
222
 
223
}