📄 probe_com.c
字号:
* | 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_ADDR addr;
CPU_INT16U nbytes;
CPU_INT08U error;
addr = 0;
nbytes = 0;
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 = (CPU_ADDR)ProbeCom_GetINT32U(&rx_buf); /* (b) Read the memory address */
if (nbytes + PROBE_COM_SIZE_TX_HEADER > 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 + PROBE_COM_SIZE_TX_HEADER); /* (d) Return TX data segment size */
/* = nbytes (= Tx data size) */
/* + 4 (= Tx header size) */
}
}
/*
*********************************************************************************************************
* Respond to FMT_SIMPLE_WR Request
*
* Description: This routine is called to parse the FMT_SIMPLE_WR request. 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): 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 write; AND
* (C) A 4-byte address , the starting address of the data to read; AND
* (D) The memory data.
*
* +-------------------------+-------------------------+
* | Format | Number of bytes |
* +-------------------------+-------------------------+
* | Address |
* +---------------------------------------------------+
* | Data |
* | . |
* | . |
* | . |
* +---------------------------------------------------+
*
* (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.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+
*
*********************************************************************************************************
*/
#if (PROBE_COM_SUPPORT_WR == DEF_TRUE)
static CPU_INT16U ProbeCom_CmdSimpleWr (CPU_INT08U *rx_buf,
CPU_INT08U *tx_buf,
CPU_INT16U rx_pkt_sz,
CPU_INT16U tx_buf_sz)
{
CPU_INT16U nbytes;
CPU_ADDR addr;
CPU_INT08U error;
error = PROBE_COM_STATUS_OK;
if (rx_pkt_sz >= 8) { /* If RX data segment is an expected size */
/* = 2 (= Rx header size ) */
/* + 2 (= Number of bytes) */
/* + 4 (= Address ) */
/* + nbytes (= Data ) */
nbytes = ProbeCom_GetINT16U(&rx_buf); /* (a) Read the number of bytes to write */
addr = (CPU_ADDR)ProbeCom_GetINT32U(&rx_buf); /* (b) Read the memory address */
if (rx_pkt_sz != 8 + nbytes) { /* (c) If RX data segment is NOT expected size */
error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE; /* (i) Error */
}
} else { /* If RX data segment is NOT an expected size */
error = PROBE_COM_STATUS_RX_PKT_WRONG_SIZE; /* (a) Error */
}
if (error != PROBE_COM_STATUS_OK) { /* Error */
return (ProbeCom_CmdError(tx_buf, error));
} else { /* No error */
Mem_Copy((void *)addr, (void *)rx_buf, nbytes); /* (a) Store data into memory */
/* (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 */
}
return (PROBE_COM_SIZE_TX_HEADER); /* Return TX data segment size */
/* = 4 (= Tx header size) */
}
#endif
/*
*********************************************************************************************************
* Respond to FMT_MULTIPLE_RD Request
*
* Description: This routine is called to parse the FMT_MULTIPLE_RD request. This command causes the
* target to write into its memory the data specified in a certain set of {memory address,
* data length, data} triplets (which are 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 5-byte item descriptor , for each item in the list, consisting of:
*
* (I) A 4-byte address , the starting address of the data to read; AND
* (II) 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; AND
* (B) A 1-byte status , indicating the status after the request; AND
* (C) A 1-byte modifier; AND
* (D) If the list is available, for each item, the following is sent:
*
* (I) The memory data.
*
* +-------------------------+------------+------------+
* | Format | Status | Modifier |
* +-------------------------+------------+------------+ ---
* | Data | | Item 1
* | . | |
* | . | |
* | . | |
* +---------------------------------------------------+ ---
* | . | .
* | . | .
* | . | .
* | . | .
* | . | .
* +---------------------------------------------------+ ---
* | Data | | Item n
* | . | |
* | . | |
* | . | |
* +---------------------------------------------------+ ---
*
*********************************************************************************************************
*/
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_INT32U tx_length;
CPU_INT32U addr;
CPU_INT16U nbytes;
CPU_INT32U rx_pkt_ix;
#if (PROBE_COM_STAT_EN == DEF_ENABLED)
CPU_INT32U sym_ctr;
CPU_INT32U sym_byte_ctr;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -