Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1601 tullio 1
//////////////////////////////////////////////////////////////
2
//  os.c        -Lex Nahumury 2006
3
//
4
// This is the OpenSource SHARK OS/kernel part.
5
// It will dynamicly link the main application ELF object
6
// through 'Dynalink'.
7
//
8
//////////////////////////////////////////////////////////////
9
#include "kernel/kern.h"
10
#include <kernel/func.h>
11
#include <stdlib.h>
12
#include <stdio.h>
13
#include <string.h>
14
#include <math.h>
15
#include "ll/i386/cons.h"
16
 
17
#include "edf/edf/edf.h"
18
#include "cbs/cbs/cbs.h"
19
#include "hardcbs/hardcbs/hardcbs.h"
20
#include "rr/rr/rr.h"
21
#include "dummy/dummy/dummy.h"
22
#include "intdrive/intdrive/intdrive.h"
23
 
24
#include "sem/sem/sem.h"
25
#include "hartport/hartport/hartport.h"
26
#include "cabs/cabs/cabs.h"
27
 
28
#include <drivers/shark_linuxc26.h>
29
#include <drivers/shark_pci26.h>
30
#include <drivers/shark_input26.h>
31
#include <drivers/shark_keyb26.h>
32
 
33
// DYNALINK
34
#include <dynalink.h>
35
 
36
// some shark pci forward declaration stuff
37
extern int pci20to26_find_class(unsigned int class_code, int index, BYTE *bus, BYTE *dev);
38
extern int pci20to26_read_config_byte(unsigned int bus, unsigned int dev, int where, BYTE *val);
39
extern int pci20to26_read_config_word(unsigned int bus, unsigned int dev, int where, WORD *val);
40
extern int pci20to26_read_config_dword(unsigned int bus, unsigned int dev, int where, DWORD *val);
41
extern int pci20to26_write_config_byte(unsigned int bus, unsigned int dev, int where, BYTE val);
42
extern int pci20to26_write_config_word(unsigned int bus, unsigned int dev, int where, WORD val);
43
extern int pci20to26_write_config_dword(unsigned int bus, unsigned int dev, int where, DWORD val);
44
 
45
 
46
#define TICK            1000    //  1ms
47
#define RRTICK          100000  //  100ms
48
 
49
/*+ IntDrive Server +*/
50
#define INTDRIVE_Q 1000
51
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
52
#define INTDRIVE_FLAG 0
53
 
54
#define NSEC_PER_SEC (1000000000L)
55
#define SHUTDOWN_TIMEOUT_SEC    0.5             // seconds
56
 
57
// prototypes
58
void call_shutdown_task(void *arg);
59
int device_drivers_init();
60
int device_drivers_close();
61
void set_shutdown_task();
62
TASK shutdown_task_body(void *arg);
63
 
64
// user application function pointer prototype
65
int (*main_app_entry)(void* arg);
66
 
67
 
68
// vars
69
static struct multiboot_info *mb = 0;
70
static struct dynalink_module_list      dml;
71
PID shutdown_task_PID = -1;
72
 
73
 
74
// user app calls this to retrieve tick
75
DWORD get_tick()
76
{
77
        return TICK;
78
};
79
 
80
TASK shutdown_task_body(void *arg)
81
{
82
        device_drivers_close();
83
        sys_shutdown_message("-- OS Closed --\n");
84
        return NULL;
85
};
86
 
87
void set_shutdown_task()
88
{
89
        NRT_TASK_MODEL nrt;
90
        nrt_task_default_model(nrt);
91
        nrt_task_def_system(nrt);
92
 
93
        shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
94
        if (shutdown_task_PID == NIL)
95
        {
96
                sys_shutdown_message("Error: Cannot create shutdown task\n");
97
                exit(1);
98
        }
99
};
100
 
101
 
102
void call_shutdown_task(void *arg)
103
{
104
        struct timespec t;
105
        sys_gettime(&t);
106
        t.tv_nsec += NSEC_PER_SEC * SHUTDOWN_TIMEOUT_SEC;
107
        kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
108
        task_activate(shutdown_task_PID);
109
};
110
 
111
 
112
TIME __kernel_register_levels__(void *arg)
113
{
114
        mb = (struct multiboot_info *)arg;
115
        LEVEL EDF_level;
116
 
117
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
118
  EDF_level = EDF_register_level(EDF_ENABLE_ALL);
119
        CBS_register_level(CBS_ENABLE_ALL, EDF_level);
120
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
121
        dummy_register_level();
122
 
123
        SEM_register_module();
124
        CABS_register_module();
125
 
126
  return TICK;
127
};
128
 
129
TASK __init__(void *arg)
130
{
131
        mb = (struct multiboot_info *)arg;
132
 
133
        //HARTPORT_init();
134
        set_shutdown_task();
135
        device_drivers_init(); 
136
 
137
        sys_atrunlevel( call_shutdown_task,
138
                                        NULL,
139
                                        RUNLEVEL_SHUTDOWN);    
140
 
141
        __call_main__(mb);
142
 
143
  return (void *)0;
144
};
145
 
146
 
147
int main(int argc, char **argv)
148
{
149
        // Any modules passed to kernel by GRUB?
150
        if(!mb->mods_count)
151
        {
152
                printk("No modules passed at all! Bye..\n");
153
                exit(1);
154
        }
155
 
156
        // Process the modules through 'dynalink'
157
        dynalink_modules(mb, &dml, "_module_entry");
158
        if(dml.num_apps == 0)
159
        {
160
                printk("No Application modules found! Bye..\n");
161
                exit(1);
162
        }
163
 
164
        // Run first found user application function
165
        // and pass the dynalink_module_list..  
166
        DWORD dynadr = dml.app[0].dyn_entry;
167
        if(dynadr)
168
        {
169
                main_app_entry = (void*)dynadr;
170
                main_app_entry(&dml);
171
        }
172
        else
173
        {
174
                printk("No Application modules found! Bye..\n");
175
                exit(1);
176
        }                      
177
return 0;
178
};
179
 
180
 
181
int device_drivers_init()
182
{      
183
        LINUXC26_register_module(TRUE);
184
        //PCI26_init();
185
        INPUT26_init();
186
 
187
        KEYB_PARMS  kparms = BASE_KEYB;
188
        keyb_def_ctrlC(kparms, NULL);  
189
        KEYB26_init(&kparms);
190
 
191
        return 0;
192
};
193
 
194
int device_drivers_close()
195
{      
196
        KEYB26_close();
197
        INPUT26_close();
198
        return 0;                                                                  
199
};
200
 
201