# Copyright (c) 2021 Percepio AB
# SPDX-License-Identifier: Apache-2.0

menu "RTT Config"
config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_UP_BUFFER_SIZE
	int "RTT buffer size up"
	default 5000
	range 0 1048576
	help
	  Defines the size of the "up" RTT buffer (target -> host) to use for writing
	  the trace data, for RTT buffer 1 or higher.
	  
	  This setting is ignored for RTT buffer 0, which can't be reconfigured
	  in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.
	  
	  Default buffer size for Tracealyzer is 5000 bytes.
	  If you have a stand-alone J-Link probe, the can be decreased to around 1 KB.
	  But integrated J-Link OB interfaces are slower and needs about 5-10 KB,
	  depending on the amount of data produced.

config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_DOWN_BUFFER_SIZE
	int "RTT buffer size down"
	default 32
	range 0 1048576
	help
	  Defines the size of the "down" RTT buffer (host -> target) to use for reading
	  commands from Tracealyzer, for RTT buffer 1 or higher.
	  
	  Default buffer size for Tracealyzer is 32 bytes.
	  
	  This setting is ignored for RTT buffer 0, which can't be reconfigured
	  in runtime and therefore hard-coded to use the defines in SEGGER_RTT_Conf.h.

config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_UP_BUFFER_INDEX
	int "RTT buffer up index"
	default 1
	range 0 32
	help
	  Defines the RTT buffer to use for writing the trace data. Make sure that
	  the PC application has the same setting (File->Settings).
	  
	  Default: 1
	  
	  We don't recommend using RTT buffer 0, since mainly intended for terminals.
	  If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h. 

config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_DOWN_BUFFER_INDEX
	int "RTT buffer down index"
	default 1
	range 0 32
	help
	  Defines the RTT buffer to use for reading the trace data. Make sure that
	  the PC application has the same setting (File->Settings).
	  
	  Default: 1
	  
	  We don't recommend using RTT buffer 0, since mainly intended for terminals.
	  If you prefer to use buffer 0, it must be configured in SEGGER_RTT_Conf.h.

choice PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE
	prompt "RTT Blocking Mode"
	default PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_NO_BLOCK_SKIP
	help
	  This stream port for J-Link streaming relies on SEGGER RTT, that contains an
	  internal RAM buffer read by the J-Link probes during execution.
	  
	  Possible values:
	    - PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_BLOCK_IF_FIFO_FULL
	    - PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_NO_BLOCK_SKIP (default)
	  
	  Using PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_BLOCK_IF_FIFO_FULL ensure that you get a
	  complete and valid trace. This may however cause blocking if your streaming
	  interface isn't fast enough, which may disturb the real-time behavior.
	  
	  We therefore recommend PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_NO_BLOCK_SKIP. In this mode,
	  Tracealyzer will report lost events if the transfer is not
	  fast enough. In that case, try increasing the size of the "up buffer".
		
config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_NO_BLOCK_SKIP
	bool "Skip: Do not block, output nothing."

config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_MODE_BLOCK_IF_FIFO_FULL
	bool "Block: Wait until there is space in the buffer."
endchoice

menu "Hidden RTT Settings"
	visible if n
config PERCEPIO_TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER
	bool "Use internal buffer"
	default n
endmenu # Hidden RTT Settings

if PERCEPIO_TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER
config PERCEPIO_TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_SIZE
	int "Internal buffer size"
	range 32 10485760
	default 10240

choice PERCEPIO_TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_TRANSFER_MODE
	prompt "Internal buffer transfer mode"
	default PERCEPIO_TRC_INTERNAL_EVENT_BUFFER_OPTION_TRANSFER_MODE_ALL

config PERCEPIO_TRC_INTERNAL_EVENT_BUFFER_OPTION_TRANSFER_MODE_ALL
	bool "Transfer all"

config PERCEPIO_TRC_INTERNAL_EVENT_BUFFER_OPTION_TRANSFER_MODE_CHUNK
	bool "Transfer chunks"
endchoice

if PERCEPIO_TRC_INTERNAL_EVENT_BUFFER_OPTION_TRANSFER_MODE_CHUNK
config PERCEPIO_TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_CHUNK_SIZE
	int "Chunk size"
	range 4 10485760
	default 2048

config PERCEPIO_TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_SIZE_LIMIT
	int "Transfer size limit for immediate re-transfer"
	range 4 10485760
	default 1024
	help
	  Defines the number of transferred bytes needed to trigger another immediate transfer.
	  This will increase throughput by immediately doing a transfer and not wait for another xTraceTzCtrl() loop.

config PERCEPIO_TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_COUNT_LIMIT
	int "Immediate re-transfer count limit"
	range 1 20
	default 5
	help
	  Defines the maximum number of times to trigger another immediate transfer before returning to xTraceTzCtrl().
	  This will increase throughput by immediately doing a transfer and not wait for another xTraceTzCtrl() loop.
endif # PERCEPIO_TRC_INTERNAL_EVENT_BUFFER_OPTION_TRANSFER_MODE_CHUNK
endif # PERCEPIO_TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER

config PERCEPIO_TRC_CFG_STREAM_PORT_RTT_NO_LOCK_WRITE
	bool "No lock write"
	default y if PERCEPIO_TRC_CFG_RECORDER_RTOS_ZEPHYR
	help
	  Sets if RTT should write without locking or not when writing
	  RTT data. This should normally be disabled with an exception being
	  Zephyr, where the SEGGER RTT locks aren't necessary and causes
	  problems if enabled.
endmenu # menu "RTT Config"
