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

📄 probe_com.c

📁 ucos-ii 的完整代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
*********************************************************************************************************
*                                       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) : rx_buf      Pointer to the receive  buffer
*
*               tx_buf      Pointer to the transmit buffer
*
*               rx_pkt_sz   Size  of the receive  packet
*
*               tx_buf_sz   Size  of the transmit buffer
*
* Return(s)   : The number of bytes written to the tx buffer.
*
* Note(s)     : (1) The RX format:
*
*                   (A) A 2-byte format  , indicating the data segment format;                      AND
*                   (B) A 2-byte length  , indicating the number of bytes to read;                  AND
*                   (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;                      AND
*                   (B) A 1-byte status  , indicating the status after the request;                 AND
*                   (C) A 1-byte modifier;                                                          AND
*                   (D) The memory data.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*                         |                        Data                       |
*                         |                         .                         |
*                         |                         .                         |
*                         |                         .                         |
*                         +---------------------------------------------------+
*
*********************************************************************************************************
*/

static  CPU_INT16U  ProbeCom_CmdSimpleRd (CPU_INT08U  *rx_buf,
                                          CPU_INT08U  *tx_buf,
                                          CPU_INT16U   rx_pkt_sz,
                                          CPU_INT16U   tx_buf_sz)
{
    CPU_ADDR     addr;
    CPU_INT16U   nbytes;


    addr   = 0;
    nbytes = 0;

    if (rx_pkt_sz == 8) {                                           /* If RX data segment is the expected size              */
                                                                    /*        =  2      (= Rx header size )                 */
                                                                    /*        +  2      (= Number of bytes)                 */
                                                                    /*        +  4      (= Address        )                 */

        nbytes = ProbeCom_GetINT16U(&rx_buf);                       /*  (a) Read the number of bytes to return              */

#if ((!defined(CPU_CFG_ADDR_SIZE)) || \
     ((defined(CPU_CFG_ADDR_SIZE)) && \
              (CPU_CFG_ADDR_SIZE   != CPU_WORD_SIZE_16)))
        addr   = (CPU_ADDR)ProbeCom_GetINT32U(&rx_buf);             /*  (b) Read the memory address                         */
#else
        addr   = (CPU_ADDR)ProbeCom_GetINT16U(&rx_buf);             /*  (b) Read the memory address                         */
#endif

        if (nbytes + PROBE_COM_SIZE_TX_HEADER > tx_buf_sz) {        /*  (c) If TX packet will NOT fit in buffer             */
            return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE));
        }

    } else {                                                        /* If RX data segment is NOT the expected size          */

        return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
    }

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    ProbeCom_TxSymCtr++;                                            /*  (a) Increment transmit symbol counter               */
    ProbeCom_TxSymByteCtr += nbytes;
#endif
                                                                    /*  (b) Save TX data segment header                     */
    ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_SIMPLE_RD);        /*          (i) TX packet format                        */
    ProbeCom_StoINT8U( &tx_buf, PROBE_COM_STATUS_OK);               /*         (ii) Target status                           */
    ProbeCom_StoINT8U( &tx_buf, ProbeCom_PktModifier());            /*        (iii) Modifier                                */

                                                                    /*  (c) Save TX data segment data                       */
    Mem_Copy((void     *)tx_buf,
             (void     *)addr,
             (CPU_SIZE_T)nbytes);

    return ((CPU_INT16U)(nbytes + PROBE_COM_SIZE_TX_HEADER));       /*  (d) Return TX data segment size                     */
                                                                    /*        =  nbytes (= Tx data   size)                  */
                                                                    /*        +  4      (= Tx header size)                  */
}


/*
*********************************************************************************************************
*                                       ProbeCom_CmdSimpleWr()
*
* Description : Parse the FMT_SIMPLE_WR request & formulate response.  This command causes the target
*               to write certain data into its memroy, for a certain {memory address, data length, data}
*               triplet (which is given in the request).
*
* Argument(s) : rx_buf      Pointer to the receive  buffer
*
*               tx_buf      Pointer to the transmit buffer
*
*               rx_pkt_sz   Size  of the receive  packet
*
*               tx_buf_sz   Size  of the transmit buffer
*
* Return(s)   : The number of bytes written to the tx buffer.
*
* Note(s)     : (1) The RX format:
*
*                   (A) A 2-byte format  , indicating the data segment format;                      AND
*                   (B) A 2-byte length  , indicating the number of bytes to write;                 AND
*                   (C) A 4-byte address , the starting address of the data to read;                AND
*                   (D) The memory data.
*
*                         +-------------------------+-------------------------+
*                         |          Format         |      Number of bytes    |
*                         +-------------------------+-------------------------+
*                         |                      Address                      |
*                         +---------------------------------------------------+
*                         |                        Data                       |
*                         |                         .                         |
*                         |                         .                         |
*                         |                         .                         |
*                         +---------------------------------------------------+
*
*               (2) The TX format:
*
*                   (A) A 2-byte format  , indicating the data segment format;                      AND
*                   (B) A 1-byte status  , indicating the status after the request;                 AND
*                   (C) A 1-byte modifier.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*
*********************************************************************************************************
*/

#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
static  CPU_INT16U  ProbeCom_CmdSimpleWr (CPU_INT08U  *rx_buf,
                                          CPU_INT08U  *tx_buf,
                                          CPU_INT16U   rx_pkt_sz,
                                          CPU_INT16U   tx_buf_sz)
{
    CPU_INT16U   nbytes;
    CPU_ADDR     addr;


    if (rx_pkt_sz >= 8) {                                           /* If RX data segment is an expected size               */
                                                                    /*        =  2      (= Rx header size )                 */
                                                                    /*        +  2      (= Number of bytes)                 */
                                                                    /*        +  4      (= Address        )                 */
                                                                    /*        +  nbytes (= Data           )                 */

        nbytes = ProbeCom_GetINT16U(&rx_buf);                       /*  (a) Read the number of bytes to write               */
        addr   = (CPU_ADDR)ProbeCom_GetINT32U(&rx_buf);             /*  (b) Read the memory address                         */

        if (rx_pkt_sz != 8 + nbytes) {                              /*  (c) If RX data segment is NOT expected size         */

            return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
        }

    } else {                                                        /* If RX data segment is NOT an expected size           */

        return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
    }

                                                                    /*  (a) Store data into memory                          */
    Mem_Copy((void     *)addr,
             (void     *)rx_buf,
             (CPU_SIZE_T)nbytes);

                                                                    /*  (b) Save TX data segment header                     */
    ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_SIMPLE_RD);        /*          (i) TX packet format                        */
    ProbeCom_StoINT8U( &tx_buf, PROBE_COM_STATUS_OK);               /*         (ii) Target status                           */
    ProbeCom_StoINT8U( &tx_buf, ProbeCom_PktModifier());            /*        (iii) Modifier                                */

    return (PROBE_COM_SIZE_TX_HEADER);                              /*  Return TX data segment size                         */
                                                                    /*        =  4      (= Tx header size)                  */
}
#endif


/*
*********************************************************************************************************
*                                       ProbeCom_CmdMultipleRd()
*
* Description : Parse the FMT_MULTIPLE_RD request & formulate respnse.  This command causes the
*               target to write into its memory the data specified in a certain set of {memory address,
*               data length, data} triplets (which are given in the request).
*
* Argument(s) : rx_buf      Pointer to the receive  buffer
*
*               tx_buf      Pointer to the transmit buffer
*
*               rx_pkt_sz   Size  of the receive  packet
*
*               tx_buf_sz   Size  of the transmit buffer
*
* Return(s)   : The number of bytes written to the tx buffer.
*
* Note(s)     : (1) The RX format:
*
*                   (A) A 2-byte format             , indicating the data segment format;           AND
*                   (B) A 5-byte item descriptor    , for each item in the list, consisting of:
*
*                           (I) A 4-byte address    , the starting address of the data to read;     AND
*                          (II) 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;                      AND
*                   (B) A 1-byte status  , indicating the status after the request;                 AND
*                   (C) A 1-byte modifier;                                                          AND
*                   (D) If the list is available, for each item, the following is sent:
*
*                           (I) The memory data.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+       ---
*                         |                        Data                       |        |    Item 1
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         +---------------------------------------------------+       ---
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         |                         .                         |        .
*                         +---------------------------------------------------+       ---
*                         |                        Data                       |        |    Item n
*                         |                         .                         |        |
*                         |                         .                         |        |

⌨️ 快捷键说明

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