Skip to content
Snippets Groups Projects
Commit 05b7ee74 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Implementadas funções proberx e probetx

parent 954c0f55
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,6 @@ typedef struct status { // status register fields (uses only ls byte) ...@@ -23,7 +23,6 @@ typedef struct status { // status register fields (uses only ls byte)
#define RXfull 0x00000020 #define RXfull 0x00000020
#define TXempty 0x00000040 #define TXempty 0x00000040
typedef union ctlStat { // control + status on same address typedef union ctlStat { // control + status on same address
Tcontrol ctl; // write-only Tcontrol ctl; // write-only
Tstatus stat; // read-only Tstatus stat; // read-only
...@@ -40,27 +39,28 @@ typedef struct serial { ...@@ -40,27 +39,28 @@ typedef struct serial {
} Tserial; } Tserial;
typedef struct{ typedef struct{
char rx_queue[16]; // reception queue and pointers char rx_q[16]; // reception queue
int rx_hd; int rx_hd; // reception queue head index
int rx_tl; int rx_tl; // reception queue tail index
char tx_queue[16]; // transmission queue and pointers char tx_q[16]; // transmission queue
int tx_hd; int tx_hd; // transmission queue head index
int tx_tl; int tx_tl; // transmission queue tail index
int nrx; // characters in RX_queue int nrx; // characters in RX_queue
int ntx; // spaces left in TX_queue int ntx; // spaces left in TX_queue
} UartControl; } UARTDriver;
#define EOF -1
int proberx(void); // retorna nrx int proberx(void); // retorna nrx
int probetx(void); // retorna ntx int probetx(void); // retorna ntx
int iostat(void); // retorna inteiro com status no byte menos sign int iostat(void); // retorna inteiro com status no byte menos sign
void ioctl(int); // escreve byte menos sign no reg de controle void ioctl(int); // escreve byte menos sign no reg de controle
char getc(void); // retorna caractere na fila, decrementa nrx char getc(void); // retorna caractere na fila, decrementa nrx
int uart_putc(char); // insere caractere na fila, decrementa ntx int Putc(char); // insere caractere na fila, decrementa ntx
int wrtc(char); // escreve caractere diretamente em txreg
extern UartControl Ud; extern UARTDriver Ud;
int main(void){ int main(){
int i; int i;
volatile int state; // tell GCC not to optimize away code volatile int state; // tell GCC not to optimize away code
volatile Tserial *uart; volatile Tserial *uart;
...@@ -77,7 +77,7 @@ int main(void){ ...@@ -77,7 +77,7 @@ int main(void){
char c; char c;
while((c=getc())!='\0') while((c=getc())!='\0')
uart_putc(c); Putc(c);
return 0; return 0;
} }
...@@ -85,21 +85,21 @@ int main(void){ ...@@ -85,21 +85,21 @@ int main(void){
char getc(){ char getc(){
char c; char c;
if(Ud.nrx > 0){ if(Ud.nrx > 0){
c = Ud.rx_queue[Ud.rx_hd]; c = Ud.rx_q[Ud.rx_hd];
Ud.rx_hd = (Ud.rx_hd+1)%16; Ud.rx_hd = (Ud.rx_hd+1)%16;
disableInterr(); disableInterr();
Ud.nrx--; Ud.nrx--;
enableInterr(); enableInterr();
}else{ }else{
c = -1; c = EOF;
} }
return c; return c;
} }
int uart_putc(char c){ int Putc(char c){
int sent; int sent;
if(Ud.ntx > 0){ if(Ud.ntx > 0){
Ud.tx_queue[Ud.tx_tl] = c; Ud.tx_q[Ud.tx_tl] = c;
Ud.tx_tl = (Ud.tx_tl+1)%16; Ud.tx_tl = (Ud.tx_tl+1)%16;
disableInterr(); disableInterr();
Ud.ntx--; Ud.ntx--;
...@@ -110,3 +110,11 @@ int uart_putc(char c){ ...@@ -110,3 +110,11 @@ int uart_putc(char c){
} }
return sent; return sent;
} }
int proberx(){
return Ud.nrx;
}
int probetx(){
return Ud.ntx;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment