Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
22 | /* Event Demo */ |
||
23 | |||
24 | #include <ll/i386/stdlib.h> |
||
25 | #include <ll/i386/cons.h> |
||
26 | #include <ll/i386/error.h> |
||
27 | #include <ll/i386/mem.h> |
||
28 | #include <ll/sys/ll/ll-func.h> |
||
29 | #include <ll/sys/ll/time.h> |
||
30 | #include <ll/sys/ll/event.h> |
||
31 | |||
32 | #define T 1000 |
||
33 | |||
34 | DWORD t1[10], t2[10]; |
||
35 | int id[10]; |
||
36 | int canEnd; |
||
37 | |||
38 | void evtHandler(void *p) |
||
39 | { |
||
40 | int i; |
||
41 | struct timespec t; |
||
42 | static int n = 0; |
||
43 | |||
44 | i = *(int *)p; |
||
45 | |||
46 | t1[++n] = ll_gettime(TIME_NEW, &t); |
||
47 | t2[n] = TIMESPEC2USEC(&t); |
||
48 | id[n] = i; |
||
49 | |||
50 | if (n == 9) { |
||
51 | canEnd = 1; |
||
52 | /*message("\t\tCan End\n");*/ |
||
53 | } |
||
54 | } |
||
55 | |||
56 | int main (int argc, char *argv[]) |
||
57 | { |
||
58 | DWORD sp1, sp2; |
||
59 | struct ll_initparms parms; |
||
60 | void *mbi; |
||
61 | struct timespec time1, time2, time3, time4, time5; |
||
62 | struct timespec time6, time7, time8, time9; |
||
63 | int par[10]; |
||
64 | int i, secs; |
||
65 | DWORD oldt, t; |
||
66 | |||
67 | sp1 = get_SP(); |
||
68 | cli(); |
||
69 | |||
70 | #ifdef PERIODIC |
||
71 | parms.mode = LL_PERIODIC; |
||
72 | parms.tick = T; |
||
73 | #else |
||
74 | parms.mode = LL_ONESHOT; |
||
75 | #endif |
||
76 | |||
77 | mbi = ll_init(); |
||
78 | event_init(&parms); |
||
79 | |||
80 | if (mbi == NULL) { |
||
81 | message("Error in LowLevel initialization code...\n"); |
||
82 | sti(); |
||
83 | l1_exit(-1); |
||
84 | } |
||
85 | sti(); |
||
86 | |||
87 | message("LowLevel started...\n"); |
||
88 | |||
89 | /* cli(); */ |
||
90 | NULL_TIMESPEC(&time1); |
||
91 | NULL_TIMESPEC(&time2); |
||
92 | NULL_TIMESPEC(&time3); |
||
93 | NULL_TIMESPEC(&time4); |
||
94 | NULL_TIMESPEC(&time5); |
||
95 | NULL_TIMESPEC(&time6); |
||
96 | NULL_TIMESPEC(&time7); |
||
97 | NULL_TIMESPEC(&time8); |
||
98 | NULL_TIMESPEC(&time9); |
||
99 | |||
100 | ADDNANO2TIMESPEC(1000000, &time1); /* Time1: 1 ms */ |
||
101 | ADDNANO2TIMESPEC(5000000, &time2); /* Time2: 5 ms */ |
||
102 | ADDNANO2TIMESPEC(10000000, &time3); /* Time 3: 10 ms */ |
||
103 | ADDNANO2TIMESPEC(3000000, &time4); /* Time 4: 3 ms */ |
||
104 | ADDNANO2TIMESPEC(7500000, &time5); /* Time 5: 7.5 ms */ |
||
105 | ADDNANO2TIMESPEC(7000000, &time6); /* Time 6: 7 ms */ |
||
106 | ADDNANO2TIMESPEC(500000000, &time7); |
||
107 | ADDNANO2TIMESPEC(500000000, &time7); |
||
108 | ADDNANO2TIMESPEC(500000000, &time7); |
||
109 | ADDNANO2TIMESPEC(500000000, &time7); |
||
110 | ADDNANO2TIMESPEC(500000000, &time7); |
||
111 | ADDNANO2TIMESPEC(500000000, &time7); /* Time 7: 6*500 ms = 3 Sec*/ |
||
112 | ADDNANO2TIMESPEC(51700000, &time8); /* Time 8: 51.7 ms */ |
||
113 | ADDNANO2TIMESPEC(51500000, &time9); /* Time 9: 51.5 ms */ |
||
114 | |||
115 | cli(); |
||
116 | t = ll_gettime(TIME_NEW, NULL); |
||
117 | sti(); |
||
118 | |||
119 | for (i = 0; i < 10; i++) { |
||
120 | par[i] = i + 1; |
||
121 | } |
||
122 | canEnd = 0; |
||
123 | |||
124 | cli(); |
||
125 | |||
126 | event_post(time1, evtHandler, &(par[0])); |
||
127 | event_post(time2, evtHandler, &(par[1])); |
||
128 | event_post(time3, evtHandler, &(par[2])); |
||
129 | event_post(time4, evtHandler, &(par[3])); |
||
130 | event_post(time5, evtHandler, &(par[4])); |
||
131 | i = event_post(time6, evtHandler, &(par[5])); |
||
132 | event_post(time7, evtHandler, &(par[6])); |
||
133 | event_post(time8, evtHandler, &(par[7])); |
||
134 | event_post(time9, evtHandler, &(par[8])); |
||
135 | |||
136 | event_delete(i); |
||
137 | event_post(time5, evtHandler, &(par[5])); |
||
138 | |||
139 | message("Now time is %lu\n", t); |
||
140 | |||
141 | secs = 0; |
||
142 | oldt = 0; |
||
143 | canEnd = 0; |
||
144 | while((canEnd == 0) && (secs < 6)) { |
||
145 | cli(); |
||
146 | t = ll_gettime(TIME_NEW, NULL); |
||
147 | sti(); |
||
148 | if (t < oldt) { |
||
149 | error("Time goes back???\n"); |
||
150 | message("ARGGGGG! %lu %lu\n", t, oldt); |
||
151 | ll_abort(100); |
||
152 | } |
||
153 | oldt = t; |
||
154 | if ((t / 1000000) > secs) { |
||
155 | secs++; |
||
156 | message(" %d %lu\n", secs, t); |
||
157 | } |
||
158 | } |
||
159 | cli(); |
||
160 | message("Can End detected\n"); |
||
161 | ll_end(); |
||
162 | sp2 = get_SP(); |
||
163 | for (i = 1; i < 10; i++) { |
||
164 | message("Event %d called at time %lu == %lu\n", id[i], |
||
165 | t1[i], t2[i]); |
||
166 | } |
||
167 | message("End reached!\n"); |
||
168 | message("Actual stack : %lx - ", sp2); |
||
169 | message("Begin stack : %lx\n", sp1); |
||
170 | message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-("); |
||
171 | |||
172 | return 1; |
||
173 | } |