📄 probe_rs232.c
字号:
break;
case PROBE_RS232_TX_STATE_LEN1: /* Tx 1st len 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: /* Tx 2nd len 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: /* Tx 1st padding byte. */
ProbeRS232_Tx1(0);
ProbeRS232_TxState = PROBE_RS232_TX_STATE_PAD2;
break;
case PROBE_RS232_TX_STATE_PAD2: /* Tx 2nd padding byte. */
ProbeRS232_Tx1(0);
ProbeRS232_TxState = PROBE_RS232_TX_STATE_DATA;
break;
case PROBE_RS232_TX_STATE_DATA: /* Tx 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) {
ProbeRS232_TxState = PROBE_RS232_TX_STATE_CHKSUM;
ProbeRS232_TxLen = 0;
}
break;
case PROBE_RS232_TX_STATE_CHKSUM: /* Tx 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: /* Tx 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, dis tx int's. */
break;
}
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LOCAL 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.
*
* Caller(s) : ProbeRS232_Task(),
* ProbeRS232_RxPkt().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_INT16U ProbeRS232_ParseRxPkt (void)
{
CPU_INT16U tx_len;
if (ProbeRS232_TxBufInUse == DEF_TRUE) { /* Do cmds only if Tx buffer is free. */
return (0);
}
ProbeRS232_TxBufInUse = DEF_TRUE;
tx_len = ProbeCom_ParseRxPkt((void *)ProbeRS232_RxBuf,
(void *)ProbeRS232_TxBuf,
(CPU_INT16U)ProbeRS232_RxLen,
(CPU_INT16U)PROBE_RS232_TX_BUF_SIZE);
return (tx_len);
}
/*
*********************************************************************************************************
* ProbeRS232_RxPkt()
*
* Description : Handle a received packet.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ProbeRS232_RxHandler().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void ProbeRS232_RxPkt (void)
{
#if (PROBE_RS232_PARSE_TASK == DEF_TRUE)
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.
*
* Caller(s) : ProbeRS232_RxHandler().
*
* Note(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.
*
* Caller(s) : ProbeRS232_RxHandler().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void ProbeRS232_RxBufClr (void)
{
ProbeRS232_RxBufWrIx = 0;
}
/*
*********************************************************************************************************
* ProbeRS232_TxStart()
*
* Description : Cause transmission to begin.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ProbeRS232_Task(),
* ProbeRS232_RxPkt().
*
* Note(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 + -