📄 probe_com.c
字号:
* Description : Parse the FMT_MULTIPLE_RD request & formulate respnse. This command causes the target
* to send data read from its memory for a certain set of {memory address, data length}
* pairs (which are given in the request).
*
* Argument(s) : prx_buf Pointer to the receive buffer
*
* ptx_buf Pointer to the transmit buffer
*
* rx_pkt_size Size of the receive packet
*
* tx_buf_size Size of the transmit buffer
*
* Return(s) : The number of bytes written to the tx buffer.
*
* Caller(s) : ProbeCom_ParseRxPkt().
*
* Note(s) : (1) The RX format:
*
* (A) A 2-byte format, indicating the data segment format;
* (B) A 5-byte item descriptor, for each item in the list, consisting of:
*
* (1) A 4-byte address, the starting address of the data to read;
* (2) A 1-byte length, indicating the number of bytes to read.
*
* +-------------------------+------------+------------+
* | Format | Num. bytes | Addr ---
* +-------------------------+------------+------------+ | Item 1
* ress | Num. bytes | ---
* +--------------------------------------+------------+ |
* | Address | | Item 2
* +------------+--------------------------------------+ ---
* | Num. bytes | Addr | Item 3
* +------------+--------------------------------------+ .
* | . | .
* | . | .
* | . | .
* | . | .
* +--------------------------------------+------------+ .
* ress | Num. bytes | ---
* ---------------------------------------+------------+ | Item n
* | Address | |
* +---------------------------------------------------+ ---
*
* (2) The TX format:
*
* (A) A 2-byte format, indicating the data segment format;
* (B) A 1-byte status, indicating the status after the request;
* (C) A 1-byte modifier;
* (D) For each item, the following is sent:
*
* (1) The memory data.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+ ---
* | Data | | Item 1
* | . | |
* | . | |
* | . | |
* +---------------------------------------------------+ ---
* | . | .
* | . | .
* | . | .
* | . | .
* | . | .
* +---------------------------------------------------+ ---
* | Data | | Item n
* | . | |
* | . | |
* | . | |
* +---------------------------------------------------+ ---
*
*********************************************************************************************************
*/
static CPU_INT16U ProbeCom_CmdMultipleRd (CPU_INT08U *prx_buf,
CPU_INT08U *ptx_buf,
CPU_INT16U rx_pkt_size,
CPU_INT16U tx_buf_size)
{
CPU_INT08U *ptx_buf_start;
CPU_INT16U tx_len;
CPU_ADDR addr;
CPU_INT16U nbytes;
CPU_INT16U rx_pkt_ix;
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
CPU_INT16U sym_ctr;
CPU_INT16U sym_byte_ctr;
#endif
/* ------------------- CHK PKT SIZE ------------------- */
/* Expected size >= 2 (= Rx header size ) */
/* + 5 (= 1 item descriptor). */
if (rx_pkt_size < 7) {
return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
}
/* -------------------- HANDLE RD --------------------- */
ptx_buf_start = ptx_buf; /* Save ptr to TX buf in case pkt is too long for buf. */
tx_len = PROBE_COM_SIZE_TX_HDR; /* Initial TX pkt len = 4 = size of hdr. */
/* Store TX pkt hdr : */
ptx_buf[0] = PROBE_COM_FMT_TX_MULTIPLE_RD_LO; /* (a) TX pkt format. */
ptx_buf[1] = PROBE_COM_FMT_TX_MULTIPLE_RD_HI;
ptx_buf[2] = PROBE_COM_STATUS_OK; /* (b) Target status. */
ptx_buf[3] = ProbeCom_PktModifier(); /* (c) Modifier. */
ptx_buf += PROBE_COM_SIZE_TX_HDR;
rx_pkt_ix = 7; /* Recv pkt ix after 1st item = 2 (= Rx header size ) */
/* + 5 (= 1 item descriptor).*/
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
sym_ctr = 0;
sym_byte_ctr = 0;
#endif
/* Store data for each item. */
while (rx_pkt_ix <= rx_pkt_size) {
nbytes = prx_buf[0]; /* (a) Get nbr of bytes to read. */
/* (b) Get read addr. */
#if ((!defined(CPU_CFG_ADDR_SIZE)) || \
((defined(CPU_CFG_ADDR_SIZE)) && \
(CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_16)))
addr = (prx_buf[4] << 8) + prx_buf[3];
addr = (addr << 8) + prx_buf[2];
addr = (addr << 8) + prx_buf[1];
#else
addr = (prx_buf[2] << 8) + prx_buf[1];
#endif
prx_buf += 5;
rx_pkt_ix += 5;
tx_len += nbytes; /* (c) Add nbr of bytes to pkt len. */
if (tx_len > tx_buf_size) { /* (d) Will pkt be too long for TX buf? ... */
ptx_buf = ptx_buf_start; /* ... rtn err. */
return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE));
}
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
sym_ctr++; /* (e) Inc local sym ctr. */
sym_byte_ctr += nbytes;
#endif
/* (f) Otherwise, save TX data. */
Mem_Copy((void *)ptx_buf,
(void *)addr,
(CPU_SIZE_T)nbytes);
ptx_buf += nbytes;
}
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
ProbeCom_TxSymCtr += sym_ctr; /* Inc global sym ctr. */
ProbeCom_TxSymByteCtr += sym_byte_ctr;
#endif
/* ------------------ RTN TX PKT SIZE ----------------- */
return (tx_len);
}
/*
*********************************************************************************************************
* ProbeCom_CmdSimpleWr()
*
* Description : Parse the FMT_SIMPLE_WR request & formulate response. This command causes the target
* to write certain data into its memroy, for a certain {memory address, data length, data}
* triplet (which is given in the request).
*
* Argument(s) : prx_buf Pointer to the receive buffer
*
* ptx_buf Pointer to the transmit buffer
*
* rx_pkt_size Size of the receive packet
*
* tx_buf_size Size of the transmit buffer
*
* Return(s) : The number of bytes written to the tx buffer.
*
* Caller(s) : ProbeCom_ParseRxPkt().
*
* Note(s) : (1) The RX format:
*
* (A) A 2-byte format, indicating the data segment format;
* (B) A 2-byte length, indicating the number of bytes to write;
* (C) A 4-byte address, the starting address at which the data should be written;
* (D) The memory data.
*
* +-------------------------+-------------------------+
* | Format | Number of bytes |
* +-------------------------+-------------------------+
* | Address |
* +---------------------------------------------------+
* | Data |
* | . |
* | . |
* | . |
* +---------------------------------------------------+
*
* (2) The TX format:
*
* (A) A 2-byte format, indicating the data segment format;
* (B) A 1-byte status, indicating the status after the request;
* (C) A 1-byte modifier.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+
*
*********************************************************************************************************
*/
#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
static CPU_INT16U ProbeCom_CmdSimpleWr (CPU_INT08U *prx_buf,
CPU_INT08U *ptx_buf,
CPU_INT16U rx_pkt_size,
CPU_INT16U tx_buf_size)
{
CPU_INT16U nbytes;
CPU_ADDR addr;
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
/* ------------------- CHK PKT SIZE ------------------- */
/* Expected size >= 2 (= Rx header size ) */
/* + 2 (= Number of bytes) */
/* + 4 (= Address ) */
/* + nbytes (= Data ). */
if (rx_pkt_size < 8) {
return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
}
/* -------------------- HANDLE WR --------------------- */
nbytes = ProbeCom_GetINT16U(&prx_buf); /* Get nbr of bytes to write. */
/* Get write addr. */
#if ((!defined(CPU_CFG_ADDR_SIZE)) || \
((defined(CPU_CFG_ADDR_SIZE)) && \
(CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_16)))
addr = (CPU_ADDR)ProbeCom_GetINT32U(&prx_buf);
#else
addr = (CPU_ADDR)ProbeCom_GetINT16U(&prx_buf);
#endif
if (rx_pkt_size != (8 + nbytes)) { /* If RX data segment is NOT expected size ... rtn err. */
return (ProbeCom_CmdErr(ptx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
}
/* Copy data into memory. */
CPU_CRITICAL_ENTER();
Mem_Copy((void *)addr,
(void *)prx_buf,
(CPU_SIZE_T)nbytes);
CPU_CRITICAL_EXIT();
/* Store TX pkt hdr : */
ProbeCom_StoINT16U(&ptx_buf, PROBE_COM_FMT_TX_SIMPLE_WR); /* (a) TX pkt format. */
ProbeCom_StoINT8U( &ptx_buf, PROBE_COM_STATUS_OK); /* (b) Target status. */
ProbeCom_StoINT8U( &ptx_buf, ProbeCom_PktModifier()); /* (c) Modifier. */
/* ------------------ RTN TX PKT SIZE ----------------- */
return ((CPU_INT16U)(PROBE_COM_SIZE_TX_HDR)); /* Tx pkt size = 4 (= Tx header size). */
}
#endif
/*
*********************************************************************************************************
* ProbeCom_CmdMultipleWr()
*
* Description : Parse the FMT_MULTIPLE_WR request & formulate response. This command causes the target
* to write certain data into its memroy, for a certain number of {memory address, data
* length, data} triplets (which are given in the request).
*
* Argument(s) : prx_buf Pointer to the receive buffer
*
* ptx_buf Pointer to the transmit buffer
*
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -