Skip to content

Commit e56f92a

Browse files
committed
Merge branch 'bugfix/fix_gpio_etm_multi_task_v5.3' into 'release/v5.3'
fix(gpio_etm): allow one GPIO binds to multiple ETM tasks (v5.3) See merge request espressif/esp-idf!30455
2 parents 14315bb + 6658832 commit e56f92a

File tree

20 files changed

+495
-240
lines changed

20 files changed

+495
-240
lines changed

components/esp_driver_gpio/include/driver/gpio_etm.h

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -13,38 +13,49 @@
1313
extern "C" {
1414
#endif
1515

16+
#define GPIO_ETM_EVENT_EDGE_TYPES 3 /*!< GPIO ETM edge events are POS/NEG/ANY */
17+
#define GPIO_ETM_TASK_ACTION_TYPES 3 /*!< GPIO ETM action tasks are SET/CLEAR/TOGGLE */
18+
1619
/**
1720
* @brief GPIO edges that can be used as ETM event
1821
*/
1922
typedef enum {
20-
GPIO_ETM_EVENT_EDGE_POS, /*!< A rising edge on the GPIO will generate an ETM event signal */
21-
GPIO_ETM_EVENT_EDGE_NEG, /*!< A falling edge on the GPIO will generate an ETM event signal */
22-
GPIO_ETM_EVENT_EDGE_ANY, /*!< Any edge on the GPIO can generate an ETM event signal */
23+
GPIO_ETM_EVENT_EDGE_POS = 1, /*!< A rising edge on the GPIO will generate an ETM event signal */
24+
GPIO_ETM_EVENT_EDGE_NEG, /*!< A falling edge on the GPIO will generate an ETM event signal */
25+
GPIO_ETM_EVENT_EDGE_ANY, /*!< Any edge on the GPIO can generate an ETM event signal */
2326
} gpio_etm_event_edge_t;
2427

2528
/**
2629
* @brief GPIO ETM event configuration
30+
*
31+
* If more than one kind of ETM edge event want to be triggered on the same GPIO pin, you can configure them together.
32+
* It helps to save GPIO ETM event channel resources for other GPIOs.
2733
*/
2834
typedef struct {
29-
gpio_etm_event_edge_t edge; /*!< Which kind of edge can trigger the ETM event module */
35+
union {
36+
gpio_etm_event_edge_t edge; /*!< Which kind of edge can trigger the ETM event module */
37+
gpio_etm_event_edge_t edges[GPIO_ETM_EVENT_EDGE_TYPES]; /*!< Array of kinds of edges to trigger the ETM event module on the same GPIO */
38+
};
3039
} gpio_etm_event_config_t;
3140

3241
/**
3342
* @brief Create an ETM event object for the GPIO peripheral
3443
*
3544
* @note The created ETM event object can be deleted later by calling `esp_etm_del_event`
3645
* @note The newly created ETM event object is not bind to any GPIO, you need to call `gpio_etm_event_bind_gpio` to bind the wanted GPIO
46+
* @note Every success call to this function will acquire a free GPIO ETM event channel
3747
*
3848
* @param[in] config GPIO ETM event configuration
3949
* @param[out] ret_event Returned ETM event handle
50+
* @param[out] ... Other returned ETM event handles if any (the order of the returned event handles is aligned with the array order in field `edges` in `gpio_etm_event_config_t`)
4051
* @return
4152
* - ESP_OK: Create ETM event successfully
4253
* - ESP_ERR_INVALID_ARG: Create ETM event failed because of invalid argument
4354
* - ESP_ERR_NO_MEM: Create ETM event failed because of out of memory
4455
* - ESP_ERR_NOT_FOUND: Create ETM event failed because all events are used up and no more free one
4556
* - ESP_FAIL: Create ETM event failed because of other reasons
4657
*/
47-
esp_err_t gpio_new_etm_event(const gpio_etm_event_config_t *config, esp_etm_event_handle_t *ret_event);
58+
esp_err_t gpio_new_etm_event(const gpio_etm_event_config_t *config, esp_etm_event_handle_t *ret_event, ...);
4859

4960
/**
5061
* @brief Bind the GPIO with the ETM event
@@ -65,16 +76,21 @@ esp_err_t gpio_etm_event_bind_gpio(esp_etm_event_handle_t event, int gpio_num);
6576
* @brief GPIO actions that can be taken by the ETM task
6677
*/
6778
typedef enum {
68-
GPIO_ETM_TASK_ACTION_SET, /*!< Set the GPIO level to high */
69-
GPIO_ETM_TASK_ACTION_CLR, /*!< Clear the GPIO level to low */
70-
GPIO_ETM_TASK_ACTION_TOG, /*!< Toggle the GPIO level */
79+
GPIO_ETM_TASK_ACTION_SET = 1, /*!< Set the GPIO level to high */
80+
GPIO_ETM_TASK_ACTION_CLR, /*!< Clear the GPIO level to low */
81+
GPIO_ETM_TASK_ACTION_TOG, /*!< Toggle the GPIO level */
7182
} gpio_etm_task_action_t;
7283

7384
/**
7485
* @brief GPIO ETM task configuration
86+
*
87+
* If multiple actions wants to be added to the same GPIO pin, you have to configure all the GPIO ETM tasks together.
7588
*/
7689
typedef struct {
77-
gpio_etm_task_action_t action; /*!< Which action to take by the ETM task module */
90+
union {
91+
gpio_etm_task_action_t action; /*!< Action to take by the ETM task module */
92+
gpio_etm_task_action_t actions[GPIO_ETM_TASK_ACTION_TYPES]; /*!< Array of actions to take by the ETM task module on the same GPIO */
93+
};
7894
} gpio_etm_task_config_t;
7995

8096
/**
@@ -83,17 +99,19 @@ typedef struct {
8399
* @note The created ETM task object can be deleted later by calling `esp_etm_del_task`
84100
* @note The GPIO ETM task works like a container, a newly created ETM task object doesn't have GPIO members to be managed.
85101
* You need to call `gpio_etm_task_add_gpio` to put one or more GPIOs to the container.
102+
* @note Every success call to this function will acquire a free GPIO ETM task channel
86103
*
87104
* @param[in] config GPIO ETM task configuration
88105
* @param[out] ret_task Returned ETM task handle
106+
* @param[out] ... Other returned ETM task handles if any (the order of the returned task handles is aligned with the array order in field `actions` in `gpio_etm_task_config_t`)
89107
* @return
90108
* - ESP_OK: Create ETM task successfully
91109
* - ESP_ERR_INVALID_ARG: Create ETM task failed because of invalid argument
92110
* - ESP_ERR_NO_MEM: Create ETM task failed because of out of memory
93111
* - ESP_ERR_NOT_FOUND: Create ETM task failed because all tasks are used up and no more free one
94112
* - ESP_FAIL: Create ETM task failed because of other reasons
95113
*/
96-
esp_err_t gpio_new_etm_task(const gpio_etm_task_config_t *config, esp_etm_task_handle_t *ret_task);
114+
esp_err_t gpio_new_etm_task(const gpio_etm_task_config_t *config, esp_etm_task_handle_t *ret_task, ...);
97115

98116
/**
99117
* @brief Add GPIO to the ETM task.

0 commit comments

Comments
 (0)