From d16c852d117b054b30399706938237e6cf550144 Mon Sep 17 00:00:00 2001
From: Jedian <jmb15@c3sl.ufpr.br>
Date: Mon, 30 May 2016 17:59:06 -0300
Subject: [PATCH] handleruart

Signed-off-by: Jedian <jmb15@c3sl.ufpr.br>
---
 cMIPS/tests/handlerUART.s | 80 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 cMIPS/tests/handlerUART.s

diff --git a/cMIPS/tests/handlerUART.s b/cMIPS/tests/handlerUART.s
new file mode 100644
index 0000000..58e2dff
--- /dev/null
+++ b/cMIPS/tests/handlerUART.s
@@ -0,0 +1,80 @@
+#UARTinterr:
+    # There is space on _uart_buff
+    # _uart_buff[0]=UARTstatus, [1]=UARTcontrol, [2]=data_inp, [3]=new,
+    #           [4]=$ra, [5]=$a0, [6]=$a1, [7]=$a2, [8]=$a3
+    #k0 = _uart_buff
+
+    andi  $a1, $k1, UART_rx_irq # Is this reception?
+    beq   $a1, $zero, UARTret   #   no, maybe transmission?
+    nop
+
+    #handle reception
+    lw    $a1, 4($a0)           # Read data from device
+    nop                         #   and store it to UART's buffer
+    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.
+
+    # saving used registers on _uart_buff
+    sw    $5, 9*4($k0)
+    sw    $6, 10*4($k0)
+    sw    $7, 11*4($k0)
+    
+    # check if queue is full, maybe increment
+    lui   $5, %hi(nrx)
+    ori   $5, $5, %lo(nrx)
+    lw    $7, 0($5)
+    slti  $6, $7, 16
+    beq   $6, $zero, overrun
+    nop
+    addiu $7, $7, 1
+    sw    $7, 0($5)
+
+    # enqueue
+    lui   $5, %hi(rx_tl)        # get rx tail address
+    ori   $5, $5, %lo(rx_tl)    
+
+    lw    $7, 0($5)
+    nop
+    addiu $7, $7, 1             # increment in 1 the tail of the circular queue
+    andi  $7, $7, 0xf           # % 16
+    sw    $7, 0($5)
+
+    #### stores on queue on tail
+    lui   $6, %hi(rx_q)         # get queue address
+    ori   $6, $6, %lo(rx_q)
+
+    addu  $6, $7, $6            # calculate address to move new char
+    lw    $7, 2*4($k0)          # get char to be stored
+    nop
+    sb    $7, 0($6)             # and store it!
+
+    #### process rx_tl -- update tail
+    #lw   $7, 0($5)
+    #nop
+
+overrun:
+
+    # do something if queue is full
+    #... (doing absolutely nothing besides stacking and unstacking regs)
+
+    # loading back used registers
+    lw    $5, 9*4($k0)
+    lw    $6, 10*4($k0)
+    lw    $7, 11*4($k0)
+
+    #Precisa coisar o nrx (incrementar)
+
+#UARTinterr2:
+#    andi  $a1, $k1, UART_tx_irq # Is this transmission?
+#    beq   $a1, $zero, UARTret   # no, ignore it and return
+#    nop
+
+    #handle transmission
+    # ... TODO
+
+    # Lembrar de inicializar os hd e tl com 0 no comeco do main
+
+#UARTret: 
-- 
GitLab