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

📄 probe_rs232.c

📁 ucos-ii 的完整代码
💻 C
📖 第 1 页 / 共 3 页
字号:
             ProbeRS232_TxState = PROBE_RS232_TX_STATE_SD3;
             break;

        case PROBE_RS232_TX_STATE_SD3:                              /* Transmit start fourth start delimiter (SD3)          */
             ProbeRS232_Tx1(PROBE_RS232_PROTOCOL_TX_SD3);
             ProbeRS232_TxState = PROBE_RS232_TX_STATE_LEN1;
             break;


        case PROBE_RS232_TX_STATE_LEN1:                             /* Transmit first  length byte                          */
             tx_data             = ProbeRS232_TxLen & 0xFF;
             ProbeRS232_Tx1(tx_data);
             ProbeRS232_TxState  = PROBE_RS232_TX_STATE_LEN2;
#if (PROBE_RS232_USE_CHECKSUM == DEF_TRUE)
             ProbeRS232_TxChkSum = tx_data;
#endif
             break;

        case PROBE_RS232_TX_STATE_LEN2:                             /* Transmit second length byte                          */
             tx_data              = ProbeRS232_TxLen >> 8;
             ProbeRS232_Tx1(tx_data);
             ProbeRS232_TxState   = PROBE_RS232_TX_STATE_PAD1;
#if (PROBE_RS232_USE_CHECKSUM == DEF_TRUE)
             ProbeRS232_TxChkSum += tx_data;
#endif
             break;


        case PROBE_RS232_TX_STATE_PAD1:                             /* Transmit first  padding byte                         */
             ProbeRS232_Tx1(0);
             ProbeRS232_TxState = PROBE_RS232_TX_STATE_PAD2;
             break;

        case PROBE_RS232_TX_STATE_PAD2:                             /* Transmit second padding byte                         */
             ProbeRS232_Tx1(0);
             ProbeRS232_TxState = PROBE_RS232_TX_STATE_DATA;
             break;


        case PROBE_RS232_TX_STATE_DATA:                             /* Transmit data                                        */
             tx_data = ProbeRS232_TxBuf[ProbeRS232_TxBufRdIx];
             ProbeRS232_Tx1(tx_data);
#if (PROBE_RS232_USE_CHECKSUM == DEF_TRUE)
             ProbeRS232_TxChkSum += tx_data;
#endif
             ProbeRS232_TxBufRdIx++;
             if (ProbeRS232_TxBufRdIx >= ProbeRS232_TxLen) {        /* ... If all data has been sent                        */
                 ProbeRS232_TxState = PROBE_RS232_TX_STATE_CHKSUM;
                 ProbeRS232_TxLen   = 0;
             }
             break;


        case PROBE_RS232_TX_STATE_CHKSUM:                           /* Transmit checksum                                    */
#if (PROBE_RS232_USE_CHECKSUM == DEF_TRUE)
             ProbeRS232_Tx1(ProbeRS232_TxChkSum);
#else
             ProbeRS232_Tx1(0);
#endif
             ProbeRS232_TxState = PROBE_RS232_TX_STATE_ED;
             break;


        case PROBE_RS232_TX_STATE_ED:                               /* Transmit end delimiter                               */
             ProbeRS232_Tx1(PROBE_RS232_PROTOCOL_TX_ED);
             ProbeRS232_TxState    = PROBE_RS232_TX_STATE_SD0;
             ProbeRS232_TxBufInUse = DEF_FALSE;
             break;


        default:
             ProbeRS232_TxState      = PROBE_RS232_TX_STATE_SD0;
             ProbeRS232_TxActiveFlag = DEF_FALSE;
             ProbeRS232_TxIntDis();                                 /* No more data to send, disable Tx interrupts          */
             break;
    }
}


/*
*********************************************************************************************************
*********************************************************************************************************
**                                  Static Packet-Handling Functions
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                       ProbeRS232_ParseRxPkt()
*
* Description : Parse a received packet & formulate a response.
*
* Argument(s) : none.
*
* Return(s)   : The number of bytes in the data segment of the packet to transmit in response.
*********************************************************************************************************
*/

static  CPU_INT16U  ProbeRS232_ParseRxPkt (void)
{
    CPU_INT16U  temp;


    if (ProbeRS232_TxBufInUse == DEF_TRUE) {                        /* Do cmds only if Tx buffer is free                    */
        return (0);
    }

    ProbeRS232_TxBufInUse = DEF_TRUE;
    temp                  = ProbeCom_ParseRxPkt((void     *)ProbeRS232_RxBuf,
                                                (void     *)ProbeRS232_TxBuf,
                                                (CPU_INT16U)ProbeRS232_RxLen,
                                                (CPU_INT16U)PROBE_RS232_TX_BUF_SIZE);

    return (temp);
}


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

/*
*********************************************************************************************************
*                                           ProbeRS232_RxPkt()
*
* Description : Handle a received packet.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  ProbeRS232_RxPkt (void)
{
#if (PROBE_RS232_PARSE_TASK > 0)
    ProbeRS232_OS_Post();                                           /* We have a whole packet, signal task to parse it      */



#else



#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR      cpu_sr = 0;
#endif
    CPU_INT16U  len;


    len = ProbeRS232_ParseRxPkt();                                  /* We have a whole packet, parse it                     */
    if (len > 0) {
        CPU_CRITICAL_ENTER();
        ProbeRS232_TxLen = len;
        ProbeRS232_TxStart();
        CPU_CRITICAL_EXIT();
    }
#endif
}


/*
*********************************************************************************************************
*                                   ProbeRS232_RxStoINT8U()
*
* Description : Store a byte in the receive buffer.
*
* Argument(s) : rx_data     Byte of data to store in the buffer.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  ProbeRS232_RxStoINT8U (CPU_INT08U rx_data)
{
    if (ProbeRS232_RxBufWrIx < PROBE_RS232_RX_BUF_SIZE) {
        ProbeRS232_RxBuf[ProbeRS232_RxBufWrIx++] = rx_data;
    }
}


/*
*********************************************************************************************************
*                                           ProbeRS232_RxBufClr()
*
* Description : Clear the data segment buffer write index.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  ProbeRS232_RxBufClr (void)
{
    ProbeRS232_RxBufWrIx = 0;
}


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

/*
*********************************************************************************************************
*                                        ProbeRS232_TxStart()
*
* Description : Cause transmission to begin.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/

static  void  ProbeRS232_TxStart (void)
{
    if (ProbeRS232_TxActiveFlag == DEF_FALSE) {                     /* If no other transmission is in progress              */
        ProbeRS232_TxHandler();                                     /*  ... Handle transmit                                 */
        ProbeRS232_TxIntEn();                                       /*  ... Enable transmit interrupts                      */
    }
}


#endif

⌨️ 快捷键说明

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