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

Adicionada funções getc e putc (uart_putc)

parent 956daa5d
Branches
No related tags found
No related merge requests found
#--------------------------------------------------------------------------
# interrupt handler for UART
#.set HW_uart_control,(x_IO_BASE_ADDR + ? * x_IO_ADDR_RANGE)
.comm uart_control 56 #TODO setar endereço no MIPS p/ acessar no C
.global uart_control
.comm uart_control 56 #TODO setar endereço no MIPS p/ acessar no C (?)
# uart_control[0]=rx_queue, [16]=rx_hd, [20]=rx_tl, [24]=nrx,
# [28]=tx_queue, [44]=tx_hd, [48]=tx_tl, [52]=ntx
RX:
andi $a0, $k1, UART_rx_irq # Is this reception?
......
......@@ -55,7 +55,7 @@ int probetx(void); // retorna ntx
int iostat(void); // retorna inteiro com status no byte menos sign
void ioctl(int); // escreve byte menos sign no reg de controle
char getc(void); // retorna caractere na fila, decrementa nrx
//void putc(char); // insere caractere na fila, decrementa ntx
int uart_putc(char); // insere caractere na fila, decrementa ntx
int wrtc(char); // escreve caractere diretamente em txreg
extern UartControl uart_control;
......@@ -75,5 +75,38 @@ int main(void){
ctrl.speed = 1; // operate at 1/2 of the highest data rate
uart->cs.ctl = ctrl;
char c;
while((c=getc())!='\0')
uart_putc(c);
return 0;
}
char getc(){
char c;
if(uart_control.nrx > 0){
c = uart_control.rx_queue[uart_control.rx_hd];
uart_control.rx_hd = (uart_control.rx_hd+1)%16;
disableInterr();
uart_control.nrx--;
enableInterr();
}else{
c = -1;
}
return c;
}
int uart_putc(char c){
int sent;
if(uart_control.ntx > 0){
uart_control.tx_queue[uart_control.tx_tl] = c;
uart_control.tx_tl = (uart_control.tx_tl+1)%16;
disableInterr();
uart_control.ntx--;
enableInterr();
sent = 1;
}else{
sent = 0;
}
return sent;
}
\ 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