diff --git a/cMIPS/include/mainjedi.c b/cMIPS/include/mainjedi.c index 668d307d184dffd0ab1164f5d718f40cc1ddaa01..23e671860358d22e372532af6a092f53b0930e85 100644 --- a/cMIPS/include/mainjedi.c +++ b/cMIPS/include/mainjedi.c @@ -1,5 +1,17 @@ #include "cMIPS.h" +typedef struct UARTdriver { +int rx_hd ; // reception queue head index +int rx_tl ; // reception queue tail index +char rx_q [16]; // reception queue +int tx_hd ; // transmission queue head index +int tx_tl ; // transmission queue tail index +char tx_q [16]; // transmission queue +int nrx ; // number of characters in rx_queue +int ntx ; // number of spaces in tx_queue +} UARTdriver ; +extern UARTdriver Ud ; + typedef struct control { // control register fields (uses only ls byte) int ign : 24, // ignore uppermost bits rts : 1, // Request to Send output (bit 7) diff --git a/cMIPS/tests/handlerUARTjedi.s b/cMIPS/tests/handlerUARTjedi.s index 4336d2190c11a06b547766f70951b987891da5e2..2c9b6890757e4da8c8be6f742828d44534f078d5 100644 --- a/cMIPS/tests/handlerUARTjedi.s +++ b/cMIPS/tests/handlerUARTjedi.s @@ -1,6 +1,11 @@ #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, UARTinterr2 # no, maybe transmission? + beq $a1, $zero, UARTret # no, maybe transmission? nop #handle reception @@ -9,15 +14,53 @@ 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 + # Jedian: when a new char is on the UART's buffer, + # i have to enqueue it and update nrx. + + #ACHO QUE ELE NAO TA RESETANDO O INTERRUPTION REQUEST, AI FICA TRAVADAO + # saving used registers on _uart_buff + sw $5, 9*4($k0) + sw $6, 10*4($k0) + sw $7, 11*4($k0) + + # enqueue + lui $5, %hi(rx_hd) # get rx head address + ori $5, $5, %lo(rx_hd) + + lw $7, 0($5) -UARTinterr2: - andi $a1, $k1, UART_tx_irq # Is this transmission? - beq $a1, $zero, UARTret # no, ignore it and return + #### stores on queue on head + lui $6, %hi(rx_q) # get queue address + ori $6, $6, %lo(rx_q) + + sll $7, $7, 2 # multiply by 4 + addu $6, $7, $6 # calculate address to move new char + lw $7, 2*4($k0) # get char to be stored nop + sw $7, 0($6) # and store it! + + #### process rx_hd -- updates head + lw $7, 0($5) + nop + addiu $7, $7, 1 # increment in 1 the head of the circular queue + andi $7, $7, 0xf # % 16 + sw $7, 0($5) + +#FIZ TUDO ERRADO, ERA NO TAIL QUE EU TINHA QUE MUDAR, EXEMPLO NA APOSTILA PAG 142 + + # loading back used registers + lw $5, 9*4($k0) + lw $6, 10*4($k0) + lw $7, 11*4($k0) + +#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: diff --git a/cMIPS/tests/handlerUARTjedi2.s b/cMIPS/tests/handlerUARTjedi2.s new file mode 100644 index 0000000000000000000000000000000000000000..ec4f00b10019483187cd265c12b3407f8ecdedc3 --- /dev/null +++ b/cMIPS/tests/handlerUARTjedi2.s @@ -0,0 +1,65 @@ +#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) + + # 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 + + # 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: diff --git a/cMIPS/tests/uartrx.c b/cMIPS/tests/uartrx.c index cc00516214d584c310d631ad1099cf933363071d..7ded407888c9192dc40a2a26f7128b8418fb9506 100644 --- a/cMIPS/tests/uartrx.c +++ b/cMIPS/tests/uartrx.c @@ -1,5 +1,18 @@ #include "cMIPS.h" +typedef struct UARTdriver { +int rx_hd ; // reception queue head index +int rx_tl ; // reception queue tail index +char rx_q [16]; // reception queue +int tx_hd ; // transmission queue head index +int tx_tl ; // transmission queue tail index +char tx_q [16]; // transmission queue +int nrx ; // number of characters in rx_queue +int ntx ; // number of spaces in tx_queue +} UARTdriver ; +extern UARTdriver Ud ; + + typedef struct control { // control register fields (uses only ls byte) int ign : 24, // ignore uppermost bits rts : 1, // Request to Send output (bit 7) @@ -67,7 +80,7 @@ int main(void) { // receive a string through the UART serial interface ctrl.rts = 1; // make RTS=1 to activate RemoteUnit ctrl.ign2 = 0; ctrl.intTX = 0; - ctrl.intRX = 0; + ctrl.intRX = 1; ctrl.speed = 1; // operate at the second highest data rate uart->cs.ctl = ctrl; @@ -78,7 +91,7 @@ int main(void) { // receive a string through the UART serial interface if (state == 0) cmips_delay(1); // just do something with state s[i] = (char)uart->d.rx; to_stdout( s[i] ); - + //to_stdout( (Ud.rx_hd+'0') ); } while (s[i] != '\0'); return(state);