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

📄 probe_com.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 5 页
字号:
*                   (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_SIZE_T  ProbeCom_ReqRd (CPU_INT08U  *prx_buf,
                                    CPU_INT08U  *ptx_buf,
                                    CPU_SIZE_T   rx_pkt_size,
                                    CPU_SIZE_T   tx_buf_size)
{
    CPU_ADDR    sym_addr;
    CPU_SIZE_T  sym_size;
    CPU_SIZE_T  tx_len;


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


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

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

    if (sym_size + PROBE_COM_SIZE_TX_HDR > tx_buf_size) {       /* If tx pkt will NOT fit in buf, rtn err.              */
        tx_len = ProbeCom_ReqErr(ptx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE);
        return (tx_len);
    }

#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
    ProbeCom_TxSymCtr++;                                        /* Inc tx sym ctr.                                      */
    ProbeCom_TxSymByteCtr += sym_size;
#endif

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

    Mem_Copy((void     *)ptx_buf,                               /* Save tx data segment data.                           */
             (void     *)sym_addr,
             (CPU_SIZE_T)sym_size);

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


/*
*********************************************************************************************************
*                                        ProbeCom_ReqRdMulti()
*
* Description : Parse the FMT_RD_MULTI 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_SIZE_T  ProbeCom_ReqRdMulti (CPU_INT08U  *prx_buf,
                                         CPU_INT08U  *ptx_buf,
                                         CPU_SIZE_T   rx_pkt_size,
                                         CPU_SIZE_T   tx_buf_size)
{
    CPU_SIZE_T   rx_pkt_ix;
#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
    CPU_INT32U   sym_byte_ctr;
    CPU_INT32U   sym_ctr;
#endif
    CPU_ADDR     sym_addr;
    CPU_SIZE_T   sym_size;
    CPU_SIZE_T   tx_len;
    CPU_INT08U  *ptx_buf_start;


                                                                /* ------------------- CHK PKT SIZE ------------------- */
                                                                /* Expected size >= 2 (= Rx hdr size)                   */
                                                                /*                + 5 (= 1 item desc).                  */
    if (rx_pkt_size  < 7) {
        tx_len = ProbeCom_ReqErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE);
        return (tx_len);
    }

                                                                /* -------------------- HANDLE RD --------------------- */
    ptx_buf_start = ptx_buf;                                    /* Save ptr to tx buf in case pkt is too long for buf.  */
    tx_len        = PROBE_COM_SIZE_TX_HDR;                      /* Init tx pkt len = 4 = size of hdr.                   */

                                                                /* Store TX pkt hdr :                                   */
    ptx_buf[0]    = PROBE_COM_FMT_TX_RD_MULTI_LO;               /* (a) TX pkt fmt.                                      */
    ptx_buf[1]    = PROBE_COM_FMT_TX_RD_MULTI_HI;
    ptx_buf[2]    = PROBE_COM_STATUS_OK;                        /* (b) Target status.                                   */
    ptx_buf[3]    = ProbeCom_PktModifier();                     /* (c) Modifier.                                        */
    ptx_buf      += PROBE_COM_SIZE_TX_HDR;

    rx_pkt_ix     = 7;                                          /* Tx pkt ix after 1st item = 2 (= Rx hdr size)         */
                                                                /*                          + 5 (= 1 item desc).        */

#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
    sym_ctr      = 0;
    sym_byte_ctr = 0;
#endif
                                                                /* Sto data for each item.                              */
    while (rx_pkt_ix <= rx_pkt_size) {
        sym_size   =  prx_buf[0];                               /* (a) Get nbr of bytes to rd.                          */

                                                                /* (b) Get rd addr.                                     */
#if ((!defined(CPU_CFG_ADDR_SIZE)) || \
     ((defined(CPU_CFG_ADDR_SIZE)) && \
              (CPU_CFG_ADDR_SIZE   != CPU_WORD_SIZE_16)))
        sym_addr   = (prx_buf[4] << 8) + prx_buf[3];
        sym_addr   = (sym_addr   << 8) + prx_buf[2];
        sym_addr   = (sym_addr   << 8) + prx_buf[1];
#else
        sym_addr   = (prx_buf[2] << 8) + prx_buf[1];
#endif

        prx_buf   += 5;
        rx_pkt_ix += 5;

        tx_len    += sym_size;                                  /* (c) Add nbr of bytes to pkt len.                     */

        if (tx_len > tx_buf_size) {                             /* (d) Will pkt be too long for TX buf? ...             */
            ptx_buf = ptx_buf_start;                            /*     ... rtn err.                                     */
            tx_len  = ProbeCom_ReqErr(ptx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE);
            return (tx_len);
        }

#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
        sym_ctr++;                                              /* (e) Inc local sym ctr.                               */
        sym_byte_ctr += sym_size;
#endif
                                                                /* (f) Otherwise, save TX data.                         */
        Mem_Copy((void     *)ptx_buf,
                 (void     *)sym_addr,
                 (CPU_SIZE_T)sym_size);

        ptx_buf += sym_size;
    }

#if (PROBE_COM_CFG_STAT_EN == DEF_ENABLED)
    ProbeCom_TxSymCtr     += sym_ctr;                           /* Inc global sym ctr.                                  */
    ProbeCom_TxSymByteCtr += sym_byte_ctr;
#endif

                                                                /* ------------------ RTN TX PKT SIZE ----------------- */
    return (tx_len);
}


/*
*********************************************************************************************************
*                                          ProbeCom_ReqWr()
*
* Description : Parse the FMT_WR request & formulate response.  This command causes the target to write
*               into its memory data from a certain {memory address, data length, data} triplet 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 write;
*                   (C) A 4-byte address, the starting address at which the data should be written;
*                   (D) The memory data.
*
*                         +-------------------------+-------------------------+
*                         |          Format         |      Number of bytes    |
*                         +-------------------------+-------------------------+
*                         |                      Address                      |
*                         +---------------------------------------------------+
*                         |                        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  |
*                         +-------------------------+------------+------------+
*
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_WR_REQ_EN == DEF_ENABLED)
static  CPU_SIZE_T  ProbeCom_ReqWr (CPU_INT08U  *prx_buf,
                                    CPU_INT08U  *ptx_buf,
                                    CPU_SIZE_T   rx_pkt_size,
                                    CPU_SIZE_T   tx_buf_size)
{

⌨️ 快捷键说明

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