diff --git a/cMIPS/tests/jedidafu.c b/cMIPS/tests/jedidafu.c index 62fac6bf96a85ecc511218d46c55588dd417dd7e..14f95ae404f2cda49509b3cc7178cb6794b48857 100644 --- a/cMIPS/tests/jedidafu.c +++ b/cMIPS/tests/jedidafu.c @@ -128,39 +128,29 @@ int int2hex (char *c, int i) { return j-1; } - - int main(void) { // receive a string through the UART serial interface 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 filonx = 0; - int valfib, qt, rxz, q; - int fim = 0; + int hdona = 0; // head of the big queue + int tlona = 0; // tail of the big queue + int filonx = 0; // store the number of received integers to be processed + int valfib, qt, rxz, q; // auxiliar variables char p[15]; Tcontrol ctrl; uart = (void *)IO_UART_ADDR; // bottom of UART address range - i = -1; - Ud.ntx = 16; + Ud.ntx = 16; // initializing number of empty spaces in tx queue ioctl(ctrl_util(2, 1, 1, 1)); // Speed = 2, intRX = 1, intTX = 1, rts = 1 do { - state++; - // se tirar fode (b520 vira 15) - while(!proberx()) to_stdout('-');//i = 1 - i; - //to_stdout('\0'); - // es - while((c=Getc()) != -1){ + state++; // state is a volatile variable just for optimize blocking + + while(!proberx()) to_stdout('-'); // wait until first reception + + while((c=Getc()) != -1){ // dump the reception queue to the big queue filona[tlona] = c; - // se tirar fode (b520 vira 15) - //to_stdout('*'); -// cmips_delay(1); - //to_stdout('\0'); - // es tlona++; tlona%=145; if(c=='\n'){ @@ -168,11 +158,12 @@ int main(void) { // receive a string through the UART serial interface filona[tlona] = 10; } } + while(filonx > 0){ qt = Strlen(filona+hdona); valfib = hex2int(qt, (filona+hdona)); - if(valfib != -1) - valfib = buf[valfib]; + if(valfib != -1) // if is a valid value (lower than 2c and bigger or equal to 0) + valfib = buf[valfib]; // if not valid, UART receives and prints ffffffff hdona += qt+1; hdona %= 145; qt = int2hex(p, valfib); @@ -180,24 +171,27 @@ int main(void) { // receive a string through the UART serial interface do { j++; while(((rxz = proberx())<10) && !(q=Putc(p[j]))); - while((c=Getc()) != -1){ - filona[tlona] = c; - tlona++; - tlona%=145; - if(c=='\n'){ - filonx++; - filona[tlona] = 10; - } - } - if(!q) - j--; + + while((c=Getc()) != -1){ + filona[tlona] = c; + tlona++; + tlona%=145; + if(c=='\n'){ + filonx++; + filona[tlona] = 10; + } + } + + if(!q) + j--; } while (p[j] != 0); + filonx--; if(!filonx) return state; } - } while (state); + } while (state < 200); return state;