Rev 1601 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1601 | tullio | 1 | /////////////////////////////////////////////////// |
2 | // app.c -Lex Nahumury 2006 |
||
3 | // |
||
4 | // This would be the Closed Source User Application part. |
||
5 | // The ELF object itself contains no GPL code. |
||
6 | // The references to GPL code are resolved |
||
7 | // by the Dynamic Linker after the kernel has loaded. |
||
8 | // |
||
9 | ////////////////////////////////////////////////// |
||
10 | |||
11 | /* |
||
12 | Usage example: |
||
13 | |||
14 | # For booting SHARK image from HD |
||
15 | title S.H.A.R.K + Boot Modules from HD 0,0 |
||
16 | kernel (hd0,0)/boot/os mount root=/dev/hda1 |
||
17 | module (hd0,0)/boot/sh_app.bin |
||
18 | module (hd0,0)/boot/data.bin |
||
19 | |||
20 | */ |
||
21 | |||
22 | #include "kernel/kern.h" |
||
23 | #include <kernel/func.h> |
||
24 | #include <stdlib.h> |
||
25 | #include <stdio.h> |
||
26 | #include <string.h> |
||
27 | #include <math.h> |
||
28 | #include "ll/i386/cons.h" |
||
29 | |||
30 | #include <drivers/shark_keyb26.h> |
||
31 | #include "../../ports/dynalink/dynalink.h" |
||
32 | |||
33 | extern void call_shutdown_task(void *arg); |
||
34 | extern DWORD get_tick(); |
||
35 | |||
36 | struct params |
||
37 | { |
||
38 | int task_nr; |
||
39 | int row; |
||
40 | int count; |
||
41 | int cycles; |
||
42 | }; |
||
43 | |||
44 | |||
45 | TASK periodic_task(void *arg) |
||
46 | { |
||
47 | int ani=0; |
||
48 | char c[2]; |
||
49 | struct params* p = (struct params*)(arg); |
||
50 | int row = p->row; |
||
51 | char txt[4]; |
||
52 | p->count=0; |
||
53 | |||
54 | while(p->count < p->cycles) |
||
55 | { |
||
56 | switch(ani) |
||
57 | { |
||
58 | case 0: |
||
59 | ani=1; sprintf(c,"%s", "\\"); |
||
60 | break; |
||
61 | case 1: |
||
62 | ani=2; sprintf(c,"/"); |
||
63 | break; |
||
64 | case 2: |
||
65 | ani=0; sprintf(c,"-"); |
||
66 | break; |
||
67 | } |
||
68 | puts_xy(12,row,YELLOW, c ); |
||
69 | |||
70 | ++p->count; |
||
71 | sprintf(txt,"%02d", p->count); |
||
72 | puts_xy(8,row,YELLOW, txt); |
||
73 | |||
74 | task_endcycle(); |
||
75 | } |
||
76 | |||
77 | cprintf("Task #%d end.\n", p->task_nr); |
||
78 | if(p->task_nr==4) call_shutdown_task(0); |
||
79 | return 0; |
||
80 | }; |
||
81 | |||
82 | |||
83 | // This is the main user application entry point. |
||
84 | int main_module_entry(void* arg) |
||
85 | { |
||
86 | struct dynalink_module_list* dml = (struct dynalink_module_list*)arg; |
||
87 | |||
88 | // make char pointer to text data module,.. |
||
89 | char* txt = (char*)(dml->dat[0].start); |
||
90 | |||
91 | // ... and print out it's data content |
||
92 | cprintf("%s", txt); |
||
93 | |||
94 | keyb_getch(BLOCK); |
||
95 | clear(); |
||
96 | |||
97 | SOFT_TASK_MODEL msoft; |
||
98 | PID p1,p2,p3,p4; |
||
99 | |||
100 | int yrow = 1; |
||
101 | puts_xy(0,yrow, 7,"Task#1:[ ]"); |
||
102 | puts_xy(0,yrow+1,7,"Task#2:[ ]"); |
||
103 | puts_xy(0,yrow+2,7,"Task#3:[ ]"); |
||
104 | puts_xy(0,yrow+3,7,"Task#4:[ ]"); |
||
105 | |||
106 | place(0,7); |
||
107 | |||
108 | // Init shared soft task model |
||
109 | soft_task_default_model(msoft); |
||
110 | soft_task_def_met(msoft,10000); |
||
111 | soft_task_def_group(msoft, 1); |
||
112 | soft_task_def_periodic(msoft); |
||
113 | soft_task_def_level(msoft, 2); |
||
114 | |||
115 | int cycles = 4; |
||
116 | |||
117 | // init Task 1 |
||
118 | float task_periode = 1.0; // 1sec |
||
119 | int tick = get_tick(); // 1000 usec = 1 ms |
||
120 | int per = (int)( task_periode *1000.0 * tick); |
||
121 | struct params pp1; |
||
122 | pp1.task_nr = 1; |
||
123 | pp1.row = yrow; |
||
124 | pp1.cycles = cycles; |
||
125 | soft_task_def_period(msoft, per); // set period |
||
126 | soft_task_def_arg(msoft, (void*)(&pp1) ); // set arguments |
||
127 | p1 = task_create("save", periodic_task, &msoft, NULL); |
||
128 | if (p1 == NIL) |
||
129 | { |
||
130 | sys_shutdown_message("Can't create task1 ...\n"); |
||
131 | exit(1); |
||
132 | } |
||
133 | |||
134 | // init Task 2 |
||
135 | task_periode = task_periode*0.5; // twice as fast as task1 |
||
136 | tick = get_tick(); // 1000 usec = 1 ms |
||
137 | per = (int)( task_periode *1000.0 * tick); |
||
138 | struct params pp2; |
||
139 | pp2.task_nr = 2; |
||
140 | pp2.row = yrow+1; |
||
141 | pp2.cycles = cycles*2; |
||
142 | soft_task_def_period(msoft, per); |
||
143 | soft_task_def_arg(msoft, (void*)(&pp2) ); |
||
144 | p2 = task_create("skip", periodic_task, &msoft, NULL); |
||
145 | if (p2 == NIL) |
||
146 | { |
||
147 | sys_shutdown_message("Can't create task2...\n"); |
||
148 | exit(1); |
||
149 | } |
||
150 | |||
151 | // init Task 3 |
||
152 | task_periode = task_periode*0.5; // twice as fast as previous task |
||
153 | tick = get_tick(); // 1000 usec = 1 ms |
||
154 | per = (int)( task_periode *1000.0 * tick); |
||
155 | struct params pp3; |
||
156 | pp3.task_nr = 3; |
||
157 | pp3.row = yrow+2; |
||
158 | pp3.cycles = cycles*4; |
||
159 | soft_task_def_period(msoft, per); |
||
160 | soft_task_def_arg(msoft, (void*)(&pp3) ); |
||
161 | p3 = task_create("skip", periodic_task, &msoft, NULL); |
||
162 | if(p3 == NIL) |
||
163 | { |
||
164 | sys_shutdown_message("Can't create task3...\n"); |
||
165 | exit(1); |
||
166 | } |
||
167 | |||
168 | // init Task 4 |
||
169 | task_periode = task_periode*0.5; // twice as fast as previous task |
||
170 | tick = get_tick(); // 1000 usec = 1 ms |
||
171 | per = (int)( task_periode *1000.0 * tick); |
||
172 | struct params pp4; |
||
173 | pp4.task_nr = 4; |
||
174 | pp4.row = yrow+3; |
||
175 | pp4.cycles = cycles*8; |
||
176 | soft_task_def_period(msoft, per); |
||
177 | soft_task_def_arg(msoft, (void*)(&pp4) ); |
||
178 | p4 = task_create("skip", periodic_task, &msoft, NULL); |
||
179 | if(p4 == NIL) |
||
180 | { |
||
181 | sys_shutdown_message("Can't create task4...\n"); |
||
182 | exit(1); |
||
183 | } |
||
184 | |||
185 | group_activate(1); |
||
186 | |||
187 | return 0; |
||
188 | }; |