Skip to content

Commit 25ffd0f

Browse files
Merge branch 'task/refactor_freertos_port_files' into 'master'
refactor(freertos): Refactor FreeRTOS port files Closes IDF-4172 See merge request espressif/esp-idf!41981
2 parents 53a250b + cf12478 commit 25ffd0f

File tree

10 files changed

+106
-65
lines changed

10 files changed

+106
-65
lines changed

components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/portmacro.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,10 @@ extern void vTaskExitCritical( void );
254254
// ------------------- Run Time Stats ----------------------
255255

256256
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
257-
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
258-
#define portGET_RUN_TIME_COUNTER_VALUE() ((configRUN_TIME_COUNTER_TYPE) esp_timer_get_time())
259-
#else
260-
#define portGET_RUN_TIME_COUNTER_VALUE() 0
261-
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
257+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
258+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void );
259+
#define portGET_RUN_TIME_COUNTER_VALUE() xPortGetRunTimeCounterValue()
260+
#endif
262261

263262
// --------------------- TCB Cleanup -----------------------
264263

@@ -420,19 +419,13 @@ portmacro.h. Therefore, we need to keep these headers around for now to allow th
420419
#include <stdlib.h>
421420
#include <stdbool.h>
422421
#include <stdarg.h>
422+
#include <limits.h>
423423
#include "esp_attr.h"
424424
#include "esp_newlib.h"
425425
#include "esp_heap_caps.h"
426426
#include "esp_rom_sys.h"
427427
#include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */
428428

429-
/* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */
430-
#include <limits.h>
431-
432-
/* [refactor-todo] introduce a port wrapper function to avoid including esp_timer.h into the public header */
433-
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
434-
#include "esp_timer.h"
435-
#endif
436429

437430
#ifdef __cplusplus
438431
}

components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "port_systick.h"
3232
#include "portmacro.h"
3333
#include "esp_memory_utils.h"
34+
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
35+
#include "esp_timer.h"
36+
#endif
3437
#ifdef CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER
3538
#include "soc/periph_defs.h"
3639
#include "soc/system_reg.h"
@@ -516,3 +519,18 @@ void vApplicationPassiveIdleHook( void )
516519
esp_vApplicationIdleHook(); //Run IDF style hooks
517520
}
518521
#endif // CONFIG_FREERTOS_USE_PASSIVE_IDLE_HOOK
522+
523+
/* ------------------------------------------------ Run Time Stats ------------------------------------------------- */
524+
525+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
526+
527+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void )
528+
{
529+
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
530+
return (configRUN_TIME_COUNTER_TYPE) esp_timer_get_time();
531+
#else
532+
return 0;
533+
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
534+
}
535+
536+
#endif /* CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS */

components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/portmacro.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -239,11 +239,10 @@ extern void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus );
239239

240240
//Timers are already configured, so nothing to do for configuration of run time stats timer
241241
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
242-
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
243-
#define portGET_RUN_TIME_COUNTER_VALUE() ((configRUN_TIME_COUNTER_TYPE) esp_timer_get_time())
244-
#else // Uses CCOUNT
245-
#define portGET_RUN_TIME_COUNTER_VALUE() ((configRUN_TIME_COUNTER_TYPE) xthal_get_ccount())
246-
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
242+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
243+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void );
244+
#define portGET_RUN_TIME_COUNTER_VALUE() xPortGetRunTimeCounterValue()
245+
#endif
247246

248247
// --------------------- TCB Cleanup -----------------------
249248

@@ -451,11 +450,6 @@ portmacro.h. Therefore, we need to keep these headers around for now to allow th
451450
#include <xtensa/config/system.h>
452451
#include <xtensa_api.h>
453452

454-
/* [refactor-todo] introduce a port wrapper function to avoid including esp_timer.h into the public header */
455-
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
456-
#include "esp_timer.h"
457-
#endif
458-
459453
#ifdef __cplusplus
460454
}
461455
#endif

components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include "esp_freertos_hooks.h"
3535
#include "esp_intr_alloc.h"
3636
#include "esp_memory_utils.h"
37+
#include <xtensa/hal.h> /* required for xthal_get_ccount() */
38+
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
39+
#include "esp_timer.h"
40+
#endif
3741
#ifdef CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER
3842
#include "soc/periph_defs.h"
3943
#include "soc/system_reg.h"
@@ -695,3 +699,18 @@ void vApplicationPassiveIdleHook( void )
695699
esp_vApplicationIdleHook(); //Run IDF style hooks
696700
}
697701
#endif // CONFIG_FREERTOS_USE_PASSIVE_IDLE_HOOK
702+
703+
/* ------------------------------------------------ Run Time Stats ------------------------------------------------- */
704+
705+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
706+
707+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void )
708+
{
709+
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
710+
return (configRUN_TIME_COUNTER_TYPE) esp_timer_get_time();
711+
#else // Uses CCOUNT
712+
return (configRUN_TIME_COUNTER_TYPE) xthal_get_ccount();
713+
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
714+
}
715+
716+
#endif /* CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS */

components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* SPDX-License-Identifier: MIT
88
*
9-
* SPDX-FileContributor: 2023-2024 Espressif Systems (Shanghai) CO LTD
9+
* SPDX-FileContributor: 2023-2025 Espressif Systems (Shanghai) CO LTD
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy of
1212
* this software and associated documentation files (the "Software"), to deal in
@@ -71,15 +71,8 @@
7171
#include "esp_heap_caps.h"
7272
#include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */
7373
#include "esp_newlib.h"
74-
75-
/* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */
7674
#include <limits.h>
7775

78-
/* [refactor-todo] introduce a port wrapper function to avoid including esp_timer.h into the public header */
79-
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
80-
#include "esp_timer.h"
81-
#endif
82-
8376
#ifdef __cplusplus
8477
extern "C" {
8578
#endif
@@ -414,11 +407,11 @@ void vApplicationSleep(TickType_t xExpectedIdleTime);
414407
/**
415408
* @brief Get the tick rate per second
416409
*
417-
* @note [refactor-todo] make this inline
418-
* @note [refactor-todo] Check if this function should be renamed (due to uint return type)
410+
* @deprecated This function will be removed in IDF 7.0. Use CONFIG_FREERTOS_HZ directly instead.
411+
* @note [refactor-todo] Remove this function in IDF 7.0 (IDF-14115)
419412
* @return uint32_t Tick rate in Hz
420413
*/
421-
uint32_t xPortGetTickRateHz(void);
414+
uint32_t xPortGetTickRateHz(void) __attribute__((deprecated("This function will be removed in IDF 7.0. Use CONFIG_FREERTOS_HZ directly instead.")));
422415

423416
/**
424417
* @brief Set a watchpoint to watch the last 32 bytes of the stack
@@ -603,11 +596,10 @@ void vPortTCBPreDeleteHook( void *pxTCB );
603596
// ------------------- Run Time Stats ----------------------
604597

605598
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
606-
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
607-
#define portGET_RUN_TIME_COUNTER_VALUE() ((configRUN_TIME_COUNTER_TYPE) esp_timer_get_time())
608-
#else
609-
#define portGET_RUN_TIME_COUNTER_VALUE() 0
610-
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
599+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
600+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void );
601+
#define portGET_RUN_TIME_COUNTER_VALUE() xPortGetRunTimeCounterValue()
602+
#endif
611603

612604
// --------------------- TCB Cleanup -----------------------
613605

components/freertos/FreeRTOS-Kernel/portable/riscv/port.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
#include "portmacro.h"
5757
#include "port_systick.h"
5858
#include "esp_memory_utils.h"
59+
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
60+
#include "esp_timer.h"
61+
#endif
5962

6063
#if SOC_CPU_HAS_HWLOOP
6164
#include "riscv/csr.h"
@@ -874,6 +877,21 @@ void vPortCoprocUsedInISR(void* frame)
874877

875878
#endif /* SOC_CPU_COPROC_NUM > 0 */
876879

880+
/* ------------------------------------------------ Run Time Stats ------------------------------------------------- */
881+
882+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
883+
884+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void )
885+
{
886+
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
887+
return (configRUN_TIME_COUNTER_TYPE) esp_timer_get_time();
888+
#else
889+
return 0;
890+
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
891+
}
892+
893+
#endif /* CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS */
894+
877895
/* ---------------------------------------------- Misc Implementations -------------------------------------------------
878896
*
879897
* ------------------------------------------------------------------------------------------------------------------ */

components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <stdbool.h>
4444
#include <stdarg.h>
4545
#include <xtensa/config/core.h>
46-
#include <xtensa/hal.h> /* required for xthal_get_ccount. [refactor-todo] use cpu_hal instead */
4746
#include <xtensa/xtruntime.h> /* required for XTOS_SET_INTLEVEL. [refactor-todo] add common intr functions to esp_hw_support */
4847
#include "xt_instr_macros.h"
4948
#include "spinlock.h"
@@ -57,16 +56,7 @@
5756
#include "esp_rom_sys.h"
5857
#include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */
5958
#include "portbenchmark.h"
60-
61-
/* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */
6259
#include <limits.h>
63-
#include <xtensa/config/system.h>
64-
#include <xtensa_api.h>
65-
66-
/* [refactor-todo] introduce a port wrapper function to avoid including esp_timer.h into the public header */
67-
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
68-
#include "esp_timer.h"
69-
#endif
7060

7161
#ifdef __cplusplus
7262
extern "C" {
@@ -355,10 +345,11 @@ void vApplicationSleep(TickType_t xExpectedIdleTime);
355345
/**
356346
* @brief Get the tick rate per second
357347
*
358-
* @note [refactor-todo] make this inline
348+
* @deprecated This function will be removed in IDF 7.0. Use CONFIG_FREERTOS_HZ directly instead.
349+
* @note [refactor-todo] Remove this function in IDF 7.0 (IDF-14115)
359350
* @return uint32_t Tick rate in Hz
360351
*/
361-
uint32_t xPortGetTickRateHz(void);
352+
uint32_t xPortGetTickRateHz(void) __attribute__((deprecated("This function will be removed in IDF 7.0. Use CONFIG_FREERTOS_HZ directly instead.")));
362353

363354
/**
364355
* @brief Set a watchpoint to watch the last 32 bytes of the stack
@@ -510,11 +501,10 @@ extern void _frxt_setup_switch( void ); //Defined in portasm.S
510501

511502
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
512503

513-
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
514-
#define portGET_RUN_TIME_COUNTER_VALUE() ((configRUN_TIME_COUNTER_TYPE) esp_timer_get_time())
515-
#else // Uses CCOUNT
516-
#define portGET_RUN_TIME_COUNTER_VALUE() ((configRUN_TIME_COUNTER_TYPE) xthal_get_ccount())
517-
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
504+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
505+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void );
506+
#define portGET_RUN_TIME_COUNTER_VALUE() xPortGetRunTimeCounterValue()
507+
#endif
518508

519509
// --------------------- TCB Cleanup -----------------------
520510

components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#include "task.h" /* Required for TaskHandle_t, tskNO_AFFINITY, and vTaskStartScheduler */
4949
#include "port_systick.h"
5050
#include "esp_cpu.h"
51+
#include <xtensa/hal.h> /* required for xthal_get_ccount() */
52+
#if CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
53+
#include "esp_timer.h"
54+
#endif
5155
#include "esp_memory_utils.h"
5256

5357
_Static_assert(portBYTE_ALIGNMENT == 16, "portBYTE_ALIGNMENT must be set to 16");
@@ -659,3 +663,18 @@ void vPortTCBPreDeleteHook( void *pxTCB )
659663
vPortCleanUpCoprocArea( pxTCB );
660664
#endif /* XCHAL_CP_NUM > 0 */
661665
}
666+
667+
/* ------------------------------------------------ Run Time Stats ------------------------------------------------- */
668+
669+
#if ( CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS )
670+
671+
configRUN_TIME_COUNTER_TYPE xPortGetRunTimeCounterValue( void )
672+
{
673+
#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
674+
return (configRUN_TIME_COUNTER_TYPE) esp_timer_get_time();
675+
#else // Uses CCOUNT
676+
return (configRUN_TIME_COUNTER_TYPE) xthal_get_ccount();
677+
#endif // CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
678+
}
679+
680+
#endif /* CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS */

components/freertos/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ menu "FreeRTOS"
299299

300300
choice FREERTOS_RUN_TIME_COUNTER_TYPE
301301
prompt "configRUN_TIME_COUNTER_TYPE"
302-
depends on FREERTOS_GENERATE_RUN_TIME_STATS && !FREERTOS_SMP
302+
depends on FREERTOS_GENERATE_RUN_TIME_STATS
303303
default FREERTOS_RUN_TIME_COUNTER_TYPE_U32
304304
help
305305
Sets the data type used for the FreeRTOS run time stats. A larger data type can be used to reduce the

components/freertos/config/include/freertos/FreeRTOSConfig.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -168,13 +168,11 @@
168168
#define configUSE_STATS_FORMATTING_FUNCTIONS 1 /* Used by vTaskList() */
169169
#endif /* CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS */
170170

171-
#if !CONFIG_FREERTOS_SMP
172-
#if CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U32
173-
#define configRUN_TIME_COUNTER_TYPE uint32_t
174-
#elif CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U64
175-
#define configRUN_TIME_COUNTER_TYPE uint64_t
176-
#endif /* CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U64 */
177-
#endif /* !CONFIG_FREERTOS_SMP */
171+
#if CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U32
172+
#define configRUN_TIME_COUNTER_TYPE uint32_t
173+
#elif CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U64
174+
#define configRUN_TIME_COUNTER_TYPE uint64_t
175+
#endif /* CONFIG_FREERTOS_RUN_TIME_COUNTER_TYPE_U64 */
178176

179177
/* -------------------- Co-routines ----------------------- */
180178

0 commit comments

Comments
 (0)