Programming of project problem to realize the mechanism of data not being re-sent

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.