Skip to content
Snippets Groups Projects
Select Git revision
  • jedian1806
  • jedian
  • Strozzi
  • master default
4 results

handlerUARTjedi2.s

Blame
  • Forked from Roberto Hexsel / cMIPS
    31 commits behind, 8 commits ahead of the upstream repository.
    handlerUARTjedi2.s 2.21 KiB
    #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: