ARM receives the PC through the serial port to send the data, the data is packaged into the form of the frame, the needle pin tail, I want to realize the function is: arm by verifying the frame head pin tail is correct, decide whether to request the PC to resend the previous frame of data.
We know that the Assembly has the function of a program that has been tuned to a specific location, but not in C, it has a goto, but Goto will be problematic, causing a dead loop and not recommended. Here I realize the above functions in two ways, both of which are verified by the actual, absolutely feasible.
1, in the main program while adding a flag bit, tell arm whether the need to resend data, the code is as follows:
int main () {
............ (Various initialization programs)
BOOL Flag=false; Mechanism for implementing data re- unsigned int ctrlflag[6]; Store data from PC while (1) {uartget (ctrlflag,0); if (Ctrlflag[0]==0xff && ctrlflag[5]==0xee) // Frame Head Frame tail correct { flag=false; ....... (Specific data processing program) }else //Receiving PC data error, request to re-send { flag=true; } if (flag==true) uartsend (retransmit,0);//serial Port re-send }}
2. Use recursive calls in child functions:
/*********uart.cpp************/...................../******* serial protocol receives data ************function:uartprotol*input: Whichuart: Serial number *output: converted 10 binary data *********************************/float *uartprotol (int whichuart) {unsigned int init_hexdata=0;unsigned int *hexdata=&init_hexdata; Store the received 16 binary number (2 bits for a set number) static float tmp_decdata[6]={0,0,0,0,0,0}; You must add static here, cannot return the local variable address float *decdata=tmp_decdata; Uartget (Hexdata,whichuart); if (Hexdata[0]==0xff && hexdata[5]==0xee) //Frame header frame End correct { ... (Specific processing procedures) return Decdata;} else //the command to re-send the data also has { unsigned int retransmit[6]= {0xff,0x22,0xff,0xff,0xff,0xee} in the main function; Data re-send command uartsend (retransmit,0); Return Uartprotol (0); Recursive call}} ....... .......
/*****main.c*****/#include "uart.cpp" int main () {while (1) {//test recursive call implementation data re-send float ch[6]={0,0,0,0,0,0}; Float *chpt=ch;chpt=uartprotol (0); int iii= (int) (*CHPT); Uartsendhex (iii,0);}}
I recommend using the second method because it is simple and easy to use.
Programming of project problem to realize the mechanism of data not being re-sent