SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
mcpwm_private.h
Go to the documentation of this file.
1/*
2 * This is a private declaration of different MCPWM structures and types.
3 * It has been copied from: https://github.com/espressif/esp-idf/blob/v5.1.4/components/driver/mcpwm/mcpwm_private.h
4 *
5 * extracted by askuric 16.06.2024
6 *
7 * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11
12#ifndef MCPWM_PRIVATE_H
13#define MCPWM_PRIVATE_H
14
15
16#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) && defined(SOC_MCPWM_SUPPORTED) && !defined(SIMPLEFOC_ESP32_USELEDC)
17
18#include "freertos/FreeRTOS.h"
19#include "esp_intr_alloc.h"
20#include "esp_heap_caps.h"
21#include "esp_pm.h"
22#include "soc/soc_caps.h"
23#include "hal/mcpwm_hal.h"
24#include "hal/mcpwm_types.h"
25#include "driver/mcpwm_types.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31typedef struct mcpwm_group_t mcpwm_group_t;
32typedef struct mcpwm_timer_t mcpwm_timer_t;
33typedef struct mcpwm_cap_timer_t mcpwm_cap_timer_t;
34typedef struct mcpwm_oper_t mcpwm_oper_t;
35typedef struct mcpwm_gpio_fault_t mcpwm_gpio_fault_t;
36typedef struct mcpwm_gpio_sync_src_t mcpwm_gpio_sync_src_t;
37typedef struct mcpwm_timer_sync_src_t mcpwm_timer_sync_src_t;
38
39struct mcpwm_group_t {
40 int group_id; // group ID, index from 0
41 int intr_priority; // MCPWM interrupt priority
42 mcpwm_hal_context_t hal; // HAL instance is at group level
43 portMUX_TYPE spinlock; // group level spinlock
44 uint32_t prescale; // group prescale
45 uint32_t resolution_hz; // MCPWM group clock resolution: clock_src_hz / clock_prescale = resolution_hz
46 esp_pm_lock_handle_t pm_lock; // power management lock
47 soc_module_clk_t clk_src; // peripheral source clock
48 mcpwm_cap_timer_t *cap_timer; // mcpwm capture timers
49 mcpwm_timer_t *timers[SOC_MCPWM_TIMERS_PER_GROUP]; // mcpwm timer array
50 mcpwm_oper_t *operators[SOC_MCPWM_OPERATORS_PER_GROUP]; // mcpwm operator array
51 mcpwm_gpio_fault_t *gpio_faults[SOC_MCPWM_GPIO_FAULTS_PER_GROUP]; // mcpwm fault detectors array
52 mcpwm_gpio_sync_src_t *gpio_sync_srcs[SOC_MCPWM_GPIO_SYNCHROS_PER_GROUP]; // mcpwm gpio sync array
53};
54
55typedef enum {
56 MCPWM_TIMER_FSM_INIT,
57 MCPWM_TIMER_FSM_ENABLE,
58} mcpwm_timer_fsm_t;
59
60struct mcpwm_timer_t {
61 int timer_id; // timer ID, index from 0
62 mcpwm_group_t *group; // which group the timer belongs to
63 mcpwm_timer_fsm_t fsm; // driver FSM
64 portMUX_TYPE spinlock; // spin lock
65 intr_handle_t intr; // interrupt handle
66 uint32_t resolution_hz; // resolution of the timer
67 uint32_t peak_ticks; // peak ticks that the timer could reach to
68 mcpwm_timer_sync_src_t *sync_src; // timer sync_src
69 mcpwm_timer_count_mode_t count_mode; // count mode
70 mcpwm_timer_event_cb_t on_full; // callback function when MCPWM timer counts to peak value
71 mcpwm_timer_event_cb_t on_empty; // callback function when MCPWM timer counts to zero
72 mcpwm_timer_event_cb_t on_stop; // callback function when MCPWM timer stops
73 void *user_data; // user data which would be passed to the timer callbacks
74};
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif
81
82#endif /* MCPWM_PRIVATE_H */