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

📄 probe_com.c

📁 ST32F10xxx+uCOSII2.85的官方源代码,带LCD驱动,支持Keil3和IAR环境.这个可以做为参考,实际使用需要修改,他做的太复杂了,目录也很深
💻 C
📖 第 1 页 / 共 5 页
字号:
    tx_buf_start = tx_buf;                                          /* Save beginning of TX buffer in case packet           */
                                                                    /*  ... ends up being too long.                         */
    tx_length    = PROBE_COM_SIZE_TX_HEADER;                        /* 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    += PROBE_COM_SIZE_TX_HEADER;

    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 *)((CPU_ADDR)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
*              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 - PROBE_COM_SIZE_TX_HEADER - 1) {    /* (ii) If too much to fit in packet            */
                                                                    /*         .... Store only [rd_ix,rd_ix + tx_buf_sz - 5)*/
                                                                    /*         .... Where 5 = 1 (NULL byte)                 */
                                                                    /*                      + 4 (TX header)                 */
                nbytes_rd = tx_buf_sz - PROBE_COM_SIZE_TX_HEADER - 1;
                rd_ix_n   = rd_ix + tx_buf_sz - PROBE_COM_SIZE_TX_HEADER;

            } 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 - PROBE_COM_SIZE_TX_HEADER - 1) {    /* (ii) If to much to fit in packet             */
                                                                    /*         .... Store only [rd_ix, rd_ix + tx_buf_sz)   */

                nbytes  = tx_buf_sz - PROBE_COM_SIZE_TX_HEADER - 1; /*              (A) Store number of bytes read          */
                rd_ix_n = rd_ix + tx_buf_sz - PROBE_COM_SIZE_TX_HEADER;
                                                                    /*              (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             */

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

                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 + PROBE_COM_SIZE_TX_HEADER + 1);             /*  (d) Return TX data segment size                     */
                                                                    /*        =  nbytes (= String    size)                  */
                                                                    /*        +  4      (= Tx header size)                  */
                                                                    /*        +  1      (= NULL byte     )                  */
    }
}
#endif


/*
*********************************************************************************************************
*********************************************************************************************************
**                                    Static Buffer 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)
{

⌨️ 快捷键说明

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