From c7314962360b365490cc1f3f168dd9117e0af879 Mon Sep 17 00:00:00 2001 From: Jedian Marcos Brambilla <jmb15@inf.ufpr.br> Date: Sun, 19 Jun 2016 16:23:52 -0300 Subject: [PATCH] Estavel, vou tentar modificar o proberxs Signed-off-by: Jedian Marcos Brambilla <jmb15@inf.ufpr.br> --- cMIPS/serial.inp | 36 +++++-------------- cMIPS/tests/handlerUART.s | 55 +++++++++++++++-------------- cMIPS/tests/jedidafu.c | 74 ++++++++++++++++++++++----------------- 3 files changed, 77 insertions(+), 88 deletions(-) diff --git a/cMIPS/serial.inp b/cMIPS/serial.inp index 0e2ca38..a7ce1d8 100644 --- a/cMIPS/serial.inp +++ b/cMIPS/serial.inp @@ -1,33 +1,13 @@ -00000001 -00000002 -fffff 1 -2 -3 -ffffff -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 +0005 +0000ffff +00000013 +00000014 +00000015 +00000017 +00000018 +00000019 1a 1b 1c diff --git a/cMIPS/tests/handlerUART.s b/cMIPS/tests/handlerUART.s index e1333fb..7c35360 100644 --- a/cMIPS/tests/handlerUART.s +++ b/cMIPS/tests/handlerUART.s @@ -67,56 +67,57 @@ UARTrxinter: sw $a1, 2*4($k0) # and return from interrupt addiu $a1, $zero, 1 sw $a1, 3*4($k0) # Signal new arrival + # i have to enqueue it and update nrx. # check if queue is full, maybe increment - lui $5, %hi(nrx) - ori $5, $5, %lo(nrx) - lw $7, 0($5) + lui $a1, %hi(nrx) + ori $a1, $a1, %lo(nrx) + lw $a3, 0($a1) nop - slti $6, $7, 16 - beq $6, $zero, overrun + slti $a2, $a3, 16 + beq $a2, $zero, overrun nop - addiu $7, $7, 1 - sw $7, 0($5) + addiu $a3, $a3, 1 + sw $a3, 0($a1) # enqueue - lui $5, %hi(rx_tl) # get rx tail address - ori $5, $5, %lo(rx_tl) + lui $a1, %hi(rx_tl) # get rx tail address + ori $a1, $a1, %lo(rx_tl) - lw $7, 0($5) + lw $a3, 0($a1) nop - addiu $7, $7, 1 # increment in 1 the tail of the circular queue - andi $7, $7, 0xf # % 16 - sw $7, 0($5) + addiu $a3, $a3, 1 # increment in 1 the tail of the circular queue + andi $a3, $a3, 0xf # % 16 + sw $a3, 0($a1) #### stores on queue on tail - lui $6, %hi(rx_q) # get queue address - ori $6, $6, %lo(rx_q) + lui $a2, %hi(rx_q) # get queue address + ori $a2, $a2, %lo(rx_q) - addu $6, $7, $6 # calculate address to move new char - lw $7, 2*4($k0) # get char to be stored + addu $a2, $a3, $a2 # calculate address to move new char + lw $a3, 2*4($k0) # get char to be stored nop - sb $7, 0($6) # and store it! + sb $a3, 0($a2) # and store it! #jal to_stdout -#move $a0, $7 +#move $a0, $a3 b endUH nop overrun: - lui $5, %hi(proberxs) - ori $5, $5, %lo(proberxs) - lw $7, 0($5) + lui $a1, %hi(proberxs) + ori $a1, $a1, %lo(proberxs) + lw $a3, 0($a1) nop - la $6, 0x40000000 - or $6, $6, $7 - sw $6, 0($5) + la $a2, 0x40000000 + or $a2, $a2, $a3 + sw $a2, 0($a1) nop #jal print - #move $a0, $6 - # move $a0, $7 + #move $a0, $a2 + # move $a0, $a3 # do something if rx queue is full or tx is empty # set overrun bit on uart statusReg #... (doing absolutely nothing besides stacking and unstacking regs) diff --git a/cMIPS/tests/jedidafu.c b/cMIPS/tests/jedidafu.c index 3800fc1..f35ebbc 100644 --- a/cMIPS/tests/jedidafu.c +++ b/cMIPS/tests/jedidafu.c @@ -2,8 +2,6 @@ #include "../include/vetorFib.h" #include "../include/structUart.h" -#define MAXPOW 7 - extern UARTdriver Ud ; extern Tproberx proberxs ; @@ -82,29 +80,24 @@ char Getc () { int Strlen (char *c) { int i= 0; - while(c[i++]-10); + while(c[i++]!=10); return i-1; } -int pow16 (int ex) { - int i, ret=1; - for (i= 0; i< ex/2; i++) - ret*=16; - ret *= ret; - return (ex%2?ret*16:ret); -} - int hex2int (int tam, char *hex) { - int i, ans= 0; - for (i = 0; i < tam; i++) { - hex[i]-= 48; - if (hex[i] > 9) - hex[i] -= 7; - if (hex[i] > 15) - hex[i] -= 32; - if(hex[i] < 0) + int i, ans= 0, exp=1, acc = 0; + for (i = 1; i < tam; i++) + exp*=16; + for (i = 0; hex[i] > 10; i++) { + acc = 48; + if (hex[i] > 9+acc) + acc += 7; + if (hex[i] > 15+acc) + acc += 32; + if(hex[i] < 0+acc) hex[i]=0; - ans += hex[i] * pow16(tam-(i+1)); + ans += (hex[i]-acc) * exp; + exp/=16; if(ans > 46) return -1; } @@ -112,9 +105,15 @@ int hex2int (int tam, char *hex) { } int int2hex (char *c, int i) { - int j= 0, val; - int p; - p = pow16(MAXPOW); + int j = 0, val; + int p = 268435456; //16^7 + if(i < 0){ + c[0] = 'I'; + c[1] = 'N'; + c[2] = 'V'; + c[3] = '\0'; + return 3; + } while (p > 0) { val= 0; if (i/p) { @@ -149,12 +148,16 @@ int main(void) { // receive a string through the UART serial interface ioctl(ctrl_util(2, 1, 1, 1)); // Speed = 2, intRX = 1, intTX = 1, rts = 1 do { + while(!proberx() && !filonx) cmips_delay(1); // wait until first reception + state++; // state is a volatile variable just for optimize blocking - while(!proberx()) to_stdout('-'); // wait until first reception - if(proberx() == -1){ + if(proberx() == -1){ //overrun checking + to_stdout('O'); + to_stdout('V'); to_stdout('E'); to_stdout('R'); - to_stdout('R'); + to_stdout('U'); + to_stdout('N'); to_stdout('\0'); return state; } @@ -179,14 +182,19 @@ int main(void) { // receive a string through the UART serial interface j = -1; do { j++; - while(((rxz = proberx())<10 && (rxz >= 0)) && !(q=Putc(p[j]))); - if(rxz == -1){ + while((rxz = proberx())<9 && (rxz >= 0) && !(q=Putc(p[j]))) cmips_delay(1); + + if(rxz == -1){ // overrun checking + to_stdout('O'); + to_stdout('V'); to_stdout('E'); to_stdout('R'); - to_stdout('R'); + to_stdout('U'); + to_stdout('N'); to_stdout('\0'); return state; } + while((c=Getc()) != -1){ filona[tlona] = c; tlona++; @@ -201,13 +209,13 @@ int main(void) { // receive a string through the UART serial interface j--; } while (p[j] != 0); - filonx--; - if(!filonx) + + if(!filonx){ return state; + } } - } while (state < 200); - + } while (1); return state; } -- GitLab