/shark/trunk/drivers/char/mcurtxt.c |
---|
File deleted |
/shark/trunk/drivers/char/crtwin.c |
---|
File deleted |
/shark/trunk/drivers/char/gpmcomp.h |
---|
File deleted |
/shark/trunk/drivers/char/sermouse.h |
---|
File deleted |
/shark/trunk/drivers/char/ps2mouse.c |
---|
File deleted |
/shark/trunk/drivers/char/ps2mouse.h |
---|
File deleted |
/shark/trunk/drivers/char/mcurgrx.c |
---|
File deleted |
/shark/trunk/drivers/char/mouse.c |
---|
File deleted |
/shark/trunk/drivers/char/rtc.c |
---|
File deleted |
/shark/trunk/drivers/char/keyb.c |
---|
File deleted |
/shark/trunk/drivers/char/keyb.his |
---|
File deleted |
/shark/trunk/drivers/char/_rtc.h |
---|
File deleted |
/shark/trunk/drivers/char/_mouse.h |
---|
File deleted |
/shark/trunk/drivers/char/makefile |
---|
File deleted |
/shark/trunk/drivers/char/8042.c |
---|
File deleted |
/shark/trunk/drivers/char/scom.c |
---|
File deleted |
/shark/trunk/drivers/char/8042.h |
---|
File deleted |
/shark/trunk/drivers/char/sermouse.c |
---|
File deleted |
/shark/trunk/drivers/oldchar/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 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
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); |
#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/oldchar/8042.h |
---|
0,0 → 1,225 |
/* |
* 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: 8042.h,v 1.1 2003-03-24 10:54:16 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:16 $ |
------------ |
8042.h |
Interface between high level drivers |
and the 8042 keyboard and PS/2 mouse controller |
Revision: 1.0 |
Last update: 22/Mar/1999 |
Created by Massimiliano Giorgi, modified by Paolo Gai to support the |
kernel 4.0.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 __8042_H__ |
#define __8042_H__ |
#include "ll/sys/cdefs.h" |
__BEGIN_DECLS |
#define C8042_KEYBOARDIRQ 1 |
#define C8042_PS2IRQ 12 |
/* |
* init, enable, disable, get data for the keyboard |
*/ |
int C8042_keyboardinit(PID task); |
int C8042_keyboarddisable(void); |
int C8042_keyboardenable(void); |
int C8042_keyboardget(BYTE *data,BYTE access); |
/* |
* init, enable, disable, get data for the ps/2 mouse (auxiliary port) |
*/ |
int C8042_auxinit(PID task); |
int C8042_auxportdisable(void); |
int C8042_auxportenable(void); |
int C8042_auxget(BYTE *data,BYTE access); |
int C8042_auxend(void); |
/* test if there is a PS/2 mouse on the aux port */ |
int C8042_ps2mousepresent(void); |
/* |
* keyboard led controll |
*/ |
void C8042_keyboardleds(BYTE numlock, BYTE cps, BYTE scrolllock); |
/* |
* |
* from Linux OS kernel 2.2.2 |
* (see GPL license) |
* with some modification |
*/ |
/* |
* Keyboard Controller Registers |
*/ |
#define KBD_STATUS_REG 0x64 /* Status register (R) */ |
#define KBD_CNTL_REG 0x64 /* Controller command register (W) */ |
#define KBD_DATA_REG 0x60 /* Keyboard data register (R/W) */ |
/* |
* Keyboard Controller Commands |
*/ |
#define KBD_CCMD_READ_MODE 0x20 /* Read mode bits */ |
#define KBD_CCMD_WRITE_MODE 0x60 /* Write mode bits */ |
#define KBD_CCMD_GET_VERSION 0xA1 /* Get controller version */ |
#define KBD_CCMD_MOUSE_DISABLE 0xA7 /* Disable mouse interface */ |
#define KBD_CCMD_MOUSE_ENABLE 0xA8 /* Enable mouse interface */ |
#define KBD_CCMD_TEST_MOUSE 0xA9 /* Mouse interface test */ |
#define KBD_CCMD_SELF_TEST 0xAA /* Controller self test */ |
#define KBD_CCMD_KBD_TEST 0xAB /* Keyboard interface test */ |
#define KBD_CCMD_KBD_DISABLE 0xAD /* Keyboard interface disable */ |
#define KBD_CCMD_KBD_ENABLE 0xAE /* Keyboard interface enable */ |
#define KBD_CCMD_WRITE_AUX_OBUF 0xD3 /* Write to output buffer as if |
initiated by the auxiliary device */ |
#define KBD_CCMD_WRITE_MOUSE 0xD4 /* Write the following byte to the mouse */ |
/* added by me (MG) */ |
#define KBD_CCMD_GET_MODE 0xCA /* Get controller mode (AT or PS/2) */ |
#define KBD_CREPLY_PS2MODE 0x01 /* PS2 mode */ |
#define KBD_CREPLY_ATMODE 0x00 /* AT mode */ |
#define KBD_CREPLY_GETMODEMASK 0x01 /* mask value for CCMD_GET_MODE */ |
/* |
* Keyboard Commands |
*/ |
#define KBD_CMD_SET_LEDS 0xED /* Set keyboard leds */ |
#define KBD_CMD_SET_RATE 0xF3 /* Set typematic rate */ |
#define KBD_CMD_ENABLE 0xF4 /* Enable scanning */ |
#define KBD_CMD_DISABLE 0xF5 /* Disable scanning */ |
#define KBD_CMD_RESET 0xFF /* Reset */ |
/* added by me (MG) */ |
#define KBD_CMD_SET_ALL_TYPEMATIC 0xF7 /* Set all key typematic */ |
#define KBD_LED_NUMLOCK 0x02 |
#define KBD_LED_CAPSLOCK 0x04 |
#define KBD_LED_SCROLLLOCK 0x01 |
#define KBD_LED_MASK 0x07 |
/* |
* Keyboard Replies |
*/ |
#define KBD_REPLY_POR 0xAA /* Power on reset */ |
#define KBD_REPLY_ACK 0xFA /* Command ACK */ |
#define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */ |
/* added by me (MG) */ |
#define KBD_REPLY_KISTOK 0x00 /* Keyboard Interface Self Test OK */ |
#define KBD_REPLY_CSTOK 0x55 /* Controller self test OK */ |
#define KBD_REPLY_MISTOK 0x00 /* Mouse Interface Self Test OK */ |
/* |
* Status Register Bits |
*/ |
#define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */ |
#define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */ |
#define KBD_STAT_SELFTEST 0x04 /* Self test successful */ |
#define KBD_STAT_CMD 0x08 /* Last write was a command write (0=data) */ |
#define KBD_STAT_UNLOCKED 0x10 /* Zero if keyboard locked */ |
#define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */ |
#define KBD_STAT_GTO 0x40 /* General receive/xmit timeout */ |
#define KBD_STAT_PERR 0x80 /* Parity error */ |
#define AUX_STAT_OBF (KBD_STAT_OBF | KBD_STAT_MOUSE_OBF) |
/* |
* Controller Mode Register Bits |
*/ |
#define KBD_MODE_KBD_INT 0x01 /* Keyboard data generate IRQ1 */ |
#define KBD_MODE_MOUSE_INT 0x02 /* Mouse data generate IRQ12 */ |
#define KBD_MODE_SYS 0x04 /* The system flag (?) */ |
#define KBD_MODE_NO_KEYLOCK 0x08 /* The keylock doesn't affect the keyboard if set */ |
#define KBD_MODE_DISABLE_KBD 0x10 /* Disable keyboard interface */ |
#define KBD_MODE_DISABLE_MOUSE 0x20 /* Disable mouse interface */ |
#define KBD_MODE_KCC 0x40 /* Scan code conversion to PC format */ |
#define KBD_MODE_RFU 0x80 |
/* |
* Mouse Commands |
*/ |
#define AUX_SET_RES 0xE8 /* Set resolution */ |
#define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */ |
#define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */ |
#define AUX_GET_SCALE 0xE9 /* Get scaling factor */ |
#define AUX_SET_STREAM 0xEA /* Set stream mode */ |
#define AUX_SET_SAMPLE 0xF3 /* Set sample rate */ |
#define AUX_ENABLE_DEV 0xF4 /* Enable aux device */ |
#define AUX_DISABLE_DEV 0xF5 /* Disable aux device */ |
#define AUX_RESET 0xFF /* Reset aux device */ |
#define AUX_ACK 0xFA /* Command byte ACK. */ |
#define AUX_BUF_SIZE 2048 /* This might be better divisible by |
three to make overruns stay in sync |
but then the read function would |
need |
*/ |
__END_DECLS |
#endif |
/shark/trunk/drivers/oldchar/include/drivers/keyb.h |
---|
0,0 → 1,169 |
/* |
* 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: keyb.h,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
**/ |
/* |
* Copyright (C) 2000 Giuseppe Lipari |
* |
* 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 8086 compatible */ |
/* Author: Giuseppe Lipari */ |
/* Start date : 19/6/96 */ |
/* CVS $Id: keyb.h,v 1.1 2003-03-24 10:54:17 pj Exp $ */ |
/* File: Keyb.H */ |
/* Revision: 1.4b */ |
/* Last update : 22/3/99 */ |
/* (MG) */ |
/* -- added keyb_enable() & keyb_disable() */ |
/* -- changed keyb_init() definition */ |
#ifndef __KEYB_H__ |
#define __KEYB_H__ |
#include <kernel/const.h> |
#include <kernel/model.h> |
#ifdef __cplusplus |
extern "C" { |
#endif |
#include <drivers/keycode.h> |
/* Ascii Codes */ |
#define BACKSPACE 8 |
#define ENTER 13 |
#define DELETE 24 |
#define ESC 27 |
#define TAB 9 |
/* Scan Codes */ |
#define UP_KEY 72 |
#define DOWN_KEY 80 |
#define LEFT_KEY 75 |
#define RIGHT_KEY 77 |
#define PGUP_KEY 73 |
#define PGDW_KEY 81 |
#define HOME_KEY 71 |
#define END_KEY 79 |
#define INS_KEY 82 |
#define F1_KEY 59 |
#define F2_KEY 60 |
#define F3_KEY 61 |
#define F4_KEY 62 |
#define F5_KEY 63 |
#define F6_KEY 64 |
#define F7_KEY 65 |
#define F8_KEY 66 |
#define F9_KEY 67 |
#define F10_KEY 68 |
/* Flag Codes */ |
#define ALTR_BIT 0x001 |
#define ALTL_BIT 0x002 |
#define CNTR_BIT 0x004 |
#define CNTL_BIT 0x008 |
#define SHFL_BIT 0x010 |
#define SHFR_BIT 0x020 |
#define SCAN_BIT 0x040 |
typedef struct { |
BYTE flag; |
BYTE ascii; |
BYTE scan; |
} KEY_EVT; |
#define isScanCode(k) (k.flag & SCAN_BIT) |
#define isLeftShift(k) (k.flag & SHFL_BIT) |
#define isRightShift(k) (k.flag & SHFR_BIT) |
#define isLeftCtrl(k) (k.flag & CNTL_BIT) |
#define isRightCtrl(k) (k.flag & CNTR_BIT) |
#define isLeftAlt(k) (k.flag & ALTL_BIT) |
#define isRightAlt(k) (k.flag & ALTR_BIT) |
#define keyb_getchar() keyb_getch(BLOCK) |
extern char engMap[]; |
extern char itaMap[]; |
typedef struct keyb_parms { |
TASK_MODEL *tm; |
char *keybmap; |
void (*ctrlcfunc)(KEY_EVT *k); |
} KEYB_PARMS; |
#define KEYB_DEFAULT ((unsigned long)(-1)) /*+ used for default params +*/ |
#define BASE_KEYB {(TASK_MODEL *)KEYB_DEFAULT, \ |
(char*)KEYB_DEFAULT, \ |
(void *)KEYB_DEFAULT} |
#define keyb_default_parm(m) (m).tm = (TASK_MODEL *) KEYB_DEFAULT, \ |
(m).keybmap = (char *) KEYB_DEFAULT, \ |
(m).ctrlcfunc = (void *) KEYB_DEFAULT |
#define keyb_def_map(s,m) (s).keybmap=(m) |
#define keyb_def_ctrlC(s,f) (s).ctrlcfunc=(f) |
#define keyb_def_task(s,m) (s).tm=(TASK_MODEL *)(m) |
int KEYB_init(KEYB_PARMS *s); |
int keyb_getch(BYTE wait); |
int keyb_getcode(KEY_EVT *k, BYTE wait); |
void keyb_hook(KEY_EVT k, void (*f)(KEY_EVT *k)); |
int keyb_enable(void); |
int keyb_disable(void); |
int keyb_end(void); |
void keyb_set_map(char *t); |
#ifdef __cplusplus |
}; |
#endif |
#endif |
/shark/trunk/drivers/oldchar/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 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
**/ |
/* |
* 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/oldchar/include/drivers/keycode.h |
---|
0,0 → 1,92 |
#define NUM_OF_KEY 130 |
#define NUM_OF_STRANGE_KEY 4 |
#define KEY_ESC 1 |
#define KEY_1 2 |
#define KEY_2 3 |
#define KEY_3 4 |
#define KEY_4 5 |
#define KEY_5 6 |
#define KEY_6 7 |
#define KEY_7 8 |
#define KEY_8 9 |
#define KEY_9 10 |
#define KEY_0 11 |
#define KEY_SUB 12 |
#define KEY_PLUS 13 |
#define KEY_BKS 14 |
#define KEY_TAB 15 |
#define KEY_Q 16 |
#define KEY_W 17 |
#define KEY_E 18 |
#define KEY_R 19 |
#define KEY_T 20 |
#define KEY_Y 21 |
#define KEY_U 22 |
#define KEY_I 23 |
#define KEY_O 24 |
#define KEY_P 25 |
#define KEY_BRL 26 |
#define KEY_BRR 27 |
#define KEY_ENT 28 |
#define KEY_CTRLL 29 |
#define KEY_A 30 |
#define KEY_S 31 |
#define KEY_D 32 |
#define KEY_F 33 |
#define KEY_G 34 |
#define KEY_H 35 |
#define KEY_J 36 |
#define KEY_K 37 |
#define KEY_L 38 |
#define KEY_COL 39 |
#define KEY_API 40 |
#define KEY_TIL 41 |
#define KEY_SHL 42 |
#define KEY_BSL 43 |
#define KEY_Z 44 |
#define KEY_X 45 |
#define KEY_C 46 |
#define KEY_V 47 |
#define KEY_B 48 |
#define KEY_N 49 |
#define KEY_M 50 |
#define KEY_LT 51 |
#define KEY_GT 52 |
#define KEY_SLH 53 |
#define KEY_SHR 54 |
#define PAD_AST 55 |
#define KEY_ALTL 56 |
#define KEY_SPC 57 |
#define KEY_CPSLOCK 58 |
#define KEY_F1 59 |
#define KEY_F2 60 |
#define KEY_F3 61 |
#define KEY_F4 62 |
#define KEY_F5 63 |
#define KEY_F6 64 |
#define KEY_F7 65 |
#define KEY_F8 66 |
#define KEY_F9 67 |
#define KEY_F10 68 |
#define KEY_SCRLOCK 0x46 |
#define PAD_NUMLOCK 69 |
#define PAD_SCRLOCK 0x35 |
#define PAD_HOME 71 |
#define PAD_UP 72 |
#define PAD_PGUP 73 |
#define PAD_SUB 74 |
#define PAD_LEFT 75 |
#define PAD_5 76 |
#define PAD_RIGHT 77 |
#define PAD_PLUS 78 |
#define PAD_END 79 |
#define PAD_DOWN 80 |
#define PAD_PGDW 81 |
#define PAD_INS 82 |
#define PAD_DEL 83 |
#define EXT_F11 87 |
#define EXT_F12 88 |
#define KEY_DEL 100 |
/shark/trunk/drivers/oldchar/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 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
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/oldchar/include/drivers/rtc.h |
---|
0,0 → 1,88 |
/* |
* 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: rtc.h,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
**/ |
/* |
* Copyright (C) 2000 Massimiliano Giorgi |
* |
* 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 8086 compatible */ |
/* Author: Massimiliano Giorgi */ |
#ifndef __RTC_H__ |
#define __RTC_H__ |
#include <time.h> |
#include "ll/sys/cdefs.h" |
__BEGIN_DECLS |
/* |
* The struct used to pass data via the following ioctl. Similar to the |
* struct tm in <time.h>, but it needs to be here so that the kernel |
* source is self contained, allowing cross-compiles, etc. etc. |
*/ |
struct rtc_time { |
int tm_sec; |
int tm_min; |
int tm_hour; |
int tm_mday; |
int tm_mon; |
int tm_year; |
int tm_wday; |
int tm_yday; |
int tm_isdst; |
}; |
int get_rtc_time (struct rtc_time *rtc_tm); |
int set_rtc_time (struct rtc_time *rtc_tm); |
time_t sys_getdate(void); |
__END_DECLS |
#endif |
/shark/trunk/drivers/oldchar/include/drivers/mouse.h |
---|
0,0 → 1,219 |
/* |
* 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: mouse.h,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
**/ |
/** |
------------ |
CVS : $Id: mouse.h,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Gerardo Lamastra |
Date: 9/5/96 |
**/ |
/* |
* 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 |
* |
*/ |
/* Revision: 1.0.1 */ |
/* -- added support for PS/2 mouse */ |
/* -- changed mouse_init() */ |
/* By Massy: |
* -- added support for mouse cursor (pointer) |
* -- interface changed |
*/ |
#ifndef __MOUSE_H__ |
#define __MOUSE_H__ |
#include <kernel/const.h> |
#ifndef __SCOM_H__ |
#include <drivers/scom.h> |
#endif |
#include "ll/sys/cdefs.h" |
__BEGIN_DECLS |
/* mouse buttons constant */ |
#define MOUSE_RBUTT 1 |
#define MOUSE_CBUTT 2 |
#define MOUSE_LBUTT 4 |
/* the mouse event struct */ |
typedef struct { |
int x,y; /* mouse position */ |
int dx,dy; /* distance covered by mouse */ |
int buttons; /* buttons flags */ |
} MOUSE_EVT; |
/* macros to test mouse buttons */ |
#define isLeftButton(m) ((m).buttons & MOUSE_LBUTT) |
#define isRightButton(m) ((m).buttons & MOUSE_RBUTT) |
#define isCentralButton(m) ((m).buttons & MOUSE_CBUTT) |
/* user mouse handler */ |
typedef void (*MOUSE_HANDLER)(MOUSE_EVT*); |
/* mouse types */ |
/* (run examples/mfind.c for a description)*/ |
#define MSMOUSE 0x00 |
#define MSPMOUSE 0x01 |
#define MSPLRMOUSE 0x02 |
#define BAREMOUSE 0x03 |
#define MSCMOUSE 0x04 |
#define SUNMOUSE 0x05 |
#define MMMOUSE 0x06 |
#define LOGIMOUSE 0x07 |
#define PS2MOUSE 0x08 |
#define NOMOUSE 0xff |
/* |
* mouse initialization |
*/ |
#define MOUSE_DEFAULT (DWORD)-1 |
/* the MOUSE_PARMS structure used by mouse_init() */ |
typedef struct mouse_parms { |
TASK_MODEL *tm; |
int type; /* mouse types (constants above) */ |
/* for serial mouse */ |
int port; /* serial port (i.e. COM1, ...) */ |
} MOUSE_PARMS; |
/* the default values for the MOUSE_PARMS structure */ |
#define BASE_MOUSE {(TASK_MODEL *)MOUSE_DEFAULT,MOUSE_DEFAULT,MOUSE_DEFAULT} |
/* to change the MOUSE_PARMS struct */ |
#define mouse_default_parms(s) (s).tm = (TASK_MODEL *)MOUSE_DEFAULT, \ |
(s).type = MOUSE_DEFAULT, \ |
(s).port = MOUSE_DEFAULT |
#define mouse_def_ms(s,p) (s).type=MSMOUSE; (s).port=(p) |
#define mouse_def_msplus(s,p) (s).type=MSPMOUSE; (s).port=(p) |
#define mouse_def_mspluslr(s,p) (s).type=MSPLRMOUSE; (s).port=(p) |
#define mouse_def_bare(s,p) (s).type=BAREMOUSE; (s).port=(p) |
#define mouse_def_msc(s,p) (s).type=MSCMOUSE; (s).port=(p) |
#define mouse_def_sun(s,p) (s).type=SUNMOUSE; (s).port=(p) |
#define mouse_def_mm(s,p) (s).type=MMMOUSE; (s).port=(p) |
#define mouse_def_logi(s,p) (s).type=LOGIMOUSE; (s).port=(p) |
#define mouse_def_ps2(s) (s).type=PS2MOUSE |
#define mouse_def_task(s,m) (s).tm=(m) |
/* |
* user mouse interface |
*/ |
int mouse_init(MOUSE_PARMS *s); |
void mouse_enable(void); |
void mouse_disable(void); |
void mouse_get(int *x,int *y,BYTE *button); |
void mouse_position(int x,int y); |
void mouse_limit(int x1,int y1,int x2,int y2); |
void mouse_threshold(unsigned t); |
void mouse_hook(MOUSE_HANDLER h); |
void mouse_end(void); |
/* |
* |
* 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 |
/* 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); |
/* enable/disable mouse pointer */ |
/* (return <0 on error) */ |
/* (for the cmd parameter see above) */ |
int mouse_grxcursor(int cmd); |
int mouse_txtcursor(int cmd); |
/* mouse on/off (or show/hide) */ |
void (*mouse_on)(void); |
void (*mouse_off)(void); |
__END_DECLS |
#endif |
/shark/trunk/drivers/oldchar/sermouse.c |
---|
0,0 → 1,553 |
/* |
* 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: sermouse.c,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Gerardo Lamastra |
Date: 9/5/96 |
Revision: 1.1b |
Date: 14/Apr/1999 |
Serial mouse driver |
The mouse driver receives data from the serial RxServer() |
Then it processes the mouse packet and sets the variables |
representing the external mouse status. |
**/ |
/* |
* 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 |
* |
*/ |
/* |
* Revision: 1.1 |
* Author: Massimiliano Giorgi |
* |
* This code were in mouse.c: |
* -- there is a mouse server (Microsoft Mouse Protocol) |
* -- there is "virtual operation" on a serial mouse |
*/ |
/* |
* Revison: 1.1b |
* Changed to compile on 3.2.0 |
* -- added wcet time to all task |
*/ |
/* |
* -- changed internal structure to integrate "gpm" code |
* -- now is used ONE task (not two!) |
*/ |
//#include <string.h> |
//#include <stdlib.h> |
//#include <cons.h> |
#include <kernel/kern.h> |
#include <time.h> |
//#include "sys/sys.h" |
//#include "vm.h" |
//#include "kern.h" |
//#include "exc.h" |
#include <drivers/scom.h> |
#include <drivers/mouse.h> |
#include "_mouse.h" |
#include "sermouse.h" |
#include <modules/sem.h> |
//#define __DEBUG_MOUSE__ |
//#define __XTRA_DEBUG_MOUSE__ |
/* if defined: trace the initialization */ |
//#define __DEBUG_INIT__ 1 |
/* if defined: show data received from serial port on the screen */ |
//#define __DEBUG_DATAIN__ 1 |
/* |
* The following code is derived from gpm (under GPL) |
*/ |
#include "gpmcomp.h" |
/* |
* START!! |
* |
* mice.c - mouse definitions for gpm-Linux |
* |
* Copyright (C) 1993 Andrew Haylett <ajh@gec-mrc.co.uk> |
* Copyright (C) 1994-1999 Alessandro Rubini <rubini@linux.it> |
* Copyright (C) 1998,1999 Ian Zimmerman <itz@rahul.net> |
*/ |
int M_ms(Gpm_Event *state, unsigned char *data) |
{ |
/* |
* some devices report a change of middle-button state by |
* repeating the current button state (patch by Mark Lord) |
*/ |
static unsigned char prev=0; |
if (data[0] == 0x40 && !(prev|data[1]|data[2])) |
state->buttons = GPM_B_MIDDLE; /* third button on MS compatible mouse */ |
else |
state->buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); |
prev = state->buttons; |
state->dx= (signed char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); |
state->dy= (signed char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); |
return 0; |
} |
int M_ms_plus(Gpm_Event *state, unsigned char *data) |
{ |
static unsigned char prev=0; |
state->buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); |
state->dx= (signed char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); |
state->dy= (signed char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); |
/* Allow motion *and* button change (Michael Plass) */ |
if ((state->dx==0) && (state->dy==0) |
&& (state->buttons == (prev&~GPM_B_MIDDLE))) |
state->buttons = prev^GPM_B_MIDDLE; /* no move or change: toggle middle */ |
else |
state->buttons |= prev&GPM_B_MIDDLE; /* change: preserve middle */ |
prev=state->buttons; |
return 0; |
} |
int M_ms_plus_lr(Gpm_Event *state, unsigned char *data) |
{ |
/* |
* Same as M_ms_plus but with an addition by Edmund GRIMLEY EVANS |
*/ |
static unsigned char prev=0; |
state->buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); |
state->dx= (signed char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); |
state->dy= (signed char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); |
/* Allow motion *and* button change (Michael Plass) */ |
if ((state->dx==0) && (state->dy==0) |
&& (state->buttons == (prev&~GPM_B_MIDDLE))) |
state->buttons = prev^GPM_B_MIDDLE; /* no move or change: toggle middle */ |
else |
state->buttons |= prev&GPM_B_MIDDLE; /* change: preserve middle */ |
/* Allow the user to reset state of middle button by pressing |
the other two buttons at once (Edmund GRIMLEY EVANS) */ |
if (!((~state->buttons)&(GPM_B_LEFT|GPM_B_RIGHT)) && |
((~prev)&(GPM_B_LEFT|GPM_B_RIGHT))) |
state->buttons &= ~GPM_B_MIDDLE; |
prev=state->buttons; |
return 0; |
} |
int M_bare(Gpm_Event *state, unsigned char *data) |
{ |
/* a bare ms protocol */ |
state->buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); |
state->dx= (signed char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F)); |
state->dy= (signed char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F)); |
return 0; |
} |
int M_sun(Gpm_Event *state, unsigned char *data) |
{ |
state->buttons= (~data[0]) & 0x07; |
state->dx= (signed char)(data[1]); |
state->dy= -(signed char)(data[2]); |
return 0; |
} |
int M_mm(Gpm_Event *state, unsigned char *data) |
{ |
state->buttons= data[0] & 0x07; |
state->dx= (data[0] & 0x10) ? data[1] : - data[1]; |
state->dy= (data[0] & 0x08) ? - data[2] : data[2]; |
return 0; |
} |
int M_logi(Gpm_Event *state, unsigned char *data) /* equal to mm */ |
{ |
state->buttons= data[0] & 0x07; |
state->dx= (data[0] & 0x10) ? data[1] : - data[1]; |
state->dy= (data[0] & 0x08) ? - data[2] : data[2]; |
return 0; |
} |
int M_msc(Gpm_Event *state, unsigned char *data) |
{ |
state->buttons= (~data[0]) & 0x07; |
state->dx= (signed char)(data[1]) + (signed char)(data[3]); |
state->dy= -((signed char)(data[2]) + (signed char)(data[4])); |
return 0; |
} |
/* |
* mice.c - mouse definitions for gpm-Linux |
* |
* END!! |
* |
*/ |
static BYTE proto_mouse0,proto_mouse1,proto_mouse2,proto_mouse3; |
static char data[4]; // serial can go here? |
static PID rx_server_pid = NIL; |
static short int mouse_port = 0; |
extern void (*com_fast)(int); |
#define SBUFFERSIZE 64 |
#define SBUFFERMASK 0x3f |
static BYTE sbuffer[SBUFFERSIZE]; |
static unsigned stail,shead; |
static int scount; |
void sermouse_fast(int); |
int sermouse_open(void *info) |
{ |
SERMOUSE_INFO *sinfo=(SERMOUSE_INFO*)info; |
// MODEL m = BASE_MODEL; |
int status; |
#ifdef __DEBUG_INIT__ |
cprintf("sermouse_open: START\n"); |
#endif |
/* |
* Open serial device |
*/ |
switch (sinfo->type) { |
case MSCMOUSE: |
case SUNMOUSE: |
case LOGIMOUSE: |
status=com_open(sinfo->port,1200,NONE,8,1); /* perhaps needs 2 stop bits */ |
break; |
case MMMOUSE: |
status=com_open(sinfo->port,1200,ODD,8,1); |
break; |
case MSMOUSE: |
case MSPMOUSE: |
case MSPLRMOUSE: |
case BAREMOUSE: |
default: |
status=com_open(sinfo->port,1200,NONE,7,1); |
break; |
} |
if (status!=1) return -1; |
#ifdef __DEBUG_INIT__ |
cprintf("sermouse_open: COM port opened\n"); |
#endif |
/* for some old logitech mouse */ |
if (sinfo->type==LOGIMOUSE) { |
static struct { |
int sample; char code[1]; |
} sampletab[]={ |
{ 0,{'O'}}, |
{ 15,{'J'}}, |
{ 27,{'K'}}, |
{ 42,{'L'}}, |
{ 60,{'R'}}, |
{ 85,{'M'}}, |
{125,{'Q'}}, |
{1E9,{'N'}} |
}; |
int opt_sample=40; |
int i; |
/* UNTESTED!!! */ |
/* probably don't work*/ |
/* this stuff is peculiar of logitech mice, also for the serial ones */ |
com_send(sinfo->port,'S'); |
/* configure the sample rate */ |
for (i=0;opt_sample<=sampletab[i].sample;i++); |
com_send(sinfo->port,sampletab[i].code[0]); |
#ifdef __DEBUG_INIT__ |
cprintf("sermouse_open: 'logi' initialization done\n"); |
#endif |
} |
proto_mouse0=proto_mouse[0]; |
proto_mouse1=proto_mouse[1]; |
proto_mouse2=proto_mouse[2]; |
proto_mouse3=proto_mouse[3]; |
scount=0; |
stail=0; |
shead=1; |
/* |
* Create Serial port task |
*/ |
/* MG: to use one task */ |
//task_def_arg(m,sinfo->port); |
//task_def_wcet(m,500); |
//rx_server_pid = task_create("RxServer",rxServer,HARD,APERIODIC,100,&m); |
rx_server_pid=sinfo->pid; |
/* test if exist the task...*/ |
if (rx_server_pid==-1) { |
com_close(sinfo->port); |
return -1; |
} |
com_fast=sermouse_fast; |
com_server(sinfo->port,RX_FULL,NIL); |
#ifdef __DEBUG_INIT__ |
cprintf("sermouse_open: COM task created\n"); |
#endif |
/* MG: not needed (the fast handler activate the task) */ |
task_activate(rx_server_pid); |
#ifdef __DEBUG_INIT__ |
//cprintf("sermouse_open: COM task activated\n"); |
#endif |
mouse_port = sinfo->port; |
com_link[sinfo->port].msk = RX_FULL; |
com_write(sinfo->port,IER,RX_FULL); |
/* this is for safety! */ |
com_link[sinfo->port].rx_buf = data; |
#ifdef __DEBUG_INIT__ |
cprintf("sermouse_open: COM port configurated\n"); |
#endif |
/* Enable RTS & DTR to activate mouse! */ |
sermouse_enable(); |
#ifdef __DEBUG_INIT__ |
cprintf("sermouse_open: mouse activated\n"); |
#endif |
return 0; |
} |
/* |
* return the server's address |
*/ |
TASK (*sermouse_getserveraddr(SERMOUSE_INFO *infoptr))(void) |
{ |
return generalmouse_server; |
} |
/* |
* test if a mouse is present |
* |
* "When DTR line is toggled, mouse should send one data byte" |
* "containing letter 'M' (ascii 77)." |
* Tomi Engdahl <then@delta.hut.fi> |
* |
* this for Microsoft Serial mouse |
*/ |
SERMOUSE_INFO *sermouse_present(void) |
{ |
static SERMOUSE_INFO info; |
int port; |
int ret; |
int found; |
struct timespec delay; |
delay.tv_sec = 0; |
delay.tv_nsec = 500000000; |
found=0; |
for (port=COM1;port<=COM4;port++) { |
ret=com_open(port,1200,NONE,7,1); |
if (ret==1) { |
com_write(port,MCR,0x0e); |
nanosleep(&delay,NULL); /* necessary? */ |
com_write(port,MCR,0x0f); |
nanosleep(&delay,NULL); /* necessary? */ |
ret=sem_wait(&com_link[mouse_port].rx_sem); |
if (ret==TRUE) { |
if (*(com_link[mouse_port].rx_buf)=='M') found=1; |
} |
com_close(port); |
if (found) { |
info.type=BAREMOUSE; |
info.port=port; |
return &info; |
} |
} |
} |
return NULL; |
} |
/* MG: the "virtual operation" operate on a serial port */ |
void sermouse_close(void) |
{ |
com_close(mouse_port); |
} |
void sermouse_disable(void) |
{ |
com_write(mouse_port,MCR,0); |
} |
void sermouse_enable(void) |
{ |
com_write(mouse_port,MCR,0x0F); |
} |
void sermouse_wait(void) |
{ |
task_endcycle(); |
/* changed to use one task */ |
//sem_wait(&com_link[mouse_port].rx_sem); |
} |
#ifdef __DEBUG_DATAIN__ |
/* debug values for keyboadget() and auxget() */ |
#define YDEB 2 |
#define COLORDEB WHITE |
static int auxx=2; |
#endif |
int sermouse_get(BYTE *data) |
{ |
SYS_FLAGS f; |
int i; |
// BYTE *p=data; |
// BYTE t; |
f=kern_fsave(); |
if (((stail+1)&SBUFFERMASK)==shead) { |
kern_frestore(f); |
return 0; |
} |
for (i=0;i<packetlen_mouse;i++) { |
stail=(stail+1)&SBUFFERMASK; |
*data++=sbuffer[stail]; |
} |
kern_frestore(f); |
#ifdef __DEBUG_DATAIN__ |
/* |
* if debug... |
* show all data from the serial port on YDEB line of the screen |
*/ |
{ |
int i; |
for (i=-packetlen_mouse;i<0;i++) { |
if (auxx+5>=80) { |
printf_xy(auxx,YDEB,COLORDEB," "); |
auxx=2; |
} |
if (auxx==2) printf_xy(0,YDEB,COLORDEB,"S "); |
printf_xy(auxx,YDEB,COLORDEB,"%02x > ",(unsigned)*(data+i)); |
auxx+=3; |
} |
} |
#endif |
return packetlen_mouse; |
//*data=com_read(mouse_port,RBR); |
//com_write(mouse_port,IER,com_link[mouse_port].msk); |
//return 1; |
/* changed to use one task */ |
//return *(com_link[mouse_port].rx_buf); |
} |
void sermouse_fast(int port) |
{ |
SYS_FLAGS f; |
BYTE data; |
f=kern_fsave(); |
data=com_read(mouse_port,RBR); |
com_write(mouse_port,IER,com_link[mouse_port].msk); |
if (scount==0&&((data&proto_mouse0)!=proto_mouse1)) { |
kern_frestore(f); |
return; |
} else if (scount==1&&((data&proto_mouse2)!=proto_mouse3)) { |
shead=(shead-scount+SBUFFERSIZE)&SBUFFERMASK; |
scount=0; |
kern_frestore(f); |
return; |
} |
scount++; |
if (stail!=shead) { |
sbuffer[shead]=data; |
shead=(shead+1)&SBUFFERMASK; |
} else { |
shead=(shead-(scount-1)+SBUFFERSIZE)&SBUFFERMASK; |
scount=0; |
} |
if (scount==packetlen_mouse) { |
scount=0; |
kern_frestore(f); |
task_activate(rx_server_pid); |
return; |
} |
kern_frestore(f); |
} |
/shark/trunk/drivers/oldchar/mcurtxt.c |
---|
0,0 → 1,340 |
/* |
* 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: mcurtxt.c,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Massimiliano Giorgi |
Date: 24/Giu/99 |
**/ |
/* |
* 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 <sys/sys.h> |
//#include <sys/vm.h> |
#include <drivers/mouse.h> |
//#include <cons.h> |
#include "_mouse.h" |
#include <modules/sem.h> |
/* these are the actual mouse coordinates (defined into mouse.c) */ |
extern short int mouse_x; |
extern short int mouse_y; |
/* these variables are managed by this module but MUST be declared |
* into mouse.c to prevent implicit inclusion of this module |
* when a user link the mouse library |
*/ |
extern MOUSE_HANDLER mouse_handler; |
extern MOUSE_HANDLER user_mouse_handler; |
extern int autocursormode; |
/* a mutex semaphore */ |
static sem_t mutex=-1; |
/* |
* |
* autocursor mouse handler |
* |
*/ |
/* >=0 hide cursor; <0 show cursor */ |
static int mouse_cursor_state=-1; |
/* 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) |
{ |
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) |
{ |
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) |
{ |
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) |
{ |
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; |
if (cond) |
show_txt_cursor(saved_x,saved_y); |
return 0; |
} |
/* |
* User interface to autocursor functions |
*/ |
/* display the cursor */ |
#define MOUSE_ON() { \ |
mouse_cursor_state--; \ |
if (mouse_cursor_state==-1) { \ |
saved_x=mouse_x; \ |
saved_y=mouse_y; \ |
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; |
else if ((cmd&WITHOUTSEM)==WITHOUTSEM) |
return autocursor_mouse_handler_2; |
else 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); |
} |
/**/ |
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; |
} |
switch (cmd&STATUSMASK) { |
case DISABLE: |
mouse_handler=user_mouse_handler; |
restore_cursor(saved_x,saved_y); |
show_cursor=dummy; |
restore_cursor=dummy; |
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=mouse_handler; |
mouse_handler=wich_handler(cmd); |
} |
mouse_cursor_state=0; |
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_getsavedposition(int *xptr, int *yptr) |
{ |
*xptr=saved_x; |
*yptr=saved_y; |
} |
/shark/trunk/drivers/oldchar/crtwin.c |
---|
0,0 → 1,358 |
/* |
* 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 2003-03-24 10:54:16 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:16 $ |
------------ |
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/keyb.h> |
#include <drivers/keycode.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) |
{ |
/* MG */ |
//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/oldchar/gpmcomp.h |
---|
0,0 → 1,15 |
/* |
* GPM compatibility stuff |
*/ |
#ifndef __GPMCOMP_H__ |
#define GPM_B_MIDDLE MOUSE_CBUTT |
#define GPM_B_LEFT MOUSE_LBUTT |
#define GPM_B_RIGHT MOUSE_RBUTT |
#define Gpm_Event MOUSE_EVT |
extern int opt_glidepoint_tap; |
#endif |
/shark/trunk/drivers/oldchar/sermouse.h |
---|
0,0 → 1,95 |
/* |
* 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: sermouse.h,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Massimiliano Giorgi |
Virtual operation for a serial mouse |
(for mouse.c) |
Initial date: 22/mar/1999 |
**/ |
/* |
* 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 __SERMOUSE_H__ |
#define __SERMOUSE_H__ |
#include <drivers/mouse.h> |
#include "ll/sys/cdefs.h" |
__BEGIN_DECLS |
typedef struct sermouse_info { |
int type; /* MSMOUSE, MMMOUSE,... */ |
int port; /* COM1,COM2,... */ |
PID pid; /* task PID */ |
} SERMOUSE_INFO; |
SERMOUSE_INFO *sermouse_present(void); |
//extern TASK microsoftmouse_server(void); |
//extern TASK mousesystem_server(void); |
TASK (*sermouse_getserveraddr(SERMOUSE_INFO *))(void); |
int sermouse_open(void*); |
void sermouse_close(void); |
void sermouse_wait(void); |
int sermouse_get(BYTE *); |
void sermouse_enable(void); |
void sermouse_disable(void); |
int M_ms(MOUSE_EVT *evt,unsigned char *data); |
int M_ms_plus(MOUSE_EVT *evt,unsigned char *data); |
int M_ms_plus_lr(MOUSE_EVT *evt,unsigned char *data); |
int M_bare(MOUSE_EVT *evt,unsigned char *data); |
int M_msc(MOUSE_EVT *evt,unsigned char *data); |
int M_sun(MOUSE_EVT *evt,unsigned char *data); |
int M_mm(MOUSE_EVT *evt,unsigned char *data); |
int M_logi(MOUSE_EVT *evt,unsigned char *data); |
__END_DECLS |
#endif |
/shark/trunk/drivers/oldchar/ps2mouse.c |
---|
0,0 → 1,308 |
/* |
* 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: ps2mouse.c,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Massimiliano Giorgi |
Date: 2/2/98 |
File: PS2MOUSE.C |
Revision: 1.0 |
Last update: 22/mar/1999 |
PS2 mouse driver |
**/ |
/* |
* 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 __DEBUG_PS2MOUSE__*/ |
//#include <string.h> |
//#include <stdlib.h> |
//#include <cons.h> |
//#include "vm.h" |
#include <kernel/kern.h> |
//#include "exc.h" |
#include <modules/hartport.h> |
#include "8042.h" |
#include <drivers/mouse.h> |
#include "_mouse.h" |
#include "ps2mouse.h" |
#define WAITING 0 |
#define WAITX 1 |
#define WAITY 2 |
//static int status; |
#ifdef __DEBUG_PS2MOUSE__ |
/* to print some debug information on line YDEB of the screen */ |
#define YDEB 2 |
#define change_status(x) { \ |
status=(x); \ |
printf_xy(0,YDEB,WHITE,"[PS2mouse server] status: %s ",#x); \ |
} |
#define debug_show_data(b1,b2,b3) { \ |
printf_xy(40,YDEB,WHITE,"B1: 0x%-2x ",b1); \ |
printf_xy(49,YDEB,WHITE,"B2: 0x%-2x ",b2); \ |
printf_xy(58,YDEB,WHITE,"B3: 0x%-2x ",b3); \ |
} |
#else |
#define change_status(x) status=(x) |
#define debug_show_data(b1,b2,b3) |
#endif |
/* |
* PS2 Mouse Server TASK |
* |
* This is the format of the incoming data. |
* |
* Data packet format: |
* |
* | D7 D6 D5 D4 D3 D2 D1 D0 |
* ------------------------------------------------------------------- |
* B1 | XV XV YS XS 1 0 R L |
* B2 | X7 X6 X5 X4 X3 X2 X1 X0 |
* B3 | Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 |
* |
* L Left button state (1 = pressed down) |
* R Right button state (1 = pressed down) |
* X0-X7 Movement in X direction |
* Y0-Y7 Movement in Y direction |
* XS,YS Movement data sign bits (1 = negative) |
* XV,YV Movement data overflow bits (1 = overflow has occured) |
* |
* Note: |
* -- X0-X7 and Y0-Y7 seems to be signed numbers |
* -- bit D3 in B1 seems to be the 3rd button (0 = pressed down) |
*/ |
/* |
* the old ps/2 mouse server! |
* now the genaral mouse serve into mouse.c is used |
*/ |
//TASK ps2mouse_server(void) |
//{ |
// int b1,b2,b3; |
// int mickey; |
// |
// b3=b1=b2=0; |
// change_status(WAITING); |
// for (;;) { |
// wait_mouse(); |
// |
// b3=get_mouse(); |
// |
// switch(status) { |
// case WAITING: |
// b1=b3; |
// debug_show_data(b1,b2,b3); |
// /* can only be tested if bit D3 is one ...*/ |
// if ((b1&0x08)!=0x08) break; |
// change_status(WAITX); |
// break; |
// case WAITX: |
// b2=b3; |
// debug_show_data(b1,b2,b3); |
// change_status(WAITY); |
// break; |
// case WAITY: |
// debug_show_data(b1,b2,b3); |
// |
// /* buttons */ |
// mouse_buttons=((b1&0x1)<<1)|((b1&0x02)>>1)|(b1&0x04); |
// |
// /* axes X */ |
// mickey=((b1&0x10)?(b2-256):b2); |
// /* this part come from "sermouse.c" */ |
// mouse_x_mick+=mickey; |
// while(mouse_x_mick>mouse_thresholdlim) { |
// mouse_x++; |
// mouse_x_mick-=mouse_thresholdlim; |
// } |
// while (mouse_x_mick<-mouse_thresholdlim) { |
// mouse_x--; |
// mouse_x_mick+=mouse_thresholdlim; |
// } |
// if (mouse_x>mouse_lim_x2) mouse_x=mouse_lim_x2; |
// else if (mouse_x<mouse_lim_x1) mouse_x=mouse_lim_x1; |
// |
// /* axes Y */ |
// mickey=((b1&0x20)?256-b3:-b3); |
// /* this part come from "sermouse.c" */ |
// mouse_y_mick+=mickey; |
// while(mouse_y_mick>mouse_thresholdlim) { |
// mouse_y++; |
// mouse_y_mick-=mouse_thresholdlim; |
// } |
// while (mouse_y_mick<-mouse_thresholdlim) { |
// mouse_y--; |
// mouse_y_mick+=mouse_thresholdlim; |
// } |
// if (mouse_y>mouse_lim_y2) mouse_y=mouse_lim_y2; |
// else if (mouse_y<mouse_lim_y1) mouse_y=mouse_lim_y1; |
// |
// /* mouse handler */ |
// if (mouse_handler != NULL) |
// mouse_handler(mouse_x,mouse_y,mouse_buttons); |
// |
// change_status(WAITING); |
// break; |
// } |
// } |
//} |
// |
TASK (*ps2mouse_getserveraddr(void))(void) |
{ |
return generalmouse_server; |
} |
/* |
* this is from gpm (see sermouse.c for comments) |
*/ |
#include "gpmcomp.h" |
int opt_glidepoint_tap=0; |
/* mice.c START */ |
int M_ps2(Gpm_Event *state, unsigned char *data) |
{ |
static int tap_active=0; /* there exist glidepoint ps2 mice */ |
state->buttons= |
!!(data[0]&1) * GPM_B_LEFT + |
!!(data[0]&2) * GPM_B_RIGHT + |
!!(data[0]&4) * GPM_B_MIDDLE; |
if (data[0]==0 && opt_glidepoint_tap) /* by default this is false */ |
state->buttons = tap_active = opt_glidepoint_tap; |
else if (tap_active) { |
if (data[0]==8) |
state->buttons = tap_active = 0; |
else state->buttons = tap_active; |
} |
/* Some PS/2 mice send reports with negative bit set in data[0] |
* and zero for movement. I think this is a bug in the mouse, but |
* working around it only causes artifacts when the actual report is -256; |
* they'll be treated as zero. This should be rare if the mouse sampling |
* rate is set to a reasonable value; the default of 100 Hz is plenty. |
* (Stephen Tell) |
*/ |
if(data[1] != 0) |
state->dx= (data[0] & 0x10) ? data[1]-256 : data[1]; |
else |
state->dx = 0; |
if(data[2] != 0) |
state->dy= -((data[0] & 0x20) ? data[2]-256 : data[2]); |
else |
state->dy = 0; |
return 0; |
} |
/* mice.c END */ |
/* |
* Virtual operation on a ps/2 mouse |
*/ |
int ps2mouse_open(void *ptrPID) |
{ |
/* some modification are made into 8042.c to allow mouse reinitialization! */ |
//static int first=1; |
//if (first) { |
C8042_auxinit(*(PID*)ptrPID); |
/* probably not needed! */ |
task_activate(*(PID*)ptrPID); |
// first=0; |
//} |
C8042_auxportenable(); |
return 0; |
} |
void ps2mouse_close(void) |
{ |
C8042_auxportdisable(); |
C8042_auxend(); |
} |
void ps2mouse_disable(void) |
{ |
C8042_auxportdisable(); |
} |
void ps2mouse_enable(void) |
{ |
C8042_auxportenable(); |
} |
void ps2mouse_wait(void) |
{ |
task_endcycle(); |
} |
int ps2mouse_get(BYTE *data) |
{ |
return C8042_auxget(data,NON_BLOCK); |
} |
/shark/trunk/drivers/oldchar/ps2mouse.h |
---|
0,0 → 1,82 |
/* |
* 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: ps2mouse.h,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Massimiliano Giorgi |
Virtual operation on a PS/2 mouse |
(for mouse.c) |
**/ |
/* |
* 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 __PS2MOUSE_H__ |
#define __PS2MOUSE_H__ |
#include <drivers/mouse.h> |
#include "ll/sys/cdefs.h" |
__BEGIN_DECLS |
extern int C8042_ps2mousepresent(void); |
#define ps2mouse_present() C8042_ps2mousepresent() |
int ps2mouse_open(void *); |
void ps2mouse_close(void); |
void ps2mouse_wait(void); |
int ps2mouse_get(BYTE *); |
void ps2mouse_enable(void); |
void ps2mouse_disable(void); |
//extern TASK ps2mouse_server(void); |
extern TASK (*ps2mouse_getserveraddr(void))(void); |
extern int M_ps2(MOUSE_EVT *evt, unsigned char *data); |
__END_DECLS |
#endif |
/shark/trunk/drivers/oldchar/mcurgrx.c |
---|
0,0 → 1,234 |
/* |
* 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: mcurgrx.c,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Massimiliano Giorgi |
Date: 24/Giu/99 |
**/ |
/* |
* 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 <sys/sys.h> |
//#include <mem.h> |
#include <drivers/mouse.h> |
#include <drivers/glib.h> |
#include "_mouse.h" |
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}; |
/* 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; |
} |
/* 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 |
/* 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) |
{ |
mouse_grxshape(saved_shapeptr,saved_maskptr); |
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 result; |
grx_vga_modeinfo info; |
int nb; |
BYTE b; |
int pc; |
int i,j; |
int saved_x,saved_y; |
int cond; |
result=gd_getmodeinfo(&info); |
if (result==-1) return -1; |
bpp=nb=info.bytesperpixel; |
cond=( |
((autocursormode&STATUSMASK)==ENABLE)&& |
((autocursormode&GRXCURSOR)==GRXCURSOR) |
); |
if (cond) { |
_mouse_getsavedposition(&saved_x,&saved_y); |
restore_grx_cursor(saved_x,saved_y); |
} |
if (shapeptr==(void*)DEFAULT) { |
//int h; |
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<nb;j++) shape[pc++]=b; |
//grx_plot(h+180,i+80,b); |
} |
} else { |
memcpy(shape,shapeptr,SHAPE_DX*SHAPE_DY*nb); |
saved_shapeptr=shapeptr; |
} |
/* |
some test! |
pc=0; |
for (i=0;i<16;i++) |
for (j=0;j<16;j++) { |
char s[16]; |
sprintf(s,"%c",shape[pc++]==0?'-':'*'); |
grx_text(s,200+j*8,200+i*8,255,0); |
} |
grx_putimage(200,80,200+15,80+16,shape); |
grx_getimage(180,80,180+16,80+16,shape); |
pc=0; |
for (i=0;i<16;i++) |
for (j=0;j<17;j++) { |
char s[16]; |
sprintf(s,"%c",shape[pc++]==0?'-':'*'); |
grx_text(s,400+j*8,400+i*8,255,0); |
} |
*/ |
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<nb;j++) mask[pc++]=b; |
} |
}else { |
memcpy(mask,maskptr,SHAPE_DX*SHAPE_DY*nb); |
saved_maskptr=maskptr; |
} |
if (cond) |
show_grx_cursor(saved_x,saved_y); |
return 0; |
} |
/shark/trunk/drivers/oldchar/mouse.c |
---|
0,0 → 1,591 |
/* |
* 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: mouse.c,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Gerardo Lamastra |
Date: 9/5/96 |
Revision: 1.1b |
Last update: 14/apr/1999 |
Serial mouse driver |
The mouse driver receives data from the serial RxServer() |
Then it processes the mouse packet and sets the variables |
representing the external mouse status. |
**/ |
/* |
* 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 |
* |
*/ |
/* Revision 1.1 |
* Author: Massimiliano Giorgi |
* |
* -- added support for PS/2 mouse |
* |
* Detailed changed from 1.0g: |
* -- now mouse.c use "virtual operation" |
* -- all procedure changed to use "virtual operation" |
* ("virtual operation" are indipendent of the phisical device that |
* is used to comunicate with mouse so it can handle serial mouse, ps/2 mouse) |
* (all changed marked with a "MG") |
*/ |
/* Revision 1.1b |
* Author: Massimiliano Giorgi |
* |
* Changed to compile on 3.2.0 |
* -- added wcet time |
* -- RECEIVE ports now are STREAM ports |
*/ |
/* |
* Changelog: |
* -- Added support for various serial mouse |
* -- Virtual operations changed |
* -- Added support for auto-pointer |
*/ |
/* |
* auto-pointer functions now are into |
* mcurtxt.c and mcurgrx.c |
* (to prevent automatic graphical library inclusion) |
*/ |
//#include <string.h> |
//#include <stdlib.h> |
//#include <cons.h> |
//#include <mem.h> |
//#include "vm.h" |
#include <kernel/kern.h> |
//#include "exc.h" |
#include <drivers/scom.h> |
#include <drivers/mouse.h> |
/*if defined: then a trace of the initialization is performed */ |
// #define __DEBUG_INIT__ |
/* if defined: when a byte is received is displayed on the screen */ |
//#define __XTRA_DEBUG_MOUSE__ |
/* |
* |
* Operation on a virtual mouse |
* (added by MG) |
* |
*/ |
#include "_mouse.h" |
#include "sermouse.h" |
#include "ps2mouse.h" |
struct mouse_operations vmouse[]={ |
{"ms", "The original ms protocol, with a middle-button extension.", |
{0x40, 0x40, 0x40, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_ms |
}, |
{"ms+", "Like 'ms', but allows dragging with the middle button.", |
{0x40, 0x40, 0x40, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_ms_plus |
}, |
{"ms+lr", "'ms+', but you can reset m by pressing lr.", |
{0x40, 0x40, 0x40, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_ms_plus_lr |
}, |
{"bare", "Unadorned ms protocol. Needed with some 2-buttons mice.", |
{0x40, 0x40, 0x40, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_bare |
}, |
{"msc", "Mouse-Systems-Compatible (5bytes). Most 3-button mice.", |
{0xf8, 0x80, 0x00, 0x00}, 5, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_msc |
}, |
{"sun", "'msc' protocol, but only 3 bytes per packet.", |
{0xf8, 0x80, 0x00, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_sun |
}, |
{"mm", "MM series. Probably an old protocol...", |
{0xe0, 0x80, 0x80, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_mm |
}, |
{"logi", "Used in some Logitech devices (only serial).", |
{0xe0, 0x80, 0x80, 0x00}, 3, 1, 0, 0, 0, |
sermouse_open, |
sermouse_close, |
sermouse_wait, |
sermouse_get, |
sermouse_enable, |
sermouse_disable, |
M_logi |
}, |
{"ps2", "Busmice of the ps/2 series. Most busmice, actually.", |
{0xc0, 0x00, 0x00, 0x00}, 3, 1, 0, 0, 0, |
ps2mouse_open, |
ps2mouse_close, |
ps2mouse_wait, |
ps2mouse_get, |
ps2mouse_enable, |
ps2mouse_disable, |
M_ps2 |
}, |
{"\0", "", |
{0, 0, 0, 0}, 0, 0, 0, 0, 0, |
NULL, |
NULL, |
NULL, |
NULL, |
NULL, |
NULL, |
NULL |
} |
}; |
int (*open_mouse)(void*); /* open comunication device */ |
void (*close_mouse)(void); /* close comunication device */ |
void (*wait_mouse)(void); /* wait to have a BYTE (blocking operation)*/ |
int (*get_mouse)(BYTE *); /* get last BYTE */ |
void (*enable_mouse)(void); /* enable interface */ |
void (*disable_mouse)(void); /* disable interface */ |
char *name_mouse; /* mouse name */ |
char *desc_mouse; /* mouse description */ |
BYTE *proto_mouse; /* mouse protocol (see below) */ |
int packetlen_mouse; /* mouse packet lenght */ |
int (*decode_mouse)(MOUSE_EVT *evt,unsigned char *data); |
/* |
* proto_mouse is used to syncronize the device driver: |
* if A is the first byte read and B the second, this is a valid |
* start of a mouse protocol packet if |
* (A&proto_mouse[0])==proto_mouse[1])&&(b&proto_mouse[2])==proto_mouse[3]) |
*/ |
/* type of mouse to use for virtual operation */ |
int mousetype=NOMOUSE; |
/* fill the variabled used to call the virtuals operations */ |
static void mouse_settype(int type) |
{ |
mousetype=type; |
open_mouse =vmouse[mousetype].open; |
close_mouse =vmouse[mousetype].close; |
wait_mouse =vmouse[mousetype].wait; |
get_mouse =vmouse[mousetype].get; |
enable_mouse =vmouse[mousetype].enable; |
disable_mouse=vmouse[mousetype].disable; |
name_mouse =vmouse[mousetype].name; |
desc_mouse =vmouse[mousetype].desc; |
proto_mouse =vmouse[mousetype].proto; |
packetlen_mouse=vmouse[mousetype].packetlen; |
decode_mouse=vmouse[mousetype].decode; |
} |
/* |
* |
* end (operation on a virtual mouse) |
* |
*/ |
/* MG: this are no "static" (they are used by sermouse.c, ps2mouse.c) */ |
/* "threshold" renamed "mouse_thresholdlim" */ |
short int mouse_lim_x1 = 0; |
short int mouse_lim_y1 = 0; |
short int mouse_lim_x2 = 79; |
short int mouse_lim_y2 = 24; |
short int mouse_x = 40; |
short int mouse_x_mick = 0; |
short int mouse_y = 12; |
short int mouse_y_mick = 0; |
short int mouse_buttons = 0; |
short int mouse_thresholdlim = 5; |
MOUSE_HANDLER mouse_handler = NULL; |
MOUSE_HANDLER user_mouse_handler = NULL; |
int autocursormode=DISABLE; |
static PID mouse_pid = NIL; |
/* |
* this is a general mouse server |
* useable by most mouse protocol implementation |
*/ |
TASK generalmouse_server(void) |
{ |
static MOUSE_EVT event; |
BYTE data[8]; |
int index; |
int mickey; |
#ifdef __XTRA_DEBUG_MOUSE__ |
char str[40]; |
#endif |
index=0; |
for(;;) { |
#ifdef __XTRA_DEBUG_MOUSE__ |
puts_xy(0,11,WHITE,"Waiting.."); |
#endif |
/* wait for mouse data */ |
wait_mouse(); |
/* get mouse data */ |
//data[index]=get_mouse(); |
index+=get_mouse(data+index); |
#ifdef __XTRA_DEBUG_MOUSE__ |
sprintf(str,"Mouse data[%01d]: %2x",index,data[index]); |
puts_xy(0,12+index,WHITE,str); |
#endif |
switch (index) { |
case 1: |
if ((data[0]&proto_mouse[0])!=proto_mouse[1]) index=0; |
break; |
case 2: |
if ((data[1]&proto_mouse[2])==proto_mouse[3]) index=0; |
break; |
default: |
if (index<packetlen_mouse) break; |
if (decode_mouse(&event,data)==0) { |
/* Y */ |
mickey=event.dy; |
mouse_y_mick += mickey; |
while (mouse_y_mick > mouse_thresholdlim) { |
mouse_y++; |
mouse_y_mick -= mouse_thresholdlim; |
} |
while (mouse_y_mick < -mouse_thresholdlim) { |
mouse_y--; |
mouse_y_mick += mouse_thresholdlim; |
} |
if (mouse_y > mouse_lim_y2) mouse_y = mouse_lim_y2; |
else if (mouse_y < mouse_lim_y1) mouse_y = mouse_lim_y1; |
event.y=mouse_y; |
/* X */ |
mickey = event.dx; |
mouse_x_mick += mickey; |
while (mouse_x_mick > mouse_thresholdlim) { |
mouse_x++; |
mouse_x_mick -= mouse_thresholdlim; |
} |
while (mouse_x_mick < -mouse_thresholdlim) { |
mouse_x--; |
mouse_x_mick += mouse_thresholdlim; |
} |
if (mouse_x > mouse_lim_x2) mouse_x = mouse_lim_x2; |
else if (mouse_x < mouse_lim_x1) mouse_x = mouse_lim_x1; |
event.x=mouse_x; |
/* mouse handler */ |
if (mouse_handler!=NULL) mouse_handler(&event); |
} |
index-=packetlen_mouse; |
if (index!=0) memcpy(data,data+packetlen_mouse,index); |
break; |
} /* switch */ |
} /* for */ |
} |
/* [for SERIAL MOUSE] */ |
/* Well, this implementation is a little dispendious as we use */ |
/* two different tasks, one as serial receiver, the other as */ |
/* mouse-protocol decoder; this has been chosen in order to */ |
/* make any mouse-protocol easier. We only need to rewrite the */ |
/* the appropriate mouse packet interpreter */ |
/* |
* MG: rewritten to handle serial and PS/2 mouse and other mouses |
*/ |
/* changed user interface */ |
int mouse_init(MOUSE_PARMS *parms) |
{ |
int status=0; |
TASK_MODEL *m; |
SOFT_TASK_MODEL base_m; |
SERMOUSE_INFO sinfo; |
MOUSE_PARMS mparms=BASE_MOUSE; |
#ifdef __DEBUG_INIT__ |
cprintf("mouse_init: START\n"); |
#endif |
if (mouse_pid != NIL) return -1; |
if (parms==NULL) parms=&mparms; |
/* default values */ |
#ifdef __DEBUG_INIT__ |
cprintf("mouse_init: default values\n"); |
#endif |
if (parms->tm == (TASK_MODEL *)MOUSE_DEFAULT) { |
soft_task_default_model(base_m); |
soft_task_def_wcet(base_m,2000); |
soft_task_def_met(base_m,500); |
soft_task_def_period(base_m,8000); |
soft_task_def_system(base_m); |
soft_task_def_nokill(base_m); |
soft_task_def_aperiodic(base_m); |
m = (TASK_MODEL *)&base_m; |
} |
else |
m = parms->tm; |
/* try autodetect mouse() */ |
if (parms->type==MOUSE_DEFAULT) { |
SERMOUSE_INFO *sinfoptr; |
#ifdef __DEBUG_INIT__ |
cprintf("mouse_init: try autodetecting\n"); |
#endif |
if (ps2mouse_present()) parms->type=PS2MOUSE; |
else { |
sinfoptr=sermouse_present(); |
if (sinfoptr==NULL) return -2; |
parms->type=sinfoptr->type; |
parms->port=sinfoptr->port; |
} |
} |
mouse_settype(parms->type); |
switch(mousetype) { |
case PS2MOUSE: |
/* max PS/2 mouse rate: 40 event per second with 3 bytes per event */ |
/* 120 bytes/sec -> 8 msec between activation (I hope)*/ |
#ifdef __DEBUG_INIT__ |
cprintf("mouse_init: creating ps2 server task\n"); |
#endif |
if (parms->tm==(TASK_MODEL *)MOUSE_DEFAULT) |
soft_task_def_period(base_m,8000); |
mouse_pid=task_create("PS2Mouse", |
ps2mouse_getserveraddr(), |
m, NULL); |
if (mouse_pid==-1) return -3; |
//task_activate(mouse_pid); |
#ifdef __DEBUG_INIT__ |
cprintf("mouse_init: opening mouse\n"); |
#endif |
status=open_mouse((void*)&mouse_pid); |
break; |
case MSMOUSE: |
case MSPMOUSE: |
case MSPLRMOUSE: |
case BAREMOUSE: |
case MSCMOUSE: |
case SUNMOUSE: |
case LOGIMOUSE: |
case MMMOUSE: |
if (parms->port==MOUSE_DEFAULT) parms->port=COM1; |
sinfo.type=parms->type; |
sinfo.port=parms->port; |
if (parms->tm == (TASK_MODEL *)MOUSE_DEFAULT) |
soft_task_def_period(base_m,12000); |
task_def_arg(*m,(void *)parms->port); |
mouse_pid=task_create("SerialMouse", |
sermouse_getserveraddr(&sinfo), |
m, NULL); |
if (mouse_pid==-1) return -3; |
sinfo.pid=mouse_pid; |
status=open_mouse((void*)&sinfo); |
//if (!status) |
// task_activate(mouse_pid); |
break; |
} |
if (status!=0) { |
task_kill(mouse_pid); |
mouse_pid=NIL; |
return -4; |
} |
#ifdef __DEBUG_INIT__ |
cputs("mouse_init: mouse activated\n"); |
#endif |
return 0; |
} |
void mouse_end(void) |
{ |
if (mouse_pid==NIL) return; |
task_kill(mouse_pid); |
mouse_pid=NIL; |
close_mouse(); |
} |
/* MG: all the following procedure are modified */ |
/* to use virtual operation */ |
void mouse_disable(void) |
{ |
disable_mouse(); |
} |
void mouse_enable(void) |
{ |
enable_mouse(); |
} |
void mouse_get(int *x,int *y,BYTE *button) |
{ |
if (x != NULL) *x = mouse_x; |
if (y != NULL) *y = mouse_y; |
if (button != NULL) *button = mouse_buttons; |
} |
void mouse_position(int x,int y) |
{ |
disable_mouse(); |
mouse_x = x; |
mouse_y = y; |
enable_mouse(); |
} |
void mouse_limit(int x1,int y1,int x2,int y2) |
{ |
disable_mouse(); |
mouse_lim_x1 = x1; |
mouse_lim_y1 = y1; |
mouse_lim_x2 = x2; |
mouse_lim_y2 = y2; |
mouse_x = (x1+x2)/2; |
mouse_y = (y1+y2)/2; |
enable_mouse(); |
} |
void mouse_threshold(unsigned t) |
{ |
disable_mouse(); |
if (t < 1) t = 1; |
else if (t > 100) t = 100; |
mouse_thresholdlim = t; |
enable_mouse(); |
} |
void mouse_hook(MOUSE_HANDLER h) |
{ |
/* changed to use the autocursor functions */ |
if ((autocursormode&STATUSMASK)==DISABLE) { |
mouse_handler = h; |
} else { |
user_mouse_handler = h; |
} |
} |
/shark/trunk/drivers/oldchar/rtc.c |
---|
0,0 → 1,406 |
/* |
* 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: rtc.c,v 1.1 2003-03-24 10:54:17 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:17 $ |
------------ |
Author: Massimiliano Giorgi |
A source from Linux 2.2.9 modified to work with 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 |
* |
*/ |
/* |
* Real Time Clock interface for Linux |
* |
* Copyright (C) 1996 Paul Gortmaker |
* |
* This driver allows use of the real time clock (built into |
* nearly all computers) from user space. It exports the /dev/rtc |
* interface supporting various ioctl() and also the /proc/rtc |
* pseudo-file for status information. |
* |
* The ioctls can be used to set the interrupt behaviour and |
* generation rate from the RTC via IRQ 8. Then the /dev/rtc |
* interface can be used to make use of these timer interrupts, |
* be they interval or alarm based. |
* |
* The /dev/rtc interface will block on reads until an interrupt |
* has been received. If a RTC interrupt has already happened, |
* it will output an unsigned long and then block. The output value |
* contains the interrupt status in the low byte and the number of |
* interrupts since the last read in the remaining high bytes. The |
* /dev/rtc interface can also be used with the select(2) call. |
* |
* 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. |
* |
* Based on other minimal char device drivers, like Alan's |
* watchdog, Ted's random, etc. etc. |
* |
* 1.07 Paul Gortmaker. |
* 1.08 Miquel van Smoorenburg: disallow certain things on the |
* DEC Alpha as the CMOS clock is also used for other things. |
* 1.09 Nikita Schmidt: epoch support and some Alpha cleanup. |
* |
*/ |
#define RTC_VERSION "1.09" |
#define RTC_IRQ 8 /* Can't see this changing soon. */ |
#define RTC_IO_EXTENT 0x10 /* Only really two ports, but... */ |
/* |
* Note that *all* calls to CMOS_READ and CMOS_WRITE are done with |
* interrupts disabled. Due to the index-port/data-port (0x70/0x71) |
* design of the RTC, we don't want two different things trying to |
* get to it at once. (e.g. the periodic 11 min sync from time.c vs. |
* this driver.) |
*/ |
#include <kernel/kern.h> |
#include <drivers/rtc.h> |
#include "_rtc.h" |
/* |
#define CMOS_READ(addr) ({ \ |
outb_p((addr),RTC_PORT(0)); \ |
inb_p(RTC_PORT(1)); \ |
}) |
#define CMOS_WRITE(val, addr) ({ \ |
outb_p((addr),RTC_PORT(0)); \ |
outb_p((val),RTC_PORT(1)); \ |
}) |
*/ |
#define CMOS_READ(addr) ( \ |
ll_out(RTC_PORT(0),addr), \ |
ll_in(RTC_PORT(1)) \ |
) |
#define CMOS_WRITE(val, addr) (\ |
ll_out(RTC_PORT(0),addr), \ |
ll_out(RTC_PORT(1),val) \ |
) |
/* |
* We sponge a minor off of the misc major. No need slurping |
* up another valuable major dev number for this. If you add |
* an ioctl, make sure you don't conflict with SPARC's RTC |
* ioctls. |
*/ |
int get_rtc_time (struct rtc_time *rtc_tm); |
int set_rtc_time (struct rtc_time *rtc_tm); |
int get_rtc_alm_time (struct rtc_time *alm_tm); |
void set_rtc_irq_bit(unsigned char bit); |
void mask_rtc_irq_bit(unsigned char bit); |
static inline unsigned char rtc_is_updating(void); |
/* |
* Bits in rtc_status. (6 bits of room for future expansion) |
*/ |
#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ |
#define RTC_TIMER_ON 0x02 /* missed irq timer active */ |
unsigned char rtc_status = 0; /* bitmapped status byte. */ |
unsigned long rtc_freq = 0; /* Current periodic IRQ rate */ |
unsigned long rtc_irq_data = 0; /* our output to the world */ |
/* |
* If this driver ever becomes modularised, it will be really nice |
* to make the epoch retain its value across module reload... |
*/ |
static unsigned long epoch = 1900; /* year corresponding to 0x00 */ |
unsigned char days_in_mo[] = |
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
/* |
* Returns true if a clock update is in progress |
*/ |
static inline unsigned char rtc_is_updating(void) |
{ |
SYS_FLAGS flags; |
unsigned char uip; |
flags=kern_fsave(); |
uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP); |
kern_frestore(flags); |
return uip; |
} |
int get_rtc_time(struct rtc_time *rtc_tm) |
{ |
SYS_FLAGS flags; |
unsigned char ctrl; |
unsigned retries=0; |
struct timespec delay; |
/* |
* read RTC once any update in progress is done. The update |
* can take just over 2ms. We wait 10 to 20ms. There is no need to |
* to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP. |
* If you need to know *exactly* when a second has started, enable |
* periodic update complete interrupts, (via ioctl) and then |
* immediately read /dev/rtc which will block until you get the IRQ. |
* Once the read clears, read the RTC time (again via ioctl). Easy. |
*/ |
/* |
if (rtc_is_updating() != 0) |
while (jiffies - uip_watchdog < 2*HZ/100) |
barrier(); |
*/ |
delay.tv_nsec = 1000000; |
delay.tv_sec = 0; |
while (rtc_is_updating()&&++retries<=5) nanosleep(&delay, NULL); |
if (retries>5) return -1; |
/* |
* Only the values that we read from the RTC are set. We leave |
* tm_wday, tm_yday and tm_isdst untouched. Even though the |
* RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated |
* by the RTC when initially set to a non-zero value. |
*/ |
flags=kern_fsave(); |
rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS); |
rtc_tm->tm_min = CMOS_READ(RTC_MINUTES); |
rtc_tm->tm_hour = CMOS_READ(RTC_HOURS); |
rtc_tm->tm_mday = CMOS_READ(RTC_DAY_OF_MONTH); |
rtc_tm->tm_mon = CMOS_READ(RTC_MONTH); |
rtc_tm->tm_year = CMOS_READ(RTC_YEAR); |
ctrl = CMOS_READ(RTC_CONTROL); |
kern_frestore(flags); |
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
{ |
BCD_TO_BIN(rtc_tm->tm_sec); |
BCD_TO_BIN(rtc_tm->tm_min); |
BCD_TO_BIN(rtc_tm->tm_hour); |
BCD_TO_BIN(rtc_tm->tm_mday); |
BCD_TO_BIN(rtc_tm->tm_mon); |
BCD_TO_BIN(rtc_tm->tm_year); |
} |
/* |
* Account for differences between how the RTC uses the values |
* and how they are defined in a struct rtc_time; |
*/ |
if ((rtc_tm->tm_year += (epoch - 1900)) <= 69) |
rtc_tm->tm_year += 100; |
rtc_tm->tm_mon--; |
return 0; |
} |
int set_rtc_time(struct rtc_time *rtc_tm) |
{ |
unsigned char mon, day, hrs, min, sec, leap_yr; |
unsigned char save_control, save_freq_select; |
unsigned int yrs; |
SYS_FLAGS flags; |
yrs = rtc_tm->tm_year + 1900; |
mon = rtc_tm->tm_mon + 1; /* tm_mon starts at zero */ |
day = rtc_tm->tm_mday; |
hrs = rtc_tm->tm_hour; |
min = rtc_tm->tm_min; |
sec = rtc_tm->tm_sec; |
if (yrs < 1970) |
return -EINVAL; |
leap_yr = ((!(yrs % 4) && (yrs % 100)) || !(yrs % 400)); |
if ((mon > 12) || (day == 0)) |
return -EINVAL; |
if (day > (days_in_mo[mon] + ((mon == 2) && leap_yr))) |
return -EINVAL; |
if ((hrs >= 24) || (min >= 60) || (sec >= 60)) |
return -EINVAL; |
if ((yrs -= epoch) > 255) /* They are unsigned */ |
return -EINVAL; |
flags=kern_fsave(); |
if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) |
|| RTC_ALWAYS_BCD) { |
if (yrs > 169) { |
kern_frestore(flags); |
return -EINVAL; |
} |
if (yrs >= 100) |
yrs -= 100; |
BIN_TO_BCD(sec); |
BIN_TO_BCD(min); |
BIN_TO_BCD(hrs); |
BIN_TO_BCD(day); |
BIN_TO_BCD(mon); |
BIN_TO_BCD(yrs); |
} |
save_control = CMOS_READ(RTC_CONTROL); |
CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL); |
save_freq_select = CMOS_READ(RTC_FREQ_SELECT); |
CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT); |
CMOS_WRITE(yrs, RTC_YEAR); |
CMOS_WRITE(mon, RTC_MONTH); |
CMOS_WRITE(day, RTC_DAY_OF_MONTH); |
CMOS_WRITE(hrs, RTC_HOURS); |
CMOS_WRITE(min, RTC_MINUTES); |
CMOS_WRITE(sec, RTC_SECONDS); |
CMOS_WRITE(save_control, RTC_CONTROL); |
CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); |
kern_frestore(flags); |
return 0; |
} |
int get_rtc_alm_time(struct rtc_time *alm_tm) |
{ |
SYS_FLAGS flags; |
unsigned char ctrl; |
/* |
* Only the values that we read from the RTC are set. That |
* means only tm_hour, tm_min, and tm_sec. |
*/ |
flags=kern_fsave(); |
alm_tm->tm_sec = CMOS_READ(RTC_SECONDS_ALARM); |
alm_tm->tm_min = CMOS_READ(RTC_MINUTES_ALARM); |
alm_tm->tm_hour = CMOS_READ(RTC_HOURS_ALARM); |
ctrl = CMOS_READ(RTC_CONTROL); |
kern_frestore(flags); |
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
{ |
BCD_TO_BIN(alm_tm->tm_sec); |
BCD_TO_BIN(alm_tm->tm_min); |
BCD_TO_BIN(alm_tm->tm_hour); |
} |
return 0; |
} |
/* |
* Used to disable/enable interrupts for any one of UIE, AIE, PIE. |
* Rumour has it that if you frob the interrupt enable/disable |
* bits in RTC_CONTROL, you should read RTC_INTR_FLAGS, to |
* ensure you actually start getting interrupts. Probably for |
* compatibility with older/broken chipset RTC implementations. |
* We also clear out any old irq data after an ioctl() that |
* meddles with the interrupt enable/disable bits. |
*/ |
void mask_rtc_irq_bit(unsigned char bit) |
{ |
unsigned char val; |
SYS_FLAGS flags; |
flags=kern_fsave(); |
//cli(); |
val = CMOS_READ(RTC_CONTROL); |
val &= ~bit; |
CMOS_WRITE(val, RTC_CONTROL); |
CMOS_READ(RTC_INTR_FLAGS); |
kern_frestore(flags); |
//rtc_irq_data = 0; |
} |
void set_rtc_irq_bit(unsigned char bit) |
{ |
unsigned char val; |
SYS_FLAGS flags; |
flags=kern_fsave(); |
//cli(); |
val = CMOS_READ(RTC_CONTROL); |
val |= bit; |
CMOS_WRITE(val, RTC_CONTROL); |
CMOS_READ(RTC_INTR_FLAGS); |
//rtc_irq_data = 0; |
kern_frestore(flags); |
} |
/* added by Massy */ |
/* to find the date in seconds from the Epoch (1 Gen 1970 00:00 GMT) */ |
/* (modifing a source from Linux) */ |
static int day_n[]={ |
0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 |
}; |
time_t sys_getdate(void) |
{ |
struct rtc_time rtc; |
time_t secs; |
get_rtc_time (&rtc); |
secs = rtc.tm_sec+60l*rtc.tm_min+rtc.tm_hour*3600l+86400l* |
(rtc.tm_mday-1+day_n[rtc.tm_mon]+(rtc.tm_year/4l) |
+rtc.tm_year*365l- |
((rtc.tm_year & 3) == 0 && rtc.tm_mon < 2 ? 1 : 0)+3653l); |
/* days since 1.1.70 plus 80's leap day */ |
/*secs += sys_tz.tz_minuteswest*60;*/ |
/*if (sys_tz.tz_dsttime) secs -= 3600;*/ |
return secs; |
} |
/shark/trunk/drivers/oldchar/keyb.c |
---|
0,0 → 1,675 |
/* |
* 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: keyb.c,v 1.1 2003-03-24 10:54:16 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:16 $ |
------------ |
Author: Giuseppe Lipari |
Start date: 19/6/96 |
File: Keyb.C |
Revision: 1.5.1 |
Last update : 14/Apr/1999 |
This file contains : |
-- A fast handler that get the scan code from the key interface |
and put it in a port (non blocking) ; Inside this handler we can't |
make any primitive call; it runs with interrupt enabled, so that the |
timer cannot be blocked. Its priority is 1 (from hardware). |
-- A sporadic soft process that gets the data from the port and |
tries to recognize any scan code. With the help of a table that varies |
from keyboad to keyboard (e.g. italian vs american) it puts the ascii |
code intoanother port, with a byte that indicates the pression of any |
control key (Shift, Ctrl, Alt). I tried to make the initialization |
of this table as standard as possible, so that one has to change only |
the include file with all the codes |
-- Some functions (exported) to initialize the interface and get the |
ascii code |
Revision 1.4 (Gerardo) Added support for italian keyboard; required |
to add a new status variable rightalt to cope with italian keybs |
assignment! Added the keyb_set_map function to select the keymaps |
and finally build the english & italian keymaps |
Revision 1.5 (Giorgi) |
Split the file into keyb.c and 8042.c: |
8042.c low level hardware interface |
keyb.c user interface to kerboard routines |
(8042.c is the "source" of data that keyb.c must interpretate) |
Modification made: |
-- fast handler remove (now in 8042.c) |
-- all function that make direct I/O with hardware now in 8042.c |
-- keyb_init() modified (to interfaces with 8042.c) |
-- key_sendKeyCmd() removed; key_sendCtrCmd() removed |
-- scanCode() & KeyProc modified (keyboard ACK are tested in KeyProc) |
-- actled() removed (now in 8042.c with name 8042_keyboardleds); all |
reference changed |
-- Key_1 port removed (comunication in handled by functions in 8042.c) |
-- added functions to enable/disable keyboard |
PS: the modification are marked with "MG" |
Revision 1.5.1 (Giorgi) |
Modification to compile on 3.2.0 |
-- added wcet time to all task |
-- RECEIVE port now are STREAM port |
**/ |
/* |
* 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 __KEYB_DEBUG__ 1 |
//#include <string.h> |
//#include <stdlib.h> |
//#include <cons.h> |
#include <kernel/kern.h> |
#include <signal.h> |
#include <modules/hartport.h> |
#include <drivers/keyb.h> |
#include <drivers/keycode.h> |
#include "8042.h" |
char engMap[] = { |
'1','2','3','4','5','6','7','8','9','0', |
'!','@','#','$','%','^','&','*','(',')', |
'-','_','=','+','[','{',']','}',';',':','\'','\"','`','~','/','?',',', |
'<','.','>','\\','|',' ',' ',8,8,9,9,27,27,13,13,24, |
'1','2','3','4','5','6','7','8','9','0','.','+','*','/','-','+','*','-', |
'a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i', |
'I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q', |
'r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z','Z', |
/* |
These are the strange keys used in the italian keyboard |
When you press Alt-Right to obtain [,], @ or #. They are left |
unbind with English Keyboard |
*/ |
' ',' ',' ',' ' |
}; |
char itaMap[] = { |
'1','2','3','4','5','6','7','8','9','0', |
'!','\"','','$','%','&','/','(',')','=', |
'\'','?','','^','','','+','*','','',' ','ø','\\','|','<','_',',', |
':','.',';','','õ',' ',' ',8,8,9,9,27,27,13,13,24, |
'1','2','3','4','5','6','7','8','9','0','.','+','*','/','-','+','*','-', |
'a','A','b','B','c','C','d','D','e','E','f','F','g','G','h','H','i', |
'I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q', |
'r','R','s','S','t','T','u','U','v','V','w','W','x','X','y','Y','z','Z', |
/* |
These are the strange keys used in the italian keyboard |
When you press Alt-Right to obtain [,], @ or # |
*/ |
'[',']','@','#' |
}; |
#define MAX_KEY_EXC 15 |
static struct keyexctable { |
KEY_EVT evt; |
void (*func)(KEY_EVT *k); |
} keyExcTable[MAX_KEY_EXC]; |
static int lastExc; |
/* the following tables contains the ascii code corresponding to the */ |
/* scan codes, with shift & no shift... */ |
static char keyTable[NUM_OF_KEY]; |
static char keyShiftTable[NUM_OF_KEY]; |
static char keyRightAltTable[NUM_OF_KEY]; |
static char *actualMap = engMap; |
/* Status variables */ |
static BYTE e0 = FALSE; |
static BYTE sh = FALSE; |
static BYTE rightalt = FALSE; |
static BYTE cps = FALSE; |
static BYTE numlock = TRUE; |
static BYTE scrolllock = FALSE; |
static int keyb_installed = FALSE; |
/* Keyboard Flags (if shift alt or control are pressed...); */ |
static BYTE keyFlag = 0x00; |
/* Communication port between the handler & the extern process */ |
/* MG: port not needed! */ |
//static PORT keyHandPort, keyProcPort; |
/* Communication port between the extern process & the user */ |
static PORT pkeyPort, ukeyPort; |
/* This function get a scan code, return an ascii code and set */ |
/* the status vars in order to handle the special keys of the AT keyboard */ |
/* (I write this code several time !!). When it finds a special code */ |
/* (Insert, Del, Up, Down, ecc) it return a code with the first byte */ |
/* at ffh and the second byte with the scan code, while normally it */ |
/* return only the ascii code */ |
WORD scanCode(BYTE c) |
{ |
/* if it's an ack, advice the actLed routine */ |
/* MG: test removed (it's in "KeyProc") */ |
//if (c == 0xfa) actLed(0); |
/* If the previous key was an 0xe0... */ |
if (e0) { |
/* throw away the pairs 0xe0-0x2a and 0xe0-0xaa */ |
if (c == 0x2a || c == 0xaa) { |
e0 = FALSE; |
return 0; |
} |
/* throw away the pairs 0xe0-0x36 and 0xe0-0xb6 */ |
if (c == 0x36 || c == 0xb6) { |
e0 = FALSE; |
return 0; |
} |
/* if it's a break code ... */ |
else if (c & 0x80) { |
e0 = FALSE; |
/* Right Alt */ |
if (c == (KEY_ALTL | 0x80)) { |
keyFlag = keyFlag & (!ALTR_BIT); |
rightalt = FALSE; |
} |
/* Right Ctrl */ |
else if (c == (KEY_CTRLL | 0x80)) { |
keyFlag = keyFlag & (!CNTR_BIT); |
} |
return 0; |
} |
else { |
e0 = FALSE; |
/* Right Alt */ |
if (c == KEY_ALTL) { |
keyFlag |= ALTR_BIT ; |
rightalt = TRUE; |
return 0; |
} |
/* Right Ctrl */ |
else if (c == KEY_CTRLL) { |
keyFlag |= CNTR_BIT ; |
return 0; |
} |
/* Numeric keypad */ |
else if (c == PAD_SCRLOCK) return keyTable[c]; |
else if (c == KEY_ENT) return keyTable[c]; |
/* simply return scan code */ |
else return(0xff00 | c); |
} |
} |
else { |
/* it's an 0xe0, we must remember */ |
if (c == 0xe0) { |
e0 = TRUE; |
return 0; |
} |
else if (c == KEY_SHL || c == KEY_SHR) { |
/* it's the shift : adjust flags */ |
sh = TRUE; |
if (c == KEY_SHL) keyFlag = keyFlag | SHFL_BIT ; |
else if (c == KEY_SHR) keyFlag = keyFlag | SHFR_BIT ; |
return 0; |
} |
else if (c == (KEY_SHL | 0x80) || c == (KEY_SHR | 0x80)) { |
/* it's the shift break code */ |
sh = FALSE; |
if (c == (KEY_SHL | 0x80)) keyFlag = keyFlag & (!SHFL_BIT); |
else if (c == (KEY_SHR | 0x80)) keyFlag = keyFlag & (!SHFR_BIT); |
return 0; |
} |
else if (c == KEY_SCRLOCK) { |
if (scrolllock == TRUE) scrolllock = FALSE; |
else scrolllock = TRUE; |
/* light the scroll lock led */ |
/* MG: changed */ |
C8042_keyboardleds(numlock,cps,scrolllock); |
return 0; |
} |
} |
/* Hovewer ...*/ |
if (c == KEY_CPSLOCK) { |
if (cps == TRUE) cps = FALSE; |
else cps = TRUE; |
/* MG: changed */ |
C8042_keyboardleds(numlock,cps,scrolllock); |
return 0; |
} |
if (c == PAD_NUMLOCK) { |
if (numlock == TRUE) numlock = FALSE; |
else numlock = TRUE; |
/* MG: changed */ |
C8042_keyboardleds(numlock,cps,scrolllock); |
return 0; |
} |
if (c == KEY_CTRLL) { |
keyFlag = keyFlag | CNTL_BIT ; |
return 0; |
} |
else if (c == KEY_ALTL) { |
keyFlag = keyFlag | ALTL_BIT ; |
return 0; |
} |
else if (c == (KEY_CTRLL | 0x80)) { |
keyFlag = keyFlag & (!CNTL_BIT); |
return 0; |
} |
else if (c == (KEY_ALTL | 0x80)) { |
keyFlag = keyFlag & (!ALTL_BIT); |
return 0; |
} |
else if (c & 0x80) { |
return 0; |
} |
else if ((c == PAD_INS) || (c == PAD_END) || (c == PAD_DEL) || |
(c == PAD_DOWN) || (c == PAD_PGDW) || (c == PAD_LEFT) || |
(c == PAD_5) || (c == PAD_RIGHT) || (c == PAD_HOME) || |
(c == PAD_UP) || (c == PAD_PGUP)) { |
if (numlock || sh) return keyShiftTable[c]; |
else return (0xff00 | c); |
} |
else if (cps && |
(((c >= KEY_Q) && (c <= KEY_P)) || |
((c >= KEY_A) && (c <= KEY_L)) || |
((c >= KEY_Z) && (c <= KEY_M))) ) { |
if (sh) return keyTable[c]; |
else return keyShiftTable[c]; |
} |
else if (sh) return keyShiftTable[c]; |
else if (rightalt) return keyRightAltTable[c]; |
else return keyTable[c]; |
} |
TASK keyProc(void) |
{ |
WORD code; |
BYTE dato,found; |
KEY_EVT dt; |
int i,res; |
while (1) { |
// kern_printf("K"); |
/* MG: used C8042_keyboardget() */ |
res=C8042_keyboardget(&dato,NON_BLOCK); |
if (res) { |
code = scanCode(dato); |
if (code != 0) { |
/* if it's a scan code , set the right bit ...*/ |
if (code & 0xff00) dt.flag = (keyFlag | SCAN_BIT); |
/* ... else simply send the keyFlag status*/ |
else dt.flag = keyFlag; |
dt.ascii = (BYTE)(code & 0x00FF); |
dt.scan = dato; |
found = FALSE; |
for (i = 0; i < lastExc; i++) |
if ((keyExcTable[i].evt.scan == dt.scan) && (keyExcTable[i].evt.flag == dt.flag)) { |
keyExcTable[i].func(&dt); |
found = TRUE; |
} |
/* when the port is full, data is lost */ |
if (!found) port_send(pkeyPort,(BYTE *)(&dt),NON_BLOCK); |
} |
} |
task_endcycle(); |
} |
} |
void keyb_set_map(char *t) |
{ |
actualMap = t; |
keyTable[KEY_1] = actualMap[0]; |
keyTable[KEY_2] = actualMap[1]; |
keyTable[KEY_3] = actualMap[2]; |
keyTable[KEY_4] = actualMap[3]; |
keyTable[KEY_5] = actualMap[4]; |
keyTable[KEY_6] = actualMap[5]; |
keyTable[KEY_7] = actualMap[6]; |
keyTable[KEY_8] = actualMap[7]; |
keyTable[KEY_9] = actualMap[8]; |
keyTable[KEY_0] = actualMap[9]; |
keyShiftTable[KEY_1] = actualMap[10]; |
keyShiftTable[KEY_2] = actualMap[11]; |
keyShiftTable[KEY_3] = actualMap[12]; |
keyShiftTable[KEY_4] = actualMap[13]; |
keyShiftTable[KEY_5] = actualMap[14]; |
keyShiftTable[KEY_6] = actualMap[15]; |
keyShiftTable[KEY_7] = actualMap[16]; |
keyShiftTable[KEY_8] = actualMap[17]; |
keyShiftTable[KEY_9] = actualMap[18]; |
keyShiftTable[KEY_0] = actualMap[19]; |
keyTable[KEY_SUB] = actualMap[20]; |
keyShiftTable[KEY_SUB] = actualMap[21]; |
keyTable[KEY_PLUS] = actualMap[22]; |
keyShiftTable[KEY_PLUS] = actualMap[23]; |
keyTable[KEY_BRL] = actualMap[24]; |
keyShiftTable[KEY_BRL] = actualMap[25]; |
keyTable[KEY_BRR] = actualMap[26]; |
keyShiftTable[KEY_BRR] = actualMap[27]; |
keyTable[KEY_COL] = actualMap[28]; |
keyShiftTable[KEY_COL] = actualMap[29]; |
keyTable[KEY_API] = actualMap[30]; |
keyShiftTable[KEY_API] = actualMap[31]; |
keyTable[KEY_TIL] = actualMap[32]; |
keyShiftTable[KEY_TIL] = actualMap[33]; |
keyTable[KEY_SLH] = actualMap[34]; |
keyShiftTable[KEY_SLH] = actualMap[35]; |
keyTable[KEY_LT] = actualMap[36]; |
keyShiftTable[KEY_LT] = actualMap[37]; |
keyTable[KEY_GT] = actualMap[38]; |
keyShiftTable[KEY_GT] = actualMap[39]; |
keyTable[KEY_BSL] = actualMap[40]; |
keyShiftTable[KEY_BSL] = actualMap[41]; |
keyTable[KEY_SPC] = actualMap[42]; |
keyShiftTable[KEY_SPC] = actualMap[43]; |
keyTable[KEY_BKS] = actualMap[44]; |
keyShiftTable[KEY_BKS] = actualMap[45]; |
keyTable[KEY_TAB] = actualMap[46]; |
keyShiftTable[KEY_TAB] = actualMap[470]; |
keyTable[KEY_ESC] = actualMap[48]; |
keyShiftTable[KEY_ESC] = actualMap[49]; |
keyTable[KEY_ENT] = actualMap[50]; |
keyShiftTable[KEY_ENT] = actualMap[51]; |
keyShiftTable[KEY_DEL] = actualMap[52]; |
keyShiftTable[PAD_END] = actualMap[53]; |
keyShiftTable[PAD_DOWN] = actualMap[54]; |
keyShiftTable[PAD_PGDW] = actualMap[55]; |
keyShiftTable[PAD_LEFT] = actualMap[56]; |
keyShiftTable[PAD_5] = actualMap[57]; |
keyShiftTable[PAD_RIGHT] = actualMap[58]; |
keyShiftTable[PAD_HOME] = actualMap[59]; |
keyShiftTable[PAD_UP] = actualMap[60]; |
keyShiftTable[PAD_PGUP] = actualMap[61]; |
keyShiftTable[PAD_INS] = actualMap[62]; |
keyShiftTable[PAD_DEL] = actualMap[63]; |
keyTable[PAD_PLUS] = actualMap[64]; |
keyTable[PAD_AST] = actualMap[65]; |
keyTable[PAD_SCRLOCK] = actualMap[66]; |
keyTable[PAD_SUB] = actualMap[67]; |
keyShiftTable[PAD_PLUS] = actualMap[68]; |
keyShiftTable[PAD_AST] = actualMap[69]; |
keyShiftTable[PAD_SUB] = actualMap[70]; |
keyTable[KEY_A] = actualMap[71]; |
keyShiftTable[KEY_A] = actualMap[72]; |
keyTable[KEY_B] = actualMap[73]; |
keyShiftTable[KEY_B] = actualMap[74]; |
keyTable[KEY_C] = actualMap[75]; |
keyShiftTable[KEY_C] = actualMap[76]; |
keyTable[KEY_D] = actualMap[77]; |
keyShiftTable[KEY_D] = actualMap[78]; |
keyTable[KEY_E] = actualMap[79]; |
keyShiftTable[KEY_E] = actualMap[80]; |
keyTable[KEY_F] = actualMap[81]; |
keyShiftTable[KEY_F] = actualMap[82]; |
keyTable[KEY_G] = actualMap[83]; |
keyShiftTable[KEY_G] = actualMap[84]; |
keyTable[KEY_H] = actualMap[85]; |
keyShiftTable[KEY_H] = actualMap[86]; |
keyTable[KEY_I] = actualMap[87]; |
keyShiftTable[KEY_I] = actualMap[88]; |
keyTable[KEY_J] = actualMap[89]; |
keyShiftTable[KEY_J] = actualMap[90]; |
keyTable[KEY_K] = actualMap[91]; |
keyShiftTable[KEY_K] = actualMap[82]; |
keyTable[KEY_L] = actualMap[93]; |
keyShiftTable[KEY_L] = actualMap[94]; |
keyTable[KEY_M] = actualMap[95]; |
keyShiftTable[KEY_M] = actualMap[96]; |
keyTable[KEY_N] = actualMap[97]; |
keyShiftTable[KEY_N] = actualMap[98]; |
keyTable[KEY_O] = actualMap[99]; |
keyShiftTable[KEY_O] = actualMap[100]; |
keyTable[KEY_P] = actualMap[101]; |
keyShiftTable[KEY_P] = actualMap[102]; |
keyTable[KEY_Q] = actualMap[103]; |
keyShiftTable[KEY_Q] = actualMap[104]; |
keyTable[KEY_R] = actualMap[105]; |
keyShiftTable[KEY_R] = actualMap[106]; |
keyTable[KEY_S] = actualMap[107]; |
keyShiftTable[KEY_S] = actualMap[108]; |
keyTable[KEY_T] = actualMap[109]; |
keyShiftTable[KEY_T] = actualMap[110]; |
keyTable[KEY_U] = actualMap[111]; |
keyShiftTable[KEY_U] = actualMap[112]; |
keyTable[KEY_V] = actualMap[113]; |
keyShiftTable[KEY_V] = actualMap[114]; |
keyTable[KEY_W] = actualMap[115]; |
keyShiftTable[KEY_W] = actualMap[116]; |
keyTable[KEY_X] = actualMap[117]; |
keyShiftTable[KEY_X] = actualMap[118]; |
keyTable[KEY_Y] = actualMap[119]; |
keyShiftTable[KEY_Y] = actualMap[120]; |
keyTable[KEY_Z] = actualMap[121]; |
keyShiftTable[KEY_Z] = actualMap[122]; |
keyRightAltTable[KEY_BRL] = actualMap[123]; |
keyRightAltTable[KEY_BRR] = actualMap[124]; |
keyRightAltTable[KEY_COL] = actualMap[125]; |
keyRightAltTable[KEY_API] = actualMap[126]; |
} |
/* default function called on ctrl-c */ |
void default_ctrlChandler(KEY_EVT *k) |
{ |
set_active_page(0); |
set_visual_page(0); |
cputs("Ctrl-C pressed!\n"); |
sys_end(); |
// exit(1); |
} |
/* This is the interface to application */ |
/* Initialize keyboard driver */ |
/* MG: this function return: */ |
/* 0 - OK */ |
/* <0 - error code */ |
/* TRUE when the 8042 keyboard initialization done */ |
static int init8042flag=FALSE; |
/* keyboard task PID */ |
static PID keybpid; |
int KEYB_init(KEYB_PARMS *s) |
{ |
KEYB_PARMS kparms=BASE_KEYB; |
WORD i; |
int status=0; |
SOFT_TASK_MODEL base_m; |
TASK_MODEL *m; |
if (keyb_installed) return 0; |
for (i = 0; i < NUM_OF_KEY; i++) { |
keyTable[i] = 0; |
keyShiftTable[i] = 0; |
} |
/* if a NULL is passed */ |
if (s==NULL) s=&kparms; |
/* keymap */ |
if (s->keybmap==(char*)KEYB_DEFAULT) s->keybmap=engMap; |
keyb_set_map(s->keybmap); |
/* MG: Key_1 port not needed! */ |
//keyHandPort = port_create("Key_1",1,50,RECEIVE,WRITE); |
//keyProcPort = port_connect("Key_1",1,RECEIVE,READ); |
/* MG: changed RECEIVE to STREAM port - added a failure test */ |
pkeyPort = port_create("KeybPort",3,20,STREAM,WRITE); |
if (pkeyPort==-1) return -2; |
ukeyPort = port_connect("KeybPort",3,STREAM,READ); |
if (ukeyPort==-1) { |
port_delete(pkeyPort); |
return -3; |
} |
/* remove all key pressed handlers */ |
lastExc = 0; |
/* and add a ctrl-c handler if requested */ |
if (s->ctrlcfunc == (void*)KEYB_DEFAULT) |
s->ctrlcfunc=(void*)default_ctrlChandler; |
if (s->ctrlcfunc!=NULL) { |
KEY_EVT emerg; |
emerg.ascii = 'c'; |
emerg.scan = KEY_C; |
emerg.flag = CNTL_BIT; |
keyb_hook(emerg,s->ctrlcfunc); |
emerg.flag = CNTR_BIT; |
keyb_hook(emerg,s->ctrlcfunc); |
} |
/* keyb task */ |
if (s->tm == (TASK_MODEL *)KEYB_DEFAULT) { |
soft_task_default_model(base_m); |
soft_task_def_wcet(base_m,2000); |
soft_task_def_met(base_m,800); |
soft_task_def_period(base_m,25000); |
soft_task_def_system(base_m); |
soft_task_def_nokill(base_m); |
soft_task_def_aperiodic(base_m); |
m = (TASK_MODEL *)&base_m; |
} |
else |
m = s->tm; |
//cprintf("keyb task: %li %li %li %li\n", |
// (long)s->pclass,(long)APERIODIC,(long)s->dline,(long)s->wcet); |
keybpid = task_create("KeyTask", keyProc, m, NULL); |
if (keybpid==-1) { |
port_delete(pkeyPort); |
port_delete(ukeyPort); |
return -1; |
} |
/* MG: 8042 keyboard controller initialization */ |
if (!init8042flag) { |
status=C8042_keyboardinit(keybpid); |
if (status) { |
port_delete(pkeyPort); |
port_delete(ukeyPort); |
task_kill(keybpid); |
return -4; |
} |
init8042flag=TRUE; |
} else { |
C8042_keyboardenable(); |
} |
/* MG: and keyboard led management */ |
C8042_keyboardleds(numlock,cps,scrolllock); |
keyb_installed = TRUE; |
return status; |
} |
/* KEYB module cleanup |
* (must be called if it's needed to re-call keyb_init() with other parameters) |
* -1 -> ERROR |
*/ |
int keyb_end(void) |
{ |
if (!keyb_installed) return -1; |
C8042_keyboarddisable(); |
task_kill(keybpid); |
port_delete(pkeyPort); |
port_delete(ukeyPort); |
return 0; |
} |
/* Function that returns the ascii code */ |
int keyb_getch(BYTE wait) |
{ |
KEY_EVT c; |
BYTE fl; |
fl = port_receive(ukeyPort,&c,wait); |
if (fl && !isScanCode(c)) return (c.ascii); |
else return 0; |
} |
/* Function that returns a structure containing the flags status, the ascii |
code, and the scan code */ |
int keyb_getcode(KEY_EVT *k,BYTE wait) |
{ |
return(port_receive(ukeyPort,(BYTE *)(k),wait)); |
} |
void keyb_hook(KEY_EVT k, void (*f)(KEY_EVT *k)) |
{ |
if (lastExc >= MAX_KEY_EXC) return; |
keyExcTable[lastExc].evt = k; |
keyExcTable[lastExc++].func = f; |
return; |
} |
/* MG: this function disable the keyboard */ |
int keyb_disable(void) |
{ |
return C8042_keyboarddisable(); |
} |
/* MG: this function enable the keyboard */ |
int keyb_enable(void) |
{ |
return C8042_keyboardenable(); |
} |
/shark/trunk/drivers/oldchar/keyb.his |
---|
0,0 → 1,18 |
1.2 |
The inp() & outp() have been substituted with VM_in() & VM_out() for |
portability purposes. |
1.3 |
Added the keyb_reset() to avoid the keyboard stuck on exit (perhaps |
due to a missed irq), especially on "fast" machines, where we |
experienced some problems; however we cannot reproduce them |
deterministically, even if they disappeared after the keyb_reset() |
appearence |
1.4 |
Different keyboard layout (keyMap) are now supported. We have |
enlgish & italian keyboard. We added a program which should help |
to build a new keymap! |
CVS 1.3 |
Changed user interface |
/shark/trunk/drivers/oldchar/_rtc.h |
---|
0,0 → 1,172 |
/* |
* 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: _rtc.h,v 1.1 2003-03-24 10:54:16 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:16 $ |
------------ |
Author: Massimiliano Giorgi |
A source from Linux 2.2.9 modified to work with S.Ha.R.K. |
mc146818rtc.h - register definitions for the Real-Time-Clock / CMOS RAM |
Copyright Torsten Duwe <duwe@informatik.uni-erlangen.de> 1993 |
derived from Data Sheet, Copyright Motorola 1984 (!). |
It was written to be part of the Linux operating system. |
**/ |
/* |
* 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 _MC146818RTC_H |
#define _MC146818RTC_H |
#include <drivers/rtc.h> |
#ifndef RTC_PORT |
#define RTC_PORT(x) (0x70 + (x)) |
#define RTC_ALWAYS_BCD 1 |
#endif |
/********************************************************************** |
* register summary |
**********************************************************************/ |
#define RTC_SECONDS 0 |
#define RTC_SECONDS_ALARM 1 |
#define RTC_MINUTES 2 |
#define RTC_MINUTES_ALARM 3 |
#define RTC_HOURS 4 |
#define RTC_HOURS_ALARM 5 |
/* RTC_*_alarm is always true if 2 MSBs are set */ |
# define RTC_ALARM_DONT_CARE 0xC0 |
#define RTC_DAY_OF_WEEK 6 |
#define RTC_DAY_OF_MONTH 7 |
#define RTC_MONTH 8 |
#define RTC_YEAR 9 |
/* control registers - Moto names |
*/ |
#define RTC_REG_A 10 |
#define RTC_REG_B 11 |
#define RTC_REG_C 12 |
#define RTC_REG_D 13 |
/********************************************************************** |
* register details |
**********************************************************************/ |
#define RTC_FREQ_SELECT RTC_REG_A |
/* update-in-progress - set to "1" 244 microsecs before RTC goes off the bus, |
* reset after update (may take 1.984ms @ 32768Hz RefClock) is complete, |
* totalling to a max high interval of 2.228 ms. |
*/ |
# define RTC_UIP 0x80 |
# define RTC_DIV_CTL 0x70 |
/* divider control: refclock values 4.194 / 1.049 MHz / 32.768 kHz */ |
# define RTC_REF_CLCK_4MHZ 0x00 |
# define RTC_REF_CLCK_1MHZ 0x10 |
# define RTC_REF_CLCK_32KHZ 0x20 |
/* 2 values for divider stage reset, others for "testing purposes only" */ |
# define RTC_DIV_RESET1 0x60 |
# define RTC_DIV_RESET2 0x70 |
/* Periodic intr. / Square wave rate select. 0=none, 1=32.8kHz,... 15=2Hz */ |
# define RTC_RATE_SELECT 0x0F |
/**********************************************************************/ |
#define RTC_CONTROL RTC_REG_B |
# define RTC_SET 0x80 /* disable updates for clock setting */ |
# define RTC_PIE 0x40 /* periodic interrupt enable */ |
# define RTC_AIE 0x20 /* alarm interrupt enable */ |
# define RTC_UIE 0x10 /* update-finished interrupt enable */ |
# define RTC_SQWE 0x08 /* enable square-wave output */ |
# define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ |
# define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ |
# define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ |
/**********************************************************************/ |
#define RTC_INTR_FLAGS RTC_REG_C |
/* caution - cleared by read */ |
# define RTC_IRQF 0x80 /* any of the following 3 is active */ |
# define RTC_PF 0x40 |
# define RTC_AF 0x20 |
# define RTC_UF 0x10 |
/**********************************************************************/ |
#define RTC_VALID RTC_REG_D |
# define RTC_VRT 0x80 /* valid RAM and time */ |
/**********************************************************************/ |
/* example: !(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) |
* determines if the following two #defines are needed |
*/ |
#ifndef BCD_TO_BIN |
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) |
#endif |
#ifndef BIN_TO_BCD |
#define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10) |
#endif |
/* |
* ioctl calls that are permitted to the /dev/rtc interface, if |
* CONFIG_RTC was enabled. |
*/ |
#define RTC_AIE_ON _IO('p', 0x01) /* Alarm int. enable on */ |
#define RTC_AIE_OFF _IO('p', 0x02) /* ... off */ |
#define RTC_UIE_ON _IO('p', 0x03) /* Update int. enable on */ |
#define RTC_UIE_OFF _IO('p', 0x04) /* ... off */ |
#define RTC_PIE_ON _IO('p', 0x05) /* Periodic int. enable on */ |
#define RTC_PIE_OFF _IO('p', 0x06) /* ... off */ |
#define RTC_ALM_SET _IOW('p', 0x07, struct rtc_time) /* Set alarm time */ |
#define RTC_ALM_READ _IOR('p', 0x08, struct rtc_time) /* Read alarm time */ |
#define RTC_RD_TIME _IOR('p', 0x09, struct rtc_time) /* Read RTC time */ |
#define RTC_SET_TIME _IOW('p', 0x0a, struct rtc_time) /* Set RTC time */ |
#define RTC_IRQP_READ _IOR('p', 0x0b, unsigned long) /* Read IRQ rate */ |
#define RTC_IRQP_SET _IOW('p', 0x0c, unsigned long) /* Set IRQ rate */ |
#define RTC_EPOCH_READ _IOR('p', 0x0d, unsigned long) /* Read epoch */ |
#define RTC_EPOCH_SET _IOW('p', 0x0e, unsigned long) /* Set epoch */ |
#endif /* _MC146818RTC_H */ |
/shark/trunk/drivers/oldchar/_mouse.h |
---|
0,0 → 1,145 |
/* |
* 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: _mouse.h,v 1.1 2003-03-24 10:54:16 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:16 $ |
------------ |
_mouse.h |
**/ |
/* |
* 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 ___MOUSE_H__ |
#define ___MOUSE_H__ |
#include "ll/sys/cdefs.h" |
__BEGIN_DECLS |
/* "virtual operations" on a mouse */ |
struct mouse_operations { |
char *name; /* name! */ |
char *desc; /* a descriptive line */ |
BYTE proto[4]; |
int packetlen; /* lenght of a packet */ |
int howmany; /* howmany bytes to read at a time (unused) */ |
int getextra; /* there is a extra byte (unused) */ |
int absolute; /* absolute pointing devide (unused) */ |
int dummy; /* (unused) */ |
int (*open)(void*); /* open comunication device */ |
void (*close)(void); /* close comunication device */ |
void (*wait)(void); /* wait to have a BYTE (blocking operation)*/ |
int (*get)(BYTE *ptr); /* get last BYTE */ |
void (*enable)(void); /* enable interface */ |
void (*disable)(void); /* disable interface */ |
/* this function decode the mouse packet into a MOUSE_EVT structure */ |
int (*decode)(MOUSE_EVT *evt,unsigned char *data); |
}; |
/* to virtualize interface beetwen a mouse device and a mouse protocol */ |
extern int mousetype; |
extern struct mouse_operations vmouse[]; |
/* functions and variables (to use virtual operation)*/ |
extern int (*open_mouse)(void*); /* open comunication device */ |
extern void (*close_mouse)(void); /* close comunication device */ |
extern void (*wait_mouse)(void); /* wait to have a BYTE (blocking operation)*/ |
extern int (*get_mouse)(BYTE *data); /* get last BYTE */ |
extern void (*enable_mouse)(void); /* enable interface */ |
extern void (*disable_mouse)(void); /* disable interface */ |
extern char *name_mouse; |
extern char *desc_mouse; |
extern BYTE *proto_mouse; |
extern int packetlen_mouse; |
/* used by mouse protocol task */ |
extern short int mouse_lim_x1; |
extern short int mouse_lim_y1; |
extern short int mouse_lim_x2; |
extern short int mouse_lim_y2; |
extern short int mouse_x; |
extern short int mouse_x_mick; |
extern short int mouse_y; |
extern short int mouse_y_mick; |
extern short int mouse_buttons; |
extern short int mouse_thresholdlim; |
extern MOUSE_HANDLER mouse_handler; |
/* a generic mouse server */ |
extern TASK generalmouse_server(void); |
/* |
* mouse autocursor variables |
*/ |
/* 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 |
/* cursor status and flags */ |
extern int autocursormode; |
/* this functions is used to enable/disable the cursor */ |
/* (it is here to be used by the mcurgrx.c module) */ |
int _mouse_cursor_init(int cmd, |
void(*my_show_cursor)(int,int), |
void(*my_restore_cursor)(int,int) |
); |
/* this is used by mcurgrx.c to know the last mouse position */ |
/* (to not declare saved_x & saved_y public) */ |
void _mouse_getsavedposition(int *xptr, int *yptr); |
__END_DECLS |
#endif |
/shark/trunk/drivers/oldchar/makefile |
---|
0,0 → 1,19 |
# The Char Devices (mouse, serial ports, keyboard) |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
LIBRARY = oldch |
OBJS_PATH = $(BASE)/drivers/oldchar |
OBJS = rtc.o keyb.o scom.o crtwin.o mouse.o sermouse.o ps2mouse.o 8042.o \ |
mcurtxt.o mcurgrx.o |
OTHERINCL += -I$(BASE)/drivers/oldchar/include |
include $(BASE)/config/lib.mk |
/shark/trunk/drivers/oldchar/8042.c |
---|
0,0 → 1,1169 |
/* |
* 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: 8042.c,v 1.1 2003-03-24 10:54:16 pj Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2003-03-24 10:54:16 $ |
------------ |
8042.h |
Interface between high level drivers |
and the 8042 keyboard and PS/2 mouse controller |
Revision: 1.0 |
Last update: 22/Mar/1999 |
Revision 1.0 |
This file contains : |
-- A fast handler that get the scan code from the key interface |
-- A fast handler for the ps2 mouse port |
-- Some functions (exported) to initialize the interface |
-- Some functions (exported) to enable/disable and get data from |
the keyboard or ps/2 mouse |
Created by Massimiliano Giorgi, modified by Paolo Gai to support the |
kernel 4.0.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 |
* |
*/ |
/* if defined: show on first two lines BYTE received from cotroller */ |
//#define __DEBUG_8042__ 1 |
//#define __DEBUG_INIT__ 1 |
/* if defined: show messages during sys_end() */ |
//#define __TRACE_EXIT__ 1 |
/* if defined: trace ps/2 enable/disable */ |
//#define __TRACE_PS2ENDIS__ 1 |
//#include <config.h> |
//#include <string.h> |
//#include <stdlib.h> |
//#include <cons.h> |
//#include "vm.h" |
#include <kernel/kern.h> |
//#include "exc.h" |
//#include "port.h" |
#include "8042.h" |
//#ifdef __SAFEXBIOS__ |
//#include "x86/xsys.h" |
//#endif |
#ifdef __DEBUG_8042__ |
static char debug_buffer[256]; |
static void debug_output(char *s,int v) |
{ |
if (v>=0) cprintf("%s: %d\n",s,v); |
else cprintf("%s: -%d\n",s,-v); |
} |
#endif |
/* there is a ps2mouse in the system? */ |
static BYTE ps2mouse_present=0; |
/* has been activated? */ |
static BYTE ps2mouse_active=0; |
/* |
* Wait (to write) |
* |
* return: |
* 0 -> input buffer empty (OK to write) |
* else -> input buffer full |
*/ |
static int C8042_wait_towrite(void) |
{ |
unsigned long counter; |
BYTE status; |
counter=0; |
while (counter++<0xffffff) { |
status=ll_in(KBD_STATUS_REG); |
/*if ((!(status&KBD_STAT_OBF))&&(!(status&KBD_STAT_IBF))) return 0;*/ |
if(!(status&KBD_STAT_IBF)) return 0; |
} |
return -1; |
} |
/* |
* Wait (to read) |
* |
* return: |
* 0 -> output buffer full (OK to read) |
* else -> output buffer empty |
*/ |
static int C8042_wait_toread(void) |
{ |
unsigned long counter; |
BYTE status; |
counter=0; |
while (counter++<0xffffff) { |
status=ll_in(KBD_STATUS_REG); |
if (status&KBD_STAT_OBF) return 0; |
} |
return -1; |
} |
/* |
* Send data to the keyboard |
* |
* return: |
* 0 -> OK |
* else -> "I can't send!" |
*/ |
static __inline__ int C8042_sendkeybdata(BYTE data) |
{ |
if (!C8042_wait_towrite()) { |
ll_out(KBD_DATA_REG,data); |
return 0; |
} |
return -1; |
} |
/* |
* Send data to the controller |
* |
* return: |
* 0 -> OK |
* else -> "I can't send!" |
*/ |
static __inline__ int C8042_sendctrldata(BYTE data) |
{ |
if (!C8042_wait_towrite()) { |
ll_out(KBD_CNTL_REG,data); |
return 0; |
} |
return -1; |
} |
/* |
* Send data to PS/2 mouse |
* |
* return: |
* 0 -> OK |
* else -> error |
*/ |
static __inline__ int C8042_sendauxdata(BYTE data) |
{ |
if (C8042_sendctrldata(KBD_CCMD_WRITE_MOUSE)) return -1; |
if (C8042_sendkeybdata(data)) return -2; |
return 0; |
} |
/* |
* Read data from the conroller |
* |
* return: |
* else -> BYTE read |
* -1 -> "I can't read!" |
*/ |
static __inline__ int C8042_readdata(void) |
{ |
if (!C8042_wait_toread()) return (int)ll_in(KBD_DATA_REG); |
return -1; |
} |
/* |
* Read aux data from the controller |
* |
* return: |
* else -> BYTE read |
* -1 -> "I can't read!" |
*/ |
static __inline__ int C8042_readauxdata(void) |
{ |
BYTE status; |
if (!C8042_wait_toread()) { |
status=ll_in(KBD_STATUS_REG); |
if (status&KBD_STAT_MOUSE_OBF) return ll_in(KBD_DATA_REG); |
} |
return -1; |
} |
/* |
* Clear output buffer |
* |
*/ |
static void C8042_clearkeyboardbuffer(void) |
{ |
unsigned long counter; |
BYTE status; |
counter=0; |
while (counter++<0xffff) { |
status=ll_in(KBD_STATUS_REG); |
if (!(status&KBD_STAT_OBF)) return; |
ll_in(KBD_DATA_REG); |
} |
} |
/* |
* Send data and receive ACK (with the keyboard) |
* |
* return: |
* 0 -> OK |
* -1 -> can't send command |
* -2 -> can't read reply |
* -3 -> reply unknown |
* -4 -> max retries |
*/ |
static int C8042_keyboardhandshake(BYTE cmd) |
{ |
int maxretries=50; |
int c; |
while (maxretries-->0) { |
if (C8042_sendkeybdata(cmd)) return -1; |
c=C8042_readdata(); |
if (c==-1) return -2; |
if (c==KBD_REPLY_ACK) return 0; |
if (c!=KBD_REPLY_RESEND) return -3; |
} |
return -4; |
} |
/* |
* Send data and receive ACK (with PS/2 mouse) |
*/ |
static int C8042_auxhandshake(BYTE cmd) |
{ |
int c; |
if (C8042_sendauxdata(cmd)) return -1; |
c=C8042_readauxdata(); |
if (c<0) return c; |
if (c!=AUX_ACK) return -2; |
return 0; |
} |
/* |
* Values for controller "command register" |
* |
* CMDREG_NORMAL: |
* normal operation (PS/2 mouse interrupts disabled) |
* |
* CMDREG_PS2: |
* keyboard and PS/2 mouse enabled |
*/ |
#define CMDREG_NORMAL (KBD_MODE_KBD_INT |\ |
KBD_MODE_SYS |\ |
KBD_MODE_DISABLE_MOUSE |\ |
KBD_MODE_KCC \ |
) |
#define CMDREG_PS2 (KBD_MODE_KCC |\ |
KBD_MODE_SYS |\ |
KBD_MODE_MOUSE_INT |\ |
KBD_MODE_KBD_INT \ |
) |
/* |
* Some default values |
*/ |
/* default typematic keyboard rate (maximum - I hope) */ |
/* (I don't know how to coding this information) */ |
#define DEFAULT_KEYBRATE 0x00 |
/* 100 samples/sec */ |
#define DEFAULT_PS2_SAMPLESEC 100 |
/* 8 count per mm */ |
#define DEFAULT_PS2_RES 3 |
/* 2:1 scaling */ |
#define DEFAULT_PS2_SCALE AUX_SET_SCALE21 |
/* |
* |
* Controller initialization |
* |
*/ |
/* |
* Reset keyboard |
* |
* Reset the keyboard and set it to a known state |
* (Must be called after exiting from S.Ha.R.K.) |
* |
* return: |
* 0 -> OK |
* else -> Error |
*/ |
#ifdef __TRACE_EXIT__ |
#define trace(x) ll_printf("%s\n",(x)) |
#else |
#define trace(x) |
#endif |
static int C8042_reset(void) |
{ |
int c=0; |
int retries=16; |
trace("8042 reset START"); |
/* Reset keyboard */ |
/* If there is not retries some machines hang */ |
while (retries-->0) { |
trace("Sending keyboard reset command..."); |
c=C8042_keyboardhandshake(KBD_CMD_RESET); |
if (c) return -3; |
trace("Waiting reply..."); |
c=C8042_readdata(); |
if (c==KBD_REPLY_POR) break; |
trace("Reset fail!!!\n"); |
} |
if (c!=KBD_REPLY_POR) return -4; |
/* Disable keyboard (for the following phase) */ |
trace("Disabling keyboard..."); |
c=C8042_keyboardhandshake(KBD_CMD_DISABLE); |
if (c) return -5; |
/* Initialize controller "command register" */ |
trace("Command register writing..."); |
C8042_sendctrldata(KBD_CCMD_WRITE_MODE); |
trace("Sending command register value..."); |
C8042_sendkeybdata(CMDREG_NORMAL); |
/* Enable keyboard */ |
trace("Enabling keyboard..."); |
c=C8042_keyboardhandshake(KBD_CMD_ENABLE); |
if (c) return -6; |
trace("8042 reset END"); |
return 0; |
} |
/* |
* 8042 restore |
* |
* This function must be called after system sthudown |
* to proper restore keyboard handling by DOS |
*/ |
#ifdef __TRACE_EXIT__ |
#define trace(x) ll_printf("%s\n",(x)) |
#else |
#define trace(x) |
#endif |
void C8042_restore(void) |
{ |
int c; |
SYS_FLAGS f; |
trace("Restore in progress"); |
/* disable interrupts */ |
f=kern_fsave(); |
/* Disable the PS/2 mouse port (if present) */ |
if (ps2mouse_active) { |
trace("Deactivating aux port (ps/2)..."); |
C8042_auxportdisable(); |
} |
/* Reset */ |
trace("Reseting start..."); |
C8042_reset(); |
trace("Resetting end"); |
/* Set keyboard typematic rate */ |
trace("Sending keyboard rate command..."); |
c=C8042_keyboardhandshake(KBD_CMD_SET_RATE); |
if (c) return; |
trace("Sending rate..."); |
c=C8042_keyboardhandshake(DEFAULT_KEYBRATE); |
if (c) return; |
/* restore interrupts status */ |
kern_frestore(f); |
trace("Restore end"); |
} |
/* |
* 8042 initialization |
* |
* test controller,set default values and search a PS/2 mouse |
* |
* return: |
* 0 -> OK |
* <0 -> error (-index into initialize_msg[]) |
* |
* set ps2mouse_present if a mouse is present! |
*/ |
#if defined(__DEBUG_8042__)||defined(__DEBUG_INIT__) |
static char *initialize_msg[]={ |
/* 0 */ |
"ok", |
/* 1..8 */ |
"controller self test failed", |
"keyboard interface self test failed", |
"keyboard reset error", |
"keyboard reset (not POR)", |
"keyboard disable (not ACK)", |
"keyboard enable (not ACK)", |
"keyboard typematic rate code (not ACK)", |
"keyboard typematic rate (not ACK)", |
/* 9.. */ |
"controller self test (can't send command)", |
"controller interface self test (can't send command)", |
"can't enable keyboard", |
"controller aux interface self test (can't send command)", |
"ps/2 mouse interface self test failed", |
/* 14.. */ |
"can't send command GET_MODE", |
"can't read GET_MODE reply", |
"error sending CODE for mouse", |
"error sending data to mouse", |
/* 18 */ |
"can't disable ps/2 mouse", |
"can't enable ps/2 mouse", |
/* 20 */ |
"PS/2 mouse not present" |
}; |
#endif |
static int C8042_initialize(void) |
{ |
int c; |
/* Disable controller and clear keyboard output buffer */ |
C8042_clearkeyboardbuffer(); |
C8042_sendctrldata(KBD_CCMD_KBD_DISABLE); |
C8042_clearkeyboardbuffer(); |
/* Controller self test */ |
c=C8042_sendctrldata(KBD_CCMD_SELF_TEST); |
if (c) return -9; |
c=C8042_readdata(); |
if (c!=KBD_REPLY_CSTOK) return -1; |
/* Controller to keyboard interface test */ |
c=C8042_sendctrldata(KBD_CCMD_KBD_TEST); |
if (c) return -10; |
c=C8042_readdata(); |
if (c!=KBD_REPLY_KISTOK) return -2; |
/* Enable data from/to keyboard */ |
c=C8042_sendctrldata(KBD_CCMD_KBD_ENABLE); |
if (c) return -11; |
/* |
* Reset keyboard |
*/ |
c=C8042_reset(); |
if (c) return c; |
/* Set keyboard typematic rate */ |
c=C8042_keyboardhandshake(KBD_CMD_SET_RATE); |
if (c) return -7; |
c=C8042_keyboardhandshake(DEFAULT_KEYBRATE); |
if (c) return -8; |
/* |
* PS/2 mouse |
*/ |
ps2mouse_present=0; |
/* Test keyboard controller type */ |
/* |
This cause a crash on some systems |
c=C8042_sendctrldata(KBD_CCMD_GET_MODE); |
if (c) return -14; |
c=C8042_readdata(); |
if (c==-1) return -15; |
*/ |
/* if it isn't in PS/2 mode... exit */ |
//if ((c&KBD_CREPLY_GETMODEMASK)!=KBD_CREPLY_PS2MODE) return 0; |
/* Mouse interface test */ |
c=C8042_sendctrldata(KBD_CCMD_TEST_MOUSE); |
if (c) return -12; |
c=C8042_readdata(); |
if (c!=KBD_REPLY_MISTOK) return -13; |
/* Enable mouse interface */ |
c=C8042_sendctrldata(KBD_CCMD_MOUSE_ENABLE); |
if (c) return -11; |
/* Detect if a mouse is connected to PS/2 port */ |
/* Send a dummy value to the mouse and wait a reply */ |
/* (this code is from Linux) */ |
c=C8042_sendctrldata(KBD_CCMD_WRITE_AUX_OBUF); |
if (c) return -16; |
c=C8042_sendkeybdata(0x5a); |
if (c) return -17; |
{ |
int loop=0xffff; |
int v; |
while (loop--) { |
v=ll_in(KBD_STATUS_REG); |
if (v&KBD_STAT_OBF) { |
c=ll_in(KBD_DATA_REG); |
if (v&KBD_STAT_MOUSE_OBF&&c==0x5a) { |
ps2mouse_present=1; /* => mouse present */ |
break; |
} |
} |
} |
} |
/* Disable mouse interface */ |
c=C8042_sendctrldata(KBD_CCMD_MOUSE_DISABLE); |
if (c) return -11; |
/* if there is a PS2 mouse... */ |
if (ps2mouse_present) { |
int v; |
ps2mouse_present=0; |
/* Enable PS/2 mouse port (to initialize) */ |
c=C8042_sendctrldata(KBD_CCMD_MOUSE_ENABLE); |
if (c) return -18; |
/* sample/sec */ |
v=C8042_auxhandshake(AUX_SET_SAMPLE); |
v+=C8042_auxhandshake(DEFAULT_PS2_SAMPLESEC); |
/* resolution */ |
v+=C8042_auxhandshake(AUX_SET_RES); |
v+=C8042_auxhandshake(DEFAULT_PS2_RES); |
/* scaling */ |
v+=C8042_auxhandshake(AUX_SET_SCALE21); |
/* Disable PS/2 mouse port */ |
c=C8042_sendctrldata(KBD_CCMD_MOUSE_DISABLE); |
if (c) return -19; |
if (!v) ps2mouse_present=1; |
} |
return 0; |
} |
#ifdef __SAFEXBIOS__ |
static void C8042_safe_after(void); |
static void C8042_safe_before(void); |
#endif |
/* 8042 initialization */ |
static int C8042_init(void) |
{ |
static int initstatus=-1; |
static int first=1; |
if (!first) return initstatus; |
cli(); |
initstatus=C8042_initialize(); |
first=0; |
sti(); |
#if defined(__DEBUG_8042__)||defined(__DEBUG_INIT__) |
#if defined(__DEBUG_INIT__)&&!defined(__DEBUG_8042__) |
if (initstatus) { |
#endif |
cprintf("8042 init : %d (%s)\n",-initstatus,initialize_msg[-initstatus]); |
cprintf("8042 mouse: %d (%s)\n",ps2mouse_present, |
ps2mouse_present?"PS/2 mouse present":"PS/2 mouse not found" |
); |
#if defined(__DEBUG_INIT)&&!defined(__DEBUG_8042__) |
} |
#endif |
#endif |
if (initstatus) { |
cli(); |
C8042_reset(); |
sti(); |
} |
#ifdef __SAFEXBIOS__ |
if (!initstatus) { |
xbios_regfun(C8042_safe_before,-1); |
xbios_regfun(C8042_safe_after,1); |
} |
#endif |
return initstatus; |
} |
/* |
* |
* Keyboard led manager |
* |
* a 1 swicth led on, a 0 off |
*/ |
/* if are waiting an ack from the keyboard */ |
static int ackStatusLed=0; |
/* last keyboard led values */ |
static unsigned ledsValue=0; |
void C8042_keyboardleds(BYTE numlock, BYTE capslock, BYTE scrolllock) |
{ |
if (capslock) ledsValue = ledsValue | KBD_LED_CAPSLOCK; |
else ledsValue = ledsValue & (KBD_LED_CAPSLOCK ^ KBD_LED_MASK); |
if (numlock) ledsValue = ledsValue | KBD_LED_NUMLOCK; |
else ledsValue = ledsValue & (KBD_LED_NUMLOCK ^ KBD_LED_MASK); |
if (scrolllock) ledsValue = ledsValue | KBD_LED_SCROLLLOCK; |
else ledsValue = ledsValue & (KBD_LED_SCROLLLOCK ^ KBD_LED_MASK); |
/* Disable keyboard */ |
C8042_sendkeybdata(KBD_CMD_DISABLE); |
/* send the command to the keyboard to light led */ |
C8042_sendkeybdata(KBD_CMD_SET_LEDS); |
/* wait for the ack */ |
ackStatusLed++; |
} |
/* |
* |
* ACK managers |
* |
*/ |
/* numebr of ACK that we are waiting for */ |
static volatile int ackPending=0; |
/* |
* this procedure is called when an ACK is received from the |
* keyboard |
* return: |
* 0 : OK (ACK processed) |
* -1 : no ACK waiting (return this ACK code to the caller) |
*/ |
static int C8042_keyboardACK(void) |
{ |
/* if some ACK are waiting... */ |
if (ackPending) { |
ackPending--; |
return 0; |
} |
/* if ACK for Led commands... */ |
if (ackStatusLed == 1){ |
/* send it to keyboard */ |
C8042_sendkeybdata(ledsValue); |
/* wait for the ack */ |
ackStatusLed++; |
return 0; |
} |
else if (ackStatusLed == 2) { |
/* ok we enable keyboard, and begin again */ |
ackStatusLed = 0; |
C8042_sendkeybdata(KBD_CMD_ENABLE); |
return 0; |
} |
/* else .... nothing */ |
return 1; |
} |
/* |
* this when an ACK is received from the PS/2 mouse |
* (return code: see C8042_keyboardACK) |
*/ |
static volatile int auxackPending=0; |
static int C8042_auxACK(void) |
{ |
if (auxackPending) { |
auxackPending--; |
return 0; |
} |
return -1; |
} |
/* |
* |
* Fast Handlers |
* |
*/ |
/* |
* Fast keyboard handler |
*/ |
/* keyboard buffer |
* (without port, semaphores, ...) |
*/ |
/* buffer size */ |
#define KBUFFERSIZE 256 |
/* buffer mask ( i=(i+1)&MASK is better than i=(i+1)%SIZE ) */ |
#define KBUFFERMASK 0xff |
/* circular buffer */ |
static BYTE kbuffer[KBUFFERSIZE]; |
/* buffer pointers */ |
/* data is inserted to khead */ |
/* data is kept from ktail+1 */ |
/* (khead point to ktail+1 when buffer is empty) */ |
static unsigned ktail,khead; |
/* keyboard fast handler */ |
static void keyb_handler(int dummy) |
{ |
BYTE data; |
SYS_FLAGS f; |
/* get data from the controller */ |
data=ll_in(KBD_DATA_REG); |
/* insert into buffer */ |
f=kern_fsave(); |
if (ktail!=khead) { |
kbuffer[khead]=data; |
khead=(khead+1)&KBUFFERMASK; |
} |
kern_frestore(f); |
} |
/* |
* Fast PS/2 mouse handler |
*/ |
/* buffer size */ |
#define ABUFFERSIZE 64 |
/* buffer mask */ |
#define ABUFFERMASK 0x3f |
/* circula buffer */ |
static BYTE abuffer[ABUFFERSIZE]; |
/* buffer pointers */ |
static unsigned atail,ahead; |
/* count bytes into a packet */ |
static int acount; |
/* ps2server is activated when a packet is received */ |
static PID ps2server=NIL; |
/* ps2 fast handler */ |
static void ps2mouse_handler(int dummy) |
{ |
BYTE data; |
SYS_FLAGS f; |
/* get data */ |
data=ll_in(KBD_DATA_REG); |
/* check packet start or ACK */ |
if (acount==0) { |
if (data==AUX_ACK) { |
auxackPending--; |
return; |
} |
if ((data&0xc0)!=0x00) return; |
} |
acount++; |
/* insert data into buffer */ |
f=kern_fsave(); |
if (atail!=ahead) { |
abuffer[ahead]=data; |
ahead=(ahead+1)&ABUFFERMASK; |
} |
else { |
ahead=(ahead-(acount-1)+ABUFFERSIZE)&ABUFFERMASK; |
acount=0; |
} |
kern_frestore(f); |
/* if a packet is received activate the task */ |
if (acount==3) { |
acount=0; |
task_activate(ps2server); |
} |
} |
/* |
* |
* Interface with high level drivers |
* |
*/ |
/* keyboard initialization */ |
int C8042_keyboardinit(PID task) |
{ |
int status; |
/* initialize buffer variables */ |
khead=1; |
ktail=0; |
/* hardware initialization */ |
status=C8042_init(); |
if (status) return status; |
/* set fast handler and task */ |
handler_set(C8042_KEYBOARDIRQ,keyb_handler,task); |
return 0; |
} |
/* PS/2 mouse port initialization */ |
int C8042_auxinit(PID task) |
{ |
int status; |
static int first=TRUE; |
/* initialize buffer variables */ |
if (first) { |
ahead=1; |
atail=0; |
acount=0; |
first=FALSE; |
} |
ps2server=task; |
/* init hardware */ |
status=C8042_init(); |
if (status) return status; |
if (!ps2mouse_present) return -20; |
/* set fast handler and task */ |
handler_set(C8042_PS2IRQ,ps2mouse_handler,NIL); |
/* OK, now ps/2 mouse port is active! */ |
ps2mouse_active=1; |
return 0; |
} |
/* PS/2 release resources */ |
int C8042_auxend(void) |
{ |
if (ps2mouse_active) C8042_auxportdisable(); |
handler_remove(C8042_PS2IRQ); |
/* now ps/2 mouse port is disabled */ |
ps2mouse_active=0; |
return 0; |
} |
/* test if there is a PS/2 mouse */ |
int C8042_ps2mousepresent(void) |
{ |
int status; |
status=C8042_init(); |
if (status) return 0; |
return ps2mouse_present; |
} |
#ifdef __DEBUG_8042__ |
/* debug values for keyboadget() and auxget() */ |
#define YDEB 0 |
#define COLORDEB WHITE |
static int keyx=2; |
static int auxx=2; |
#endif |
/* |
* get data from the keyboard (primary port) |
* |
* it's follow the port_receive() semantic |
*/ |
int C8042_keyboardget(BYTE *data,BYTE access) |
{ |
SYS_FLAGS f; |
f=kern_fsave(); |
//if (khead!=(ktail+1)%KBUFFERMASK) { |
ktail=(ktail+1)&KBUFFERMASK; |
*data=kbuffer[ktail]; |
//} |
kern_frestore(f); |
#ifdef __DEBUG_8042__ |
/* |
* if debug... |
* show all data from the keyboard on YDEB line of the screen |
*/ |
{ |
if (keyx+5>=80) { |
printf_xy(keyx,YDEB,COLORDEB," "); |
keyx=2; |
} |
if (keyx==2) printf_xy(0,YDEB,COLORDEB,"K "); |
if (*data==0) { |
/* why this if? seems to be a bug in ucvt() (the initial test)*/ |
printf_xy(keyx,YDEB,COLORDEB,"00 > "); |
} else { |
printf_xy(keyx,YDEB,COLORDEB,"%-2x > ",(unsigned)*data); |
} |
keyx+=3; |
} |
#endif |
/* check for ACK */ |
if (*data==KBD_REPLY_ACK) |
return C8042_keyboardACK(); |
return 1; |
} |
/* |
* get data from PS/2 mouse port (auxiliary port) |
* |
* it's follows the port_receive() semantic |
*/ |
int C8042_auxget(BYTE *data,BYTE access) |
{ |
SYS_FLAGS f; |
f=kern_fsave(); |
atail=(atail+1)&ABUFFERMASK; |
*data++=abuffer[atail]; |
atail=(atail+1)&ABUFFERMASK; |
*data++=abuffer[atail]; |
atail=(atail+1)&ABUFFERMASK; |
*data++=abuffer[atail]; |
kern_frestore(f); |
#ifdef __DEBUG_8042__ |
/* |
* if debug... |
* show all data from the keyboard on YDEB line of the screen |
*/ |
{ |
int i; |
for (i=-3;i<0;i++) { |
if (auxx+5 >= 80) { |
printf_xy(auxx,YDEB+1,COLORDEB," "); |
auxx=2; |
} |
if (auxx==2) printf_xy(0,YDEB+1,COLORDEB,"M "); |
printf_xy(auxx,YDEB+1,COLORDEB,"%02x > ",(unsigned)*(data+i)); |
auxx+=3; |
} |
} |
#endif |
return 3; |
} |
/* |
* Enable/Disable keyboard |
*/ |
int C8042_keyboarddisable(void) |
{ |
/* Disable keyboard */ |
ackPending++; |
return C8042_sendkeybdata(KBD_CMD_DISABLE); |
} |
int C8042_keyboardenable(void) |
{ |
/* Enable keyboard */ |
ackPending++; |
return C8042_sendkeybdata(KBD_CMD_ENABLE); |
} |
/* |
* Enable/Disable PS/2 mouse |
*/ |
#ifdef __TRACE_PS2ENDIS__ |
#define trace(x) ll_printf("%s\n",(x)) |
#else |
#define trace(x) |
#endif |
int C8042_auxportdisable(void) |
{ |
//int retries; |
SYS_FLAGS f; |
int c=0; |
trace("auxportdisable() START"); |
/* DISABLE ps/2 mouse (not port)*/ |
auxackPending++; |
C8042_sendauxdata(AUX_DISABLE_DEV); |
//retries=1000000; |
//while (auxackPending&&retries) { |
// retries--; |
//} |
/* disable interrupts */ |
trace("disabling interrupts"); |
f=kern_fsave(); |
/* Disable keyboard (for the following phase) */ |
trace("disabling keyboard"); |
c=C8042_keyboardhandshake(KBD_CMD_DISABLE); |
if (c) return -5; |
/* Disable PS/2 mouse port */ |
trace("disabling PS/2 mouse port"); |
c+=C8042_sendctrldata(KBD_CCMD_MOUSE_DISABLE); |
/* Initialize controller "command register" */ |
trace("senfing WRITE_MODE command"); |
C8042_sendctrldata(KBD_CCMD_WRITE_MODE); |
trace("sending normal command mode"); |
C8042_sendkeybdata(CMDREG_NORMAL); |
/* Enable keyboard */ |
trace("enabling keyboard"); |
c+=C8042_keyboardhandshake(KBD_CMD_ENABLE); |
/* restore interrupt mask */ |
trace("enabling interrupts"); |
kern_frestore(f); |
trace("auxportdisable() END"); |
ps2mouse_active=0; |
return c; |
} |
int C8042_auxportenable(void) |
{ |
SYS_FLAGS f; |
int c; |
trace("auxportenabled() START"); |
if (!ps2mouse_present) return -1; |
/* disable interrupts */ |
trace("disabling interrupts"); |
f=kern_fsave(); |
/* Disable keyboard (for the following phase) */ |
trace("disabling keyboard"); |
c=C8042_keyboardhandshake(KBD_CMD_DISABLE); |
if (c) return -5; |
/* Initialize controller "command register" */ |
trace("senfing WRITE_MODE command"); |
C8042_sendctrldata(KBD_CCMD_WRITE_MODE); |
trace("sending ps/2 command mode"); |
C8042_sendkeybdata(CMDREG_PS2); |
/* Enable PS/2 mouse port */ |
trace("enabling ps/2 mouse port"); |
c=C8042_sendctrldata(KBD_CCMD_MOUSE_ENABLE); |
if (c) return -18; |
/* Enable keyboard */ |
trace("enabling keyboard"); |
c=C8042_keyboardhandshake(KBD_CMD_ENABLE); |
if (c) return -37; |
/* restore interrupt mask */ |
trace("enabling interrupts"); |
kern_frestore(f); |
/* Enable ps/2 mouse */ |
/* PS: auxackPending is a share resource and shall be protected */ |
/* by a semaphore */ |
trace("enabling ps/2 mouse"); |
auxackPending++; |
C8042_sendauxdata(AUX_ENABLE_DEV); |
trace("auxportenable() end"); |
ps2mouse_active=1; |
return 0; |
} |
/* |
* Safe procedure |
*/ |
#ifdef __SAFEXBIOS__ |
static int ps2_flag; |
static void C8042_safe_before(void) |
{ |
/* don't work */ |
/* |
if (ps2mouse_active) { |
C8042_auxportdisable(); |
ps2_flag=1; |
} else |
ps2_flag=0 |
C8042_keyboarddisable(); |
*/ |
} |
static void C8042_safe_after(void) |
{ |
/* don't work */ |
/* |
BYTE status; |
SYS_FLAGS f; |
C8042_keyboardenable(); |
if (ps2_flag) C8042_auxportenable(); |
ps2_flag=0; |
*/ |
} |
#endif |