RTT 主机侧
以下内容自动抽取自 sdk-headers/HFLinkDriver_rtt.h ,含 12 个公开函数及全部公开类型。函数指针回调类型不单独列出,见所属结构体成员说明。
枚举
-
enum HFLink_RTTCommand
RTT control commands (per SEGGER JLINKARM_RTTERMINAL_CMD_*)
Values:
-
enumerator HFLINK_RTT_CMD_START
Start RTT (locate the control block + register the background poll task); p = HFLink_RTT_START* or NULL
-
enumerator HFLINK_RTT_CMD_STOP
Stop RTT; p = HFLink_RTT_STOP* or NULL
-
enumerator HFLINK_RTT_CMD_GETNUMBUF
Query the number of up/down buffers; p = HFLink_RTT_NUMBUF* (required)
-
enumerator HFLINK_RTT_CMD_GETDESC
Query buffer description (name/size/flags); p = HFLink_RTT_BUFDESC* (required)
-
enumerator HFLINK_RTT_CMD_SETTELNETCFG
Configure the telnet server (must be called before START); p = HFLink_RTT_TELNETCFG* (required)
-
enumerator HFLINK_RTT_CMD_START
结构体
-
struct HFLink_RTT_START
START command parameters (per SEGGER JLINK_RTTERMINAL_START).
-
struct HFLink_RTT_STOP
STOP command parameters (per SEGGER JLINK_RTTERMINAL_STOP).
-
struct HFLink_RTT_NUMBUF
GETNUMBUF command parameters (per SEGGER: Direction in, NumBuffers out).
-
struct HFLink_RTT_BUFDESC
GETDESC command parameters (per SEGGER JLINK_RTTERMINAL_BUFDESC).
Public Members
-
int32_t BufferIndex
In: buffer index within the direction (0-based)
-
uint32_t Direction
In: HFLINK_RTT_DIRECTION_UP / HFLINK_RTT_DIRECTION_DOWN
-
char acName[HFLINK_RTT_NAME_SIZE]
Out: buffer name, NUL-terminated (target sName; empty if unnamed)
-
uint32_t SizeOfBuffer
Out: buffer size in bytes (0 for unconfigured channels)
-
uint32_t Flags
Out: target-side SEGGER_RTT_MODE_* flags
-
int32_t BufferIndex
-
struct HFLink_RTT_TELNETCFG
SETTELNETCFG command parameters: configure the telnet server (HFLinkSDK extension, no SEGGER equivalent)
The telnet server starts/stops automatically with RTT START/STOP (default 127.0.0.1:19021); this command must be called before START, and calling it while RTT is running returns HFLINK_ERR_BUSY. If the port is already in use, startup is silently skipped (no warning, START is unaffected; the condition is only observable via GetLastError), and the RTT API data plane is unaffected.
API
-
int HFLink_RTT_Control(HFLink_RTTHandle *rtt, uint32_t cmd, void *p)
Execute an RTT control command (per SEGGER JLINK_RTTERMINAL_Control)
CMD_START: locate and validate the control block (first time), then register the poll task with the CoreSight polling scheduler; idempotent, returns 0 when already running. Returns HFLINK_ERR_NOT_INITIALIZED when no debug session is attached to the target.
CMD_STOP: unregister the poll task (in-flight callbacks have exited on return). Returns 0 if RTT was running, 1 if it was not (SEGGER semantics); negative values are errors.
CMD_GETNUMBUF / CMD_GETDESC: return HFLINK_ERR_NOT_INITIALIZED (-2) when RTT was not started, matching the -2 of SEGGER's "RTT Control Block not found yet".
- 参数:
cmd -- HFLINK_RTT_CMD_* command
p -- Pointer to the command parameter struct (see each command; START/STOP may be NULL)
- 返回:
>= 0 on success (CMD_STOP: 0/1 distinguishes the previous state); < 0 error code
-
int HFLink_RTT_Read(HFLink_RTTHandle *rtt, uint32_t buffer_index, uint8_t *s_buffer, uint32_t buffer_size)
Read up-channel data from the host-side buffer (per SEGGER JLINK_RTTERMINAL_Read)
Pure memory copy: data is moved from the target into the host buffer by the background poll task; this call never accesses the debug bus and never blocks. Data is consumed on read (same as SEGGER).
- 参数:
buffer_index -- up-channel index (0-based)
s_buffer -- Output buffer
buffer_size -- Output buffer capacity
- 返回:
>= 0 actual number of bytes read (0 if no new data); < 0 error code
-
int HFLink_RTT_Write(HFLink_RTTHandle *rtt, uint32_t buffer_index, const uint8_t *s_buffer, uint32_t buffer_size)
Write data to a down channel (host -> target; per SEGGER JLINK_RTTERMINAL_Write)
Synchronous write into the target-side ring buffer; when space is insufficient, writing stops once the buffer is full and the actual number of bytes written is returned (same partial-write semantics as SEGGER). In M0/M0+ degraded mode, writes while the target is running return 0.
- 参数:
buffer_index -- down-channel index (0-based)
s_buffer -- Data to write
buffer_size -- Number of bytes to write
- 返回:
>= 0 actual number of bytes written; < 0 error code
-
int HFLink_RTT_GetNumBytesOnBuffer(const HFLink_RTTHandle *rtt, uint32_t buffer_index, uint32_t *num_bytes)
Query the number of readable bytes in the host buffer (semantics of the newer SEGGER JLINK_RTTERMINAL_GetNumBytesOnBuffer)
Pure memory query; never touches the debug bus. The watermark only covers data already harvested into the host buffer; new data not yet harvested from the target is not counted.
- 参数:
buffer_index -- up-channel index (0-based)
num_bytes -- Outputs the number of readable bytes
- 返回:
HFLINK_OK; HFLINK_ERR_NOT_INITIALIZED if not started; HFLINK_ERR if the channel is invalid
-
HFLink_RTTHandle *HFLink_RTT_Create(HFLink_CoreSightTarget *target)
Create an RTT session. If target is NULL, only configuration calls are allowed (START returns an error).
-
void HFLink_RTT_Destroy(HFLink_RTTHandle *rtt)
Destroy the session (unregisters the poll task and frees all resources automatically).
-
int HFLink_RTT_SetScanRange(HFLink_RTTHandle *rtt, uint64_t base, uint64_t size)
Set the automatic scan range (Method 1)
备注
If no range is set, an error is returned when the scan path is ultimately taken; the range also bounds structure validation of explicit addresses
-
int HFLink_RTT_SetLuaState(HFLink_RTTHandle *rtt, HFLink_LuaState *state)
Bind a Lua runtime (Method 2: the hf.rtt.set_control_block setting is read at START).
-
int HFLink_RTT_SetPollInterval(HFLink_RTTHandle *rtt, uint32_t interval_ms)
Set the background poll interval (milliseconds, default 2; range 1..1000)
备注
Takes effect immediately while RTT is running (implemented internally by unregistering + re-registering with the scheduler)
-
int HFLink_RTT_GetControlBlockAddress(const HFLink_RTTHandle *rtt, uint64_t *address)
Query the located control block address (returns HFLINK_ERR_NOT_INITIALIZED if not located).
-
int HFLink_RTT_GetLastError(const HFLink_RTTHandle *rtt, char *buffer, int length)
Query the most recent error description (outputs an empty string when there is no error).
-
int HFLink_RTT_GetLuaConfiguredAddress(HFLink_LuaState *state, uint64_t *address)
Read the address configured via hf.rtt.set_control_block in the Lua runtime (Method 2)
- 返回:
HFLINK_OK with a valid *address; HFLINK_ERR if not configured