数据流的分析先从串口的中断开始
/*接收一个字节*/
@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();
}
}
}
在串口中断中触发了uart_rx_hook();
void uart_rx_hook(void)
{
uart_file_infor[0].busy_rxing = UART_CHAR_MAX_DELAY;
notify(EV_RXCHAR);
}
在串口中断的钩函数中触发了scan_uart_opt(void *args)
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;
//增加2小时无通讯复位载波芯片功能
clear_rst_time(pframe);
plc_machine_opt(pframe); //protocol handle (buffer[i] is a complete frame data)
}
//看不懂????
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);//这一句的意义在哪里????
}
}
void task_100ms(void *args)
{
notify(EV_STATE);//启动state_machine
uart_tick_hook();
//learning_wave();
emitt_wave();
}
这个函数主要是解决超时的问题
void uart_tick_hook(void)
{
if(uart_file_infor[0].busy_rxing > 0x00)
{
uart_file_infor[0].busy_rxing--;
if(0x00 == uart_file_infor[0].busy_rxing)
{
empty_a_chn_slot(&(uart_file_infor[0].rx_slot));
}
}
}