📄 probe_com.c
字号:
*
* Description: This routine is called to send an error response when the target receives a request it
* cannot handle.
*
* Argument(s): tx_buf is a pointer to the transmit buffer
* com_error is the error that occurred
*
* Returns : The number of bytes written to the tx buffer.
*
* Note(s) : (1) The TX format:
* (A) A 2-byte format , indicating the data segment format; AND
* (B) A 1-byte constant, PROBE_RS232_OK, if the location can be read; OR
* A 1-byte constant, PROBE_RS232_FAIL, if the location cannot be read.
* (C) A 1-byte modifier.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+
*
*********************************************************************************************************
*/
static CPU_INT16U ProbeCom_CmdError (CPU_INT08U *tx_buf, CPU_INT16U com_error)
{
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
ProbeCom_ErrPktCtr++;
#endif
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_ERROR); /* (a) TX packet format */
ProbeCom_StoINT8U( &tx_buf, com_error); /* (b) Target status */
ProbeCom_StoINT8U( &tx_buf, ProbeCom_PktModifier()); /* (c) Modifier */
return (4); /* (d) Return TX data segment size */
/* = 4 (= Tx header size) */
}
/*
*********************************************************************************************************
* Respond to FMT_QUERY Command
*
* Description: This routine is called to parse the FMT_QUERY command. This command asks the target
* about its capabilities, which are returned in response.
*
* Argument(s): rx_buf is a pointer to the receive buffer
* tx_buf is a pointer to the transmit buffer
* rx_pkt_sz is the size of the receive packet
* tx_buf_sz is the size of the transmit buffer
*
* Returns : The number of bytes written to the tx buffer.
*
* Note(s) : (1) The RX format:
*
* (A) A 2-byte format , indicating the data segment format; AND
* (B) A 2-byte query , indicating the length of the remaining data.
*
* +-------------------------+-------------------------+
* | Format | Query |
* +-------------------------+-------------------------+
*
* (2) The TX format:
* (A) A 2-byte format , indicating the data segment format; AND
* (B) A 1-byte status , indicating the status after the request; AND
* (C) A 1-byte modifier; AND
* (E) A n-byte answer , the answer to the query.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+
* | Answer |
* | . |
* | . |
* | . |
* +---------------------------------------------------+
*
*********************************************************************************************************
*/
static CPU_INT16U ProbeCom_CmdQuery (CPU_INT08U *rx_buf, CPU_INT08U *tx_buf, CPU_INT16U rx_pkt_sz, CPU_INT16U tx_buf_sz)
{
CPU_INT16U query;
CPU_INT16U nbytes;
CPU_INT08U error;
error = PROBE_COM_STATUS_OK;
nbytes = 0;
if (rx_pkt_sz == 4) { /* If RX data segment is the expected size */
/* = 2 (= Rx header size) */
/* + 2 (= Query ) */
query = ProbeCom_GetINT16U(&rx_buf); /* (a) Read the query */
switch (query) {
case PROBE_COM_QUERY_MAX_RX_SIZE:
case PROBE_COM_QUERY_MAX_TX_SIZE:
case PROBE_COM_QUERY_FMT_SUPPORT:
break;
default:
error = PROBE_COM_STATUS_QUERY_NOT_SUPPORTED;
break;
}
} else { /* If RX data segment is NOT the expected size */
error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE;
}
if (error != PROBE_COM_STATUS_OK) { /* Error */
return (ProbeCom_CmdError(tx_buf, error));
}
/* No error */
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_QUERY); /* (a) TX packet format */
ProbeCom_StoINT8U( &tx_buf, PROBE_COM_STATUS_OK); /* (b) Target status */
ProbeCom_StoINT8U( &tx_buf, ProbeCom_PktModifier()); /* (c) Modifier */
/* (d) Save TX data segment data */
switch (query) {
case PROBE_COM_QUERY_MAX_RX_SIZE:
ProbeCom_StoINT32U(&tx_buf, PROBE_COM_RX_MAX_SIZE);
nbytes = 4;
break;
case PROBE_COM_QUERY_MAX_TX_SIZE:
ProbeCom_StoINT32U(&tx_buf, PROBE_COM_TX_MAX_SIZE);
nbytes = 4;
break;
case PROBE_COM_QUERY_FMT_SUPPORT:
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_RX_QUERY );
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_RX_SIMPLE_RD );
nbytes = 4;
#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_RX_SIMPLE_WR );
nbytes += 2;
#endif
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_RX_MULTIPLE_RD);
nbytes += 2;
#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_RX_STR_GET);
nbytes += 2;
#endif
break;
default:
break;
}
return (nbytes + 4); /* (e) Return TX data segment size */
/* = nbytes (= Tx data size) */
/* + 4 (= Tx header size) */
}
/*
*********************************************************************************************************
* Respond to FMT_SIMPLE_RD Request
*
* Description: This routine is called to parse the FMT_SIMPLE_RD request. This command causes the target
* to send data read from its memory for a certain {memory address, data length} pair (which
* is given in the request).
*
* Argument(s): rx_buf is a pointer to the receive buffer
* tx_buf is a pointer to the transmit buffer
* rx_pkt_sz is the size of the receive packet
* tx_buf_sz is the size of the transmit buffer
*
* Returns : The number of bytes written to the tx buffer.
*
* Note(s) : (1) The RX format:
* (A) A 2-byte format , indicating the data segment format; AND
* (B) A 2-byte length , indicating the number of bytes to read; AND
* (C) A 4-byte address , the starting address of the data to read.
*
* +-------------------------+-------------------------+
* | Format | Number of bytes |
* +-------------------------+-------------------------+
* | Address |
* +-------------------------+-------------------------+
*
* (2) The TX format:
* (A) A 2-byte format , indicating the data segment format; AND
* (B) A 1-byte status , indicating the status after the request; AND
* (C) A 1-byte modifier; AND
* (D) The memory data.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+
* | Data |
* | . |
* | . |
* | . |
* +---------------------------------------------------+
*
*********************************************************************************************************
*/
static CPU_INT16U ProbeCom_CmdSimpleRd (CPU_INT08U *rx_buf, CPU_INT08U *tx_buf, CPU_INT16U rx_pkt_sz, CPU_INT16U tx_buf_sz)
{
CPU_INT32U addr;
CPU_INT16U nbytes;
CPU_INT08U error;
error = PROBE_COM_STATUS_OK;
if (rx_pkt_sz == 8) { /* If RX data segment is the expected size */
/* = 2 (= Rx header size ) */
/* + 2 (= Number of bytes) */
/* + 4 (= Address ) */
nbytes = ProbeCom_GetINT16U(&rx_buf); /* (a) Read the number of bytes to return */
addr = ProbeCom_GetINT32U(&rx_buf); /* (b) Read the memory address */
if (nbytes + 4 > tx_buf_sz) { /* (c) If TX packet will NOT fit in buffer */
error = PROBE_COM_STATUS_TX_PKT_TOO_LARGE; /* (i) Error */
}
} else { /* If RX data segment is NOT the expected size */
error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE;
}
if (error != PROBE_COM_STATUS_OK) { /* Error */
return (ProbeCom_CmdError(tx_buf, error));
} else { /* No error */
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
ProbeCom_TxSymCtr++; /* (a) Increment transmit symbol counter */
ProbeCom_TxSymByteCtr += nbytes;
#endif
/* (b) Save TX data segment header */
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_SIMPLE_RD); /* (i) TX packet format */
ProbeCom_StoINT8U( &tx_buf, PROBE_COM_STATUS_OK); /* (ii) Target status */
ProbeCom_StoINT8U( &tx_buf, ProbeCom_PktModifier()); /* (iii) Modifier */
Mem_Copy((void *)tx_buf, (void *)addr, nbytes); /* (c) Save TX data segment data */
return (nbytes + 4); /* (d) Return TX data segment size */
/* = nbytes (= Tx data size) */
/* + 4 (= Tx header size) */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -