AbinayaSivam
Member level 1
itoa Function in C : How to read all DestinationBuffer values (int) into String Forma
For hardware implementation, I am writing this function to read the data in Hercules. In Hercules, integer data can be read in string format. So, i have tried itoa conversion in XSDK. I am running counter module for e.g. N times. That N number of data should be converted into String from int and should read in Hercules.
I have tried with below code but single data i am able to read. How to put loop for N times for DestinationBuffer.
Data stored in DestinationBuffer should be converted into string using itoa function.
For hardware implementation, I am writing this function to read the data in Hercules. In Hercules, integer data can be read in string format. So, i have tried itoa conversion in XSDK. I am running counter module for e.g. N times. That N number of data should be converted into String from int and should read in Hercules.
I have tried with below code but single data i am able to read. How to put loop for N times for DestinationBuffer.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 char buf[32] = {0}; extern u32 DestinationBuffer[10]; // Global int transfer_data() { return 0; } char *itoa(int val, int base) { int i = 30; for(; val && i ; --i, val /= base) buf[i] = "0123456789abcdef"[val % base]; return &buf[i+1]; } err_t recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { int i,j,Status; Status=aurora_rx_main(); ///FUNCTION CALL for(i=0;i<10;i++) { xil_printf(" Data:%d,",DestinationBuffer[i]); } int base=10; // here 10 means decimal char *result={0}; result= itoa(DestinationBuffer[0],base); //// How to make it into loop to read all the DestinationBuffer values into String in Hercules. Now, i am able to read only 0th position values if (!p) { tcp_close(tpcb); tcp_recv(tpcb, NULL); return ERR_OK; } /* indicate that the packet has been received */ tcp_recved(tpcb, p->len); if (tcp_sndbuf(tpcb) > 10) { err = tcp_write(tpcb,result,10,1); } else xil_printf("no space in tcp_sndbuf\n\r"); /* free the received pbuf */ pbuf_free(p); return ERR_OK; }
Data stored in DestinationBuffer should be converted into string using itoa function.