diff --git a/cMIPS/serial.inp b/cMIPS/serial.inp index f98e928dd92f29a59385f0c3de6f5b395f9dd2e8..0e2ca38004ed124ca7986133ed710d26054f79c8 100644 --- a/cMIPS/serial.inp +++ b/cMIPS/serial.inp @@ -1,8 +1,11 @@ -0 +00000001 +00000002 +fffff 1 2 3 +ffffff 4 5 6 diff --git a/cMIPS/tests/jedidafu.c b/cMIPS/tests/jedidafu.c index eaa8b3bff79918ca29432468519b20a16cdbe108..62fac6bf96a85ecc511218d46c55588dd417dd7e 100644 --- a/cMIPS/tests/jedidafu.c +++ b/cMIPS/tests/jedidafu.c @@ -101,6 +101,8 @@ int hex2int (int tam, char *hex) { if(hex[i] < 0) hex[i]=0; ans += hex[i] * pow16(tam-(i+1)); + if(ans > 46) + return -1; } return ans; } @@ -129,12 +131,12 @@ int int2hex (char *c, int i) { int main(void) { // receive a string through the UART serial interface - int i, j; - volatile int state; + int i, j; // and responds with the i-eth hex-based fibonacci sequence number + volatile int state = 0; volatile Tstatus status; char filona[145], c; - int hdona=0; - int tlona=0; + int hdona = 0; + int tlona = 0; int filonx = 0; int valfib, qt, rxz, q; int fim = 0; @@ -143,11 +145,11 @@ int main(void) { // receive a string through the UART serial interface uart = (void *)IO_UART_ADDR; // bottom of UART address range i = -1; - ioctl(ctrl_util(2, 1, 1, 1)); Ud.ntx = 16; + ioctl(ctrl_util(2, 1, 1, 1)); // Speed = 2, intRX = 1, intTX = 1, rts = 1 do { - state = i = i+1; + state++; // se tirar fode (b520 vira 15) while(!proberx()) to_stdout('-');//i = 1 - i; //to_stdout('\0'); @@ -155,7 +157,8 @@ int main(void) { // receive a string through the UART serial interface while((c=Getc()) != -1){ filona[tlona] = c; // se tirar fode (b520 vira 15) - to_stdout('*'); + //to_stdout('*'); +// cmips_delay(1); //to_stdout('\0'); // es tlona++; @@ -168,7 +171,8 @@ int main(void) { // receive a string through the UART serial interface while(filonx > 0){ qt = Strlen(filona+hdona); valfib = hex2int(qt, (filona+hdona)); - valfib = buf[valfib]; + if(valfib != -1) + valfib = buf[valfib]; hdona += qt+1; hdona %= 145; qt = int2hex(p, valfib); @@ -190,13 +194,11 @@ int main(void) { // receive a string through the UART serial interface } while (p[j] != 0); filonx--; + if(!filonx) + return state; } - if(filonx == 0 && !fim) - fim = 1; - else if (filonx == 0 && fim) - return state+i; - } while (i<20); + } while (state); - return(state+i); + return state; }