📄 probe_com.c
字号:
/*
*********************************************************************************************************
* uC/Probe Communication
*
* (c) Copyright 2007; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* uC/Probe
*
* Communication: Generic
*
* Filename : probe_com.c
* Version : V1.50
* Programmer(s) : BAN
* Note(s) : (1) This file contains code to respond to generic (non protocol-dependent)
* commands received by the target.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define PROBE_COM_MODULE
#include <probe_com.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA FORMATS
*
* Note(s): (1) The first word in all TX data segments is identical:
*
* (A) A 2-byte format;
* (B) A 1-byte status;
* (C) A 1-byte modifier, currently unused.
*
*
* (2) The first two bytes in all RX data segments is identical:
* (A) A 2-byte format;
*
* (3) The following data formats are currently defined:
*
* (A) PROBE_COM_FMT_?X_QUERY. The RX request queries the target about a particular setup
* parameter or capability.
*
* (B) PROBE_COM_FMT_?X_SIMPLE_RD. The RX request instructs the target to send data read
* from its memory, for a certain {memory address, data length} pair (which is given in
* the request).
*
* (C) PROBE_COM_FMT_?X_SIMPLE_WR. The RX request instructs the target to write certain
* data into its memory, for a certain {memory address, data length, data} triplet
* (which is given in the request).
*
* (D) PROBE_COM_FMT_?X_MULTIPLE_RD. The RX request instructs 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).
*
* (E) PROBE_COM_FMT_?X_STR_RD. The RX request instructs the target to return a string
* that the user has stored in the target's string buffer.
**********************************************************************************************************
*/
#define PROBE_COM_FMT_TX_ERROR 0x8000
#define PROBE_COM_FMT_RX_QUERY 0x0001
#define PROBE_COM_FMT_TX_QUERY 0x8001
#define PROBE_COM_FMT_RX_SIMPLE_RD 0x0002
#define PROBE_COM_FMT_TX_SIMPLE_RD 0x8002
#define PROBE_COM_FMT_RX_SIMPLE_WR 0x0003
#define PROBE_COM_FMT_TX_SIMPLE_WR 0x8003
#define PROBE_COM_FMT_RX_INFO 0x0004
#define PROBE_COM_FMT_TX_INFO 0x8004
#define PROBE_COM_FMT_RX_MULTIPLE_RD 0x0007
#define PROBE_COM_FMT_TX_MULTIPLE_RD 0x8007
#define PROBE_COM_FMT_TX_MULTIPLE_RD_LO 0x07
#define PROBE_COM_FMT_TX_MULTIPLE_RD_HI 0x80
#define PROBE_COM_FMT_RX_MULTIPLE_WR 0x0008
#define PROBE_COM_FMT_TX_MULTIPLE_WR 0x8008
#define PROBE_COM_FMT_RX_STR_RD 0x0009
#define PROBE_COM_FMT_TX_STR_RD 0x8009
#define PROBE_COM_FMT_RX_STR_WR 0x000A
#define PROBE_COM_FMT_TX_STR_WR 0x800A
#define PROBE_COM_FMT_RX_TELEMETRY_GET 0x000B
#define PROBE_COM_FMT_TX_TELEMETRY_GET 0x800B
/*
*********************************************************************************************************
* STATUS CONSTANTS
*
* Note(s): (1) The following status constants are currently defined:
*
* (A) PROBE_COM_STATUS_OK. The target was able to respond to the command.
*
* (B) PROBE_COM_STATUS_STR_NONE. A PROBE_COM_FMT_RX_STR_GET packet is received, but the
* target has no string to send.
*
* (C) PROBE_COM_STATUS_UNKNOWN_REQUEST. A request packet with an unknown type was
* received.
*
* (D) PROBE_COM_STATUS_QUERY_NOT_SUPPORTED. A PROBE_COM_FMT_RX_QUERY packet is received,
* but the query is not supported.
*
* (E) PROBE_COM_STATUS_TX_PKT_TOO_LARGE. The response to the request would be too large
* to fit into the target.
*
* (F) PROBE_COM_STATUS_RX_PKT_WRONG_SIZE. The request packet is not the expected size.
*
* (G) PROBE_COM_STATUS_FAIL. Another error occurred.
**********************************************************************************************************
*/
#define PROBE_COM_STATUS_OK 0x01
#define PROBE_COM_STATUS_TELEMETRY_NONE 0xF7
#define PROBE_COM_STATUS_STR_NONE 0xF8
#define PROBE_COM_STATUS_UNKNOWN_REQUEST 0xF9
#define PROBE_COM_STATUS_QUERY_NOT_SUPPORTED 0xFC
#define PROBE_COM_STATUS_TX_PKT_TOO_LARGE 0xFD
#define PROBE_COM_STATUS_RX_PKT_WRONG_SIZE 0xFE
#define PROBE_COM_STATUS_FAIL 0xFF
/*
*********************************************************************************************************
* QUERIES
*
* Note(s): (1) The following queries are currently defined:
*
* (A) PROBE_COM_QUERY_MAX_RX_SIZE. The target responds with the data size of the largest
* packet it can receive.
*
* (B) PROBE_COM_QUERY_MAX_TX_SIZE. The target responds with the data size of the largest
* packet it can send.
*
* (C) PROBE_COM_ENDIANNESS_TEST. The target responds with a 4-byte data value. On
* little-endian CPUs, this will be received as 0x12345678; on big-endian CPUs, this
* will be received as 0x87654321.
*
* (D) PROBE_COM_QUERY_FMT_SUPPORT. The target responds with a list of the formats the
* target can respond to.
*
* (E) PROBE_COM_QUERY_VERSION. The target responds with the communication module version.
**********************************************************************************************************
*/
/* ------------------- CONFIGURATION ------------------ */
#define PROBE_COM_QUERY_MAX_RX_SIZE 0x0101
#define PROBE_COM_QUERY_MAX_TX_SIZE 0x0102
/* ----------------- TARGET PROPERTIES ---------------- */
#define PROBE_COM_QUERY_ENDIANNESS_TEST 0x0201
/* ------------- COMMUNICATION CAPABILITIES ----------- */
#define PROBE_COM_QUERY_FMT_SUPPORT 0x1001
#define PROBE_COM_QUERY_VERSION 0x1002
/*
*********************************************************************************************************
* INFO PACKET TYPES
*
* Note(s): (1) The following info packet types are currently defined:
*
* (A) PROBE_COM_INFO_PKT_SIZE. Probe supplies the size of the next packet.
**********************************************************************************************************
*/
#define PROBE_COM_INFO_PKT_SIZE 0x0001
/*
*********************************************************************************************************
* MODIFIERS
*
* Note(s): (1) The following modifiers are currently defined:
*
* (A) PROBE_COM_MODIFIER_NONE. This is the generic modifier.
*
* (B) PROBE_COM_MODIFIER_STR_HAVE. The target indicates that it has a string to transmit.
**********************************************************************************************************
*/
#define PROBE_COM_MODIFIER_NONE 0x00
#define PROBE_COM_MODIFIER_STR_HAVE 0x01
#define PROBE_COM_MODIFIER_TELEMETRY_HAVE 0x02
/*
*********************************************************************************************************
* HEADER SIZES
*
* Note(s): (1) Every RX packet has a 2-byte "header".
*
* (2) Every TX packet has a 4-byte "header".
**********************************************************************************************************
*/
#define PROBE_COM_SIZE_RX_HDR 2
#define PROBE_COM_SIZE_TX_HDR 4
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
#if (PROBE_COM_SUPPORT_STR == DEF_TRUE)
static CPU_INT16U ProbeCom_StrBufWrIx;
static CPU_INT16U ProbeCom_StrBufRdIx;
static CPU_CHAR ProbeCom_StrBuf[PROBE_COM_STR_BUF_SIZE];
static PROBE_COM_STR_HDNLR_FNCT ProbeCom_StrHndlr;
#endif
#if (PROBE_COM_SUPPORT_TELEMETRY == DEF_TRUE)
static PROBE_COM_TELEMETRY_BUF ProbeCom_TelemetryBufTbl[PROBE_COM_TELEMETRY_NBR];
static PROBE_COM_TELEMETRY_BUF *ProbeCom_TelemetryFreePoolPtr;
static PROBE_COM_TELEMETRY_BUF *ProbeCom_TelemetryRdyPoolPtr;
static CPU_INT16U ProbeCom_TelemetryBufNbrFree;
static CPU_INT16U ProbeCom_TelemetryBufNbrRdy;
#endif
static CPU_INT32U ProbeCom_EndiannessTest;
static PROBE_COM_INFO_HDNLR_FNCT ProbeCom_InfoHndlr;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
/* ---------- PROCESS REQUEST & FORM RESPONSE --------- */
static CPU_INT08U ProbeCom_PktModifier (void);
static CPU_INT16U ProbeCom_CmdErr (CPU_INT08U *ptx_buf,
CPU_INT08U pcomm_err);
static CPU_INT16U ProbeCom_CmdQuery (CPU_INT08U *prx_buf,
CPU_INT08U *ptx_buf,
CPU_INT16U rx_pkt_size,
CPU_INT16U tx_buf_size);
static CPU_INT16U ProbeCom_CmdInfo (CPU_INT08U *prx_buf,
CPU_INT08U *ptx_buf,
CPU_INT16U rx_pkt_size,
CPU_INT16U tx_buf_size);
static CPU_INT16U ProbeCom_CmdSimpleRd (CPU_INT08U *prx_buf,
CPU_INT08U *ptx_buf,
CPU_INT16U rx_pkt_size,
CPU_INT16U tx_buf_size);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -