?? probe_rs232.c
字號:
case PROBE_RS232_TX_STATE_LEN1: /* Transmit first length byte */
tx_data = ProbeRS232_TxLen & 0xFF;
ProbeRS232_Tx1(tx_data);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxState = PROBE_RS232_TX_STATE_LEN2;
ProbeRS232_TxChkSum = tx_data;
break;
case PROBE_RS232_TX_STATE_LEN2: /* Transmit second length byte */
tx_data = ProbeRS232_TxLen >> 8;
ProbeRS232_Tx1(tx_data);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxState = PROBE_RS232_TX_STATE_PAD1;
ProbeRS232_TxChkSum += tx_data;
break;
case PROBE_RS232_TX_STATE_PAD1: /* Transmit first padding byte */
ProbeRS232_Tx1(0);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxState = PROBE_RS232_TX_STATE_PAD2;
break;
case PROBE_RS232_TX_STATE_PAD2: /* Transmit second padding byte */
ProbeRS232_Tx1(0);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
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);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
ProbeRS232_TxChkSum += tx_data;
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 */
ProbeRS232_Tx1(ProbeRS232_TxChkSum);
ProbeRS232_TxCtr++; /* ... Increment Tx counter */
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_TxCtr++;
ProbeRS232_TxState = PROBE_RS232_TX_STATE_SD0;
ProbeRS232_TxBufInUse = DEF_FALSE;
ProbeRS232_TxPktCtr++;
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
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Parse Receive Packet
*
* Description: This routine is called after a complete packet has been received.
*
* Argument(s): None.
*
* Returns : 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,
ProbeRS232_RxLen,
PROBE_RS232_TX_BUF_SIZE);
return (temp);
}
/*
*********************************************************************************************************
*********************************************************************************************************
** Static Rx Functions
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* PROCESS RECEIVED PACKET
*
* Description: This function is called when a packet has been received and needs to be processed.
*
* Argument(s): None.
*
* Returns : 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
}
/*
*********************************************************************************************************
* STORE DATA IN Rx DATA SEGMENT BUFFER
*
* Description: This routine is called whenever a valid byte of a packet's data segment has been received.
*
* Argument(s): rx_data is a byte of data to store in the buffer.
*
* Returns : None.
*********************************************************************************************************
*/
static void ProbeRS232_RxStoINT8U (CPU_INT08U rx_data)
{
if (ProbeRS232_RxBufWrIx < PROBE_RS232_RX_BUF_SIZE) {
ProbeRS232_RxBuf[ProbeRS232_RxBufWrIx++] = rx_data;
}
}
/*
*********************************************************************************************************
* CLEAR Rx BUFFER
*
* Description: This routine clears the data segment buffer write index.
*
* Argument(s): None.
*
* Returns : None.
*********************************************************************************************************
*/
static void ProbeRS232_RxBufClr (void)
{
ProbeRS232_RxBufWrIx = 0;
}
/*
*********************************************************************************************************
*********************************************************************************************************
** Static Tx Functions
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* START TRANSMISSION
*
* Description: This routine causes transmission to begin.
*
* Argument(s): None.
*
* Returns : 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 */
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -