mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-16 06:54:22 +00:00
mcpwm: clean up hal driver and add doc
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
@@ -18,18 +10,28 @@
|
||||
* See readme.md in hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The HAL layer for MCPWM (common part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/mcpwm_struct.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct mcpwm_dev_t *mcpwm_soc_handle_t; // MCPWM SOC layer handle
|
||||
|
||||
/**
|
||||
* @brief HAL layer configuration
|
||||
*/
|
||||
typedef struct {
|
||||
int host_id; ///< Which MCPWM peripheral to use, 0-1.
|
||||
int group_id; // Indicate the MCPWM hardware group
|
||||
} mcpwm_hal_init_config_t;
|
||||
|
||||
/**
|
||||
* Context that should be maintained by both the driver and the HAL
|
||||
*/
|
||||
typedef struct {
|
||||
mcpwm_dev_t *dev; ///< Beginning address of the peripheral registers of a single MCPWM unit. Call `mcpwm_hal_init` to initialize it.
|
||||
mcpwm_soc_handle_t dev; // MCPWM SOC layer handle
|
||||
} mcpwm_hal_context_t;
|
||||
|
||||
/**
|
||||
@@ -39,3 +41,39 @@ typedef struct {
|
||||
* @param init_config Configuration for the HAL to be used only once.
|
||||
*/
|
||||
void mcpwm_hal_init(mcpwm_hal_context_t *hal, const mcpwm_hal_init_config_t *init_config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize the HAL driver.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
*/
|
||||
void mcpwm_hal_deinit(mcpwm_hal_context_t *hal);
|
||||
|
||||
/**
|
||||
* @brief Reset MCPWM timer
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param timer_id Timer ID
|
||||
*/
|
||||
void mcpwm_hal_timer_reset(mcpwm_hal_context_t *hal, int timer_id);
|
||||
|
||||
/**
|
||||
* @brief Reset MCPWM operator
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param oper_id Operator ID
|
||||
*/
|
||||
void mcpwm_hal_operator_reset(mcpwm_hal_context_t *hal, int oper_id);
|
||||
|
||||
/**
|
||||
* @brief Reset MCPWM generator
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param oper_id Operator ID
|
||||
* @param gen_id Generator ID
|
||||
*/
|
||||
void mcpwm_hal_generator_reset(mcpwm_hal_context_t *hal, int oper_id, int gen_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,29 +1,47 @@
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/clk_tree_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief MCPWM timer clock source
|
||||
*/
|
||||
typedef soc_periph_mcpwm_timer_clk_src_t mcpwm_timer_clock_source_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM capture clock source
|
||||
*/
|
||||
typedef soc_periph_mcpwm_capture_clk_src_t mcpwm_capture_clock_source_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM timer count direction
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_TIMER_DIRECTION_UP, /*!< Counting direction: Increase */
|
||||
MCPWM_TIMER_DIRECTION_DOWN, /*!< Counting direction: Decrease */
|
||||
} mcpwm_timer_direction_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM timer events
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_TIMER_EVENT_ZERO, /*!< MCPWM timer counts to zero */
|
||||
MCPWM_TIMER_EVENT_PEAK, /*!< MCPWM timer counts to peak */
|
||||
MCPWM_TIMER_EVENT_EMPTY, /*!< MCPWM timer counts to zero (i.e. counter is empty) */
|
||||
MCPWM_TIMER_EVENT_FULL, /*!< MCPWM timer counts to peak (i.e. counter is full) */
|
||||
MCPWM_TIMER_EVENT_INVALID, /*!< MCPWM timer invalid event */
|
||||
} mcpwm_timer_event_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM timer count modes
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_TIMER_COUNT_MODE_PAUSE, /*!< MCPWM timer paused */
|
||||
MCPWM_TIMER_COUNT_MODE_UP, /*!< MCPWM timer counting up */
|
||||
@@ -31,14 +49,20 @@ typedef enum {
|
||||
MCPWM_TIMER_COUNT_MODE_UP_DOWN, /*!< MCPWM timer counting up and down */
|
||||
} mcpwm_timer_count_mode_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM timer commands, specify the way to start or stop the timer
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_TIMER_STOP_AT_ZERO, /*!< MCPWM timer stops when couting to zero */
|
||||
MCPWM_TIMER_STOP_AT_PEAK, /*!< MCPWM timer stops when counting to peak */
|
||||
MCPWM_TIMER_START_NO_STOP, /*!< MCPWM timer starts couting */
|
||||
MCPWM_TIMER_START_STOP_AT_ZERO, /*!< MCPWM timer starts counting and stops when couting to zero */
|
||||
MCPWM_TIMER_START_STOP_AT_PEAK, /*!< MCPWM timer starts counting and stops when counting to peak */
|
||||
} mcpwm_timer_execute_cmd_t;
|
||||
MCPWM_TIMER_STOP_EMPTY, /*!< MCPWM timer stops when next count reaches zero */
|
||||
MCPWM_TIMER_STOP_FULL, /*!< MCPWM timer stops when next count reaches peak */
|
||||
MCPWM_TIMER_START_NO_STOP, /*!< MCPWM timer starts couting, and don't stop until received stop command */
|
||||
MCPWM_TIMER_START_STOP_EMPTY, /*!< MCPWM timer starts counting and stops when next count reaches zero */
|
||||
MCPWM_TIMER_START_STOP_FULL, /*!< MCPWM timer starts counting and stops when next count reaches peak */
|
||||
} mcpwm_timer_start_stop_cmd_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM generator actions
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_GEN_ACTION_KEEP, /*!< Generator action: Keep the same level */
|
||||
MCPWM_GEN_ACTION_LOW, /*!< Generator action: Force to low level */
|
||||
@@ -46,7 +70,23 @@ typedef enum {
|
||||
MCPWM_GEN_ACTION_TOGGLE, /*!< Generator action: Toggle level */
|
||||
} mcpwm_generator_action_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM operator brake mode
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_TRIP_TYPE_CBC, /*!< CBC trip type, shut down the operator cycle by cycle*/
|
||||
MCPWM_TRIP_TYPE_OST, /*!< OST trip type, shut down the operator in one shot */
|
||||
} mcpwm_trip_type_t;
|
||||
MCPWM_OPER_BRAKE_MODE_CBC, /*!< Brake mode: CBC (cycle by cycle)*/
|
||||
MCPWM_OPER_BRAKE_MODE_OST, /*!< Brake mode, OST (one shot) */
|
||||
MCPWM_OPER_BRAKE_MODE_INVALID, /*!< MCPWM operator invalid brake mode */
|
||||
} mcpwm_operator_brake_mode_t;
|
||||
|
||||
/**
|
||||
* @brief MCPWM capture edge
|
||||
*/
|
||||
typedef enum {
|
||||
MCPWM_CAP_EDGE_POS, /*!< Capture on the positive edge */
|
||||
MCPWM_CAP_EDGE_NEG, /*!< Capture on the negative edge */
|
||||
} mcpwm_capture_edge_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,23 +1,56 @@
|
||||
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// The HAL layer for MCPWM (common part)
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/mcpwm_hal.h"
|
||||
#include "hal/mcpwm_ll.h"
|
||||
|
||||
void mcpwm_hal_init(mcpwm_hal_context_t *hal, const mcpwm_hal_init_config_t *init_config)
|
||||
{
|
||||
hal->dev = MCPWM_LL_GET_HW(init_config->host_id);
|
||||
hal->dev = MCPWM_LL_GET_HW(init_config->group_id);
|
||||
mcpwm_ll_group_enable_shadow_mode(hal->dev);
|
||||
mcpwm_ll_group_flush_shadow(hal->dev);
|
||||
}
|
||||
|
||||
void mcpwm_hal_deinit(mcpwm_hal_context_t *hal)
|
||||
{
|
||||
hal->dev = NULL;
|
||||
}
|
||||
|
||||
void mcpwm_hal_timer_reset(mcpwm_hal_context_t *hal, int timer_id)
|
||||
{
|
||||
mcpwm_ll_timer_set_count_mode(hal->dev, timer_id, MCPWM_TIMER_COUNT_MODE_PAUSE);
|
||||
mcpwm_ll_timer_update_period_at_once(hal->dev, timer_id);
|
||||
// disable sync input and output by default
|
||||
mcpwm_ll_timer_disable_sync_out(hal->dev, timer_id);
|
||||
mcpwm_ll_timer_enable_sync_input(hal->dev, timer_id, false);
|
||||
mcpwm_ll_timer_clear_sync_input(hal->dev, timer_id);
|
||||
}
|
||||
|
||||
void mcpwm_hal_operator_reset(mcpwm_hal_context_t *hal, int oper_id)
|
||||
{
|
||||
// allow to update action, compare, and dead time configuration
|
||||
mcpwm_ll_operator_stop_update_action(hal->dev, oper_id, false);
|
||||
mcpwm_ll_operator_update_action_at_once(hal->dev, oper_id);
|
||||
mcpwm_ll_deadtime_stop_update_delay(hal->dev, oper_id, false);
|
||||
mcpwm_ll_deadtime_update_delay_at_once(hal->dev, oper_id);
|
||||
for (int i = 0; i < SOC_MCPWM_COMPARATORS_PER_OPERATOR; i++) {
|
||||
mcpwm_ll_operator_stop_update_compare(hal->dev, oper_id, i, false);
|
||||
mcpwm_ll_operator_update_compare_at_once(hal->dev, oper_id, i);
|
||||
}
|
||||
mcpwm_ll_brake_enable_cbc_refresh_on_tez(hal->dev, oper_id, false);
|
||||
mcpwm_ll_fault_enable_cbc_refresh_on_tep(hal->dev, oper_id, false);
|
||||
mcpwm_ll_brake_enable_soft_cbc(hal->dev, oper_id, false);
|
||||
mcpwm_ll_brake_enable_soft_ost(hal->dev, oper_id, false);
|
||||
}
|
||||
|
||||
void mcpwm_hal_generator_reset(mcpwm_hal_context_t *hal, int oper_id, int gen_id)
|
||||
{
|
||||
mcpwm_ll_generator_reset_actions(hal->dev, oper_id, gen_id);
|
||||
mcpwm_ll_gen_disable_continue_force_action(hal->dev, oper_id, gen_id);
|
||||
mcpwm_ll_gen_disable_noncontinue_force_action(hal->dev, oper_id, gen_id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user