logging: swo: Add option to set custom reference frequency

Some devices may use different reference than cpu clock. Add
support for using swo-ref-frequency property when present.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-02-10 00:22:05 -08:00 committed by Carles Cufí
commit 1a5fce97b7

View file

@ -36,18 +36,26 @@
#if CONFIG_LOG_BACKEND_SWO_FREQ_HZ == 0 #if CONFIG_LOG_BACKEND_SWO_FREQ_HZ == 0
#define SWO_FREQ_DIV 1 #define SWO_FREQ_DIV 1
#else #else
#if DT_NODE_HAS_PROP(DT_PATH(cpus, cpu_0), clock_frequency)
#define CPU_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) /* Set reference frequency which can be custom or cpu frequency. */
#if DT_NODE_HAS_PROP(DT_PATH(cpus, cpu_0), swo_ref_frequency)
#define SWO_REF_FREQ DT_PROP(DT_PATH(cpus, cpu_0), swo_ref_frequency)
#elif DT_NODE_HAS_PROP(DT_PATH(cpus, cpu_0), clock_frequency)
#define SWO_REF_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency)
#else #else
#error "Missing DT 'clock-frequency' property on cpu@0 node" #error "Missing DT 'clock-frequency' property on cpu@0 node"
#endif #endif
#define SWO_FREQ (CPU_FREQ + (CONFIG_LOG_BACKEND_SWO_FREQ_HZ / 2))
#define SWO_FREQ_DIV (SWO_FREQ / CONFIG_LOG_BACKEND_SWO_FREQ_HZ) #define SWO_FREQ_DIV \
((SWO_REF_FREQ + (CONFIG_LOG_BACKEND_SWO_FREQ_HZ / 2)) / \
CONFIG_LOG_BACKEND_SWO_FREQ_HZ)
#if SWO_FREQ_DIV > 0xFFFF #if SWO_FREQ_DIV > 0xFFFF
#error CONFIG_LOG_BACKEND_SWO_FREQ_HZ is too low. SWO clock divider is 16-bit. \ #error CONFIG_LOG_BACKEND_SWO_FREQ_HZ is too low. SWO clock divider is 16-bit. \
Minimum supported SWO clock frequency is \ Minimum supported SWO clock frequency is \
[CPU Clock Frequency]/2^16. [Reference Clock Frequency]/2^16.
#endif #endif
#endif #endif
static uint8_t buf[1]; static uint8_t buf[1];