/shark/trunk/drivers/serial/scom.c |
---|
0,0 → 1,492 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: scom.c,v 1.1 2004-03-29 18:31:42 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-03-29 18:31:42 $ |
------------ |
Author: Massimiliano Giorgi |
Author: Gerardo Lamastra |
Date: 9/5/96 |
File: SCOM.C |
Revision: 1.0g |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/* Serial communication device */ |
/* This implementation is capable of handling 4 distinct COM ports */ |
/* The COM port settings are the standard PC settings: */ |
/* PORT ADDRESS IRQ */ |
/* 1 0x3F8 4 */ |
/* 2 0x2F8 3 */ |
/* 3 0x3E8 4 */ |
/* 4 0x2E8 2 */ |
/* By Massy |
* I have modified the fast handler routines to support serial |
* mouse better (see below) |
*/ |
//#include <string.h> |
//#include <stdlib.h> |
//#include <cons.h> |
#include <kernel/kern.h> |
//#include "exc.h" |
#include <modules/sem.h> |
#include <drivers/scom.h> |
/* #define __DEBUG_SERIAL__ */ |
/* #define __STUB__ */ |
/* Base address for each standard COM link */ |
static unsigned com_base[] = {0x03F8,0x02F8,0x03E8,0x02E8}; |
/* Irq linked to each serial channel */ |
static unsigned com_irq[] = {COM1_IRQ,COM2_IRQ,COM3_IRQ,COM4_IRQ}; |
/* COM port which shares interrupt with indexed one */ |
/* I assume standard AT assignement where each irq line can */ |
/* hold up to 2 different COM port */ |
static const int com_share[] = {COM3,COM4,COM1,COM2}; |
/* Used for decoding the IIR status */ |
const int IIRbits[] = {MS_CHANGED,TX_EMPTY,RX_FULL,LS_CHANGED}; |
/* The descriptor of a serial link */ |
/* Each array entry is associated to a COM port */ |
/* The control field is used to specify which kind of interrupts */ |
/* are going to be served; the status field tracks if the entry */ |
/* is curretly used & if the shared fast handler is linked */ |
/* The semaphores are opened if you use an asyncronous server */ |
/* with the link */ |
struct COM_LINK com_link[COM_LINKS]; |
/* Register level access functions */ |
unsigned com_read(unsigned port,unsigned reg) |
{ |
unsigned b; |
if (port > 3 || reg > 7) return(0); |
b = ll_in(com_base[port]+reg); |
return(b); |
} |
void com_write(unsigned port,unsigned reg,unsigned value) |
{ |
if (port > 3 || reg > 7) return; |
ll_out(com_base[port]+reg,value); |
} |
/* Polled send/receive */ |
void com_send(unsigned port,BYTE b) |
{ |
while ((com_read(port,LSR) & 32) == 0); |
com_write(port,THR,b); |
} |
unsigned com_receive(unsigned port) |
{ |
while ((com_read(port,LSR) & 1) == 0); |
return(com_read(port,RBR)); |
} |
/* Fast routines for cascaded irq */ |
/* By massy */ |
/* com_fast must be called if there isn't a server |
* and an interrupt is detected (so sermouse.c module can |
* activate mouse task only if a packet not a byte is received). |
*/ |
static void dummy(int x) {} |
void (*com_fast)(int)=dummy; |
#ifdef __DEBUG_SERIAL__ |
int fast_times1 = 0,fast_times3 = 0; |
#endif |
static void com_1_3_fast(int n) |
{ |
unsigned iir1,iir3; |
iir1 = DECODE(com_read(COM1,IIR)); |
iir3 = DECODE(com_read(COM3,IIR)); |
if ((iir1 & com_link[COM1].control)) { |
#ifdef __DEBUG_SERIAL__ |
fast_times1++; |
#endif |
com_write(COM1,IER,0); |
com_link[COM1].request = iir1; |
if (com_link[COM1].server==NIL) |
com_fast(COM1); |
else |
task_activate(com_link[COM1].server); |
} |
else if ((iir3 & com_link[COM3].control)) { |
#ifdef __DEBUG_SERIAL__ |
fast_times3++; |
#endif |
com_write(COM3,IER,0); |
com_link[COM3].request = iir3; |
if (com_link[COM3].server==NIL) |
com_fast(COM3); |
else |
task_activate(com_link[COM3].server); |
} |
} |
#ifdef __DEBUG_SERIAL__ |
int fast_times2 = 0,fast_times4 = 0; |
#endif |
static void com_2_4_fast(int n) |
{ |
unsigned iir2,iir4; |
iir2 = DECODE(com_read(COM2,IIR)); |
iir4 = DECODE(com_read(COM4,IIR)); |
if ((iir2 & com_link[COM2].control)) { |
#ifdef __DEBUG_SERIAL__ |
fast_times2++; |
#endif |
com_write(COM2,IER,0); |
com_link[COM2].request = iir2; |
if (com_link[COM2].server==NIL) |
com_fast(COM2); |
else |
task_activate(com_link[COM2].server); |
} |
else if ((iir4 & com_link[COM4].control)) { |
#ifdef __DEBUG_SERIAL__ |
fast_times4++; |
#endif |
com_write(COM4,IER,0); |
com_link[COM4].request = iir4; |
if (com_link[COM4].server==NIL) |
com_fast(COM4); |
else |
task_activate(com_link[COM4].server); |
} |
} |
/* Initialize a serial channel */ |
int com_open(unsigned port,DWORD speed,BYTE parity,BYTE len,BYTE stop) |
{ |
unsigned long div,b_mask; |
/* Check if link is already open */ |
cli(); |
if (com_link[port].status & LINK_BUSY) { |
sti(); |
return(-1); |
} else com_link[port].status |= LINK_BUSY; |
sti(); |
/* Now set up the serial link */ |
b_mask = (parity & 3) * 8 + (stop & 1) * 4 + ((len - 5) & 3); |
div = 115200L / speed; |
/* Clear serial interrupt enable register */ |
com_write(port,IER,0); |
/* Empty input buffer */ |
com_read(port,RBR); |
/* Activate DLAB bit for speed setting */ |
com_write(port,LCR,0x80); |
/* Load baud divisor */ |
com_write(port,0,div & 0x00FF); |
div >>= 8; |
com_write(port,1,div & 0x00FF); |
/* Load control word (parity,stop bit,bit len) */ |
com_write(port,LCR,b_mask); |
/* Attiva OUT1 & OUT2 */ |
com_write(port,MCR,0x0C); |
return(1); |
} |
/* Link a particular server to a serial channel */ |
/* The semaphores are opened to syncronize the server and the */ |
/* application task which use serial communication */ |
int com_server(unsigned port,unsigned control,PID server) |
{ |
unsigned hndl = com_irq[port]; |
unsigned shared = com_share[port]; |
void (*com_fast)(int n); |
/* Select appropriate fast routine */ |
if (port == COM1 || port == COM3) com_fast = com_1_3_fast; |
else if (port == COM2 || port == COM4) com_fast = com_2_4_fast; |
else return(-1); |
if ((control & (RX_FULL|TX_EMPTY)) == 0) return(-1); |
/* If the fast routine is not already installed, install it! */ |
cli(); |
if (!(com_link[port].status & FAST_INSTALLED)) { |
bit_on(com_link[port].status,FAST_INSTALLED); |
bit_on(com_link[shared].status,FAST_INSTALLED); |
handler_set(hndl,com_fast,NIL, TRUE); |
#ifdef __DEBUG_SERIAL__ |
cputs("Handler OK\n"); |
#endif |
} |
sti(); |
/* Set com link tasks & flags */ |
com_link[port].control = control; |
com_link[port].server = server; |
com_link[port].msk = 0; |
if (control & RX_FULL) sem_init(&com_link[port].rx_sem,0,0); |
if (control & TX_EMPTY) sem_init(&com_link[port].tx_sem,0,0); |
sem_init(&com_link[port].mutex,0,1); |
return(1); |
} |
/* Close port channel & release the server */ |
int com_close(unsigned port) |
{ |
unsigned hndl = com_irq[port]; |
unsigned shared = com_share[port]; |
/* Check if fast is already installed */ |
cli(); |
if (!(com_link[port].status & LINK_BUSY)) { |
sti(); |
return(-1); |
} else { |
if (com_link[port].control & RX_FULL) sem_destroy(&com_link[port].rx_sem); |
if (com_link[port].control & TX_EMPTY) sem_destroy(&com_link[port].tx_sem); |
com_write(port,IER,0); |
com_read(port,IIR); |
com_read(port,RBR); |
com_link[port].status = 0; |
com_link[port].control = 0; |
com_link[port].msk = 0; |
sti(); |
sem_destroy(&com_link[port].mutex); |
if (com_link[port].server != NIL) { |
task_kill(com_link[port].server); |
com_link[port].server = NIL; |
} |
} |
/* If the fast routine is no more necessary, remove it */ |
if (!(com_link[shared].status & FAST_INSTALLED)) |
handler_remove(hndl); |
/* If the other link still uses it, we must remember this */ |
else com_link[port].status = FAST_INSTALLED; |
return(1); |
} |
#ifdef __DEBUG_SERIAL__ |
int rx_time = 0; |
int tx_time = 0; |
#endif |
/* This is the full duplex server; used for bidirectional data */ |
/* transmission. */ |
/* As intr is masked, the server can only be activated once */ |
/* and operates in mutex with the fast handler */ |
/* This server operates in conjunction with the com_Async... */ |
/* procedures! */ |
TASK duplexServer(int port) |
{ |
char data; |
for(;;) { |
if (com_link[port].request & RX_FULL) { |
#ifdef __DEBUG_SERIAL__ |
putc_xy(78,0,RED,'R'); |
rx_time++; |
#endif |
data = com_read(port,RBR); |
*(com_link[port].rx_buf + com_link[port].rx_cnt) = data; |
com_link[port].rx_cnt++; |
if (com_link[port].rx_cnt == com_link[port].rx_len) { |
bit_off(com_link[port].msk,RX_FULL); |
sem_post(&com_link[port].rx_sem); |
} |
} |
if (com_link[port].request & TX_EMPTY) { |
#ifdef __DEBUG_SERIAL__ |
putc_xy(79,0,GREEN,'T'); |
tx_time++; |
#endif |
data = *(com_link[port].tx_buf + com_link[port].tx_cnt); |
com_link[port].tx_cnt++; |
com_write(port,THR,data); |
if (com_link[port].tx_cnt == com_link[port].tx_len) { |
bit_off(com_link[port].msk,TX_EMPTY); |
sem_post(&com_link[port].tx_sem); |
} |
} |
cli(); |
com_write(port,IER,com_link[port].msk); |
task_endcycle(); |
sti(); |
} |
} |
/* This routines provides asyncronous decoupling between the server */ |
/* and the tasks which produce/consume serial data */ |
void com_AsyncSend(int port,void *buf,unsigned len) |
{ |
sem_wait(&com_link[port].mutex); |
com_link[port].tx_buf = buf; |
com_link[port].tx_cnt = 0; |
com_link[port].tx_len = len; |
bit_on(com_link[port].msk,TX_EMPTY); |
sem_post(&com_link[port].mutex); |
com_write(port,IER,com_link[port].msk); |
sem_wait(&com_link[port].tx_sem); |
} |
void com_AsyncReceive(int port,void *buf,unsigned len) |
{ |
sem_wait(&com_link[port].mutex); |
com_link[port].rx_buf = buf; |
com_link[port].rx_cnt = 0; |
com_link[port].rx_len = len; |
bit_on(com_link[port].msk,RX_FULL); |
sem_post(&com_link[port].mutex); |
com_write(port,IER,com_link[port].msk); |
sem_wait(&com_link[port].rx_sem); |
} |
/* Receive Only Server */ |
/* This server is used for passive devices which cannot receive */ |
/* data, but only transmit. I assume that only one byte is pro- */ |
/* cessed each time and the byte is got to the control process */ |
TASK rxServer(int port) |
{ |
static char data; |
com_link[port].rx_buf = &data; |
for(;;) { |
#ifdef __DEBUG_SERIAL__ |
putc_xy(76,0,YELLOW,'R'); |
#endif |
data = com_read(port,RBR); |
sem_post(&com_link[port].rx_sem); |
cli(); |
com_write(port,IER,com_link[port].msk); |
task_endcycle(); |
sti(); |
} |
} |
/* Debug Stub */ |
#ifdef __STUB__ |
#include "keyb.h" |
TASK Visualize(void) |
{ |
char str[40]; |
char buf[80]; |
unsigned long times = 0; |
for (;;) { |
com_AsyncReceive(COM2,str,10); |
sprintf(buf,"Str : %s (Times : %lu)",str,times++); |
puts_xy(0,1,WHITE,buf); |
} |
} |
TASK Sender(void) |
{ |
char buf[80]; |
unsigned long times = 0; |
cputs("Sender has started...\n"); |
for (;;) { |
buf[0] = keyb_getchar(); |
if (buf[0] == 'x') task_activate(MAIN_INDEX); |
if ((times % 10) == 9) buf[0] = 0; |
com_AsyncSend(COM2,buf,1); |
sprintf(buf,"Sender (Times : %lu)",times++); |
puts_xy(0,3,WHITE,buf); |
} |
} 0 |
void main() |
{ |
PID p1,p2,p3; |
BYTE m1 = TX_EMPTY|RX_FULL; |
BYTE m2 = RX_FULL; |
BYTE m3 = TX_EMPTY; |
MODEL m = BASE_MODEL; |
MODEL mm = BASE_MODEL; |
sys_init(1000,uSec,0); |
keyb_init(HARD,50); |
clear(); |
/* This is the sequence of operations needed to setup */ |
/* a serial asyncronous bidirectional link */ |
task_def_arg(m,COM2); |
task_def_wcet(m,500); |
p1 = task_create("ComDuplex",duplexServer,HARD,APERIODIC,100,&m); |
if (p1 == -1) { |
ll_printf("Error creating comduplex task\n"); |
sys_end(); |
exit(-1); |
} |
com_open(COM2,9600,NONE,8,1); |
com_server(COM2,m1,p1); |
/* Well, that is some other stuff ... */ |
task_def_wcet(mm,500); |
p2 = task_create("Visor",Visualize,NRT,APERIODIC,11,&mm); |
p3 = task_create("Sender",Sender,NRT,APERIODIC,11,&mm); |
task_activate(p2); |
task_activate(p3); |
task_endcycle(); |
sys_end(); |
#ifdef __DEBUG_SERIAL__ |
cprintf("RxServer was activated %d times\n",rx_time); |
cprintf("TxServer was activated %d times\n",tx_time); |
cprintf("Fast : %d\n",fast_times1); |
#endif |
} |
#endif |
/shark/trunk/drivers/serial/include/drivers/scom.h |
---|
0,0 → 1,155 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: scom.h,v 1.1 2004-03-29 18:31:42 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-03-29 18:31:42 $ |
------------ |
**/ |
/* |
* Copyright (C) 2000 Gerardo Lamastra |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/* Project: HARTIK 3.0 */ |
/* Description: Hard Real TIme Kernel for 386 & higher machines */ |
/* Author: Gerardo Lamastra */ |
/* Date: 9/5/96 */ |
/* File: SCOM.H */ |
/* Revision: 2.0 */ |
#ifndef __SCOM_H__ |
#define __SCOM_H__ |
#ifdef __cplusplus |
extern "C" { |
#endif |
#include <modules/sem.h> |
/* Number of available COM links */ |
#define COM_LINKS 4 |
#define COM1 0 |
#define COM2 1 |
#define COM3 2 |
#define COM4 3 |
/* These values identify interrupt type */ |
#define RX_FULL 1 |
#define TX_EMPTY 2 |
#define LS_CHANGED 4 |
#define MS_CHANGED 8 |
/* This is set when the channel is open */ |
#define LINK_BUSY 128 |
/* This is set if the fast handler is installed */ |
#define FAST_INSTALLED 64 |
/* Register displacements */ |
#define THR 0 |
#define RBR 0 |
#define IER 1 |
#define FCR 2 |
#define IIR 2 |
#define LCR 3 |
#define MCR 4 |
#define LSR 5 |
#define MSR 6 |
#define SPad 7 |
/* Parity value */ |
#define NONE 0 |
#define ODD 1 |
#define EVEN 3 |
/* Used for decoding the IIR status */ |
extern const int IIRbits[]; |
#define DECODE(v) IIRbits[((v >> 1) & 3)] |
#define PENDIRQ(v) !((v) & 1) |
/* Bit setting macros */ |
#define bit_on(v,b) v |= (b) |
#define bit_off(v,b) v &= (~(b)) |
/* The descriptor of a serial link */ |
/* Each array entry is associated to a COM port */ |
/* The control field is used to specify which kind of interrupts */ |
/* are going to be served; the status field tracks if the entry */ |
/* is curretly used & if the shared fast handler is linked */ |
/* The semaphores are opened if you use an asyncronous server */ |
/* with the link */ |
extern struct COM_LINK { |
/* These fields are for general use */ |
BYTE status; |
BYTE control; |
BYTE request; |
BYTE msk; |
PID server; |
sem_t mutex; |
sem_t tx_sem; |
sem_t rx_sem; |
BYTE *tx_buf; |
BYTE *rx_buf; |
unsigned tx_len,rx_len; |
unsigned tx_cnt,rx_cnt; |
} com_link[COM_LINKS]; |
/* Available servers */ |
TASK duplexServer(int port); |
TASK rxServer(int port); |
int com_open(unsigned int port,DWORD speed,BYTE parity,BYTE len,BYTE stop); |
int com_server(unsigned int port,unsigned int control,PID server); |
int com_close(unsigned int port); |
unsigned com_read(unsigned int port,unsigned int reg); |
unsigned com_receive(unsigned int port); |
void com_write(unsigned int port,unsigned int reg,unsigned int value); |
void com_send(unsigned int port,BYTE b); |
void com_AsyncSend(int port,void *buf,unsigned int len); |
void com_AsyncReceive(int port,void *buf,unsigned int len); |
#ifdef __cplusplus |
}; |
#endif |
#endif |
/shark/trunk/drivers/serial/makefile |
---|
0,0 → 1,18 |
# The Serial Devices |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
LIBRARY = serial |
OBJS_PATH = $(BASE)/drivers/serial |
OBJS = scom.o |
OTHERINCL += -I$(BASE)/drivers/serial/include |
include $(BASE)/config/lib.mk |
/shark/trunk/drivers/input/makefile.full |
---|
File deleted |
/shark/trunk/drivers/input/joystick/analog.c |
---|
1,5 → 1,5 |
/* |
* $Id: analog.c,v 1.1 2004-03-08 18:47:38 giacomo Exp $ |
* $Id: analog.c,v 1.2 2004-03-29 18:27:43 mauro Exp $ |
* |
* Copyright (c) 1996-2001 Vojtech Pavlik |
*/ |
139,9 → 139,13 |
*/ |
#ifdef __i386__ |
#define GET_TIME(x) do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0) |
/* !!! Added by Nino !!! */ |
#define GET_TIME(x) (x = get_time_pit()) |
#define DELTA(x,y) ((y)-(x)) |
#define TIME_NAME ("Shark") |
/*#define GET_TIME(x) do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0) |
#define DELTA(x,y) (cpu_has_tsc?((y)-(x)):((x)-(y)+((x)<(y)?1193182L/HZ:0))) |
#define TIME_NAME (cpu_has_tsc?"TSC":"PIT") |
#define TIME_NAME (cpu_has_tsc?"TSC":"PIT")*/ |
static unsigned int get_time_pit(void) |
{ |
extern spinlock_t i8253_lock; |
335,7 → 339,7 |
if (port->analog[i].mask) |
analog_decode(port->analog + i, port->axes, port->initial, port->buttons); |
mod_timer(&port->timer, jiffies + ANALOG_REFRESH_TIME); |
mod_timer(&port->timer, jiffies26 + ANALOG_REFRESH_TIME); |
} |
/* |
346,7 → 350,7 |
{ |
struct analog_port *port = dev->private; |
if (!port->used++) |
mod_timer(&port->timer, jiffies + ANALOG_REFRESH_TIME); |
mod_timer(&port->timer, jiffies26 + ANALOG_REFRESH_TIME); |
return 0; |
} |
/shark/trunk/drivers/input/include/drivers/shark_joy26.h |
---|
0,0 → 1,46 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Mauro Marinoni <mauro.marinoni@unipv.it> |
* |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/* Game Header Linux Input Driver*/ |
#ifndef __SHARK_JOY26_H__ |
#define __SHARK_JOY26_H__ |
int JOY26_init(void); |
int JOY26_close(void); |
#endif |
/shark/trunk/drivers/input/include/drivers/shark_mouse26.h |
---|
125,6 → 125,66 |
int mouse_setthreshold(int t); |
void mouse_hook(MOUSE_HANDLER h); |
/* |
* |
* mouse autocursor management |
* |
*/ |
/* commands for mouse_grxcursor() & mouse_txtcursor() */ |
#define DISABLE 0x00 |
#define ENABLE 0x01 |
/* flags for mouse_grxcursor() & mouse_txtcursor() (to use with '|') */ |
#define WITHOUTSEM 0x10 |
#define AUTOOFF 0x20 |
/* mask to extrac the status from autocursormode */ |
#define STATUSMASK 0x0f |
/* flags for autocursormode (there are some other flags into mouse.h) */ |
#define GRXCURSOR 0x100 |
#define TXTCURSOR 0x200 |
/* dimensions of the grx shape */ |
#define MOUSESHAPEDX 16 |
#define MOUSESHAPEDY 16 |
/* hot-spot of the grx image (coordinates of the center's shape, zero-based) */ |
#define MOUSEHOTSPOTX 3 |
#define MOUSEHOTSPOTY 1 |
/* those macros can be used to set the correct mouse_limit() when |
* the graphics autocursor is enable (to avoid wrong shape position because |
* there is not graphics clip functions) |
*/ |
#define XMINLIMIT(dimx,dimy) (MOUSEHOTSPOTX) |
#define XMAXLIMIT(dimx,dimy) ((dimx)-MOUSESHAPEDX+MOUSEHOTSPOTX) |
#define YMINLIMIT(dimx,dimy) (MOUSEHOTSPOTY) |
#define YMAXLIMIT(dimx,dimy) ((dimy)-MOUSESHAPEDY+MOUSEHOTSPOTY) |
#define mouse_grxlimit(dimx,dimy) mouse_limit(\ |
XMINLIMIT(dimx,dimy), \ |
YMINLIMIT(dimx,dimy), \ |
XMAXLIMIT(dimx,dimy), \ |
YMAXLIMIT(dimx,dimy) \ |
) |
/* these are used to select the mouse shape */ |
int mouse_txtshape(DWORD img); |
int mouse_grxshape(BYTE *shape, BYTE *mask, int bpp_in); |
/* enable/disable mouse pointer */ |
/* (return <0 on error) */ |
/* (for the cmd parameter see above) */ |
int mouse_grxcursor(int cmd, int bpp); |
int mouse_txtcursor(int cmd); |
/* mouse on/off (or show/hide) */ |
void (*mouse_on)(void); |
void (*mouse_off)(void); |
#ifdef __cplusplus |
}; |
#endif |
/shark/trunk/drivers/input/shark/shark_mouse.c |
---|
75,7 → 75,8 |
static int mouse_z = 0; |
static unsigned long mouse_buttons = 0; |
static MOUSE_HANDLER mouse_handler = NULL; |
MOUSE_HANDLER user_mouse_handler = NULL; |
MOUSE_HANDLER show_mouse_handler = NULL; |
#ifdef MOUSE_TASK |
/* mouse task PID */ |
143,7 → 144,10 |
dx, dy, dz, (int)dbuttons, mouse_x, mouse_y, mouse_z, (int)mouse_buttons); |
#endif |
/* mouse handler */ |
if (mouse_handler!=NULL) mouse_handler(&ev); |
if (show_mouse_handler != NULL) |
show_mouse_handler(&ev); |
else if (user_mouse_handler != NULL) |
user_mouse_handler(&ev); |
} |
} |
#ifdef MOUSE_TASK |
216,7 → 220,7 |
void mouse_hook(MOUSE_HANDLER h) |
{ |
mouse_handler = h; |
user_mouse_handler = h; |
} |
int mouse_getthreshold(void) |
/shark/trunk/drivers/input/shark/mcurtxt.c |
---|
0,0 → 1,348 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* Mauro Marinoni <mauro.marinoni@unipv.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/* |
* |
* Auto Pointer management |
* |
*/ |
#include <kernel/kern.h> |
#include <modules/sem.h> |
#include "../include/drivers/shark_input26.h" |
#include "../include/drivers/shark_mouse26.h" |
//#define CURTXT_DEBUG |
/* these variables are managed by this module but MUST be declared |
* into shark_mouse.c to prevent implicit inclusion of this module |
* when a user link the mouse library |
*/ |
extern MOUSE_HANDLER show_mouse_handler; |
extern MOUSE_HANDLER user_mouse_handler; |
/* a mutex semaphore */ |
static sem_t mutex=-1; |
/* Setup function */ |
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int)); |
/* |
* |
* autocursor mouse handler |
* |
*/ |
/* >=0 hide cursor; <0 show cursor */ |
static int mouse_cursor_state = 0; |
/* mouse status */ |
static int autocursormode = 0; |
/* saved mouse_position */ |
static int saved_x, saved_y; |
static void dummy(int x,int y){} |
static void (*show_cursor)(int x, int y) = dummy; |
static void (*restore_cursor)(int x, int y) = dummy; |
/* those are the 4 mouse handlers */ |
/* AUTOOFF -> call the user handler with no mouse displayed */ |
/* WITHOUTSEM -> does not use a mutex semaphore */ |
/* with no flags */ |
static void autocursor_mouse_handler_1(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_1\n"); |
#endif |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
sem_wait(&mutex); |
if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
show_cursor(saved_x, saved_y); |
} |
sem_post(&mutex); |
} |
/* with WITHOUTSEM flag*/ |
static void autocursor_mouse_handler_2(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_2\n"); |
#endif |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
if ( (mouse_cursor_state < 0) && (event->x != saved_x || event->y != saved_y)) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
show_cursor(saved_x, saved_y); |
} |
} |
/* with AUTOOFF flag*/ |
static void autocursor_mouse_handler_3(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_3\n"); |
#endif |
sem_wait(&mutex); |
if (mouse_cursor_state < 0) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
show_cursor(saved_x, saved_y); |
} else if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
sem_post(&mutex); |
} |
/* with WITHOUTSEM & AUTOOFF flags */ |
static void autocursor_mouse_handler_4(MOUSE_EVT *event) |
{ |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mcurtxt.c: autocursor_mouse_handler_4\n"); |
#endif |
if (mouse_cursor_state < 0) { |
restore_cursor(saved_x, saved_y); |
saved_x = event->x; |
saved_y = event->y; |
if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
show_cursor(saved_x, saved_y); |
} else if (user_mouse_handler != NULL) |
user_mouse_handler(event); |
} |
/* -------------- |
* TXT management |
* -------------- |
*/ |
/* text cursor shape */ |
#define DEFAULTTXTSHAPE 0x7700ffff |
static DWORD saved_txtshape = DEFAULTTXTSHAPE; |
static BYTE attr_andmask, attr_xormask; |
static BYTE c_andmask, c_xormask; |
/* saved values */ |
static BYTE saved_attr, saved_c; |
/* show txt cursor */ |
void show_txt_cursor(int x, int y) |
{ |
int attr,c; |
getc_xy(x, y, &saved_attr, &saved_c); |
attr = (saved_attr & attr_andmask) ^ attr_xormask; |
c = (saved_c & c_andmask) ^ c_xormask; |
putc_xy(x, y, attr, c); |
} |
/* restore txt cursor */ |
static void restore_txt_cursor(int x, int y) |
{ |
putc_xy(x, y, saved_attr, saved_c); |
} |
/* define text shape */ |
int mouse_txtshape(DWORD img) |
{ |
int cond; |
if (img == DEFAULT) |
img = DEFAULTTXTSHAPE; |
cond = ( (autocursormode & STATUSMASK) == ENABLE && (autocursormode & TXTCURSOR) == TXTCURSOR ); |
if (cond) |
restore_txt_cursor(saved_x, saved_y); |
saved_txtshape = img; |
c_andmask = img & 0xff; |
attr_andmask = (img & 0xff00) >> 8; |
c_xormask = (img & 0xff0000) >> 16; |
attr_xormask = (img & 0xff000000) >> 24; |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "MouseTxt_Shape: %x %x %x %x\n", c_andmask, attr_andmask, c_xormask, attr_xormask); |
#endif |
if (cond) |
show_txt_cursor(saved_x, saved_y); |
return 0; |
} |
/* |
* User interface to autocursor functions |
*/ |
/* display the cursor */ |
#define MOUSE_ON() { \ |
int unused; \ |
unsigned long lunused; \ |
mouse_cursor_state--; \ |
if (mouse_cursor_state == -1) { \ |
mouse_getpos(&saved_x, &saved_y, &unused, &lunused); \ |
show_cursor(saved_x, saved_y); \ |
} \ |
} |
static void mouse_on_sem(void) |
{ |
sem_wait(&mutex); |
MOUSE_ON(); |
sem_post(&mutex); |
} |
static void mouse_on_nosem(void) |
{ |
MOUSE_ON(); |
} |
void (*mouse_on)(void)=mouse_on_nosem; |
/* hide the cursor */ |
#define MOUSE_OFF() { \ |
mouse_cursor_state++; \ |
if (mouse_cursor_state == 0) \ |
restore_cursor(saved_x, saved_y); \ |
} |
void mouse_off_sem(void) |
{ |
sem_wait(&mutex); |
MOUSE_OFF(); |
sem_post(&mutex); |
} |
void mouse_off_nosem(void) |
{ |
MOUSE_OFF(); |
} |
void (*mouse_off)(void) = mouse_off_nosem; |
static MOUSE_HANDLER wich_handler(int cmd) |
{ |
if ( ((cmd & WITHOUTSEM) == WITHOUTSEM) && ((cmd & AUTOOFF) == AUTOOFF) ) |
return autocursor_mouse_handler_4; |
if ((cmd & WITHOUTSEM) == WITHOUTSEM) |
return autocursor_mouse_handler_2; |
if ((cmd & AUTOOFF) == AUTOOFF) |
return autocursor_mouse_handler_3; |
return autocursor_mouse_handler_1; |
} |
int mouse_txtcursor(int cmd) |
{ |
mouse_txtshape(saved_txtshape); |
return _mouse_cursor_init(cmd|TXTCURSOR, show_txt_cursor, restore_txt_cursor); |
} |
/* Generic functions, both for text & graphics mode */ |
int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int)) |
{ |
if (mutex == -1) { |
if (sem_init(&mutex, 0, 1) == -1) |
return -1; |
} |
#ifdef CURTXT_DEBUG |
printk(KERN_DEBUG "mouse_cursor_init: command %x\n", cmd); |
#endif |
switch (cmd & STATUSMASK) { |
case DISABLE: |
//show_mouse_handler = user_mouse_handler; |
show_mouse_handler = NULL; |
restore_cursor(saved_x, saved_y); |
show_cursor = dummy; |
restore_cursor = dummy; |
mouse_cursor_state = 0; |
break; |
case ENABLE: |
restore_cursor(saved_x, saved_y); |
restore_cursor = my_restore_cursor; |
show_cursor = my_show_cursor; |
if ((autocursormode & STATUSMASK) == DISABLE) { |
//user_mouse_handler = show_mouse_handler; |
show_mouse_handler = wich_handler(cmd); |
} |
mouse_cursor_state = -1; |
break; |
default: |
return -1; |
} |
autocursormode = cmd; |
if ((autocursormode & STATUSMASK) == ENABLE) { |
if ((cmd & WITHOUTSEM) == WITHOUTSEM) { |
mouse_on = mouse_on_nosem; |
mouse_off = mouse_off_nosem; |
} else { |
mouse_on = mouse_on_sem; |
mouse_off = mouse_off_sem; |
} |
} |
return 0; |
} |
void _mouse_cursor_getposition(int *xptr, int *yptr) |
{ |
*xptr = saved_x; |
*yptr = saved_y; |
} |
/shark/trunk/drivers/input/shark/shark_input.c |
---|
51,16 → 51,6 |
/*extern int serport_init(void); |
extern int serport_exit(void);*/ |
/* Devices */ |
/*extern int ns558_init(void); |
extern int ns558_exit(void); |
extern int analog_init(void); |
extern int analog_exit(void); |
extern int joydump_init(void); |
extern int joydump_exit(void);*/ |
/* Handlers */ |
extern int evbug_init(void); |
extern int evbug_exit(void); |
116,41 → 106,7 |
return -1; |
} |
/* Init the Linux Joystick Driver */ |
/*int JOY26_init() { |
int ret; |
if (input_installed == FALSE) |
if (INPUT26_init()) { |
printk(KERN_ERR "Unable to open Input SubSystem.\n"); |
return -1; |
} |
ret = ns558_init(); |
if (ret) { |
printk(KERN_ERR "Gameport_Init return: %d\n", ret); |
return -1; |
} |
//ret = analog_init(); |
ret = joydump_init(); |
if (ret) { |
printk(KERN_ERR "Joystick_Init return: %d\n", ret); |
return -1; |
} |
return 0; |
} |
int JOY26_close() { |
//analog_exit(); |
joydump_exit(); |
ns558_exit(); |
return 0; |
}*/ |
/* Init the Linux Event Debug Driver */ |
int EVBUG26_init() { |
evbug_init(); |
/shark/trunk/drivers/input/shark/mcurgrx.c |
---|
0,0 → 1,205 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
/*---------------* |
* GRX Management* |
*---------------*/ |
#include <kernel/kern.h> |
//#include <drivers/glib.h> |
#include "../include/drivers/shark_input26.h" |
#include "../include/drivers/shark_mouse26.h" |
/* External functions */ |
extern void grx_getimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf); |
extern void grx_putimage(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf); |
extern int _mouse_cursor_init(int cmd, void(*my_show_cursor)(int, int), void(*my_restore_cursor)(int, int)); |
extern void _mouse_cursor_getposition(int *xptr, int *yptr); |
extern int autocursormode; |
static BYTE left_ptr_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, |
0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, 0xf8, 0x03, |
0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01, |
0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00 }; |
static BYTE left_ptrmsk_bits[] = { 0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00, |
0xfc, 0x00, 0xfc, 0x01, 0xfc, 0x03, 0xfc, 0x07, |
0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03, |
0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03 }; |
/* dimensions (16x16) */ |
#define SHAPE_DX MOUSESHAPEDX |
#define SHAPE_DY MOUSESHAPEDY |
/* shape hot spot (3,1) */ |
#define HOTSPOT_X MOUSEHOTSPOTX |
#define HOTSPOT_Y MOUSEHOTSPOTY |
/* cursor shape */ |
static BYTE shape[SHAPE_DX * SHAPE_DY * 4]; |
/* cursor mask */ |
static BYTE mask[SHAPE_DX * SHAPE_DY * 4]; |
/* old memory buffer */ |
static BYTE saved_shape[SHAPE_DX * SHAPE_DY * 4]; |
/* new memory buffer */ |
static BYTE new_shape[SHAPE_DX * SHAPE_DY * 4]; |
static BYTE *saved_shapeptr = (void*)DEFAULT; |
static BYTE *saved_maskptr = (void*)DEFAULT; |
static int bpp; // bytes per pixel |
/* if called with NULL -> retrieve next bit of a bits-stream |
* else -> initialize the bit stream |
*/ |
static int get_bit(BYTE *p) |
{ |
static BYTE *ptr; |
static BYTE val; |
static int c; |
if (p != NULL) { |
ptr = p; |
val = 0; |
c = 8; |
return 0; |
} |
if (c==8) { |
c = 0; |
val = *ptr; |
ptr++; |
} else |
val >>= 1; |
c++; |
return val&1; |
} |
/* show grx cursor */ |
static void show_grx_cursor(int x, int y) |
{ |
int i; |
x -= HOTSPOT_X - 1; |
y -= HOTSPOT_Y - 1; |
grx_getimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape); |
for(i=0; i < SHAPE_DX*SHAPE_DY*bpp/4; i++) |
((DWORD*)new_shape)[i] = ( ((DWORD*)saved_shape)[i] & ((DWORD*)mask)[i] ) | ((DWORD*)shape)[i]; |
grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, new_shape); |
} |
/* restore grx cursor */ |
static void restore_grx_cursor(int x, int y) |
{ |
x -= HOTSPOT_X - 1; |
y -= HOTSPOT_Y - 1; |
grx_putimage(x, y, x+SHAPE_DX-1, y+SHAPE_DY-1, saved_shape); |
} |
int mouse_grxcursor(int cmd, int bpp) |
{ |
mouse_grxshape(saved_shapeptr, saved_maskptr, bpp); |
return _mouse_cursor_init(cmd|GRXCURSOR, show_grx_cursor, restore_grx_cursor); |
} |
/* compute the shape and mask array */ |
int mouse_grxshape(BYTE *shapeptr, BYTE *maskptr, int bpp_in) |
{ |
BYTE b; |
int pc; |
int i,j; |
int saved_x, saved_y; |
int cond; |
/*int result; |
grx_vga_modeinfo info;*/ |
/* Autocalculate bpp */ |
/*result = gd_getmodeinfo(&info); |
if (result == -1) |
return -1; |
bpp = info.bytesperpixel;*/ |
cond = ( ((autocursormode & STATUSMASK) == ENABLE) && ((autocursormode & GRXCURSOR) == GRXCURSOR) ); |
if (cond) { |
_mouse_cursor_getposition(&saved_x,&saved_y); |
restore_grx_cursor(saved_x,saved_y); |
} |
if (bpp_in != -1) |
bpp = bpp_in; |
if (shapeptr == (void*)DEFAULT) { |
shapeptr = left_ptr_bits; |
pc = 0; |
get_bit(left_ptr_bits); |
for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) { |
b = get_bit(NULL) ? 255 : 0; |
for (j = 0; j < bpp; j++) |
shape[pc++] = b; |
} |
} else { |
memcpy(shape, shapeptr, SHAPE_DX*SHAPE_DY*bpp); |
saved_shapeptr = shapeptr; |
} |
if (maskptr == (void*)DEFAULT) { |
maskptr = left_ptrmsk_bits; |
pc = 0; |
get_bit(left_ptrmsk_bits); |
for (i = 0; i < SHAPE_DX*SHAPE_DY; i++) { |
b=get_bit(NULL)?0:255; |
for (j = 0; j < bpp; j++) |
mask[pc++] = b; |
} |
} else { |
memcpy(mask, maskptr, SHAPE_DX*SHAPE_DY*bpp); |
saved_maskptr = maskptr; |
} |
if (cond) |
show_grx_cursor(saved_x,saved_y); |
return 0; |
} |
/shark/trunk/drivers/input/shark/shark_joy.c |
---|
0,0 → 1,112 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Mauro Marinoni <mauro.marinoni@unipv.it> |
* |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#define __JOY_DEBUG__ |
//#define __JOY_DUMP__ |
#include <kernel/kern.h> |
#include "../include/drivers/shark_input26.h" |
#include "../include/drivers/shark_joy26.h" |
#include <kernel/func.h> |
/* Devices */ |
extern int ns558_init(void); |
extern int ns558_exit(void); |
extern int analog_init(void); |
extern int analog_exit(void); |
extern int joydump_init(void); |
extern int joydump_exit(void); |
/* Handler */ |
extern int joystick_init(void); |
extern int joystick_exit(void); |
extern int input_installed; |
/* User Functions */ |
/* Init the Linux Joystick Driver */ |
int JOY26_init() { |
int ret; |
if (input_installed == FALSE) |
if (INPUT26_init()) { |
printk(KERN_ERR "Unable to open Input SubSystem.\n"); |
return -1; |
} |
ret = ns558_init(); |
if (ret) { |
printk(KERN_ERR "Gameport_Init return: %d\n", ret); |
return -1; |
} |
#ifdef __JOY_DUMP__ |
ret = joydump_init(); |
#else |
ret = analog_init(); |
#endif |
if (ret) { |
printk(KERN_ERR "Joystick_Device_Init return: %d\n", ret); |
return -1; |
} |
ret = joystick_init(); |
if (ret) { |
printk(KERN_ERR "Joystick_Handler_Init return: %d\n", ret); |
return -1; |
} |
return 0; |
} |
int JOY26_close() { |
joystick_exit(); |
#ifdef __JOY_DUMP__ |
joydump_exit(); |
#else |
analog_exit(); |
#endif |
ns558_exit(); |
return 0; |
} |
/shark/trunk/drivers/input/handler/joystick.c |
---|
0,0 → 1,126 |
/* |
* Input driver event debug module - dumps all events into syslog |
*/ |
/* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ |
#include <linuxcomp.h> |
#include <linux/slab.h> |
#include <linux/module.h> |
#include <linux/input.h> |
#include <linux/init.h> |
#include <linux/device.h> |
//#define DEBUG_JOY |
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
MODULE_DESCRIPTION("Input driver joystick module"); |
MODULE_LICENSE("GPL"); |
static char joystick_name[] = "joystick"; |
static struct input_handler joystick_handler; |
static void joystick_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) |
{ |
#ifdef DEBUG_JOY |
printk(KERN_DEBUG "joystick.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", handle->dev->phys, type, code, value); |
#endif |
} |
static struct input_handle *joystick_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) |
{ |
struct input_handle *handle; |
/* Avoid tablets */ |
if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_TOUCH, dev->keybit)) |
return NULL; |
if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) |
return NULL; |
memset(handle, 0, sizeof(struct input_handle)); |
handle->dev = dev; |
handle->handler = handler; |
handle->name = joystick_name; |
input_open_device(handle); |
#ifdef DEBUG_JOY |
printk(KERN_DEBUG "joystick.c: Connected device: \"%s\", %s\n", dev->name, dev->phys); |
#endif |
return handle; |
} |
static void joystick_disconnect(struct input_handle *handle) |
{ |
#ifdef DEBUG_JOY |
printk(KERN_DEBUG "joystick.c: Disconnected device: %s\n", handle->dev->phys); |
#endif |
input_close_device(handle); |
kfree(handle); |
} |
/*static struct input_device_id joystick_ids[] = { |
{ .driver_info = 1 }, // Matches all devices |
{ }, // Terminating zero entry |
};*/ |
static struct input_device_id joystick_ids[] = { |
{ |
.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, |
.evbit = { BIT(EV_ABS) }, |
.absbit = { BIT(ABS_X) }, |
}, |
{ |
.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, |
.evbit = { BIT(EV_ABS) }, |
.absbit = { BIT(ABS_WHEEL) }, |
}, |
{ |
.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT, |
.evbit = { BIT(EV_ABS) }, |
.absbit = { BIT(ABS_THROTTLE) }, |
}, |
{ }, /* Terminating entry */ |
}; |
MODULE_DEVICE_TABLE(input, joystick_ids); |
static struct input_handler joystick_handler = { |
.event = joystick_event, |
.connect = joystick_connect, |
.disconnect = joystick_disconnect, |
.name = "joystick", |
.id_table = joystick_ids, |
}; |
int __init joystick_init(void) |
{ |
input_register_handler(&joystick_handler); |
return 0; |
} |
void __exit joystick_exit(void) |
{ |
input_unregister_handler(&joystick_handler); |
} |
module_init(joystick_init); |
module_exit(joystick_exit); |
/shark/trunk/drivers/input/handler/keyboard.c |
---|
1,14 → 1,8 |
/* |
* $Id: keyboard.c,v 1.2 2004-03-23 15:37:21 mauro Exp $ |
* |
* Copyright (c) 1999-2001 Vojtech Pavlik |
* Input driver keyboard module |
*/ |
/* |
* Input driver event debug module - dumps all events into syslog |
*/ |
/* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
38,7 → 32,7 |
//#define DEBUG_KBD |
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
MODULE_DESCRIPTION("Input driver event debug module"); |
MODULE_DESCRIPTION("Input driver keyboard module"); |
MODULE_LICENSE("GPL"); |
extern void shark_kbd_exec(void); |
/shark/trunk/drivers/input/handler/mouse.c |
---|
1,14 → 1,8 |
/* |
* $Id: mouse.c,v 1.2 2004-03-25 10:37:48 mauro Exp $ |
* |
* Copyright (c) 1999-2001 Vojtech Pavlik |
* Input driver mouse module |
*/ |
/* |
* Input driver event debug module - dumps all events into syslog |
*/ |
/* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
31,7 → 25,7 |
//#define DEBUG_MOUSE |
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
MODULE_DESCRIPTION("Input driver event debug module"); |
MODULE_DESCRIPTION("Input driver mouse module"); |
MODULE_LICENSE("GPL"); |
extern void shark_mouse_exec(void); |
/shark/trunk/drivers/input/handler/speaker.c |
---|
1,14 → 1,8 |
/* |
* $Id: speaker.c,v 1.1 2004-03-22 14:48:15 mauro Exp $ |
* |
* Copyright (c) 1999-2001 Vojtech Pavlik |
* Input driver speaker module |
*/ |
/* |
* Input driver event debug module - dumps all events into syslog |
*/ |
/* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
35,7 → 29,7 |
//#define DEBUG_SPK |
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
MODULE_DESCRIPTION("Input driver event debug module"); |
MODULE_DESCRIPTION("Input driver joystick module"); |
MODULE_LICENSE("GPL"); |
static char speaker_name[] = "speaker"; |
/shark/trunk/drivers/input/makefile |
---|
14,11 → 14,14 |
mouse/psmouse-base.o mouse/logips2pp.o mouse/synaptics.o\ |
keyboard/atkbd.o\ |
misc/pcspkr.o\ |
handler/evbug.o handler/keyboard.o\ |
handler/mouse.o handler/speaker.o\ |
gameport/gameport.o gameport/ns558.o\ |
joystick/analog.o joystick/joydump.o\ |
handler/mouse.o handler/keyboard.o handler/speaker.o\ |
handler/evbug.o handler/joystick.o\ |
shark/shark_input.o shark/shark_mouse.o\ |
shark/shark_keymap.o shark/shark_keyb.o\ |
shark/shark_spk.o |
shark/mcurtxt.o shark/mcurgrx.o\ |
shark/shark_spk.o shark/shark_joy.o |
OTHERINCL += -I$(BASE)/drivers/linuxc26/include |
25,7 → 28,3 |
C_OPT += -D__KERNEL__ |
include $(BASE)/config/lib.mk |
clean:: |
rm -f $(OBJS) |
/shark/trunk/drivers/input/gameport/ns558.c |
---|
1,5 → 1,5 |
/* |
* $Id: ns558.c,v 1.1 2004-03-08 18:47:38 giacomo Exp $ |
* $Id: ns558.c,v 1.2 2004-03-29 18:27:42 mauro Exp $ |
* |
* Copyright (c) 1999-2001 Vojtech Pavlik |
* Copyright (c) 1999 Brian Gerst |
93,6 → 93,7 |
outb(c, io); |
return; |
} |
/* |
* After a trigger, there must be at least some bits changing. |
*/ |
104,6 → 105,7 |
return; |
} |
wait_ms(3); |
/* |
* After some time (4ms) the axes shouldn't change anymore. |
*/ |
/shark/trunk/drivers/cons/include/drivers/crtwin.h |
---|
0,0 → 1,105 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: crtwin.h,v 1.1 2004-03-29 18:31:40 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-03-29 18:31:40 $ |
------------ |
Author: Giuseppe Lipari |
Date: 2/7/96 |
File: CrtWin.H |
Revision: 1.0 |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#ifndef __CRTWIN_H__ |
#define __CRTWIN_H__ |
#ifdef __cplusplus |
extern "C" { |
#endif |
typedef struct { |
/* Window location & size */ |
int x,y,dx,dy; |
/* Cursor position inside the window */ |
int px,py; |
} WIN; |
/* |
The window layout is depicted here |
(x,y) (x+dx,y) |
************************ |
*(0,0) * |
* * |
* * |
* (dx-1,dy-1)* |
************************ |
(x+dx,y+dy) |
Inside the window relative coords are used! |
*/ |
#define SINGLE_FRAME 1 |
#define DOUBLE_FRAME 2 |
#define NO_FRAME 0 |
void win_init(WIN *w,int x, int y, int dx, int dy); |
void win_frame(WIN *w,BYTE bcol,BYTE fcol,char *title,BYTE type); |
void win_scroll(WIN *w); |
void win_clear(WIN *w); |
void win_puts(WIN *w, char *s); |
int win_gets(WIN *w, char *s,int l); |
//void cons_init(void); |
#ifdef __cplusplus |
}; |
#endif |
#endif |
/shark/trunk/drivers/cons/crtwin.c |
---|
0,0 → 1,355 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: crtwin.c,v 1.1 2004-03-29 18:31:40 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-03-29 18:31:40 $ |
------------ |
Author: Gerardo Lamastra |
Date: 9/5/96 |
File: CrtWin.C |
Revision: 1.1g |
Text windowing functions for S.Ha.R.K. |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
//#include <string.h> |
//#include <cons.h> |
#include <kernel/kern.h> |
#include <ll/string.h> |
#include <drivers/crtwin.h> |
#define CUPS1 201 /* Definizione caratteri per */ |
#define LOR1 205 /* La cornice delle varie */ |
#define CUPD1 187 /* Finestre */ |
#define LVR1 186 |
#define CDWS1 200 |
#define CDWD1 188 |
#define CUPS2 218 |
#define LOR2 196 |
#define CUPD2 191 |
#define LVR2 179 |
#define CDWS2 192 |
#define CDWD2 217 |
void win_init(WIN *w, int x, int y, int dx, int dy) |
{ |
w->x = x; |
w->y = y; |
w->dx = dx; |
w->dy = dy; |
w->px = 0; |
w->py = 0; |
} |
void win_clear(WIN *w) |
{ |
_clear(' ',WHITE,w->x+1,w->y+1,w->x+w->dx-1,w->y+w->dy-1); |
} |
void win_scroll(WIN *w) |
{ |
_scroll(WHITE,w->x+1,w->y+1,w->x+w->dx-1,w->y+w->dy-1); |
} |
void win_frame(WIN *w,BYTE bcol,BYTE fcol,char *title,BYTE type) |
{ |
unsigned char var,var2,len; |
register int i; |
char cus,lv,cud,lo,cds,cdd,cl = ((bcol << 4) | fcol); |
len = strlen(title); |
switch(type) { |
case 1 : cus = CUPS1; lv = LVR1; cud = CUPD1; |
lo = LOR1; cds = CDWS1; cdd = CDWD1; |
break; |
case 2 : cus = CUPS2; lv = LVR2; cud = CUPD2; |
lo = LOR2; cds = CDWS2; cdd = CDWD2; |
break; |
default : cus = lv = cud = lo = cds = cdd = 32; |
break; |
} |
for (i = w->x+1; i < w->x+w->dx; i++) { |
putc_xy(i,w->y,cl,lo); |
putc_xy(i,w->y+w->dy,cl,lo); |
} |
putc_xy(w->x+w->dx,w->y,cl,cud); |
putc_xy(w->x,w->y,cl,cus); |
if (title != NULL) { |
var2 = w->x+(w->dx/2) - len/2 - 1; |
var = 0; |
putc_xy(var2,w->y,cl,'['); |
puts_xy(var2+1,w->y,cl,title); |
putc_xy(var2+len+1,w->y,cl,']'); |
} |
for (i = w->y+1; i < w->y+w->dy; i++) { |
putc_xy(w->x,i,cl,lv); |
putc_xy(w->x+w->dx,i,cl,lv); |
} |
putc_xy(w->x,w->y+w->dy,cl,cds); |
putc_xy(w->x+w->dx,w->y+w->dy,cl,cdd); |
} |
void win_puts(WIN *w1, char *s) |
{ |
unsigned pos; |
char c; |
static unsigned short scan_x,x,y; |
WIN w; |
w = *w1; |
x = w.px + w.x + 1; |
y = w.py + w.y + 1; |
pos = 2*(y*80 + x); |
while (*s != '\0') { |
c = *s++; |
switch (c) { |
case '\t' : x += 8; |
if (x >= w.x+w.dx) { |
x = w.x+1; |
if (y == w.y+w.dy-1) win_scroll(&w); |
else y++; |
} else { |
scan_x = w.x+1; |
while ((scan_x+8) < x) scan_x += 8; |
x = scan_x; |
} |
pos = 2*(x + 80*y); |
break; |
case '\n' : y += (x - w.x - 1) / w.dx + 1; |
x = w.x + 1; |
while (y > (w.y+w.dy-1)) { |
win_scroll(&w); |
y--; |
} |
pos = 2*(x + 80*y); |
break; |
case '\b' : putc_xy(x-1,y,WHITE,' '); |
break; |
default : putc_xy(x,y,WHITE,c); |
pos += 2; |
x++; |
if (x >= w.x + w.dx) { |
x = w.x+1; |
if (y >= (w.y + w.dy - 1)) win_scroll(&w); |
else y++; |
pos = 2*(x + 80*y); |
} |
} |
} |
if (x > (w.x+w.dx-1)) { |
y += (x - w.x - 1) / w.dx; |
x = (x - w.x - 1) % w.dx + w.x + 1; |
while (y >= (w.y+w.dy)) { |
win_scroll(&w); |
y--; |
} |
} |
w1->px = x - w.x - 1; |
w1->py = y - w.y - 1; |
} |
/*int win_gets(WIN *w, char *s,int len) |
{ |
int strpos = 0,lungh = 0; |
int x,y,tx,ty,i; |
BYTE flag = FALSE; |
KEY_EVT c; |
x = w->px + w->x + 1; |
y = w->py + w->y + 1; |
s[0] = 0; |
place(x,y); |
while (!flag) { |
keyb_getcode(&c,BLOCK); |
if (isScanCode(c) && (c.scan == LEFT_KEY) && (strpos > 0)) { |
strpos--; |
x--; |
if (x <= w->x) { |
x = w->x + w->dx - 1; |
y--; |
if (y <= w->y) y = w->y + 1; |
} |
place(x,y); |
} |
else if (isScanCode(c) && (c.scan == RIGHT_KEY) && s[strpos] != 0) { |
strpos++; |
x++; |
if (x >= (w->x + w->dx)) { |
x = w->x + 1; |
y++; |
if (y >= (w->y + w->dy)) { |
y--; |
win_scroll(w); |
} |
} |
place(x,y); |
} |
switch (c.ascii) { |
case ENTER : |
if (!isScanCode(c)) flag = TRUE; |
break; |
case BACKSPACE : |
if (!isScanCode(c) && (strpos > 0)) { |
strpos--; |
x--; |
if (x <= w->x) { |
x = w->x + w->dx - 1; |
y --; |
if (y <= w->y) y = w->y + 1; |
} |
tx = x; ty = y; |
i = strpos; |
while (s[i] != 0) { |
s[i] = s[i+1]; |
putc_xy(tx,ty,WHITE,s[i]); |
i++; |
tx++; |
if (tx >= w->x + w->dx) { |
tx = w->x + 1; |
ty++; |
} |
} |
lungh--; |
} |
place(x,y); |
break; |
case DELETE : |
if (s[strpos] != 0) lungh--; |
tx = x; ty = y; |
i = strpos; |
while (s[i] != 0) { |
s[i] = s[i+1]; |
putc_xy(tx,ty,WHITE,s[i]); |
i++; |
tx++; |
if (tx >= w->x + w->dx) { |
tx = w->x; |
ty++; |
} |
} |
place(x,y); |
break; |
default : |
if (!isScanCode(c)) { |
i = lungh; |
while (i > strpos) { |
s[i] = s[i-1]; |
i--; |
} |
s[lungh+1] = 0; |
s[strpos] = c.ascii; |
strpos++; |
lungh++; |
if (lungh == (len - 1)) flag = TRUE; |
tx = x; |
ty = y; |
i = strpos - 1; |
while (s[i] != 0) { |
putc_xy(tx,ty,WHITE,s[i]); |
tx++; |
i++; |
if (tx >= (w->x + w->dx)) { |
tx = w->x + 1; |
ty++; |
if (ty >= (w->y + w->dy)) { |
ty--; |
y--; |
win_scroll(w); |
} |
} |
} |
x++; |
if (x >= (w->x + w->dx)) { |
x = w->x + 1; |
y++; |
} |
} |
place(x,y); |
break; |
} |
} |
w->px = 0; |
w->py = y - w->y; |
if (w->py >= w->dy - 1) { |
w->py--; |
win_scroll(w); |
} |
return(lungh); |
} |
static void cons_end(void *arg) |
{ |
set_active_page(0); |
set_visual_page(0); |
} |
static void cons_change(KEY_EVT *k) |
{ |
//k.scan -= KEY_1; |
set_visual_page(k->scan-KEY_1); |
} |
void screen_init(void) |
{ |
KEY_EVT k; |
int i; |
k.flag = ALTR_BIT; |
for (i = 0; i < 8; i++) { |
k.ascii = '1' + i; |
k.scan = KEY_1 + i; |
keyb_hook(k,cons_change); |
} |
sys_atrunlevel(cons_end,NULL,RUNLEVEL_AFTER_EXIT); |
}*/ |
/shark/trunk/drivers/cons/makefile |
---|
11,7 → 11,9 |
OBJS_PATH = $(BASE)/drivers/cons |
OBJS = cons1.o cons2.o message.o cprintf.o |
OBJS = cons1.o cons2.o message.o cprintf.o crtwin.o |
OTHERINCL += -I$(BASE)/drivers/cons/include |
include $(BASE)/config/lib.mk |
/shark/trunk/drivers/oldchar/crtwin.c |
---|
File deleted |
/shark/trunk/drivers/oldchar/include/drivers/crtwin.h |
---|
File deleted |
/shark/trunk/drivers/oldchar/makefile |
---|
10,7 → 10,7 |
OBJS_PATH = $(BASE)/drivers/oldchar |
OBJS = rtc.o keyb.o scom.o crtwin.o mouse.o sermouse.o ps2mouse.o 8042.o \ |
OBJS = rtc.o keyb.o scom.o mouse.o sermouse.o ps2mouse.o 8042.o \ |
mcurtxt.o mcurgrx.o |
OTHERINCL += -I$(BASE)/drivers/oldchar/include -I$(BASE)/drivers/grx/include |