📄 probe_com.c
字号:
* | . | |
* +---------------------------------------------------+ ---
*
*********************************************************************************************************
*/
static CPU_INT16U ProbeCom_CmdMultipleRd (CPU_INT08U *rx_buf,
CPU_INT08U *tx_buf,
CPU_INT16U rx_pkt_sz,
CPU_INT16U tx_buf_sz)
{
CPU_INT08U *tx_buf_start;
CPU_INT16U tx_length;
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
tx_buf_start = tx_buf; /* Save beginning of TX buffer in case packet */
/* ... ends up being too long. */
tx_length = PROBE_COM_SIZE_TX_HEADER; /* Initial TX packet length = 4 = size of header */
if (rx_pkt_sz < 7) { /* If the RX data packet is NOT expected size */
/* = 2 (= Rx header size ) */
/* + 5 (= 1 item descriptor) */
return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
}
/* No error (yet) */
/* (a) Save TX data segment header */
tx_buf[0] = PROBE_COM_FMT_TX_MULTIPLE_RD_LO; /* (i) TX packet format */
tx_buf[1] = PROBE_COM_FMT_TX_MULTIPLE_RD_HI;
tx_buf[2] = PROBE_COM_STATUS_OK; /* (ii) Target status */
tx_buf[3] = ProbeCom_PktModifier(); /* (iii) Modifier */
tx_buf += PROBE_COM_SIZE_TX_HEADER;
rx_pkt_ix = 7; /* (b) Receive packet index after first item */
/* = 2 (= Rx header size ) */
/* + 5 (= 1 item descriptor) */
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
sym_ctr = 0;
sym_byte_ctr = 0;
#endif
/* (c) Store data for each item */
while (rx_pkt_ix <= rx_pkt_sz) {
nbytes = rx_buf[0];
#if ((!defined(CPU_CFG_ADDR_SIZE)) || \
((defined(CPU_CFG_ADDR_SIZE)) && \
(CPU_CFG_ADDR_SIZE != CPU_WORD_SIZE_16)))
addr = (rx_buf[4] << 8) + rx_buf[3];
addr = (addr << 8) + rx_buf[2];
addr = (addr << 8) + rx_buf[1];
#else
addr = (rx_buf[2] << 8) + rx_buf[1];
#endif
rx_buf += 5;
tx_length += nbytes; /* (iii) Add number of bytes to pkt len. */
if (tx_length > tx_buf_sz) { /* (iv) Will be too long for TX buffer? */
tx_buf = tx_buf_start;
return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_TX_PKT_TOO_LARGE));
}
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
sym_ctr++; /* (v) Increment local sym. counter */
sym_byte_ctr += nbytes;
#endif
/* (vi) Otherwise, save TX data */
Mem_Copy((void *)tx_buf,
(void *)addr,
(CPU_SIZE_T)nbytes);
tx_buf += nbytes;
rx_pkt_ix += 5;
}
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
ProbeCom_TxSymCtr += sym_ctr; /* Increment global sym. counter */
ProbeCom_TxSymByteCtr += sym_byte_ctr;
#endif
return (tx_length);
}
/*
*********************************************************************************************************
* ProbeCom_CmdStrGet()
*
* Description : Parse the FMT_STR_GET command & formulate response. This command asks the target
* to send a string that it is currently storing.
*
* Argument(s) : rx_buf Pointer to the receive buffer
*
* tx_buf Pointer to the transmit buffer
*
* rx_pkt_sz Size of the receive packet
*
* tx_buf_sz Size of the transmit buffer
*
* Return(s) : 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 padding.
*
* +-------------------------+-------------------------+
* | Format | Padding |
* +-------------------------+-------------------------+
*
* (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) A n-byte string , the string which is stored in the target's buffer.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+
* | String |
* | . |
* | . |
* | . |
* +---------------------------------------------------+
*
* (3) See Notes for 'ProbeCom_TxStr()'.
*
* (4) uC/Probe requires that a NULL byte ends the string. Consequently, if the data
* section of the TX packet is n bytes long, then only (n - 1) bytes have been read
* from the string buffer.
*********************************************************************************************************
*/
#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
static CPU_INT16U ProbeCom_CmdStrGet (CPU_INT08U *rx_buf,
CPU_INT08U *tx_buf,
CPU_INT16U rx_pkt_sz,
CPU_INT16U tx_buf_sz)
{
CPU_INT16U wr_ix;
CPU_INT16U rd_ix;
CPU_INT16U nbytes;
CPU_INT16U nbytes_rd;
CPU_INT16U rd_ix_n;
CPU_INT16U tx_max;
wr_ix = ProbeComStrBufWrIx;
rd_ix = ProbeComStrBufRdIx;
nbytes = 0;
if (rx_pkt_sz == 4) { /* If RX data segment is the expected size */
/* = 2 (= Rx header size) */
/* + 2 (= Padding ) */
if (wr_ix == rd_ix) { /* (a) If there is NO string, then error */
return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_STR_NONE));
}
} else { /* If RX data segment is NOT the expected size */
return (ProbeCom_CmdError(tx_buf, PROBE_COM_STATUS_RX_PKT_WRONG_SIZE));
}
/* (a) Save TX data segment header */
ProbeCom_StoINT16U(&tx_buf, PROBE_COM_FMT_TX_STR_GET); /* (i) TX packet format */
ProbeCom_StoINT8U( &tx_buf, PROBE_COM_STATUS_OK); /* (ii) Target status */
ProbeCom_StoINT8U( &tx_buf, 0); /* (iii) Modifier */
tx_max = tx_buf_sz - PROBE_COM_SIZE_TX_HEADER - 1; /* ( ) Calculate size of largest tx string. */
if (wr_ix > rd_ix) { /* (b) If wr_ix > rd_ix */
/* ... Store in pkt the bytes [rd_ix, wr_ix) */
nbytes_rd = wr_ix - rd_ix; /* (i) Calculate num. bytes to read */
if (nbytes_rd >= tx_max) { /* (ii) If too much to fit in packet */
/* .... Store only [rd_ix,rd_ix + tx_buf_sz - 5)*/
/* .... Where 5 = 1 (NULL byte) */
/* + 4 (TX header) */
nbytes_rd = tx_max;
rd_ix_n = rd_ix + tx_max;
} else {
rd_ix_n = wr_ix;
}
nbytes = nbytes_rd; /* (iii) Store number of bytes read */
/* (iv) Read from the string buffer */
Mem_Copy((void *)tx_buf,
(void *)&ProbeComStrBuf[rd_ix],
(CPU_SIZE_T)nbytes_rd);
*(tx_buf + nbytes) = 0; /* (vi) Store NULL byte */
} else { /* (c) If wr_ix < rd_ix */
/* ... Store in pkt the bytes [rd_ix, end_ix) */
/* ... Then store in pkt the bytes [0, wr_ix) */
nbytes_rd = PROBE_COM_STR_BUF_SIZE - rd_ix; /* (i) Calculate num. bytes to read */
if (nbytes_rd >= tx_max) { /* (ii) If to much to fit in packet */
/* .... Store only [rd_ix, rd_ix + tx_buf_sz) */
nbytes = tx_max; /* (A) Store number of bytes read */
rd_ix_n = rd_ix + tx_max;
/* (B) Read from string buffer */
Mem_Copy((void *)tx_buf,
(void *)&ProbeComStrBuf[rd_ix],
(CPU_SIZE_T)nbytes);
*(tx_buf + nbytes) = 0; /* (C) Store NULL byte */
} else { /* (iii) If not too much for packet */
/* ------- [rd_ix, end_ix) ------ */
nbytes = nbytes_rd; /* (A) Store number of bytes read */
rd_ix_n = 0; /* (B) Buffer read ix after read */
/* (C) Read from the string buffer */
Mem_Copy((void *)tx_buf,
(void *)&ProbeComStrBuf[rd_ix],
(CPU_SIZE_T)nbytes_rd);
rd_ix = rd_ix_n; /* (D) Update local read index */
/* --------- [0, wr_ix) --------- */
tx_buf += nbytes_rd;
nbytes_rd = wr_ix; /* (E) Number of bytes to read */
/* (F) Too much to fit in packet */
if (nbytes_rd + nbytes >= tx_max) {
nbytes_rd = tx_max - nbytes; /* ... Store only [0, tx_buf_sz - 5] */
}
nbytes += nbytes_rd; /* (G) Update total num. bytes read */
rd_ix_n = rd_ix + nbytes_rd; /* (H) Buffer read ix after read */
/* (I) Read from the string buffer */
Mem_Copy((void *)tx_buf,
(void *)&ProbeComStrBuf[rd_ix],
(CPU_SIZE_T)nbytes_rd);
*(tx_buf + nbytes_rd) = 0; /* (J) Store NULL byte */
}
}
ProbeComStrBufRdIx = rd_ix_n; /* (d) Update global read index */
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
ProbeCom_TxStrCtr += nbytes;
#endif
re
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -