📄 drvpwm.c
字号:
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------*/
/* Includes of local headers */
/*---------------------------------------------------------------------------------------------------------*/
#include "DrvPWM.h"
#include "DrvSYS.h"
/*---------------------------------------------------------------------------------------------------------*/
/* Macro, type and constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define PWMA_CNR0 PWMA_BASE + 0x0C
#define PWMA_CMR0 PWMA_BASE + 0x10
#define PWMA_PDR0 PWMA_BASE + 0x14
#define PWMA_CRLR0 PWMA_BASE + 0x58
#define PWMA_CFLR0 PWMA_BASE + 0x5C
#define PWMB_CNR0 PWMB_BASE + 0x0C
#define PWMB_CMR0 PWMB_BASE + 0x10
#define PWMB_PDR0 PWMB_BASE + 0x14
#define PWMB_CRLR0 PWMB_BASE + 0x58
#define PWMB_CFLR0 PWMB_BASE + 0x5C
#define CCR_MASK 0x000F000F
/*---------------------------------------------------------------------------------------------------------*/
/* Global file scope (static) variables */
/*---------------------------------------------------------------------------------------------------------*/
static S_DRVPWM_CALLBACK_T g_sDrvPWMAHandler = {0};
static S_DRVPWM_CALLBACK_T g_sDrvPWMBHandler = {0};
static int32_t s_i32Option = 0;
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvPWM_GetVersion */
/* */
/* Parameters: */
/* None */
/* */
/* Returns: */
/* The DrvPWM version number */
/* */
/* Description: */
/* This function is used to get the DrvPWM version number */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t DrvPWM_GetVersion(void)
{
return DRVPWM_VERSION_NUM;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: <PWMA_IRQHandler> */
/* */
/* Parameter: */
/* None */
/* Returns: */
/* None */
/* */
/* Description: */
/* ISR to handle PWMA interrupt event */
/*---------------------------------------------------------------------------------------------------------*/
void PWMA_IRQHandler(void)
{
uint32_t u32pwmIntFlag, u32CapIntFlag0, u32CapIntFlag1;
/* Handle PWMA Timer function */
u32pwmIntFlag = *((__IO uint32_t *) &PWMA->PIIR);
if (u32pwmIntFlag & BIT0)
{
*((__IO uint32_t *) &PWMA->PIIR) = BIT0;
if (g_sDrvPWMAHandler.pfnPWM0CallBack != NULL)
{
g_sDrvPWMAHandler.pfnPWM0CallBack();
}
}
if (u32pwmIntFlag & BIT1)
{
*((__IO uint32_t *) &PWMA->PIIR) = BIT1;
if (g_sDrvPWMAHandler.pfnPWM1CallBack != NULL)
{
g_sDrvPWMAHandler.pfnPWM1CallBack();
}
}
if (u32pwmIntFlag & BIT2)
{
*((__IO uint32_t *) &PWMA->PIIR) = BIT2;
if (g_sDrvPWMAHandler.pfnPWM2CallBack != NULL)
{
g_sDrvPWMAHandler.pfnPWM2CallBack();
}
}
if (u32pwmIntFlag & BIT3)
{
*((__IO uint32_t *) &PWMA->PIIR) = BIT3;
if (g_sDrvPWMAHandler.pfnPWM3CallBack != NULL)
{
g_sDrvPWMAHandler.pfnPWM3CallBack();
}
}
/* Handle PWMA Capture function */
u32CapIntFlag0 = *((__IO uint32_t *) &PWMA->CCR0);
u32CapIntFlag1 = *((__IO uint32_t *) &PWMA->CCR2);
if (u32CapIntFlag0 & BIT4)
{
if (s_i32Option)
outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & (CCR_MASK | BIT4));
else
outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & ~BIT20);
if (g_sDrvPWMAHandler.pfnCAP0CallBack != NULL)
{
g_sDrvPWMAHandler.pfnCAP0CallBack();
}
}
if (u32CapIntFlag0 & BIT20)
{
if (s_i32Option)
outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & (CCR_MASK | BIT20));
else
outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & ~BIT4);
if (g_sDrvPWMAHandler.pfnCAP1CallBack != NULL)
{
g_sDrvPWMAHandler.pfnCAP1CallBack();
}
}
if (u32CapIntFlag1 & BIT4)
{
if (s_i32Option)
outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT4));
else
outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & ~BIT20);
if (g_sDrvPWMAHandler.pfnCAP2CallBack != NULL)
{
g_sDrvPWMAHandler.pfnCAP2CallBack();
}
}
if (u32CapIntFlag1 & BIT20)
{
if (s_i32Option)
outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT20));
else
outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & ~BIT4);
if (g_sDrvPWMAHandler.pfnCAP3CallBack != NULL)
{
g_sDrvPWMAHandler.pfnCAP3CallBack();
}
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: <PWMB_IRQHandler> */
/* */
/* Parameter: */
/* None */
/* Returns: */
/* None */
/* */
/* Description: */
/* ISR to handle PWMB interrupt event */
/*---------------------------------------------------------------------------------------------------------*/
void PWMB_IRQHandler(void)
{
uint32_t u32pwmIntFlag, u32CapIntFlag0, u32CapIntFlag1;
/* Handle PWMB Timer function */
u32pwmIntFlag = *((__IO uint32_t *) &PWMB->PIIR);
if (u32pwmIntFlag & BIT0)
{
*((__IO uint32_t *) &PWMB->PIIR) = BIT0;
if (g_sDrvPWMBHandler.pfnPWM0CallBack != NULL)
{
g_sDrvPWMBHandler.pfnPWM0CallBack();
}
}
if (u32pwmIntFlag & BIT1)
{
*((__IO uint32_t *) &PWMB->PIIR) = BIT1;
if (g_sDrvPWMBHandler.pfnPWM1CallBack != NULL)
{
g_sDrvPWMBHandler.pfnPWM1CallBack();
}
}
if (u32pwmIntFlag & BIT2)
{
*((__IO uint32_t *) &PWMB->PIIR) = BIT2;
if (g_sDrvPWMBHandler.pfnPWM2CallBack != NULL)
{
g_sDrvPWMBHandler.pfnPWM2CallBack();
}
}
if (u32pwmIntFlag & BIT3)
{
*((__IO uint32_t *) &PWMB->PIIR) = BIT3;
if (g_sDrvPWMBHandler.pfnPWM3CallBack != NULL)
{
g_sDrvPWMBHandler.pfnPWM3CallBack();
}
}
/* Handle PWMB Capture function */
u32CapIntFlag0 = *((__IO uint32_t *) &PWMB->CCR0);
u32CapIntFlag1 = *((__IO uint32_t *) &PWMB->CCR2);
if (u32CapIntFlag0 & BIT4)
{
if (s_i32Option)
outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & (CCR_MASK | BIT4));
else
outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & ~BIT20);
if (g_sDrvPWMBHandler.pfnCAP0CallBack != NULL)
{
g_sDrvPWMBHandler.pfnCAP0CallBack();
}
}
if (u32CapIntFlag0 & BIT20)
{
if (s_i32Option)
outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & (CCR_MASK | BIT20));
else
outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & ~BIT4);
if (g_sDrvPWMBHandler.pfnCAP1CallBack != NULL)
{
g_sDrvPWMBHandler.pfnCAP1CallBack();
}
}
if (u32CapIntFlag1 & BIT4)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -