refactor(mcpwm): add RCC related LL functions

This commit is contained in:
morris
2023-09-13 19:13:01 +08:00
parent 608fca9d31
commit 3234ee3f9e
10 changed files with 279 additions and 39 deletions

View File

@@ -20,6 +20,7 @@
#include "hal/mcpwm_types.h"
#include "hal/misc.h"
#include "hal/assert.h"
#include "soc/system_struct.h"
#ifdef __cplusplus
extern "C" {
@@ -67,6 +68,45 @@ typedef enum {
////////////////////////////////////////MCPWM Group Specific////////////////////////////////////////////////////////////
/**
* @brief Enable the bus clock for MCPWM module
*
* @param group_id Group ID
* @param enable true to enable, false to disable
*/
static inline void mcpwm_ll_enable_bus_clock(int group_id, bool enable)
{
if (group_id == 0) {
SYSTEM.perip_clk_en0.pwm0_clk_en = enable;
} else {
SYSTEM.perip_clk_en0.pwm1_clk_en = enable;
}
}
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define mcpwm_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; mcpwm_ll_enable_bus_clock(__VA_ARGS__)
/**
* @brief Reset the MCPWM module
*
* @param group_id Group ID
*/
static inline void mcpwm_ll_reset_register(int group_id)
{
if (group_id == 0) {
SYSTEM.perip_rst_en0.pwm0_rst = 1;
SYSTEM.perip_rst_en0.pwm0_rst = 0;
} else {
SYSTEM.perip_rst_en0.pwm1_rst = 1;
SYSTEM.perip_rst_en0.pwm1_rst = 0;
}
}
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define mcpwm_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; mcpwm_ll_reset_register(__VA_ARGS__)
/**
* @brief Set the clock source for MCPWM
*