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

📄 probe_com.c

📁 uCOS-II V2.84 LM3S6965 TCPIP Demo
💻 C
📖 第 1 页 / 共 5 页
字号:
*              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 padding.
*
*                         +-------------------------+-------------------------+
*                         |          Format         |         Padding         |
*                         +-------------------------+-------------------------+
*
*              (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) A n-byte string  , the string which is stored in the target's buffer.
*
*                         +-------------------------+------------+------------+
*                         |          Format         |   Status   |  Modifier  |
*                         +-------------------------+------------+------------+
*                         |                       String                      |
*                         |                         .                         |
*                         |                         .                         |
*                         |                         .                         |
*                         +---------------------------------------------------+
*
*              (3) See Notes for ProbeCom_TxStr().
*********************************************************************************************************
*/

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
static  CPU_INT16U  ProbeCom_CmdStrGet (CPU_INT08U *rx_buf, CPU_INT08U *tx_buf, CPU_INT16U rx_pkt_sz, CPU_INT16U  tx_buf_sz)
{
    CPU_INT08U   error;
    CPU_INT32U   wr_ix;
    CPU_INT32U   rd_ix;
    CPU_INT16U   nbytes;

    CPU_INT32U   nbytes_rd;
    CPU_INT32U   rd_ix_n;
    CPU_INT08U  *tx_buf_p;


    error  = PROBE_COM_STATUS_OK;
    wr_ix  = ProbeComStrBufWrIx;
    rd_ix  = ProbeComStrBufRdIx;
    nbytes = 0;

    if (rx_pkt_sz == 4) {                                               /* If RX data segment is the expected size      */
                                                                        /*        =  2      (= Rx header size)          */
                                                                        /*        +  2      (= Padding       )          */

        if (wr_ix == rd_ix) {                                           /*  (a) If there is NO string, then error       */
            error = PROBE_COM_STATUS_STR_NONE;
        }

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

        error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE;
    }

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

    } else {                                                            /* No error                                     */
                                                                        /*  (a) Save TX data segment header             */
        ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_STR_GET);          /*          (i) TX packet format                */
        ProbeCom_StoINT8U( &tx_buf, PROBE_COM_STATUS_OK);               /*         (ii) Target status                   */
        ProbeCom_StoINT8U( &tx_buf, 0);                                 /*        (iii) Modifier                        */

        tx_buf_p = tx_buf;

        if (wr_ix > rd_ix) {                                            /*  (b) If wr_ix > rd_ix                        */
                                                                        /*  ... Store in pkt the bytes [rd_ix, wr_ix)   */

            nbytes_rd = wr_ix - rd_ix;                                  /*          (i) Calculate num. bytes to read    */

            if (nbytes_rd >= tx_buf_sz) {                               /*         (ii) If too much to fit in packet    */
                                                                        /*         .... Store only [rd_ix,              */
                                                                        /*         ...              rd_ix + tx_buf_sz)  */
                nbytes_rd = tx_buf_sz - 1;
                rd_ix_n   = rd_ix + tx_buf_sz;

            } else {
                rd_ix_n   = wr_ix;
            }

            nbytes = nbytes_rd;                                         /*        (iii) Store number of bytes read      */
                                                                        /*         (iv) Read from the string buffer     */
            Mem_Copy((void *)tx_buf, (void *)&ProbeComStrBuf[rd_ix], nbytes_rd);

            ProbeComStrBufRdIx = rd_ix_n;                               /*          (v) Update global read index        */

        } else {                                                        /*  (c) If wr_ix < rd_ix                        */
                                                                        /*  ... Store in pkt the bytes [rd_ix, end_ix)  */
                                                                        /*  ... Then store in pkt the bytes [0, wr_ix)  */

            nbytes_rd = PROBE_COM_STR_BUF_SIZE - rd_ix;                 /*          (i) Calculate num. bytes to read    */

            if (nbytes_rd >= tx_buf_sz) {                               /*         (ii) If to much to fit in packet     */
                                                                        /*         .... Store only [rd_ix,              */
                                                                        /*         ...              rd_ix + tx_buf_sz)  */

                nbytes  = tx_buf_sz - 1;                                /*              (A) Store number of bytes read  */
                rd_ix_n = rd_ix + tx_buf_sz;
                                                                        /*              (B) Read from string buffer     */
                Mem_Copy((void *)tx_buf, (void *)&ProbeComStrBuf[rd_ix], nbytes);

                ProbeComStrBufRdIx  = rd_ix_n;                          /*              (C) Update global read index    */

            } else {                                                    /*         (iii) If not too much for packet     */

                                                                        /*               ------- [rd_ix, end_ix) ------ */

                nbytes  = nbytes_rd;                                    /*              (A) Store number of bytes read  */
                rd_ix_n = 0;                                            /*              (B) Buffer read ix after read   */

                                                                        /*              (C) Read from the string buffer */
                Mem_Copy((void *)tx_buf, (void *)&ProbeComStrBuf[rd_ix], nbytes_rd);
                rd_ix     = rd_ix_n;                                    /*              (D) Update local read index     */

                                                                        /*               --------- [0, wr_ix) --------- */
                tx_buf   += nbytes_rd;
                nbytes_rd = wr_ix;                                      /*              (E) Number of bytes to read     */

                if (nbytes_rd + nbytes >= tx_buf_sz) {                  /*              (F) Too much to fit in packet   */
                    nbytes_rd = tx_buf_sz - nbytes - 1;                 /*              ... Store only [0, tx_buf_sz]   */
                }

                nbytes  += nbytes_rd;                                   /*              (G) Update total num. bytes read*/
                rd_ix_n  = rd_ix + nbytes_rd;                           /*              (H) Buffer read ix after read   */

                                                                        /*              (I) Read from the string buffer */
                Mem_Copy((void *)tx_buf, (void *)&ProbeComStrBuf[rd_ix], nbytes_rd);

                ProbeComStrBufRdIx = rd_ix_n;                           /*              (J) Update global read index    */
            }
        }

      *(tx_buf_p + nbytes) = 0;

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
        ProbeCom_TxStrCtr += nbytes;
#endif

        return (nbytes + 5);                                            /*  (d) Return TX data segment size             */
                                                                        /*        =  nbytes (= String    size)          */
                                                                        /*        +  4      (= Tx header size)          */
                                                                        /*        +  1      (= NULL byte     )          */
    }
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
**                                       Static Functions
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                 GET DATA FROM DATA SEGMENT BUFFER
*
* Description: This routine is called to retrieve data from a buffer.
*
* Argument(s): None.
*
* Returns    : Either an 8-, 16-, or 32-bit datum.
*********************************************************************************************************
*/

static  CPU_INT08U  ProbeCom_GetINT8U (CPU_INT08U **buf)
{
    return (*((*buf)++));
}


static  CPU_INT16U  ProbeCom_GetINT16U (CPU_INT08U **buf)
{
    CPU_INT16U  lowbyte;
    CPU_INT16U  highbyte;


    lowbyte  = ProbeCom_GetINT8U(buf);
    highbyte = ProbeCom_GetINT8U(buf);
    return ((highbyte << 8) | lowbyte);
}


static  CPU_INT32U  ProbeCom_GetINT32U (CPU_INT08U **buf)
{
    CPU_INT32U  highword;
    CPU_INT32U  lowword;


    lowword  = ProbeCom_GetINT16U(buf);
    highword = ProbeCom_GetINT16U(buf);
    return ((highword << 16) | lowword);
}


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                       Static Tx Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                      STORE DATA INTO BUFFER
*
* Description: This routine is called to store data into a buffer and increment the buffer pointer.
*
* Argument(s): buf      is the pointer to the buffer pointer
*              data     is either a 8-, 16-, or 32-bit datum.
*
* Returns    : None.
*********************************************************************************************************
*/

static  void  ProbeCom_StoINT8U (CPU_INT08U **buf, CPU_INT08U data)
{
    *((*buf)++) = data;
}


static  void  ProbeCom_StoINT16U (CPU_INT08U **buf, CPU_INT16U data)
{
    ProbeCom_StoINT8U(buf, data & 0x00FF);
    ProbeCom_StoINT8U(buf, data >> 8);
}


static  void  ProbeCom_StoINT32U (CPU_INT08U **buf, CPU_INT32U data)
{
    ProbeCom_StoINT16U(buf, data & 0x0000FFFFL);
    ProbeCom_StoINT16U(buf, data >> 16);
}

⌨️ 快捷键说明

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