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

📄 probe_com.c

📁 uCOS-II example for MC9S12DPxxx
💻 C
📖 第 1 页 / 共 5 页
字号:
*                                           ProbeCom_CmdInfo()
*
* Description : Parse the FMT_INFO command & formulate response.  This command supplies information
*               to the target about the Windows program's capabilitied & configuration.
*
* 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 info  , indicating the type of the info packet;
*                   (C) A 4-byte data  , the packet data.
*
*                         +-------------------------+-------------------------+
*                         |          Format         |          Info           |
*                         +-------------------------+-------------------------+
*                         |                       Data                        |
*                         +---------------------------------------------------+
*
*              (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.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*                         |                       Answer                      |
*                         |                         .                         |
*                         |                         .                         |
*                         |                         .                         |
*                         +---------------------------------------------------+
*
*********************************************************************************************************
*/

static  CPU_INT16U  ProbeCom_CmdInfo (CPU_INT08U  *prx_buf,
                                      CPU_INT08U  *ptx_buf,
                                      CPU_INT16U   rx_pkt_size,
                                      CPU_INT16U   tx_buf_size)
{
    CPU_INT16U                 info;
    CPU_INT32U                 data;
    PROBE_COM_INFO_HDNLR_FNCT  hndlr;
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR                     cpu_sr;
#endif


                                                                /* ------------------- CHK PKT SIZE ------------------- */
                                                                /* Expected size = 2 (= Rx header size)                 */
                                                                /*               + 2 (= Info          )                 */
                                                                /*               + 4 (= Data          ).                */
    if (rx_pkt_size != 8) {
        return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
    }
                                                                /* ------------------- HANDLE INFO -------------------- */
    CPU_CRITICAL_ENTER();
    hndlr = ProbeCom_InfoHndlr;
    CPU_CRITICAL_EXIT();
    if (hndlr != (PROBE_COM_INFO_HDNLR_FNCT)0) {                /* Invoke callback if callback is set.                  */
        info = ProbeCom_GetINT16U(&prx_buf);
        data = ProbeCom_GetINT32U(&prx_buf);
        hndlr(info, data);
    }

                                                                /* Store TX pkt hdr :                                   */
    ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_TX_INFO);        /*  (a) TX pkt format.                                  */
    ProbeCom_StoINT8U( &ptx_buf, PROBE_COM_STATUS_OK);          /*  (b) Target status.                                  */
    ProbeCom_StoINT8U( &ptx_buf, ProbeCom_PktModifier());       /*  (c) Modifier.                                       */

                                                                /* ------------------ RTN TX PKT SIZE ----------------- */
    return ((CPU_INT16U)(PROBE_COM_SIZE_TX_HDR));               /* Tx pkt size = 4 (= Tx header size).                  */
}


/*
*********************************************************************************************************
*                                         ProbeCom_CmdSimpleRd()
*
* Description : Parse the FMT_SIMPLE_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:
*
*                   (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;
*                   (D) The memory data.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*                         |                        Data                       |
*                         |                         .                         |
*                         |                         .                         |
*                         |                         .                         |
*                         +---------------------------------------------------+
*
*********************************************************************************************************
*/

static  CPU_INT16U  ProbeCom_CmdSimpleRd (CPU_INT08U  *prx_buf,
                                          CPU_INT08U  *ptx_buf,
                                          CPU_INT16U   rx_pkt_size,
                                          CPU_INT16U   tx_buf_size)
{
    CPU_ADDR     addr;
    CPU_INT16U   nbytes;


    addr   = 0;
    nbytes = 0;

                                                                /* ------------------- CHK PKT SIZE ------------------- */
                                                                /* Expected size = 2 (= Rx header size )                */
                                                                /*               + 2 (= Number of bytes)                */
                                                                /*               + 4 (= Address        ).               */
    if (rx_pkt_size != 8) {
        return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
    }


                                                                /* -------------------- HANDLE RD --------------------- */
    nbytes = ProbeCom_GetINT16U(&prx_buf);                      /* Get nbr of bytes to read.                            */

                                                                /* Get read addr.                                       */
#if ((!defined(CPU_CFG_ADDR_SIZE)) || \
     ((defined(CPU_CFG_ADDR_SIZE)) && \
              (CPU_CFG_ADDR_SIZE   != CPU_WORD_SIZE_16)))
    addr   = (CPU_ADDR)ProbeCom_GetINT32U(&prx_buf);
#else
    addr   = (CPU_ADDR)ProbeCom_GetINT16U(&prx_buf);
#endif

    if (nbytes + PROBE_COM_SIZE_TX_HDR > tx_buf_size) {         /* If TX pkt will NOT fit in buf, rtn err.            */
        return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE));
    }

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    ProbeCom_TxSymCtr++;                                        /* Increment transmit symbol counter.                   */
    ProbeCom_TxSymByteCtr += nbytes;
#endif

                                                                /* Store TX pkt hdr :                                   */
    ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_TX_SIMPLE_RD);   /*  (a) TX pkt format.                                  */
    ProbeCom_StoINT8U( &ptx_buf, PROBE_COM_STATUS_OK);          /*  (b) Target status.                                  */
    ProbeCom_StoINT8U( &ptx_buf, ProbeCom_PktModifier());       /*  (c) Modifier.                                       */

    Mem_Copy((void     *)ptx_buf,                               /* Save TX data segment data.                           */
             (void     *)addr,
             (CPU_SIZE_T)nbytes);

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


/*
*********************************************************************************************************
*                                        ProbeCom_CmdMultipleRd()
*
* Description : Parse the FMT_MULTIPLE_RD request & formulate respnse.  This command causes the target
*               to send data read from its memory for a certain set of {memory address, data length}
*               pairs (which are 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 5-byte item descriptor, for each item in the list, consisting of:
*
*                       (1) A 4-byte address, the starting address of the data to read;
*                       (2) A 1-byte length,  indicating the number of bytes to read.
*
*                         +-------------------------+------------+------------+
*                         |          Format         | Num. bytes |         Addr       ---
*                         +-------------------------+------------+------------+        |    Item 1
*                         ress                                   | Num. bytes |       ---
*                         +--------------------------------------+------------+        |
*                         |                      Address                      |        |    Item 2
*                         +------------+--------------------------------------+       ---
*                         | Num. bytes |                                   Addr        |    Item 3
*                         +------------+--------------------------------------+        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         +--------------------------------------+------------+        .
*                         ress                                   | Num. bytes |       ---
*                         ---------------------------------------+------------+        |   Item n
*                         |                      Address                      |        |
*                         +---------------------------------------------------+       ---
*
*               (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;
*                   (D) For each item, the following is sent:
*
*                       (1) The memory data.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+       ---
*                         |                        Data                       |        |    Item 1
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         +---------------------------------------------------+       ---
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         +---------------------------------------------------+       ---
*                         |                        Data                       |        |    Item n
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         +---------------------------------------------------+       ---
*
*********************************************************************************************************
*/

static  CPU_INT16U  ProbeCom_CmdMultipleRd (CPU_INT08U  *prx_buf,
                                            CPU_INT08U  *ptx_buf,
                                            CPU_INT16U   rx_pkt_size,
                                            CPU_INT16U   tx_buf_size)
{
    CPU_INT08U  *ptx_buf_start;
    CPU_INT16U   tx_len;

    CPU_ADDR     addr;
    CPU_INT16U   nbytes;
    CPU_INT16U   rx_pkt_ix;

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    CPU_INT16U   sym_ctr;
    CPU_INT16U   sym_byte_ctr;
#endif


                                                                /* ------------------- CHK PKT SIZE ------------------- */
                                                                /* Expected size >= 2 (= Rx header

⌨️ 快捷键说明

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