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

📄 probe_com.c

📁 ST32F10xxx+uCOSII2.85的官方源代码,带LCD驱动,支持Keil3和IAR环境.这个可以做为参考,实际使用需要修改,他做的太复杂了,目录也很深
💻 C
📖 第 1 页 / 共 5 页
字号:
static  CPU_INT08U  ProbeCom_GetINT8U     (CPU_INT08U **buf);

static  CPU_INT16U  ProbeCom_GetINT16U    (CPU_INT08U **buf);

static  CPU_INT32U  ProbeCom_GetINT32U    (CPU_INT08U **buf);

                                                                    /* ----------------- WRITE TO TX BUFFER --------------- */
static  void        ProbeCom_StoINT8U     (CPU_INT08U **buf,
                                           CPU_INT08U   data);

static  void        ProbeCom_StoINT16U    (CPU_INT08U **buf,
                                           CPU_INT16U   data);

static  void        ProbeCom_StoINT32U    (CPU_INT08U **buf,
                                           CPU_INT32U   data);

                                                                    /* ------ DETERMINE IF STRING IS IN STRING BUFFER ----- */
#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
static  CPU_BOOLEAN ProbeCom_StrRdy       (void);
#endif


/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*********************************************************************************************************
**                                          Global Functions
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                Initialize uC/Probe Communication Module
*
* Description: This function initializes the module.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  ProbeCom_Init (void)
{
#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
    ProbeComStrBufWrIx = 0;
    ProbeComStrBufRdIx = 0;

    ProbeCom_OS_Init();
#endif

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    ProbeCom_RxPktCtr     = 0;
    ProbeCom_TxPktCtr     = 0;
    ProbeCom_TxSymByteCtr = 0;
    ProbeCom_TxSymCtr     = 0;
    ProbeCom_ErrPktCtr    = 0;

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
    ProbeCom_TxStrCtr     = 0;
#endif
#endif
}


/*
*********************************************************************************************************
*                                         Parse Receive Packet
*
* Description: This routine is called after a complete packet has been received.
*
* Argument(s): rx_pkt       is a pointer to the receive  packet buffer
*              tx_pkt       is a pointer to the transmit packet buffer
*              rx_pkt_sz    is the size of the received packet
*              tx_pkt_sz    is the size of the transmit packet buffer
*
* Returns    : The number of bytes in the data segment of the packet to transmit in response.
*********************************************************************************************************
*/

CPU_INT16U  ProbeCom_ParseRxPkt (void        *rx_pkt,
                                 void        *tx_pkt,
                                 CPU_INT16U   rx_pkt_sz,
                                 CPU_INT16U   tx_buf_sz)
{
    CPU_INT16U   tx_buf_wr;
    CPU_INT16U   format;
    CPU_INT08U  *rx_buf;
    CPU_INT08U  *tx_buf;


    rx_buf  = (CPU_INT08U *)rx_pkt;
    tx_buf  = (CPU_INT08U *)tx_pkt;
    format  = (rx_buf[1] << 8) + rx_buf[0];
    rx_buf += 2;

#if (PROBE_COM_STAT_EN == DEF_ENABLED)
    ProbeCom_RxPktCtr++;
    ProbeCom_TxPktCtr++;
#endif

    switch (format) {
        case PROBE_COM_FMT_RX_QUERY:
             tx_buf_wr = ProbeCom_CmdQuery(     rx_buf, tx_buf, rx_pkt_sz, tx_buf_sz);
             break;

        case PROBE_COM_FMT_RX_SIMPLE_RD:
             tx_buf_wr = ProbeCom_CmdSimpleRd(  rx_buf, tx_buf, rx_pkt_sz, tx_buf_sz);
             break;

#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
        case PROBE_COM_FMT_RX_SIMPLE_WR:
             tx_buf_wr = ProbeCom_CmdSimpleWr(  rx_buf, tx_buf, rx_pkt_sz, tx_buf_sz);
             break;
#endif

        case PROBE_COM_FMT_RX_MULTIPLE_RD:
             tx_buf_wr = ProbeCom_CmdMultipleRd(rx_buf, tx_buf,  rx_pkt_sz, tx_buf_sz);
             break;

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
        case PROBE_COM_FMT_RX_STR_GET:
             tx_buf_wr = ProbeCom_CmdStrGet(    rx_buf, tx_buf,  rx_pkt_sz, tx_buf_sz);
             break;
#endif

        default:
             tx_buf_wr = ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_UNKNOWN_REQUEST);
             break;
    }

    return (tx_buf_wr);
}


/*
*********************************************************************************************************
*                                    Queue String for Transmission
*
* Description: This routine is called to append a string in the string buffer.
*
* Argument(s): s          is a pointer to the string to send.
*
*              dly        allows the calling task to delay for a certain number of milliseconds until
*                         the entire string has been queued in the buffer.  If this value is zero, then
*                         the function will return after queueing in the buffer the portion that fits
*                         immediately.
*
* Returns    : DEF_TRUE   if the entire string was queued in the buffer.
*              DEF_FALSE  if the entire string could not be queued in the buffer.
*
* Note(s)    : (1) The string buffer is implemented as a circular buffer.  This function is one of two
*                  points of access for this buffer, the other being in the task or ISR which forms the .
*                  tx packets.  Only this function should modify the global current write index
*                  (ProbeComStrBufWrIx); only the task or ISR which forms the packets should modify the
*                  global current read index (ProbeComStrBufRdIx).
*
*              (2) The global current write index (ProbeComStrBufWrIx) is the index of the next location
*                  in the buffer to write.  The global current read index (ProbeComStrBufRdIx) is the
*                  index of the next location in the buffer to read.
*
*              (3) The string buffer, an array of PROBE_COM_STR_BUF_SIZE bytes, can only hold
*                  (PROBE_COM_STR_BUF_SIZE - 1) bytes so that the condition
*
*                                        ProbeComStrBufWrIx == ProbeComStrBufRdIx
*
*                  will be true if and only if the buffer is empty.  Consequently, this function
*                  always leaves an empty space in the buffer.
*
*              (4) If called from an ISR, dly MUST be 0.
*********************************************************************************************************
*/

#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
CPU_BOOLEAN  ProbeCom_TxStr (CPU_CHAR    *s,
                             CPU_INT16U   dly)
{
    CPU_BOOLEAN  ret;
    CPU_INT32U   len;
    CPU_INT32U   wr_ix;
    CPU_INT32U   rd_ix;
    CPU_INT32U   wr_ix_n;

    CPU_INT32U   nbytes_free;
    CPU_INT32U   nbytes_wr;


    if (dly == 0) {
        ret = ProbeCom_OS_Pend(DEF_FALSE);
    } else {
        ret = ProbeCom_OS_Pend(DEF_TRUE);
    }

    if (ret == DEF_FALSE) {
        return (DEF_FALSE);
    }

    len = (CPU_INT32U)Str_Len(s);                                   /* Determine length of the string (without NULL byte    */

    while (DEF_TRUE) {
        if (len == 0) {                                             /* If entire string has been placed in buffer           */
            ProbeCom_OS_Post();
            return (DEF_TRUE);                                      /* ... Return DEF_TRUE to indicate success.             */
        }

        rd_ix = ProbeComStrBufRdIx;
        wr_ix = ProbeComStrBufWrIx;

        if (rd_ix > wr_ix) {                                        /* If rd_ix > wr_ix, store string into                  */
                                                                    /*           buffer locations [wr_ix, rd_ix - 1)        */
            nbytes_free = rd_ix - wr_ix - 1;

        } else {
            if (rd_ix == 0) {                                       /* If rd_ix <= wr_ix && rd_ix == 0, store string at     */
                                                                    /*           buffer locations [wr_ix, end_ix - 1)       */
                nbytes_free = PROBE_COM_STR_BUF_SIZE - wr_ix - 1;

            } else {                                                /* If rd_ix <= wr_ix && rd_ix != 0, store string at     */
                                                                    /*           buffer locations [wr_ix, end_ix)           */

                nbytes_free = PROBE_COM_STR_BUF_SIZE - wr_ix;
            }
        }

        if (nbytes_free == 0) {                                     /* If the buffer is full                                */
            if (dly == 0) {                                         /* (a) Return if dly = 0                                */
                ProbeCom_OS_Post();
                return (DEF_FALSE);
            } else {                                                /* (b) Call OS function to delay and continue           */
                ProbeCom_OS_Dly(dly);
                continue;
            }
        }

        if (nbytes_free > len) {                                    /* If string is shorter than free space                 */
            nbytes_wr = len;
        } else {
            nbytes_wr = nbytes_free;
        }

        wr_ix_n = wr_ix + nbytes_wr;                                /* Assign write index after write                       */

        if (wr_ix_n == PROBE_COM_STR_BUF_SIZE) {                    /* Wrap buffer index around                             */
            wr_ix_n = 0;
        }

        Mem_Copy(&ProbeComStrBuf[wr_ix], s, nbytes_wr);             /* Copy string to buffer                                */

        ProbeComStrBufWrIx  = wr_ix_n;                              /* Assign new global write index                        */
        s                  += nbytes_wr;                            /* Increase string pointer                              */
        len                -= nbytes_wr;                            /* Decrease string length                               */
    }
}
#endif

⌨️ 快捷键说明

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