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