?? probe_rs232.c
字號:
#endif
ProbeRS232_InitTarget(baud_rate); /* Initialize target specific code */
}
/*
*********************************************************************************************************
*********************************************************************************************************
** Task
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Task for uC/Probe RS-232 Communication Module
*
* Description: This task parses the received packet, forms a response, and begins transmission.
*
* Argument(s): p_arg is passed to ProbeRS232_Task() by OSCreateTask().
*
* Returns : None
*********************************************************************************************************
*/
#if (PROBE_RS232_PARSE_TASK > 0)
void ProbeRS232_Task (void *p_arg)
{
CPU_INT16U len;
(void)p_arg;
while (DEF_TRUE) {
ProbeRS232_OS_Pend(); /* Wait for a packet to be received */
len = ProbeRS232_ParseRxPkt(); /* Parse packet and formulate a response */
if (len > 0) { /* If we have a response */
ProbeRS232_TxLen = len;
ProbeRS232_TxStart();
}
}
}
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
** Rx and Tx Handlers
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Rx Handler
*
* Description: This routine is called from the Rx interrupt service handler.
*
* Argument(s): rx_data is a received data byte.
*
* Returns : None
*********************************************************************************************************
*/
void ProbeRS232_RxHandler (CPU_INT08U rx_data)
{
ProbeRS232_RxCtr++;
switch (ProbeRS232_RxState) {
case PROBE_RS232_RX_STATE_SD0: /* Receive the start first start delimiter (SD0) */
if (rx_data == PROBE_RS232_PROTOCOL_RX_SD0) {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD1;
ProbeRS232_RxBufClr();
}
break;
case PROBE_RS232_RX_STATE_SD1: /* Receive the start second start delimiter (SD1) */
if (rx_data == PROBE_RS232_PROTOCOL_RX_SD1) {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD2;
} else {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD0;
}
break;
case PROBE_RS232_RX_STATE_SD2: /* Receive the start third start delimiter (SD2) */
if (rx_data == PROBE_RS232_PROTOCOL_RX_SD2) {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD3;
} else {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD0;
}
break;
case PROBE_RS232_RX_STATE_SD3: /* Receive the start fourth start delimiter (SD3) */
if (rx_data == PROBE_RS232_PROTOCOL_RX_SD3) {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_LEN1;
} else {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD0;
}
break;
case PROBE_RS232_RX_STATE_LEN1: /* Receive the first length byte */
ProbeRS232_RxChkSum = rx_data;
ProbeRS232_RxRemainLen = rx_data;
ProbeRS232_RxState = PROBE_RS232_RX_STATE_LEN2;
break;
case PROBE_RS232_RX_STATE_LEN2: /* Receive the second length byte */
ProbeRS232_RxChkSum += rx_data;
ProbeRS232_RxRemainLen |= rx_data << 8;
if ((ProbeRS232_RxRemainLen == 0) || (ProbeRS232_RxRemainLen > PROBE_RS232_RX_BUF_SIZE)) {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD0; /* ... Cannot handle a packet of this size */
} else {
ProbeRS232_RxLen = ProbeRS232_RxRemainLen;
ProbeRS232_RxState = PROBE_RS232_RX_STATE_PAD1;
}
break;
case PROBE_RS232_RX_STATE_PAD1: /* Receive the first padding byte */
ProbeRS232_RxState = PROBE_RS232_RX_STATE_PAD2;
break;
case PROBE_RS232_RX_STATE_PAD2: /* Receive the second padding byte */
ProbeRS232_RxState = PROBE_RS232_RX_STATE_DATA;
break;
case PROBE_RS232_RX_STATE_DATA: /* Receive the data */
ProbeRS232_RxStoINT8U(rx_data);
ProbeRS232_RxChkSum += rx_data;
if (--ProbeRS232_RxRemainLen == 0) {
ProbeRS232_RxState = PROBE_RS232_RX_STATE_CHKSUM;
}
break;
case PROBE_RS232_RX_STATE_CHKSUM: /* Receive the checksum */
ProbeRS232_RxChkSum += rx_data;
ProbeRS232_RxState = PROBE_RS232_RX_STATE_ED;
break;
case PROBE_RS232_RX_STATE_ED: /* Receive the end delimiter */
if (rx_data == PROBE_RS232_PROTOCOL_RX_ED) {
ProbeRS232_RxPktCtr++; /* ... Increment Rx packet counter */
ProbeRS232_RxPkt(); /* ... Parse received packet */
}
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD0;
break;
default:
ProbeRS232_RxState = PROBE_RS232_RX_STATE_SD0;
break;
}
}
/*
*********************************************************************************************************
* Tx Handler
*
* Description: This routine is called from the transmitter buffer empty interrupt service handler.
* It will send out the next byte in the buffer.
*
* Argument(s): None.
*
* Returns : None
*********************************************************************************************************
*/
void ProbeRS232_TxHandler (void)
{
CPU_INT08U tx_data;
switch (ProbeRS232_TxState) {
case PROBE_RS232_TX_STATE_SD0:
if (ProbeRS232_TxLen > 0) { /* If packet is waiting to be sent */
ProbeRS232_Tx1(PROBE_RS232_PROTOCOL_TX_SD0); /* ... Transmit start first start delimiter (SD0) */
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxActiveFlag = DEF_TRUE; /* ... Transmit in process */
ProbeRS232_TxState = PROBE_RS232_TX_STATE_SD1;
ProbeRS232_TxBufRdIx = 0;
} else { /* If no packet is waiting to be sent */
ProbeRS232_TxActiveFlag = DEF_FALSE; /* ... Transmission not active */
ProbeRS232_TxIntDis(); /* ... Disable transmit interrupts */
}
break;
case PROBE_RS232_TX_STATE_SD1: /* Transmit start second start delimiter (SD1) */
ProbeRS232_Tx1(PROBE_RS232_PROTOCOL_TX_SD1);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxState = PROBE_RS232_TX_STATE_SD2;
break;
case PROBE_RS232_TX_STATE_SD2: /* Transmit start third start delimiter (SD2) */
ProbeRS232_Tx1(PROBE_RS232_PROTOCOL_TX_SD2);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
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_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxState = PROBE_RS232_TX_STATE_LEN1;
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -