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

📄 probe_com.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 5 页
字号:
*********************************************************************************************************
*                                       ProbeCom_PktModifier()
*
* Description : Get packet modfier byte.
*
* Argument(s) : none.
*
* Return(s)   : The modifier byte.
*
* Caller(s)   : Various command handlers (ProbeCom_Req????()).
*
* Note(s)     : none.
*********************************************************************************************************
*/

static  CPU_INT08U  ProbeCom_PktModifier (void)
{
#if ((PROBE_COM_CFG_STR_REQ_EN      == DEF_ENABLED) || \
     (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED))
    CPU_BOOLEAN  avail;
#endif
#if  (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
    CPU_BOOLEAN  done;
#endif
    CPU_INT08U   mod;


    mod = PROBE_COM_MODIFIER_NONE;

#if (PROBE_COM_CFG_STR_REQ_EN == DEF_ENABLED)
    avail = ProbeCom_StrOutAvail();
    if (avail == DEF_TRUE) {
        DEF_BIT_SET(mod, PROBE_COM_MODIFIER_STR_OUT_AVAIL);
    }
#endif

#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
    avail = ProbeCom_TerminalOutAvail();
    if (avail == DEF_TRUE) {
        DEF_BIT_SET(mod, PROBE_COM_MODIFIER_TERMINAL_OUT_AVAIL);
    }

    done = ProbeCom_TerminalExecDone();
    if (done == DEF_TRUE) {
        DEF_BIT_SET(mod, PROBE_COM_MODIFIER_TERMINAL_EXEC_DONE);
    }
#endif

    return (mod);
}


/*
*********************************************************************************************************
*                                          ProbeCom_ReqErr()
*
* Description : Formulate error response when the target receives a request it cannot handle.
*
* Argument(s) : ptx_buf      Pointer to the transmit buffer
*
*               comm_err     Error that occurred
*
* Return(s)   : The number of bytes written to the tx buffer.
*
* Caller(s)   : Various command handlers (ProbeCom_Req????()).
*
* Note(s)     : (1) The TX format:
*
*                   (A) A 2-byte format  , indicating the data segment format;
*                   (B) A 1-byte constant, PROBE_RS232_OK,   if the location can    be read;
*                       A 1-byte constant, PROBE_RS232_FAIL, if the location cannot be read.
*                   (C) A 1-byte modifier.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*********************************************************************************************************
*/

static  CPU_SIZE_T  ProbeCom_ReqErr (CPU_INT08U  *ptx_buf,
                                     CPU_INT08U   comm_err)
{
    CPU_SIZE_T  tx_len;


#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
    ProbeCom_ErrPktCtr++;
#endif

    ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_TX_ERR);         /* Tx pkt fmt.                                          */
    ProbeCom_StoINT08U(&ptx_buf, comm_err);                     /* Target status.                                       */
    ProbeCom_StoINT08U(&ptx_buf, ProbeCom_PktModifier());       /* Modifier.                                            */

    tx_len = (CPU_SIZE_T)PROBE_COM_SIZE_TX_HDR;
    return (tx_len);                                            /* Rtn TX data segment size =  4 (= Tx hdr size).       */
}


/*
*********************************************************************************************************
*                                         ProbeCom_ReqQuery()
*
* Description : Parse the FMT_QUERY command & formulate response.  This command asks the target
*               about its capabilities, which are returned in response.
*
* Argument(s) : prx_buf         Pointer to the receive  buffer
*
*               ptx_buf         Pointer to the transmit buffer
*
*               rx_pkt_size     Size of the receive  packet
*
*               tx_buf_size     Size of the transmit buffer
*
* Return(s)   : The number of bytes written to the tx buffer.
*
* Caller(s)   : ProbeCom_ParseRxPkt().
*
* Note(s)     : (1) The RX format:
*
*                   (A) A 2-byte format, indicating the data segment format;
*                   (B) A 2-byte query , indicating the query type.
*
*                         +-------------------------+-------------------------+
*                         |          Format         |          Query          |
*                         +-------------------------+-------------------------+
*
*              (2) The TX format:
*
*                   (A) A 2-byte format, indicating the data segment format;
*                   (B) A 1-byte status, indicating the status after the request;
*                   (C) A 1-byte modifier;
*                   (E) A n-byte answer, the answer to the query.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*                         |                       Answer                      |
*                         |                         .                         |
*                         |                         .                         |
*                         |                         .                         |
*                         +---------------------------------------------------+
*
*********************************************************************************************************
*/

static  CPU_SIZE_T  ProbeCom_ReqQuery (CPU_INT08U  *prx_buf,
                                       CPU_INT08U  *ptx_buf,
                                       CPU_SIZE_T   rx_pkt_size,
                                       CPU_SIZE_T   tx_buf_size)
{
    CPU_INT16U  query;
    CPU_INT32U  status;
    CPU_SIZE_T  tx_len;
    CPU_INT32U  version;


    query  = 0;
    tx_len = 0;

                                                                /* ------------------- CHK PKT SIZE ------------------- */
                                                                /* Expected size =  2 (= Rx hdr size)                   */
                                                                /*               +  2 (= Query      ).                  */
    if (rx_pkt_size != 4) {
        tx_len = ProbeCom_ReqErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE);
        return (tx_len);
    }

                                                                /* ------------------- HANDLE QUERY ------------------- */
    query = ProbeCom_GetINT16U(&prx_buf);                       /* Rd the query.                                        */

    switch (query) {                                            /* Determine if query is supported.                     */
        case PROBE_COM_QUERY_MAX_RX_SIZE:
        case PROBE_COM_QUERY_MAX_TX_SIZE:
        case PROBE_COM_QUERY_FMT_SUPPORT:
        case PROBE_COM_QUERY_ENDIANNESS_TEST:
        case PROBE_COM_QUERY_STATUS:
        case PROBE_COM_QUERY_VERSION:
             break;

        default:
             tx_len = ProbeCom_ReqErr(ptx_buf, PROBE_COM_STATUS_QUERY_NOT_SUPPORTED);
             return (tx_len);
    }

                                                                /* Sto tx pkt hdr :                                     */
    ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_TX_QUERY);       /*  (a) TX pkt fmt.                                     */
    ProbeCom_StoINT08U(&ptx_buf, PROBE_COM_STATUS_OK);          /*  (b) Target status.                                  */
    ProbeCom_StoINT08U(&ptx_buf, ProbeCom_PktModifier());       /*  (c) Modifier.                                       */

                                                                /* Sto tx data segment data.                            */
    switch (query) {
        case PROBE_COM_QUERY_MAX_RX_SIZE:
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_CFG_RX_MAX_SIZE);
             ProbeCom_StoINT16U(&ptx_buf, 0);
             tx_len  = 4;
             break;


        case PROBE_COM_QUERY_MAX_TX_SIZE:
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_CFG_TX_MAX_SIZE);
             ProbeCom_StoINT16U(&ptx_buf, 0);
             tx_len  = 4;
             break;


        case PROBE_COM_QUERY_FMT_SUPPORT:
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_QUERY);
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_RD);
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_RD_MULTI);
             tx_len  = 8;
#if (PROBE_COM_CFG_WR_REQ_EN == DEF_ENABLED)
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_WR);
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_WR_MULTI);
             tx_len += 4;
#endif
#if (PROBE_COM_CFG_STR_REQ_EN == DEF_ENABLED)
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_STR_IN);
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_STR_OUT);
             tx_len += 4;
#endif
#if (PROBE_COM_CFG_TERMINAL_REQ_EN == DEF_ENABLED)
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_TERMINAL_EXEC);
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_TERMINAL_IN);
             ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_RX_TERMINAL_OUT);
             tx_len += 6;
#endif
             break;


        case PROBE_COM_QUERY_ENDIANNESS_TEST:
             ProbeCom_EndiannessTest = 0x12345678;
             Mem_Copy((void     *) ptx_buf,
                      (void     *)&ProbeCom_EndiannessTest,
                      (CPU_SIZE_T) 4);
             tx_len  = 4;
             break;


        case PROBE_COM_QUERY_STATUS:
             status = (CPU_INT32U)ProbeCom_PktModifier();
             Mem_Copy((void     *) ptx_buf,
                      (void     *)&status,
                      (CPU_SIZE_T) 4);
             tx_len = 4;
             break;


        case PROBE_COM_QUERY_VERSION:
             version = PROBE_COM_VERSION;
             Mem_Copy((void     *) ptx_buf,
                      (void     *)&version,
                      (CPU_SIZE_T) 4);
             tx_len  = 4;
             break;


        default:
             tx_len  = 0;
             break;
    }

                                                                /* ------------------ RTN TX PKT SIZE ----------------- */
    tx_len += PROBE_COM_SIZE_TX_HDR;
    return (tx_len);                                            /* TX pkt size = nbytes (= Tx data size)                */
                                                                /*             + 4      (= Tx hdr  size).               */
}


/*
*********************************************************************************************************
*                                          ProbeCom_ReqRd()
*
* Description : Parse the FMT_RD request & formulate response.  This command causes the target to send
*               data read from its memory for a certain {memory address, data length} pair (which is
*               given in the request).
*
* Argument(s) : prx_buf         Pointer to the receive  buffer
*
*               ptx_buf         Pointer to the transmit buffer
*
*               rx_pkt_size     Size of the receive  packet
*
*               tx_buf_size     Size of the transmit buffer
*
* Return(s)   : The number of bytes written to the tx buffer.
*
* Caller(s)   : ProbeCom_ParseRxPkt().
*
* Note(s)     : (1) The RX format:
*
*                   (A) A 2-byte format , indicating the data segment format;
*                   (B) A 2-byte length , indicating the number of bytes to read;
*                   (C) A 4-byte address, the starting address of the data to read.
*
*                         +-------------------------+-------------------------+
*                         |          Format         |     Number of bytes     |
*                         +-------------------------+-------------------------+
*                         |                      Address                      |
*                         +-------------------------+-------------------------+
*
*               (2) The TX format:
*

⌨️ 快捷键说明

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