From 1dd59a11a3b7d5053bfa87c06f5c282ea2906753 Mon Sep 17 00:00:00 2001 From: VytorCalixto <vytorcalixto@gmail.com> Date: Tue, 9 Jun 2015 14:51:22 -0300 Subject: [PATCH] Transmission and reception working :) --- cMIPS/tests/handlerUART.s | 10 ++++------ cMIPS/tests/uart.c | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cMIPS/tests/handlerUART.s b/cMIPS/tests/handlerUART.s index 806c52f..6b4a998 100644 --- a/cMIPS/tests/handlerUART.s +++ b/cMIPS/tests/handlerUART.s @@ -9,9 +9,6 @@ RX: ori $a0, $a0, %lo(Ud) # $a0 <- Ud lw $a1, 48($a0) # Read nrx - - la $2,x_IO_BASE_ADDR - sw $a1,0($2) # Print for debug addiu $k1, $zero, 16 slt $k1, $a1, $k1 # If nrx >= 16 the queue is full @@ -30,12 +27,13 @@ RX: lui $a1, %hi(HW_uart_addr) ori $a1, $a1, %lo(HW_uart_addr) - lbu $k1, 4($a1) # Read data + lbu $k1, 4($a1) # Read data nop sb $k1, 0($a0) # Put data on RX_queue tail - la $2,x_IO_BASE_ADDR - sw $a0,0($2) # Print for debug + # lui $a0, %hi(x_IO_BASE_ADDR) + # ori $a0, $a0, %lo(x_IO_BASE_ADDR) + # sw $k1, 0($a0) # Print for debug diff --git a/cMIPS/tests/uart.c b/cMIPS/tests/uart.c index 76915cc..111bad6 100644 --- a/cMIPS/tests/uart.c +++ b/cMIPS/tests/uart.c @@ -61,26 +61,26 @@ int Putc(char); // inserts char in queue, decrements ntx void initUd(); extern UARTDriver Ud; +volatile Tserial *uart; int main(){ int i; volatile int state; // tell GCC not to optimize away code - volatile Tserial *uart; volatile Tstatus status; - volatile char c; + volatile char c, last; + uart = (void *)IO_UART_ADDR; // bottom of UART address range Tcontrol ctrl; - uart = (void *)IO_UART_ADDR; // bottom of UART address range ctrl.ign = 0; ctrl.intTX = 0; ctrl.intRX = 1; - ctrl.speed = 1; // operate at 1/2 of the highest data rate + ctrl.speed = 2; // operate at 1/2 of the highest data rate uart->cs.ctl = ctrl; initUd(); - uart->d.tx = 'a'; + //uart->d.tx = 'a'; //print(lol); /*while(c!='\n'){ @@ -90,8 +90,13 @@ int main(){ c=getc(); }*/ - while(1) - c=getc(); + last = '0'; + while((c=getc()) != '\0'){ + if(c != EOF) { + while(!Putc(c)); // Wait till there's space on queue + } + } + Putc(c); // Sends '\0' return 0; } @@ -119,7 +124,7 @@ char getc(){ //print(2); c = EOF; } - // print((int)c); + //print((int)c); // to_stdout(c); // to_stdout('\n'); return c; @@ -127,6 +132,11 @@ char getc(){ int Putc(char c){ int sent; + if(Ud.ntx == 16) { + uart->d.tx = c; + return 1; + } + if(Ud.ntx > 0){ Ud.tx_q[Ud.tx_tl] = c; Ud.tx_tl = (Ud.tx_tl+1)%16; -- GitLab