Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1035 → Rev 1034

/shark/trunk/drivers/serial/include/drivers/scom.h
90,6 → 90,6
unsigned com_read(unsigned port, unsigned reg);
unsigned com_receive(unsigned port);
void com_write(unsigned port, unsigned reg, unsigned value);
unsigned com_send(unsigned port, BYTE b, unsigned wait);
unsigned com_send(unsigned port, BYTE b);
 
#endif
/shark/trunk/drivers/serial/scom.c
9,7 → 9,6
* 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)
61,62 → 60,45
/* Used for decoding the IIR status */
const int IIRbits[] = {MS_CHANGED,TX_EMPTY,RX_FULL,LS_CHANGED};
 
int serial_initialized[4] = {0, 0, 0, 0};
/* Register level access functions */
 
/**
* Register level access functions.
*/
unsigned com_read(unsigned port, unsigned reg) {
unsigned com_read(unsigned port, unsigned reg)
{
unsigned b;
if (port > 3 || reg > 7 || (!serial_initialized[port])) return(0);
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 || (!serial_initialized[port])) return;
void com_write(unsigned port, unsigned reg, unsigned value)
{
if (port > 3 || reg > 7) return;
ll_out(com_base[port]+reg,value);
}
 
/**
* 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);
}
/* Polled send/receive */
 
unsigned com_send(unsigned port, BYTE b)
{
while ((com_read(port,LSR) & 32) == 0);
com_write(port,THR,b);
return(0);
return 0;
}
 
/**
* Read a character from the port "port".
* Polls the port until a character is ready to be read.
*/
unsigned com_receive(unsigned port) {
unsigned com_receive(unsigned port)
{
while ((com_read(port,LSR) & 1) == 0);
return(com_read(port,RBR));
}
 
/**
* 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) {
/* Initialize a serial channel */
 
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);
135,8 → 117,6
com_write(port,LCR,b_mask);
/* Attiva OUT1 & OUT2 */
com_write(port,MCR,0x0C);
serial_initialized[port] = 1;
 
kern_frestore(f);
 
144,9 → 124,8
 
}
 
/**
* Close port channel & release the server.
*/
/* Close port channel & release the server */
 
int com_close(unsigned port)
{
SYS_FLAGS f;
157,8 → 136,6
com_read(port,IIR);
com_read(port,RBR);
serial_initialized[port] = 0;
kern_frestore(f);
 
return(0);