シリアル受信情報関数


/********************************************************************************************************
* Description: reciever message via uart
*
* Arguments  : ptr ---- a pointer used for data storage
*              nCmd---- the count of command
*
* Returns    : the length of data    
*              
* Notes      : 
********************************************************************************************************/
INT8U uart_recieve_msg(INT8U *ptr)
{
    INT8U wait_times = 0;
    run_on();
    while(g_rxcnt > 0) 
    {
        if(g_rxbuffer[g_rxhead] == CMD_START)
        {
            do{
                if(g_rxcnt > 0)
                {
                    *ptr++ = g_rxbuffer[g_rxhead];
                    g_rxhead = (g_rxhead+1)%UART_BUFFER_SIZE;
                    g_rxcnt--;
                }
                else
                {
                    wait_times++;
                    usleep(1000);
                    if(wait_times >20)
                        return (READ_CMD_TIMEOUT);
                }
            }while(g_rxbuffer[g_rxhead] != CMD_END);
            *ptr++ = g_rxbuffer[g_rxhead];
            run_off();
            return (READ_CMD_OK);
        } 
        else
        {
            g_rxhead = (g_rxhead+1)%UART_BUFFER_SIZE;
            g_rxcnt--;
        }
    }
    return (UART_NO_DATA);
}