~aleteoryx/muditaos

fb22548963ca132274054e26e61634dca631fdc9 — Maciej Gibowicz 5 years ago a7403f8
[EGD-4723] PowerManagement: Enable FreeRTOS Run Time Statistics (#1147)

Add FreeRTOS Run Time Statistics for measuring CPU load
M changelog.md => changelog.md +1 -0
@@ 18,6 18,7 @@
* `[text]` Added vertical scrolling.
* `[text]` Added cursor starting position handling.
* `[alarms]` Added main window
* `[PowerManagement]` PowerManagement: Enable FreeRTOS Run Time Statistics

### Changed


M module-os/FreeRTOS/include/FreeRTOSConfig.h => module-os/FreeRTOS/include/FreeRTOSConfig.h +6 -1
@@ 95,7 95,7 @@ extern uint32_t SystemCoreClock;
#define configUSE_DAEMON_TASK_STARTUP_HOOK      0

/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS           0
#define configGENERATE_RUN_TIME_STATS           1
#define configUSE_TRACE_FACILITY                1
#define configUSE_STATS_FORMATTING_FUNCTIONS    1
#define configRECORD_STACK_HIGH_ADDRESS		    1


@@ 177,4 177,9 @@ standard names. */
#define configSYSTEM_HEAP_INTEGRITY_CHECK (1)
#endif

extern void vConfigureTimerForRunTimeStats(void);
extern uint32_t ulHighFrequencyTimerTicks(void);
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()
#define portGET_RUN_TIME_COUNTER_VALUE() ulHighFrequencyTimerTicks()

#endif /* FREERTOS_CONFIG_H */

A module-os/board/linux/fsl_runtimestat_gpt.c => module-os/board/linux/fsl_runtimestat_gpt.c +13 -0
@@ 0,0 1,13 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <stdint.h>

void vConfigureTimerForRunTimeStats(void)
{
}

uint32_t ulHighFrequencyTimerTicks(void)
{
	return 0;
}

A module-os/board/rt1051/fsl_runtimestat_gpt.c => module-os/board/rt1051/fsl_runtimestat_gpt.c +39 -0
@@ 0,0 1,39 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "fsl_gpt.h"

static inline GPT_Type *vPortGetGptBase(void)
{
    return GPT1;
}

void vConfigureTimerForRunTimeStats(void)
{
	const gpt_config_t GPT1_config = {
	  .clockSource = kGPT_ClockSource_Periph,
	  // freq = (f_Osc / divider) -> (24 MHz / 2400) = 10 kHz
	  .divider = 2400UL,
	  .enableFreeRun = false,
	  .enableRunInWait = true,
	  .enableRunInStop = true,
	  .enableRunInDoze = false,
	  .enableRunInDbg = false,
	  .enableMode = true
	};

	GPT_Type *pxGptBase = vPortGetGptBase();

	/* GPT device and channels initialization */
	GPT_Init(pxGptBase, &GPT1_config);
	GPT_SetOscClockDivider(pxGptBase, 1);
	/* Enable GPT interrupt sources */
	GPT_EnableInterrupts(pxGptBase, 0);
	/* Start the GPT timer */
	GPT_StartTimer(pxGptBase);
}

uint32_t ulHighFrequencyTimerTicks(void)
{
	return GPT_GetCurrentTimerCount(vPortGetGptBase());
}

M module-os/targets/Target_Linux.cmake => module-os/targets/Target_Linux.cmake +6 -1
@@ 1,4 1,9 @@
set(BOARD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/port.c CACHE INTERNAL "")
set(BOARD_SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/port.c 
        ${CMAKE_CURRENT_SOURCE_DIR}/board/linux/fsl_runtimestat_gpt.c
        
		CACHE INTERNAL ""
		)

set(BOARD_DIR_INCLUDES  ${CMAKE_CURRENT_SOURCE_DIR}/board/linux CACHE INTERNAL "")


M module-os/targets/Target_RT1051.cmake => module-os/targets/Target_RT1051.cmake +1 -0
@@ 1,6 1,7 @@
set(BOARD_SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/fsl_tickless_gpt.c
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/fsl_tickless_systick.c
        ${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/fsl_runtimestat_gpt.c

        CACHE INTERNAL ""
        )