9,6 → 9,7 |
* Paolo Gai <pj@gandalf.sssup.it> |
* Massimiliano Giorgi <massy@gandalf.sssup.it> |
* Luca Abeni <luca@gandalf.sssup.it> |
* Tullio Facchinetti <tullio.facchinetti@unipv.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
60,45 → 61,62 |
/* Used for decoding the IIR status */ |
const int IIRbits[] = {MS_CHANGED,TX_EMPTY,RX_FULL,LS_CHANGED}; |
|
/* Register level access functions */ |
int serial_initialized[4] = {0, 0, 0, 0}; |
|
unsigned com_read(unsigned port, unsigned reg) |
{ |
/** |
* Register level access functions. |
*/ |
unsigned com_read(unsigned port, unsigned reg) { |
unsigned b; |
if (port > 3 || reg > 7) return(0); |
if (port > 3 || reg > 7 || (!serial_initialized[port])) 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; |
void com_write(unsigned port, unsigned reg, unsigned value) { |
if (port > 3 || reg > 7 || (!serial_initialized[port])) return; |
ll_out(com_base[port]+reg,value); |
} |
|
/* Polled send/receive */ |
|
unsigned com_send(unsigned port, BYTE b) |
{ |
while ((com_read(port,LSR) & 32) == 0); |
/** |
* Write the character "b" to the port "port". |
* If wait is 0 then a busy port makes the fuction to return immediately. |
* If wait is 1 loops until the port become free. |
* Return 0 if the byte has been sent. Return 1 otherwise. |
*/ |
unsigned com_send(unsigned port, BYTE b, unsigned wait) { |
if (wait) { |
while ((com_read(port,LSR) & 32) == 0); |
} else { |
if ((com_read(port,LSR) & 32) == 0) return(1); |
} |
com_write(port,THR,b); |
return 0; |
return(0); |
} |
|
unsigned com_receive(unsigned port) |
{ |
/** |
* Read a character from the port "port". |
* Polls the port until a character is ready to be read. |
*/ |
unsigned com_receive(unsigned port) { |
while ((com_read(port,LSR) & 1) == 0); |
return(com_read(port,RBR)); |
} |
|
/* Initialize a serial channel */ |
|
int com_open(unsigned port,DWORD speed,BYTE parity,BYTE len,BYTE stop) |
{ |
/** |
* Initialize a serial channel. |
* Do not do anything if the port has been already initialized. |
*/ |
int com_open(unsigned port,DWORD speed,BYTE parity,BYTE len,BYTE stop) { |
unsigned long div,b_mask; |
SYS_FLAGS f; |
|
f = kern_fsave(); |
|
if (serial_initialized[port]) { |
kern_frestore(f); |
return(0); |
} |
|
/* Now set up the serial link */ |
b_mask = (parity & 3) * 8 + (stop & 1) * 4 + ((len - 5) & 3); |
117,6 → 135,8 |
com_write(port,LCR,b_mask); |
/* Attiva OUT1 & OUT2 */ |
com_write(port,MCR,0x0C); |
|
serial_initialized[port] = 1; |
|
kern_frestore(f); |
|
124,8 → 144,9 |
|
} |
|
/* Close port channel & release the server */ |
|
/** |
* Close port channel & release the server. |
*/ |
int com_close(unsigned port) |
{ |
SYS_FLAGS f; |
136,6 → 157,8 |
com_read(port,IIR); |
com_read(port,RBR); |
|
serial_initialized[port] = 0; |
|
kern_frestore(f); |
|
return(0); |