ESP-IDF
Select one of the symbols to view example projects that use it.
Symbol previews are coming soon...
Outline
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "esp_attr.h"
#include "esp_freertos_hooks.h"
#include "esp_cpu.h"
#include "sdkconfig.h"
#include "esp_pm.h"
#include "esp_private/pm_impl.h"
#define MAX_HOOKS
hooks_spinlock
idle_cb
tick_cb
esp_vApplicationTickHook()
for
(n = 0; n < MAX_HOOKS; n++)
if
(tick_cb[core][n] != NULL)
esp_vApplicationIdleHook()
for
(int n = 0; n < MAX_HOOKS; n++)
if
(idle_cb[core][n] != NULL && !idle_cb[core][n]())
if
(!can_go_idle)
esp_register_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t, UBaseType_t)
if
(cpuid >= CONFIG_FREERTOS_NUMBER_OF_CORES)
for
(int n = 0; n < MAX_HOOKS; n++)
if
(idle_cb[cpuid][n] == NULL)
esp_register_freertos_idle_hook(esp_freertos_idle_cb_t)
esp_register_freertos_tick_hook_for_cpu(esp_freertos_tick_cb_t, UBaseType_t)
if
(cpuid >= CONFIG_FREERTOS_NUMBER_OF_CORES)
for
(int n = 0; n < MAX_HOOKS; n++)
if
(tick_cb[cpuid][n] == NULL)
esp_register_freertos_tick_hook(esp_freertos_tick_cb_t)
esp_deregister_freertos_idle_hook_for_cpu(esp_freertos_idle_cb_t, UBaseType_t)
if
(cpuid >= CONFIG_FREERTOS_NUMBER_OF_CORES)
for
(int n = 0; n < MAX_HOOKS; n++)
if
(idle_cb[cpuid][n] == old_idle_cb)
esp_deregister_freertos_idle_hook(esp_freertos_idle_cb_t)
for
(int m = 0; m < CONFIG_FREERTOS_NUMBER_OF_CORES; m++)
esp_deregister_freertos_tick_hook_for_cpu(esp_freertos_tick_cb_t, UBaseType_t)
if
(cpuid >= CONFIG_FREERTOS_NUMBER_OF_CORES)
for
(int n = 0; n < MAX_HOOKS; n++)
if
(tick_cb[cpuid][n] == old_tick_cb)
esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t)
for
(int m = 0; m < CONFIG_FREERTOS_NUMBER_OF_CORES; m++)
Files
loading (3/5)...
SourceVu
ESP-IDF Framework and Examples
ESP-IDF
components/esp_system/freertos_hooks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* ... */
#include
<
stdint.h>
#include
<
stdlib.h>
#include
<
stdbool.h>
#include
"
freertos
/
FreeRTOS.h"
#include
"
esp_attr.h"
#include
"
esp_freertos_hooks.h"
#include
"
esp_cpu.h"
#include
"
sdkconfig.h"
8 includes
#if
CONFIG_PM_ENABLE
#include
"
esp_pm.h"
#include
"
esp_private
/
pm_impl.h"
/* ... */
#endif
//We use just a static array here because it's not expected many components will need
//an idle or tick hook.
#define
MAX_HOOKS
8
static
portMUX_TYPE
hooks_spinlock
=
portMUX_INITIALIZER_UNLOCKED
;
static
esp_freertos_idle_cb_t
idle_cb
[
CONFIG_FREERTOS_NUMBER_OF_CORES
]
[
MAX_HOOKS
]
=
{
0
}
;
static
esp_freertos_tick_cb_t
tick_cb
[
CONFIG_FREERTOS_NUMBER_OF_CORES
]
[
MAX_HOOKS
]
=
{
0
}
;
void
IRAM_ATTR
esp_vApplicationTickHook
(
void
)
{
int
n
;
int
core
=
xPortGetCoreID
(
)
;
for
(
n
=
0
;
n
<
MAX_HOOKS
;
n
++
)
{
if
(
tick_cb
[
core
]
[
n
]
!=
NULL
)
{
tick_cb
[
core
]
[
n
]
(
)
;
}
{...}
}
{...}
}
{ ... }
void
esp_vApplicationIdleHook
(
void
)
{
bool
can_go_idle
=
true
;
int
core
=
xPortGetCoreID
(
)
;
for
(
int
n
=
0
;
n
<
MAX_HOOKS
;
n
++
)
{
if
(
idle_cb
[
core
]
[
n
]
!=
NULL
&&
!
idle_cb
[
core
]
[
n
]
(
)
)
{
can_go_idle
=
false
;
}
{...}
}
{...}
if
(
!
can_go_idle
)
{
return
;
}
{...}
#ifdef
CONFIG_PM_ENABLE
esp_pm_impl_idle_hook
(
)
;
esp_pm_impl_waiti
(
)
;
/* ... */
#else
esp_cpu_wait_for_intr
(
)
;
#endif
}
{ ... }
esp_err_t
esp_register_freertos_idle_hook_for_cpu
(
esp_freertos_idle_cb_t
new_idle_cb
,
UBaseType_t
cpuid
)
{
if
(
cpuid
>=
CONFIG_FREERTOS_NUMBER_OF_CORES
)
{
return
ESP_ERR_INVALID_ARG
;
}
{...}
portENTER_CRITICAL
(
&
hooks_spinlock
)
;
for
(
int
n
=
0
;
n
<
MAX_HOOKS
;
n
++
)
{
if
(
idle_cb
[
cpuid
]
[
n
]
==
NULL
)
{
idle_cb
[
cpuid
]
[
n
]
=
new_idle_cb
;
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
return
ESP_OK
;
}
{...}
}
{...}
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
return
ESP_ERR_NO_MEM
;
}
{ ... }
esp_err_t
esp_register_freertos_idle_hook
(
esp_freertos_idle_cb_t
new_idle_cb
)
{
return
esp_register_freertos_idle_hook_for_cpu
(
new_idle_cb
,
xPortGetCoreID
(
)
)
;
}
{ ... }
esp_err_t
esp_register_freertos_tick_hook_for_cpu
(
esp_freertos_tick_cb_t
new_tick_cb
,
UBaseType_t
cpuid
)
{
if
(
cpuid
>=
CONFIG_FREERTOS_NUMBER_OF_CORES
)
{
return
ESP_ERR_INVALID_ARG
;
}
{...}
portENTER_CRITICAL
(
&
hooks_spinlock
)
;
for
(
int
n
=
0
;
n
<
MAX_HOOKS
;
n
++
)
{
if
(
tick_cb
[
cpuid
]
[
n
]
==
NULL
)
{
tick_cb
[
cpuid
]
[
n
]
=
new_tick_cb
;
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
return
ESP_OK
;
}
{...}
}
{...}
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
return
ESP_ERR_NO_MEM
;
}
{ ... }
esp_err_t
esp_register_freertos_tick_hook
(
esp_freertos_tick_cb_t
new_tick_cb
)
{
return
esp_register_freertos_tick_hook_for_cpu
(
new_tick_cb
,
xPortGetCoreID
(
)
)
;
}
{ ... }
void
esp_deregister_freertos_idle_hook_for_cpu
(
esp_freertos_idle_cb_t
old_idle_cb
,
UBaseType_t
cpuid
)
{
if
(
cpuid
>=
CONFIG_FREERTOS_NUMBER_OF_CORES
)
{
return
;
}
{...}
portENTER_CRITICAL
(
&
hooks_spinlock
)
;
for
(
int
n
=
0
;
n
<
MAX_HOOKS
;
n
++
)
{
if
(
idle_cb
[
cpuid
]
[
n
]
==
old_idle_cb
)
{
idle_cb
[
cpuid
]
[
n
]
=
NULL
;
}
{...}
}
{...}
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
}
{ ... }
void
esp_deregister_freertos_idle_hook
(
esp_freertos_idle_cb_t
old_idle_cb
)
{
portENTER_CRITICAL
(
&
hooks_spinlock
)
;
for
(
int
m
=
0
;
m
<
CONFIG_FREERTOS_NUMBER_OF_CORES
;
m
++
)
{
esp_deregister_freertos_idle_hook_for_cpu
(
old_idle_cb
,
m
)
;
}
{...}
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
}
{ ... }
void
esp_deregister_freertos_tick_hook_for_cpu
(
esp_freertos_tick_cb_t
old_tick_cb
,
UBaseType_t
cpuid
)
{
if
(
cpuid
>=
CONFIG_FREERTOS_NUMBER_OF_CORES
)
{
return
;
}
{...}
portENTER_CRITICAL
(
&
hooks_spinlock
)
;
for
(
int
n
=
0
;
n
<
MAX_HOOKS
;
n
++
)
{
if
(
tick_cb
[
cpuid
]
[
n
]
==
old_tick_cb
)
{
tick_cb
[
cpuid
]
[
n
]
=
NULL
;
}
{...}
}
{...}
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
}
{ ... }
void
esp_deregister_freertos_tick_hook
(
esp_freertos_tick_cb_t
old_tick_cb
)
{
portENTER_CRITICAL
(
&
hooks_spinlock
)
;
for
(
int
m
=
0
;
m
<
CONFIG_FREERTOS_NUMBER_OF_CORES
;
m
++
)
{
esp_deregister_freertos_tick_hook_for_cpu
(
old_tick_cb
,
m
)
;
}
{...}
portEXIT_CRITICAL
(
&
hooks_spinlock
)
;
}
{ ... }
Details
Show:
from
Types:
Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.
xPortGetCoreID()
esp_register_freertos_idle_hook_for_cpu()
esp_deregister_freertos_idle_hook_for_cpu()
esp_cpu_wait_for_intr()
esp_register_freertos_tick_hook_for_cpu()
esp_vApplicationTickHook()
esp_vApplicationIdleHook()
esp_register_freertos_tick_hook()
esp_deregister_freertos_tick_hook_for_cpu()
esp_register_freertos_idle_hook()
esp_deregister_freertos_idle_hook()
esp_deregister_freertos_tick_hook()
NULL
esp_err_t
ESP_OK
false
true
ESP_ERR_INVALID_ARG
ESP_ERR_NO_MEM
UBaseType_t
IRAM_ATTR
portEXIT_CRITICAL
portENTER_CRITICAL
portMUX_INITIALIZER_UNLOCKED
hooks_spinlock
esp_freertos_idle_cb_t
esp_freertos_tick_cb_t
MAX_HOOKS
idle_cb
tick_cb
esp_register_freertos_idle_hook_for_cpu()::cpuid
esp_register_freertos_tick_hook_for_cpu()::cpuid
esp_deregister_freertos_idle_hook_for_cpu()::cpuid
esp_deregister_freertos_tick_hook_for_cpu()::cpuid
esp_register_freertos_idle_hook_for_cpu()::new_idle_cb
esp_register_freertos_idle_hook()::new_idle_cb
esp_register_freertos_tick_hook_for_cpu()::new_tick_cb
esp_register_freertos_tick_hook()::new_tick_cb
esp_deregister_freertos_idle_hook_for_cpu()::old_idle_cb
esp_deregister_freertos_idle_hook()::old_idle_cb
esp_deregister_freertos_tick_hook_for_cpu()::old_tick_cb
esp_deregister_freertos_tick_hook()::old_tick_cb
portMUX_TYPE