Rev 1006 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
519 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Mauro Marinoni <mauro.marinoni@unipv.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
1063 | tullio | 19 | /* |
20 | * This program is free software; you can redistribute it and/or modify |
||
21 | * it under the terms of the GNU General Public License as published by |
||
22 | * the Free Software Foundation; either version 2 of the License, or |
||
23 | * (at your option) any later version. |
||
24 | * |
||
25 | * This program is distributed in the hope that it will be useful, |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | * GNU General Public License for more details. |
||
29 | * |
||
30 | * You should have received a copy of the GNU General Public License |
||
31 | * along with this program; if not, write to the Free Software |
||
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
33 | * |
||
34 | */ |
||
35 | |||
523 | mauro | 36 | //#define __MOUSE_DEBUG__ |
1006 | mauro | 37 | #define MOUSE_TASK |
519 | mauro | 38 | |
39 | #include <kernel/kern.h> |
||
40 | |||
41 | #include "../include/drivers/shark_input26.h" |
||
42 | #include "../include/drivers/shark_mouse26.h" |
||
43 | |||
44 | /* Devices */ |
||
45 | extern int psmouse_init(void); |
||
46 | extern int psmouse_exit(void); |
||
47 | |||
48 | /* Handlers */ |
||
49 | extern int mouse_init(void); |
||
50 | extern void mouse_exit(void); |
||
51 | |||
523 | mauro | 52 | /* Functions */ |
53 | extern int mouse_get(int *dx, int *dy, int *dz, unsigned long *buttons); |
||
54 | |||
55 | /* Mouse driver currently installed/actived */ |
||
519 | mauro | 56 | static int mouse_installed = FALSE; |
523 | mauro | 57 | static int mouse_enabled = FALSE; |
519 | mauro | 58 | |
523 | mauro | 59 | static int mouse_xmin_tick; |
60 | static int mouse_ymin_tick; |
||
61 | static int mouse_xmax_tick; |
||
62 | static int mouse_ymax_tick; |
||
519 | mauro | 63 | |
523 | mauro | 64 | #define MOUSE_DEF_THRESHOLD 10 |
65 | static int mouse_threshold; |
||
66 | |||
67 | static int mouse_x = 0; |
||
68 | static int mouse_y = 0; |
||
69 | static int mouse_x_tick = 0; |
||
70 | static int mouse_y_tick = 0; |
||
71 | static int mouse_z = 0; |
||
72 | static unsigned long mouse_buttons = 0; |
||
73 | |||
538 | mauro | 74 | MOUSE_HANDLER user_mouse_handler = NULL; |
75 | MOUSE_HANDLER show_mouse_handler = NULL; |
||
519 | mauro | 76 | |
523 | mauro | 77 | #ifdef MOUSE_TASK |
78 | /* mouse task PID */ |
||
79 | static PID mousepid = NIL; |
||
80 | #else |
||
81 | void mouseProc(void); |
||
82 | #endif |
||
522 | mauro | 83 | |
84 | |||
519 | mauro | 85 | /* |
86 | * Start mouseProc Task |
||
87 | */ |
||
523 | mauro | 88 | void shark_mouse_exec(void) |
519 | mauro | 89 | { |
523 | mauro | 90 | #ifdef MOUSE_TASK |
91 | task_activate(mousepid); |
||
92 | #else |
||
93 | mouseProc(); |
||
94 | #endif |
||
519 | mauro | 95 | } |
96 | |||
523 | mauro | 97 | #ifdef MOUSE_TASK |
98 | TASK mouseProc(void) |
||
99 | #else |
||
100 | void mouseProc(void) |
||
101 | #endif |
||
102 | { |
||
103 | static MOUSE_EVT ev; |
||
104 | unsigned long dbuttons; |
||
105 | int dx, dy, dz; |
||
106 | int res; |
||
107 | |||
108 | #ifdef MOUSE_TASK |
||
109 | while (1) { |
||
110 | #endif |
||
111 | if (mouse_enabled) { |
||
112 | res = mouse_get(&dx, &dy, &dz, &dbuttons); |
||
113 | if (res >= 0) { |
||
114 | mouse_x_tick += dx; |
||
115 | if (mouse_x_tick < mouse_xmin_tick) |
||
116 | mouse_x_tick = mouse_xmin_tick; |
||
117 | if (mouse_x_tick > mouse_xmax_tick) |
||
118 | mouse_x_tick = mouse_xmax_tick; |
||
119 | mouse_x = (mouse_x_tick + (mouse_threshold/2)) / mouse_threshold; |
||
120 | ev.x = mouse_x; |
||
121 | ev.dx = dx; |
||
519 | mauro | 122 | |
523 | mauro | 123 | mouse_y_tick -= dy; |
124 | if (mouse_y_tick < mouse_ymin_tick) |
||
125 | mouse_y_tick = mouse_ymin_tick; |
||
126 | if (mouse_y_tick > mouse_ymax_tick) |
||
127 | mouse_y_tick = mouse_ymax_tick; |
||
128 | mouse_y = (mouse_y_tick + (mouse_threshold/2)) / mouse_threshold; |
||
129 | ev.y = mouse_y; |
||
130 | ev.dy = dy; |
||
131 | |||
132 | mouse_z += dz; |
||
133 | ev.z = mouse_z; |
||
134 | ev.dz = dz; |
||
135 | |||
136 | mouse_buttons = dbuttons; |
||
137 | ev.buttons = mouse_buttons; |
||
138 | #ifdef __MOUSE_DEBUG__ |
||
139 | printk(KERN_DEBUG "shark_mouse.c: delta ( %3d %3d %3d - %6x) -> ( %3d %3d %3d - %6x)\n", |
||
140 | dx, dy, dz, (int)dbuttons, mouse_x, mouse_y, mouse_z, (int)mouse_buttons); |
||
141 | #endif |
||
142 | /* mouse handler */ |
||
538 | mauro | 143 | if (show_mouse_handler != NULL) |
144 | show_mouse_handler(&ev); |
||
145 | else if (user_mouse_handler != NULL) |
||
146 | user_mouse_handler(&ev); |
||
523 | mauro | 147 | } |
148 | } |
||
149 | #ifdef MOUSE_TASK |
||
150 | task_endcycle(); |
||
151 | } |
||
152 | #endif |
||
153 | } |
||
154 | |||
155 | /**** Start User Functions ****/ |
||
156 | |||
157 | void mouse_enable(void) |
||
158 | { |
||
159 | mouse_enabled = TRUE; /* TODO */ |
||
160 | } |
||
161 | |||
162 | void mouse_disable(void) |
||
163 | { |
||
164 | mouse_enabled = FALSE; /* TODO */ |
||
165 | } |
||
166 | |||
549 | mauro | 167 | void mouse_getposition(int *x,int *y,int *z, unsigned long *buttons) |
523 | mauro | 168 | { |
548 | mauro | 169 | if (x) |
170 | *x = mouse_x; |
||
171 | if (y) |
||
172 | *y = mouse_y; |
||
173 | if (z) |
||
174 | *z = mouse_z; |
||
175 | if (buttons) |
||
176 | *buttons = mouse_buttons; |
||
523 | mauro | 177 | } |
178 | |||
549 | mauro | 179 | void mouse_setposition(int x,int y, int z) |
523 | mauro | 180 | { |
181 | mouse_enabled = FALSE; |
||
182 | |||
898 | mauro | 183 | mouse_x_tick = x * mouse_threshold; |
184 | if (mouse_x_tick < mouse_xmin_tick) |
||
185 | mouse_x_tick = mouse_xmin_tick; |
||
186 | if (mouse_x_tick > mouse_xmax_tick) |
||
187 | mouse_x_tick = mouse_xmax_tick; |
||
188 | mouse_x = (mouse_x_tick + (mouse_threshold/2)) / mouse_threshold; |
||
523 | mauro | 189 | |
898 | mauro | 190 | mouse_y_tick = y * mouse_threshold; |
191 | if (mouse_y_tick < mouse_ymin_tick) |
||
192 | mouse_y_tick = mouse_ymin_tick; |
||
193 | if (mouse_y_tick > mouse_ymax_tick) |
||
194 | mouse_y_tick = mouse_ymax_tick; |
||
195 | mouse_y = (mouse_y_tick + (mouse_threshold/2)) / mouse_threshold; |
||
196 | |||
523 | mauro | 197 | mouse_z = z; |
198 | |||
199 | mouse_enabled = TRUE; |
||
200 | } |
||
201 | |||
549 | mauro | 202 | void mouse_getlimits(int *xmin, int *ymin, int *xmax, int *ymax) |
523 | mauro | 203 | { |
548 | mauro | 204 | if (xmin) |
205 | *xmin = mouse_xmin_tick / mouse_threshold; |
||
206 | if (ymin) |
||
207 | *ymin = mouse_ymin_tick / mouse_threshold; |
||
208 | if (xmax) |
||
209 | *xmax = mouse_xmax_tick / mouse_threshold; |
||
210 | if (ymax) |
||
211 | *ymax = mouse_ymax_tick / mouse_threshold; |
||
523 | mauro | 212 | } |
213 | |||
549 | mauro | 214 | int mouse_setlimits(int xmin, int ymin, int xmax, int ymax) |
523 | mauro | 215 | { |
216 | if ((xmin < 0) && (ymin < 0) && (xmax < xmin) && (ymax < ymin)) |
||
217 | return -1; |
||
218 | |||
219 | mouse_xmin_tick = xmin * mouse_threshold; |
||
220 | mouse_ymin_tick = ymin * mouse_threshold; |
||
221 | mouse_xmax_tick = xmax * mouse_threshold; |
||
222 | mouse_ymax_tick = ymax * mouse_threshold; |
||
223 | |||
224 | return 0; |
||
225 | } |
||
226 | |||
227 | void mouse_hook(MOUSE_HANDLER h) |
||
228 | { |
||
538 | mauro | 229 | user_mouse_handler = h; |
523 | mauro | 230 | } |
231 | |||
232 | int mouse_getthreshold(void) |
||
233 | { |
||
234 | return mouse_threshold; |
||
235 | } |
||
236 | |||
237 | int mouse_setthreshold(int t) |
||
238 | { |
||
239 | mouse_enabled = FALSE; |
||
240 | |||
241 | if ((t>0) && (t<=200)) { |
||
242 | mouse_xmin_tick = (mouse_xmin_tick * t) / mouse_threshold; |
||
243 | mouse_ymin_tick = (mouse_ymin_tick * t) / mouse_threshold; |
||
244 | mouse_xmax_tick = (mouse_xmax_tick * t) / mouse_threshold; |
||
245 | mouse_ymax_tick = (mouse_ymax_tick * t) / mouse_threshold; |
||
246 | mouse_threshold = t; |
||
247 | return 0; |
||
248 | } else { |
||
249 | return -1; |
||
250 | } |
||
251 | |||
252 | mouse_enabled = TRUE; |
||
253 | } |
||
254 | |||
255 | /**** End User Functions ****/ |
||
256 | |||
519 | mauro | 257 | /* Init the Linux Speaker Driver */ |
549 | mauro | 258 | int MOUSE26_installed(void) |
259 | { |
||
260 | return mouse_installed; |
||
261 | } |
||
262 | |||
523 | mauro | 263 | int MOUSE26_init(MOUSE_PARMS *s) |
519 | mauro | 264 | { |
523 | mauro | 265 | MOUSE_PARMS mparms = BASE_MOUSE; |
519 | mauro | 266 | int status = 0; |
267 | |||
523 | mauro | 268 | #ifdef MOUSE_TASK |
269 | TASK_MODEL *m; |
||
270 | SOFT_TASK_MODEL base_m; |
||
271 | #endif |
||
272 | |||
519 | mauro | 273 | if (mouse_installed == TRUE) return 0; |
274 | |||
522 | mauro | 275 | /* if a NULL is passed */ |
523 | mauro | 276 | if (s == NULL) |
522 | mauro | 277 | s = &mparms; |
278 | |||
523 | mauro | 279 | /* set mouse threshold */ |
549 | mauro | 280 | if ((s->threshold == (int) MOUSE_DEFAULT) || (s->threshold == 0)) |
523 | mauro | 281 | mouse_threshold = MOUSE_DEF_THRESHOLD; |
282 | else |
||
283 | mouse_threshold = s->threshold; |
||
284 | |||
285 | /* set mouse limits */ |
||
286 | if ((s->xmin == (int) MOUSE_DEFAULT) || (s->xmin < 0)) |
||
287 | mouse_xmin_tick = 0; |
||
288 | else |
||
289 | mouse_xmin_tick = s->xmin * mouse_threshold; |
||
290 | |||
291 | if ((s->ymin == (int) MOUSE_DEFAULT) || (s->ymin < 0)) |
||
292 | mouse_ymin_tick = 0; |
||
293 | else |
||
294 | mouse_ymin_tick = s->ymin * mouse_threshold; |
||
295 | |||
296 | if ((s->xmax == (int) MOUSE_DEFAULT) || ((s->xmax * mouse_threshold) < mouse_xmin_tick)) |
||
297 | mouse_xmax_tick = 79 * mouse_threshold; |
||
298 | else |
||
299 | mouse_xmax_tick = s->xmax * mouse_threshold; |
||
300 | |||
301 | if ((s->ymax == (int) MOUSE_DEFAULT) || ((s->ymax * mouse_threshold) < mouse_ymin_tick)) |
||
302 | mouse_ymax_tick = 24 * mouse_threshold; |
||
303 | else |
||
304 | mouse_ymax_tick = s->ymax * mouse_threshold; |
||
305 | |||
549 | mauro | 306 | /* set initial mouse position */ |
307 | if (s->x0 == (int) MOUSE_DEFAULT) |
||
308 | mouse_x_tick = mouse_x = 0; |
||
309 | else { |
||
310 | mouse_x_tick = s->x0 * mouse_threshold; |
||
311 | mouse_x = mouse_x_tick / mouse_threshold; |
||
312 | } |
||
313 | |||
314 | if (s->y0 == (int) MOUSE_DEFAULT) |
||
315 | mouse_y_tick = mouse_y = 0; |
||
316 | else { |
||
317 | mouse_y_tick = s->y0 * mouse_threshold; |
||
318 | mouse_y = mouse_y_tick / mouse_threshold; |
||
319 | } |
||
320 | |||
321 | if (s->z0 == (int) MOUSE_DEFAULT) |
||
322 | mouse_z = 0; |
||
323 | else |
||
324 | mouse_z = s->z0; |
||
325 | |||
523 | mauro | 326 | #ifdef MOUSE_TASK |
522 | mauro | 327 | if (s->tm == (TASK_MODEL *)MOUSE_DEFAULT) { |
328 | soft_task_default_model(base_m); |
||
329 | soft_task_def_wcet(base_m,2000); |
||
330 | soft_task_def_met(base_m,500); |
||
331 | soft_task_def_period(base_m,8000); |
||
332 | soft_task_def_system(base_m); |
||
826 | mauro | 333 | soft_task_def_nokill (base_m); |
522 | mauro | 334 | soft_task_def_aperiodic(base_m); |
335 | m = (TASK_MODEL *)&base_m; |
||
336 | } else |
||
523 | mauro | 337 | m = s->tm; |
522 | mauro | 338 | |
523 | mauro | 339 | mousepid = task_create ("MouseTask", mouseProc, m, NULL); |
340 | if (mousepid == -1) { |
||
341 | return -1; |
||
342 | } |
||
343 | #endif |
||
344 | |||
549 | mauro | 345 | if (INPUT26_installed() == FALSE) { |
519 | mauro | 346 | status = INPUT26_init(); |
347 | if (status) { |
||
523 | mauro | 348 | |
519 | mauro | 349 | printk(KERN_ERR "shark_mouse.c: Unable to open Input SubSystem.\n"); |
350 | return -1; |
||
351 | } |
||
352 | } |
||
353 | |||
354 | status = psmouse_init(); |
||
355 | if (status) { |
||
356 | printk(KERN_ERR "shark_mouse.c: PsMouse_Init return: %d\n", status); |
||
357 | return -1; |
||
358 | } |
||
359 | |||
360 | status = mouse_init(); |
||
361 | if (status) { |
||
362 | printk(KERN_ERR "shark_mouse.c: Mouse_Init return: %d\n", status); |
||
363 | return -1; |
||
364 | } |
||
365 | |||
366 | mouse_installed = TRUE; |
||
523 | mauro | 367 | mouse_enabled = TRUE; |
519 | mauro | 368 | |
369 | return status; |
||
370 | } |
||
371 | |||
372 | int MOUSE26_close() |
||
373 | { |
||
523 | mauro | 374 | #ifdef MOUSE_TASK |
375 | int free; |
||
376 | SYS_FLAGS f; |
||
377 | #endif |
||
378 | |||
519 | mauro | 379 | if (!mouse_installed) |
380 | return -1; |
||
381 | |||
523 | mauro | 382 | mouse_enabled = FALSE; |
519 | mauro | 383 | mouse_exit(); |
384 | psmouse_exit(); |
||
523 | mauro | 385 | |
386 | #ifdef MOUSE_TASK |
||
387 | f = kern_fsave(); |
||
388 | free = (proc_table[mousepid].status == FREE); |
||
389 | kern_frestore(f); |
||
390 | #ifdef __MOUSE_DEBUG__ |
||
391 | printk(KERN_DEBUG "shark_mouse.c: MouseTask is %s.\n", free ? "killed" : "alive"); |
||
392 | #endif |
||
393 | if (free) |
||
394 | task_kill (mousepid); |
||
395 | #endif |
||
396 | |||
519 | mauro | 397 | mouse_installed = FALSE; |
398 | |||
399 | return 0; |
||
400 | } |
||
401 |