Analysis of serial port data stream

Source: Internet
Author: User

Data flow analysis begins with the interruption of the serial port

/* Receive one BYTE */@far @interrupt void uart2rx_interrupt (void)
{
U8 byte;


if (UART2->SR & Uart2_flag_rxne)
{
byte = uart2->sr;
byte = Uart2_receivedata8 ();
if (Uart_chn_rx_byte (byte))
{
Uart_rx_hook ();
}
}

}

The Uart_rx_hook () was triggered in the serial interrupt;

void Uart_rx_hook (void)
{
uart_file_infor[0].busy_rxing = Uart_char_max_delay;
Notify (Ev_rxchar);
}

Scan_uart_opt (void *args) triggered in the hook function of the serial interrupt

void scan_uart_opt (void *args)
{
struct Shs_frame *pframe;
Uint8 Idx,len;

IDX = Sys_uart_peek_data (g_frame_buffer, sizeof (G_frame_buffer));


Pframe = Get_smart_frame (G_FRAME_BUFFER,IDX);


if (NULL = = pframe) return;


IDX = (uint8 *) Pframe-g_frame_buffer;
Len = pframe->length+shs_frame_head+1;
Clear_uart (idx + len);
Memmove_my (&g_frame_buffer[0], &g_frame_buffer[idx], Len);
Pframe = (struct shs_frame *) G_frame_buffer;
Added 2-hour non-communication reset carrier chip function
Clear_rst_time (pframe);


Plc_machine_opt (pframe); Protocol handle (Buffer[i] is a complete frame data)
}


Don't understand ....
void plc_machine_opt (void *args)
{
struct Plc_state *pstate = plc_state.pstate;
Uint8 Init;


init = Plc_state.init;
if (init) plc_state.wait_t=0;
Plc_state.init = 0;
if (NULL! = pstate)
{
Pstate->action (init, args);//Where is the meaning of this sentence ....
}
}


void task_100ms (void *args)
{
    notify (ev_state);//start state_machine
    Uart_tick_ Hook ();
   //learning_wave ();  
    Emitt_wave ();
} The function of

is primarily to solve the problem of timeouts
void Uart_tick_hook (void)
{   
    if (uart_file_infor[0].busy_ Rxing  > 0x00)
    {
        uart_file_infor[0].busy_rxing--;
  &NB Sp     if (0x00 = = uart_file_infor[0].busy_rxing)
        {
            Empty_a_chn_slot (& (Uart_file_infor[0].rx_slot));
       }
   }
}

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.