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

📄 probe_rs232.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                       uC/Probe Communication
*
*                         (c) Copyright 2007-2008; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                        COMMUNICATION: RS-232
*
* Filename      : probe_rs232.c
* Version       : V2.20
* Programmer(s) : BAN
*********************************************************************************************************
* Note(s)       : (1) The abbreviations RX and TX refer to communication from the target's perspective.
*
*                 (2) The abbreviations RD and WR refer to reading data from the target memory and
*                     writing data to the target memory, respectively.
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#define    PROBE_RS232_MODULE
#include  <probe_com.h>
#include  <probe_rs232.h>


/*
*********************************************************************************************************
*                                               ENABLE
*
* Note(s) : (1) See 'probe_rs232.h  ENABLE'.
*********************************************************************************************************
*/

#if (PROBE_COM_CFG_RS232_EN == DEF_ENABLED)                     /* See Note #1.                                         */


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                        RS-232 PACKET FORMAT
*
* Note(s):  (1) All packets include the following parts:
*
*                   (A)  4 1-byte start delimiters, forming the ASCII representation of "uCPr".  These
*                        are the constants PROBE_RS232_PROTOCOL_RX_SD0-PROBE_RS232_PROTOCOL_?X_SD4;
*                   (B)  1 2-byte length, the length of the data segment;
*                   (C)  1 2-byte padding, unused;
*                   (D)  n   bytes of data; and
*                   (E)  1 1-byte checksum; and
*                   (F)  1 1-byte end delimiter, the character '/', which is the constant PROBE_RS232_PROTOCOL_?X_ED.
*
*                                       +-------------------+-------------------+
*                                       |   'u'   |   'C'   |   'P'   |   'r'   |
*                                       +-------------------+-------------------+
*                                       |       Length      |     Padding       |
*                                       +-------------------+-------------------+
*                                       |                  Data                 |   The data segment does not need to end on
*                                       |                   .                   |   a four-byte boundary, as might be inferred
*                                       |                   .                   |   from this diagram.
*                                       |                   .                   |
*                                       +-------------------+-------------------+
*                                       | Checksum|   '/'   |
*                                       +-------------------+
*********************************************************************************************************
*/

                                                                /* ------------- INBOUND PACKET DELIMITERS ------------ */
#define  PROBE_RS232_PROTOCOL_RX_SD0                    0x75    /* Start delimiters.                                    */
#define  PROBE_RS232_PROTOCOL_RX_SD1                    0x43
#define  PROBE_RS232_PROTOCOL_RX_SD2                    0x50
#define  PROBE_RS232_PROTOCOL_RX_SD3                    0x72
#define  PROBE_RS232_PROTOCOL_RX_ED                     0x2F    /* End   delimiter.                                     */

                                                                /* ------------ OUTBOUND PACKET DELIMITERS ------------ */
#define  PROBE_RS232_PROTOCOL_TX_SD0                    0x75    /* Start delimiters.                                    */
#define  PROBE_RS232_PROTOCOL_TX_SD1                    0x43
#define  PROBE_RS232_PROTOCOL_TX_SD2                    0x50
#define  PROBE_RS232_PROTOCOL_TX_SD3                    0x72
#define  PROBE_RS232_PROTOCOL_TX_ED                     0x2F    /* End   delimiter.                                     */

                                                                /* ----------- RECEIVE STATE MACHINE STATES ----------- */
#define  PROBE_RS232_RX_STATE_SD0                          0    /* Waiting for start first  start delimiter (SD0).      */
#define  PROBE_RS232_RX_STATE_SD1                          1    /* Waiting for start second start delimiter (SD1).      */
#define  PROBE_RS232_RX_STATE_SD2                          2    /* Waiting for start third  start delimiter (SD2).      */
#define  PROBE_RS232_RX_STATE_SD3                          3    /* Waiting for start fourth start delimiter (SD3).      */
#define  PROBE_RS232_RX_STATE_LEN1                         4    /* Waiting for length,  first  byte.                    */
#define  PROBE_RS232_RX_STATE_LEN2                         5    /* Waiting for length,  second byte.                    */
#define  PROBE_RS232_RX_STATE_PAD1                         6    /* Waiting for padding, first  byte.                    */
#define  PROBE_RS232_RX_STATE_PAD2                         7    /* Waiting for padding, second byte.                    */
#define  PROBE_RS232_RX_STATE_DATA                         8    /* Waiting for data.                                    */
#define  PROBE_RS232_RX_STATE_CHKSUM                       9    /* Waiting for checksum.                                */
#define  PROBE_RS232_RX_STATE_ED                          10    /* Waiting for end delimiter.                           */

                                                                /* ---------- TRANSMIT STATE MACHINE STATES ----------- */
#define  PROBE_RS232_TX_STATE_SD0                          0    /* Waiting to send start first  start delim. (SD0).     */
#define  PROBE_RS232_TX_STATE_SD1                          1    /* Waiting to send start second start delim. (SD1).     */
#define  PROBE_RS232_TX_STATE_SD2                          2    /* Waiting to send start third  start delim. (SD2).     */
#define  PROBE_RS232_TX_STATE_SD3                          3    /* Waiting to send start fourth start delim. (SD3).     */
#define  PROBE_RS232_TX_STATE_LEN1                         4    /* Waiting to send length,  first  byte.                */
#define  PROBE_RS232_TX_STATE_LEN2                         5    /* Waiting to send length,  second byte.                */
#define  PROBE_RS232_TX_STATE_PAD1                         6    /* Waiting to send padding, first  byte.                */
#define  PROBE_RS232_TX_STATE_PAD2                         7    /* Waiting to send padding, second byte.                */
#define  PROBE_RS232_TX_STATE_DATA                         8    /* Waiting to send data.                                */
#define  PROBE_RS232_TX_STATE_CHKSUM                       9    /* Waiting to send checksum.                            */
#define  PROBE_RS232_TX_STATE_ED                          10    /* Waiting to send end delimiter.                       */

#define  PROBE_RS232_CHKSUM_EN                      DEF_FALSE    /* DO NOT CHANGE                                        */


/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/

                                                                /* ---------------- RX STATE VARIABLES ---------------- */
static  CPU_INT08U   ProbeRS232_RxState;                        /* Current state of rx state machine.                   */
static  CPU_SIZE_T   ProbeRS232_RxLenRem;                       /* Rem bytes of data to rd.                             */

static  CPU_SIZE_T   ProbeRS232_RxLen;                          /* Length  of data in current pkt.                      */
                                                                /* Data    of current pkt.                              */
static  CPU_INT08U   ProbeRS232_RxBuf[PROBE_RS232_CFG_RX_BUF_SIZE];
#if (PROBE_RS232_CHKSUM_EN == DEF_TRUE)
static  CPU_INT08U   ProbeRS232_RxChkSum;                       /* Checksum of current pkt.                             */
#endif

static  CPU_SIZE_T   ProbeRS232_RxBufWrIx;                      /* Index of next write; also number of bytes in buf.    */


                                                                /* ---------------- TX STATE VARIABLES ---------------- */
static  CPU_INT08U   ProbeRS232_TxState;                        /* Current state of tx state machine.                   */
static  CPU_BOOLEAN  ProbeRS232_TxActiveFlag;                   /* Indicates tx is currently active.                    */

static  CPU_SIZE_T   ProbeRS232_TxLen;                          /* Length  of data in current pkt.                      */
                                                                /* Data    of current pkt.                              */
static  CPU_INT08U   ProbeRS232_TxBuf[PROBE_RS232_CFG_TX_BUF_SIZE];
#if (PROBE_RS232_CHKSUM_EN == DEF_TRUE)
static  CPU_INT08U   ProbeRS232_TxChkSum;                       /* Checksum of current pkt.                             */
#endif

static  CPU_BOOLEAN  ProbeRS232_TxBufInUse;                     /* Indicates tx buf currently holds a pkt.              */
static  CPU_SIZE_T   ProbeRS232_TxBufRdIx;                      /* Index of next read.                                  */



/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  CPU_SIZE_T  ProbeRS232_ParseRxPkt(void);

static  void        ProbeRS232_RxPkt     (void);

static  void        ProbeRS232_RxStoINT8U(CPU_INT08U  rx_data);

static  void        ProbeRS232_RxBufClr  (void);

static  void        ProbeRS232_TxStart   (void);


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


/*
*********************************************************************************************************
*                                          ProbeRS232_Init()
*
* Description : Initialize the RS-232 communication module.
*
* Argument(s) : baud_rate       The RS-232 baud rate which will be passed to the hardware initialization.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  ProbeRS232_Init (CPU_INT32U baud_rate)
{
    ProbeRS232_RxState             =  PROBE_RS232_RX_STATE_SD0; /* Setup rx & tx state machines.                        */
    ProbeRS232_TxState             =  PROBE_RS232_TX_STATE_SD0;

    ProbeRS232_TxLen               =  0;
    ProbeRS232_TxActiveFlag        =  DEF_FALSE;
    ProbeRS232_TxBufInUse          =  DEF_FALSE;

#if (PROBE_COM_CFG_STAT_EN         == DEF_ENABLED)
    ProbeRS232_RxCtr               =  0;
    ProbeRS232_TxCtr               =  0;
#endif

#if (PROBE_RS232_CFG_PARSE_TASK_EN == DEF_ENABLED)
    ProbeRS232_OS_Init();
#endif

⌨️ 快捷键说明

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