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

📄 probe_com.c

📁 uCOS-II V2.84 LM3S6965 TCPIP Demo
💻 C
📖 第 1 页 / 共 5 页
字号:


/*
*********************************************************************************************************
*                                       Respond to FMT_SIMPLE_WR Request
*
* Description: This routine is called to parse the FMT_SIMPLE_WR request.  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       is a pointer to the receive  buffer
*              tx_buf       is a pointer to the transmit buffer
*              rx_pkt_sz    is the size  of the receive  packet
*              tx_buf_sz    is the size  of the transmit buffer
*
* Returns    : 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_INT32U   addr;
    CPU_INT08U   error;


    error = PROBE_COM_STATUS_OK;


    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   = ProbeCom_GetINT32U(&rx_buf);                           /*  (b) Read the memory address                 */

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

            error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE;                 /*          (i) Error                           */
        }

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

        error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE;                     /*  (a) Error                                   */
    }


    if (error != PROBE_COM_STATUS_OK) {                                 /* Error                                        */
        return (ProbeCom_CmdError(tx_buf, error));

    } else {                                                            /* No error                                     */
        Mem_Copy((void *)addr, (void *)rx_buf, nbytes);                 /*  (a) Store data into memory                  */

                                                                        /*  (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 (4);                                                         /*  Return TX data segment size                 */
                                                                        /*        =  4      (= Tx header size)          */
}
#endif


/*
*********************************************************************************************************
*                                       Respond to FMT_MULTIPLE_RD Request
*
* Description: This routine is called to parse the FMT_MULTIPLE_RD request.  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       is a pointer to the receive  buffer
*              tx_buf       is a pointer to the transmit buffer
*              rx_pkt_sz    is the size  of the receive  packet
*              tx_buf_sz    is the size  of the transmit buffer
*
* Returns    : 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
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         |                         .                         |        |
*                         +---------------------------------------------------+       ---
*
*********************************************************************************************************
*/

static  CPU_INT16U  ProbeCom_CmdMultipleRd (CPU_INT08U *rx_buf, CPU_INT08U *tx_buf, CPU_INT16U rx_pkt_sz, CPU_INT16U  tx_buf_sz)
{
    CPU_INT08U  *tx_buf_start;
    CPU_INT32U   tx_length;

    CPU_INT32U   addr;
    CPU_INT16U   nbytes;
    CPU_INT32U   rx_pkt_ix;

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

    tx_buf_start = tx_buf;                                              /* Save beginning of TX buffer in case packet   */
                                                                        /*  ... ends up being too long.                 */
    tx_length    = 4;                                                   /* Initial TX packet length = 4 = size of header*/

    if (rx_pkt_sz  < 7) {                                               /* If the RX data packet is NOT expected size   */
                                                                        /*        =  2      (= Rx header size   )       */
                                                                        /*        +  5      (= 1 item descriptor)       */
        return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
    }

                                                                        /* No error (yet)                               */
                                                                        /*  (a) Save TX data segment header             */
    tx_buf[0]  = PROBE_COM_FMT_TX_MULTIPLE_RD_LO;                       /*          (i) TX packet format                */
    tx_buf[1]  = PROBE_COM_FMT_TX_MULTIPLE_RD_HI;
    tx_buf[2]  = PROBE_COM_STATUS_OK;                                   /*         (ii) Target status                   */
    tx_buf[3]  = ProbeCom_PktModifier();                                /*        (iii) Modifier                        */
    tx_buf    += 4;

    rx_pkt_ix  = 7;                                                     /*  (b) Receive packet index after first item   */
                                                                        /*        =  2      (= Rx header size   )       */
                                                                        /*        +  5      (= 1 item descriptor)       */

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    sym_ctr      = 0;
    sym_byte_ctr = 0;
#endif
                                                                        /*  (c) Store data for each item                */
    while (rx_pkt_ix <= rx_pkt_sz) {
        nbytes     =  rx_buf[0];
        addr       = (rx_buf[4] << 8) + rx_buf[3];
        addr       = (addr      << 8) + rx_buf[2];
        addr       = (addr      << 8) + rx_buf[1];

        rx_buf    += 5;

        tx_length += nbytes;                                            /*        (iii) Add number of bytes to pkt len. */

        if (tx_length > tx_buf_sz) {                                    /*         (iv) Will be too long for TX buffer? */
            tx_buf = tx_buf_start;
            return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE));
        }

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
        sym_ctr++;                                                      /*          (v) Increment local sym. counter    */
        sym_byte_ctr += nbytes;
#endif

        Mem_Copy((void *)tx_buf, (void *)addr, nbytes);                 /*         (vi) Otherwise, save TX data         */

        tx_buf    += nbytes;
        rx_pkt_ix += 5;
    }

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
        ProbeCom_TxSymCtr     += sym_ctr;                               /* Increment global sym. counter                */
        ProbeCom_TxSymByteCtr += sym_byte_ctr;
#endif

    return (tx_length);
}


/*
*********************************************************************************************************
*                                    Respond to FMT_STR_GET Command
*
* Description: This routine is called to parse the FMT_STR_GET command.  This command asks the target
*              to send a string that it is currently storing.
*
* Argument(s): rx_buf       is a pointer to the receive  buffer

⌨️ 快捷键说明

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