From dd35e7cb55ddfcb1318c1d7bc2650ba5df93188d Mon Sep 17 00:00:00 2001
From: Jedian Marcos Brambilla <jmb15@inf.ufpr.br>
Date: Sat, 18 Jun 2016 15:30:15 -0300
Subject: [PATCH] proberx correto, falta fazer funcionar de verdade so

Signed-off-by: Jedian Marcos Brambilla <jmb15@inf.ufpr.br>
---
 cMIPS/tests/handlerUART.s |  2 --
 cMIPS/tests/jedidafu.c    | 22 +++++++++++++++-------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/cMIPS/tests/handlerUART.s b/cMIPS/tests/handlerUART.s
index 627910a..e1333fb 100644
--- a/cMIPS/tests/handlerUART.s
+++ b/cMIPS/tests/handlerUART.s
@@ -67,8 +67,6 @@ UARTrxinter:
     sw    $a1, 2*4($k0)         #   and return from interrupt
     addiu $a1, $zero, 1
     sw    $a1, 3*4($k0)         # Signal new arrival
-                                # Jedian: when a new char is on the UART's buffer, 
-                                #         i have to enqueue it and update nrx.
     
     # check if queue is full, maybe increment
     lui   $5, %hi(nrx)
diff --git a/cMIPS/tests/jedidafu.c b/cMIPS/tests/jedidafu.c
index 5aaa726..3800fc1 100644
--- a/cMIPS/tests/jedidafu.c
+++ b/cMIPS/tests/jedidafu.c
@@ -10,6 +10,8 @@ extern Tproberx proberxs ;
 volatile Tserial *uart;  // tell GCC not to optimize away code
 
 int proberx () {
+    if(proberxs.overun)
+        return -1;
     return Ud.nrx;
 }
 
@@ -144,15 +146,15 @@ int main(void) { // receive a string through the UART serial interface
     uart = (void *)IO_UART_ADDR; // bottom of UART address range
 
     Ud.ntx = 16; // initializing number of empty spaces in tx queue
-    ioctl(ctrl_util(1, 1, 1, 1)); // Speed = 2, intRX = 1, intTX = 1, rts = 1
+    ioctl(ctrl_util(2, 1, 1, 1)); // Speed = 2, intRX = 1, intTX = 1, rts = 1
 
     do {
         state++; // state is a volatile variable just for optimize blocking
         while(!proberx()) to_stdout('-'); // wait until first reception
-        if(proberxs.overun){
-            to_stdout('e');
-            to_stdout('r');
-            to_stdout('r');
+        if(proberx() == -1){
+            to_stdout('E');
+            to_stdout('R');
+            to_stdout('R');
             to_stdout('\0');
             return state;
         }
@@ -177,8 +179,14 @@ int main(void) { // receive a string through the UART serial interface
             j = -1;
             do {
                 j++;
-                while(((rxz = proberx())<10) && !(q=Putc(p[j])));
-
+                while(((rxz = proberx())<10 && (rxz >= 0)) && !(q=Putc(p[j])));
+                if(rxz == -1){
+                    to_stdout('E');
+                    to_stdout('R');
+                    to_stdout('R');
+                    to_stdout('\0');
+                    return state;
+                }
                 while((c=Getc()) != -1){
                     filona[tlona] = c;
                     tlona++;
-- 
GitLab