From 968857b39ad99bcd16fe0c8072adcb8c1390d802 Mon Sep 17 00:00:00 2001
From: Roberto Hexsel <roberto@inf.ufpr.br>
Date: Mon, 24 Apr 2017 08:48:50 -0300
Subject: [PATCH] UART now has an independent register for clearing individual
 IRQs -- files missing

---
 cMIPS/tests/uart_defs.c | 20 +++++++++++++-------
 cMIPS/tests/uart_irx.c  |  4 ++--
 cMIPS/tests/uartrx.c    | 17 +++++++++--------
 cMIPS/tests/uarttx.c    |  4 ++--
 4 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/cMIPS/tests/uart_defs.c b/cMIPS/tests/uart_defs.c
index 249cc4c..348451f 100644
--- a/cMIPS/tests/uart_defs.c
+++ b/cMIPS/tests/uart_defs.c
@@ -8,6 +8,15 @@ typedef struct control { // control register fields (uses only ls byte)
     speed   : 3;         // 4,8,16... {tx,rx}clock data rates  (bits 0..2)
 } Tcontrol;
 
+typedef struct interr  { // interrupt clear bits (uses only ls byte)
+  unsigned int ign : 24, // ignore uppermost 3 bytes
+    rts     : 1,         // Request to Send output (bit 7)
+    ign2    : 2,         // bits 6,5 ignored
+    clrTX   : 1,         // interrupt on TX buffer empty (bit 4)
+    clrRX   : 1,         // interrupt on RX buffer full (bit 3)
+    ign3    : 3;         // bits 2..0 ignored
+} Tinterr;
+
 typedef struct status {  // status register fields (uses only ls byte)
   unsigned int ign : 24, // ignore uppermost 3 bytes
     cts     : 1,         // Clear To Send input=1 (bit 7)
@@ -20,19 +29,16 @@ typedef struct status {  // status register fields (uses only ls byte)
     overun  : 1;         // overun error (bit 0)
 } Tstatus;
 
-typedef union ctlStat { // control + status on same address
-  Tcontrol  ctl;        // write-only
-  Tstatus   stat;       // read-only
-} TctlStat;
-
 typedef union data {    // data registers on same address
   int tx;               // write-only
   int rx;               // read-only
 } Tdata;
 
 typedef struct serial {
-  TctlStat cs;          // address is (int *)IO_UART_ADDR
-  Tdata    d;           // address is (int *)(IO_UART_ADDR+1)
+  Tcontrol  ctl;        // read-writ,  address is (int *)IO_UART_ADDR
+  Tstatus   stat;       // read-only,  address is (int *)(IO_UART_ADDR+1)
+  Tinterr   interr;     // write-only, address is (int *)(IO_UART_ADDR+2)
+  Tdata    d;           // read-write, address is (int *)(IO_UART_ADDR+3)
 } Tserial;
 
 
diff --git a/cMIPS/tests/uart_irx.c b/cMIPS/tests/uart_irx.c
index a2b2bc4..b5f473f 100644
--- a/cMIPS/tests/uart_irx.c
+++ b/cMIPS/tests/uart_irx.c
@@ -39,7 +39,7 @@ int main(void) {  // receive a string through the UART serial interface
   ctrl.intTX = 0;
   ctrl.intRX = 0;
   ctrl.speed = SPEED;
-  uart->cs.ctl = ctrl; // initizlize UART
+  uart->ctl = ctrl; // initizlize UART
 
   // handler sets flag=[U_FLAg] to 1 after new character is received;
   // this program resets the flag on fetching a new character from buffer
@@ -50,7 +50,7 @@ int main(void) {  // receive a string through the UART serial interface
   ctrl.intTX = 0;
   ctrl.intRX = 1;  // do generate interrupts on RXbuffer full
   ctrl.speed = SPEED;  // operate at 1/4 of the highest data rate
-  uart->cs.ctl = ctrl;
+  uart->ctl = ctrl;
 
   do {
     while ( (c = (char)bfr[U_FLAG]) == 0 )  // check flag in Ud[]
diff --git a/cMIPS/tests/uartrx.c b/cMIPS/tests/uartrx.c
index a783eff..016e7b6 100644
--- a/cMIPS/tests/uartrx.c
+++ b/cMIPS/tests/uartrx.c
@@ -35,7 +35,7 @@ int main(void) { // receive a string through the UART serial interface
   ctrl.intTX = 0;
   ctrl.intRX = 0;
   ctrl.speed = SPEED;  // operate at the second highest data rate
-  uart->cs.ctl = ctrl;
+  uart->ctl  = ctrl;
 
   i = -1;
 
@@ -45,19 +45,20 @@ int main(void) { // receive a string through the UART serial interface
   ctrl.intTX = 0;
   ctrl.intRX = 0;
   ctrl.speed = SPEED;  // operate at the second highest data rate
-  uart->cs.ctl = ctrl;
+  uart->ctl  = ctrl;
 
   do {
     i = i+1;
 
-    while ( (state = (int)uart->cs.stat.rxFull) == 0 )
-      delay_cycle(1); // just do something
+    while ( (state = (int)uart->stat.rxFull) == 0 )
+      delay_cycle(1);        // just do something
     s[i] = (char)uart->d.rx;
-    if (s[i] != EOT) 
+    if (s[i] != EOT) {
       to_stdout( s[i] );     //   and print new char
-    else
-      to_stdout( '\n' );     //   and print new-line
-
+    } else {
+      to_stdout( '\n' );     //   print new-line
+      to_stdout( EOT );      //   and signal End Of Transmission
+    }
   } while (s[i] != EOT);
 
   return(state);
diff --git a/cMIPS/tests/uarttx.c b/cMIPS/tests/uarttx.c
index f3fa173..cf3fe50 100644
--- a/cMIPS/tests/uarttx.c
+++ b/cMIPS/tests/uarttx.c
@@ -62,13 +62,13 @@ int main(void) { // send a string through the UART serial interface
   ctrl.ign2  = 0;
   ctrl.ign   = 0;
   ctrl.rts   = 0;  // make RTS=0 so RemoteUnit won't transmit, just receive
-  uart->cs.ctl = ctrl;
+  uart->ctl = ctrl;
 
   i = -1;
   do {
 
     i = i+1;
-    while ( (state = (int)uart->cs.stat.txEmpty) == 0 )
+    while ( (state = (int)uart->stat.txEmpty) == 0 )
       delay_cycle(1);      // do something
     uart->d.tx = (int)s[i];
 
-- 
GitLab