logging: log_backend_swo: Get clock frequency from DTS

The log_backend_swo used system clock frequency
as a base for SWO clock calculation. This commit
corrects that by obtaining the needed value from DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit is contained in:
Piotr Zięcik 2019-04-11 14:28:52 +02:00 committed by Carles Cufí
commit 09b64467a9
6 changed files with 9 additions and 5 deletions

View file

@ -18,8 +18,8 @@
* this frequency should much the one set by the SWO viewer program.
*
* The initialization code assumes that SWO core frequency is equal to HCLK
* as defined by SYS_CLOCK_HW_CYCLES_PER_SEC Kconfig option. This may require
* additional, vendor specific configuration.
* as defined by DT_CPU_CLOCK_FREQUENCY. This may require additional,
* vendor specific configuration.
*/
#include <logging/log_backend.h>
@ -36,13 +36,12 @@
#if CONFIG_LOG_BACKEND_SWO_FREQ_HZ == 0
#define SWO_FREQ_DIV 1
#else
#define SWO_FREQ (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
+ (CONFIG_LOG_BACKEND_SWO_FREQ_HZ / 2))
#define SWO_FREQ (DT_CPU_CLOCK_FREQUENCY + (CONFIG_LOG_BACKEND_SWO_FREQ_HZ / 2))
#define SWO_FREQ_DIV (SWO_FREQ / CONFIG_LOG_BACKEND_SWO_FREQ_HZ)
#if SWO_FREQ_DIV > 0xFFFF
#error CONFIG_LOG_BACKEND_SWO_FREQ_HZ is too low. SWO clock divider is 16-bit. \
Minimum supported SWO clock frequency is \
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC/2^16.
[CPU Clock Frequency]/2^16.
#endif
#endif