⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 probe_com.c

📁 力天电子的ARM72103_ucosII实验
💻 C
📖 第 1 页 / 共 5 页
字号:
                                            CPU_INT16U    tx_buf_size);

#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
static  CPU_INT16U   ProbeCom_CmdSimpleWr  (CPU_INT08U   *prx_buf,
                                            CPU_INT08U   *ptx_buf,
                                            CPU_INT16U    rx_pkt_size,
                                            CPU_INT16U    tx_buf_size);

static  CPU_INT16U   ProbeCom_CmdMultipleWr(CPU_INT08U   *prx_buf,
                                            CPU_INT08U   *ptx_buf,
                                            CPU_INT16U    rx_pkt_size,
                                            CPU_INT16U    tx_buf_size);
#endif

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
static  CPU_INT16U   ProbeCom_CmdStrRd     (CPU_INT08U   *prx_buf,
                                            CPU_INT08U   *ptx_buf,
                                            CPU_INT16U    rx_pkt_size,
                                            CPU_INT16U    tx_buf_size);

static  CPU_INT16U   ProbeCom_CmdStrWr     (CPU_INT08U   *prx_buf,
                                            CPU_INT08U   *ptx_buf,
                                            CPU_INT16U    rx_pkt_size,
                                            CPU_INT16U    tx_buf_size);
#endif


                                                                /* ------------------- RD FROM RX PKT ----------------- */
static  CPU_INT08U   ProbeCom_GetINT8U     (CPU_INT08U  **pbuf);

static  CPU_INT16U   ProbeCom_GetINT16U    (CPU_INT08U  **pbuf);

static  CPU_INT32U   ProbeCom_GetINT32U    (CPU_INT08U  **pbuf);

                                                                /* -------------------- WR TO TX BUF ----------------- */
static  void         ProbeCom_StoINT8U     (CPU_INT08U  **pbuf,
                                            CPU_INT08U    data);

static  void         ProbeCom_StoINT16U    (CPU_INT08U  **pbuf,
                                            CPU_INT16U    data);

#if 0
static  void         ProbeCom_StoINT32U    (CPU_INT08U  **pbuf,
                                            CPU_INT32U    data);
#endif

                                                                /* -------------- DETERMINE PKT MODIFIER -------------- */
#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
static  CPU_BOOLEAN  ProbeCom_StrRdy       (void);
#endif


/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*********************************************************************************************************
*                                           GLOBAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                           ProbeCom_Init()
*
* Description : Initialize the module.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  ProbeCom_Init (void)
{
#if (PROBE_COM_SUPPORT_STR  == DEF_TRUE)
    ProbeCom_StrBufWrIx     = 0;
    ProbeCom_StrBufRdIx     = 0;

    ProbeCom_OS_Init();
#endif

#if (PROBE_COM_STAT_EN      == DEF_ENABLED)
    ProbeCom_RxPktCtr       = 0;
    ProbeCom_TxPktCtr       = 0;
    ProbeCom_TxSymCtr       = 0;
    ProbeCom_TxSymByteCtr   = 0;
    ProbeCom_ErrPktCtr      = 0;

#if (PROBE_COM_SUPPORT_STR  == DEF_TRUE)
    ProbeCom_TxStrCtr       = 0;
#endif

#if (PROBE_COM_SUPPORT_WR   == DEF_TRUE)
    ProbeCom_RxSymCtr       = 0;
    ProbeCom_RxSymByteCtr   = 0;
#endif
#endif

    ProbeCom_EndiannessTest = 0x12345678L;

    ProbeCom_InfoHndlr      = (PROBE_COM_INFO_HDNLR_FNCT)0;
#if (PROBE_COM_SUPPORT_STR  == DEF_TRUE)
    ProbeCom_StrHndlr       = (PROBE_COM_STR_HDNLR_FNCT )0;
#endif
}


/*
*********************************************************************************************************
*                                         ProbeCom_ParseRxPkt()
*
* Description : Parse a packet & formulate a response.
*
* Argument(s) : prx_pkt         Pointer to the receive  packet buffer
*
*               ptx_pkt         Pointer to the transmit packet buffer
*
*               rx_pkt_size     Size of the received packet
*
*               tx_pkt_size     Size of the transmit packet buffer
*
* Return(s)   : The number of bytes in the data segment of the packet to transmit in response.
*
* Caller(s)   : Tasks/receive handlers in communications-specific drivers, e.g., probe_rs232,
*               probe_usb, probe_tcpip, etc.).
*
* Note(s)     : none.
*********************************************************************************************************
*/

CPU_INT16U  ProbeCom_ParseRxPkt (void        *prx_pkt,
                                 void        *ptx_pkt,
                                 CPU_INT16U   rx_pkt_size,
                                 CPU_INT16U   tx_buf_size)
{
    CPU_INT16U   tx_buf_wr;
    CPU_INT16U   format;
    CPU_INT08U  *prx_pkt_08;
    CPU_INT08U  *ptx_pkt_08;


    if (rx_pkt_size < 2) {
        return (0);
    }

    prx_pkt_08  = (CPU_INT08U *)prx_pkt;
    ptx_pkt_08  = (CPU_INT08U *)ptx_pkt;
    format      = (prx_pkt_08[1] << 8) + prx_pkt_08[0];
    prx_pkt_08 += 2;

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    ProbeCom_RxPktCtr++;
    ProbeCom_TxPktCtr++;
#endif

    switch (format) {
        case PROBE_COM_FMT_RX_QUERY:
             tx_buf_wr = ProbeCom_CmdQuery(       prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_INFO:
             tx_buf_wr = ProbeCom_CmdInfo(        prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_SIMPLE_RD:
             tx_buf_wr = ProbeCom_CmdSimpleRd(    prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_MULTIPLE_RD:
             tx_buf_wr = ProbeCom_CmdMultipleRd(  prx_pkt_08, ptx_pkt_08,  rx_pkt_size, tx_buf_size);
             break;

#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
        case PROBE_COM_FMT_RX_SIMPLE_WR:
             tx_buf_wr = ProbeCom_CmdSimpleWr(    prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_MULTIPLE_WR:
             tx_buf_wr = ProbeCom_CmdMultipleWr(  prx_pkt_08, ptx_pkt_08, rx_pkt_size, tx_buf_size);
             break;
#endif

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
        case PROBE_COM_FMT_RX_STR_RD:
             tx_buf_wr = ProbeCom_CmdStrRd(       prx_pkt_08, ptx_pkt_08,  rx_pkt_size, tx_buf_size);
             break;

        case PROBE_COM_FMT_RX_STR_WR:
             tx_buf_wr = ProbeCom_CmdStrWr(       prx_pkt_08, ptx_pkt_08,  rx_pkt_size, tx_buf_size);
             break;
#endif

        default:
             tx_buf_wr = ProbeCom_CmdErr(                     ptx_pkt_08,  PROBE_COM_STATUS_UNKNOWN_REQUEST);
             break;
    }

    return (tx_buf_wr);
}


/*
*********************************************************************************************************
*                                         ProbeCom_InfoHndlrSet()
*
* Description : Set the handler that will be invoked when an info packet is received.
*
* Argument(s) : hndlr           The handler that will be invoked.
*
* Return(s)   : none.
*
* Caller(s)   : Application or communications-specific driver.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  ProbeCom_InfoHndlrSet (PROBE_COM_INFO_HDNLR_FNCT  hndlr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


    CPU_CRITICAL_ENTER();
    ProbeCom_InfoHndlr = hndlr;
    CPU_CRITICAL_EXIT();
}


/*
*********************************************************************************************************
*                                         ProbeCom_StrHndlrSet()
*
* Description : Set the handler that will be invoked when an string write packet is received.
*
* Argument(s) : hndlr           The handler that will be invoked.
*
* Return(s)   : none.
*
* Caller(s)   : Application or communications-specific driver.
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
void  ProbeCom_StrHndlrSet (PROBE_COM_STR_HDNLR_FNCT  hndlr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


    CPU_CRITICAL_ENTER();
    ProbeCom_StrHndlr = hndlr;
    CPU_CRITICAL_EXIT();
}
#endif


/*
*********************************************************************************************************
*                                            ProbeCom_TxStr()
*
* Description : Append a string in the string buffer.
*
* Argument(s) : pstr        Pointer to the string to send.
*
*               dly         Delay time (in milliseconds).  If this value is zero, then
*                           the function will return after queueing in the buffer the portion that fits
*                           immediately.  Otherwise, the function will delay for a certain number of
*                           milliseconds until the entire string has been queued in the buffer.
*
* Return(s)   : DEF_TRUE   if the entire string was queued in the buffer.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -