⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drvpwm.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 5 页
字号:
                outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & ~BIT4);
            break;
        case DRVPWM_CAP2:
            if (s_i32Option)
                outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT4));
            else
                outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & ~BIT20);
            break;
        case DRVPWM_CAP3:
            if (s_i32Option)
                outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT20));
            else
                outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & ~BIT4);
            break;
        case DRVPWM_CAP4:
            if (s_i32Option)
                outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & (CCR_MASK | BIT4));
            else
                outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & ~BIT20);
            break;
        case DRVPWM_CAP5:
            if (s_i32Option)
                outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & (CCR_MASK | BIT20));
            else
                outp32(&PWMB->CCR0, inp32(&PWMB->CCR0) & ~BIT4);
            break;
        case DRVPWM_CAP6:
            if (s_i32Option)
                outp32(&PWMB->CCR2, inp32(&PWMB->CCR2) & (CCR_MASK | BIT4));
            else
                outp32(&PWMB->CCR2, inp32(&PWMB->CCR2) & ~BIT20);
            break;
        case DRVPWM_CAP7:
            if (s_i32Option)
                outp32(&PWMB->CCR2, inp32(&PWMB->CCR2) & (CCR_MASK | BIT20));
            else
                outp32(&PWMB->CCR2, inp32(&PWMB->CCR2) & ~BIT4);
            break;
    }
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvPWM_GetIntFlag                                                                             */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u8Timer        - [in]      DRVPWM_TIMER0 / DRVPWM_TIMER1 / DRVPWM_TIMER2 / DRVPWM_TIMER3  */
/*                                          DRVPWM_TIMER4 / DRVPWM_TIMER5 / DRVPWM_TIMER6 / DRVPWM_TIMER7  */
/*                                          DRVPWM_CAP0   / DRVPWM_CAP1   / DRVPWM_CAP2   / DRVPWM_CAP3    */
/*                                          DRVPWM_CAP4   / DRVPWM_CAP5   / DRVPWM_CAP6   / DRVPWM_CAP7    */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               0      FALSE                                                                              */
/*               1      TRUE                                                                               */
/* Description:                                                                                            */
/*               This function is used to get the PWM0~7 timer/capture interrupt flag                      */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvPWM_GetIntFlag(uint8_t u8Timer)
{
    int32_t status = 0;
    
    switch (u8Timer)
    {
        case DRVPWM_TIMER0:
        case DRVPWM_TIMER1:
        case DRVPWM_TIMER2:
        case DRVPWM_TIMER3:
            status = ( inp32(&PWMA->PIIR) & (1<<u8Timer) )? 1 : 0;
            break;
        case DRVPWM_TIMER4:
        case DRVPWM_TIMER5:
        case DRVPWM_TIMER6:
        case DRVPWM_TIMER7:
            status = ( inp32(&PWMB->PIIR) & (1<<(u8Timer-DRVPWM_TIMER4)) )? 1 : 0;
            break;

        case DRVPWM_CAP0:
            status = PWMA->CCR0.CAPIF0;
            break;
        case DRVPWM_CAP1:
            status = PWMA->CCR0.CAPIF1;             
            break;
        case DRVPWM_CAP2:
            status = PWMA->CCR2.CAPIF2;
            break;
        case DRVPWM_CAP3:
            status = PWMA->CCR2.CAPIF3;
            break;
        case DRVPWM_CAP4:
            status = PWMB->CCR0.CAPIF0;
            break;
        case DRVPWM_CAP5:
            status = PWMB->CCR0.CAPIF1;             
            break;
        case DRVPWM_CAP6:
            status = PWMB->CCR2.CAPIF2;
            break;
        case DRVPWM_CAP7:
            status = PWMB->CCR2.CAPIF3;
            break;
    }   

    return status;      
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvPWM_GetRisingCounter                                                                       */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u8Capture      - [in]      DRVPWM_CAP0 / DRVPWM_CAP1 / DRVPWM_CAP2 / DRVPWM_CAP3          */
/*                                          DRVPWM_CAP4 / DRVPWM_CAP5 / DRVPWM_CAP6 / DRVPWM_CAP7          */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               The value which latches the counter when thereˇs a rising transition                     */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to get value which latches the counter when thereˇs a rising       */       
/*               transition                                                                                */
/*---------------------------------------------------------------------------------------------------------*/
uint16_t DrvPWM_GetRisingCounter(uint8_t u8Capture)
{
    uint32_t u32Reg = 0;
    
    if (u8Capture >= DRVPWM_CAP4)
    {
        u32Reg = *((__IO uint32_t *) (PWMB_CRLR0 + ((u8Capture - DRVPWM_CAP4) << 3)));
    }
    else
    {
        u32Reg = *((__IO uint32_t *) (PWMA_CRLR0 + ((u8Capture & 0x7) << 3)));  
    }

    return u32Reg;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvPWM_GetFallingCounter                                                                      */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u8Capture      - [in]      DRVPWM_CAP0 / DRVPWM_CAP1 / DRVPWM_CAP2 / DRVPWM_CAP3          */
/*                                          DRVPWM_CAP4 / DRVPWM_CAP5 / DRVPWM_CAP6 / DRVPWM_CAP7          */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               The value which latches the counter when thereˇs a falling transition                    */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to get value which latches the counter when thereˇs a falling      */       
/*               transition                                                                                */
/*---------------------------------------------------------------------------------------------------------*/
uint16_t DrvPWM_GetFallingCounter(uint8_t u8Capture)
{
    uint32_t u32Reg = 0;
    
    if (u8Capture >= DRVPWM_CAP4)
    {
        u32Reg = *((__IO uint32_t *) (PWMB_CFLR0 + ((u8Capture - DRVPWM_CAP4) << 3)));
    }
    else
    {
        u32Reg = *((__IO uint32_t *) (PWMA_CFLR0 + ((u8Capture & 0x7) << 3)));  
    }

    return u32Reg;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvPWM_GetCaptureIntStatus                                                                    */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u8Capture      - [in]      DRVPWM_CAP0 / DRVPWM_CAP1 / DRVPWM_CAP2 / DRVPWM_CAP3          */
/*                                          DRVPWM_CAP4 / DRVPWM_CAP5 / DRVPWM_CAP6 / DRVPWM_CAP7          */
/*               u8IntType      - [in]      DRVPWM_CAP_RISING_FLAG / DRVPWM_CAP_FALLING_FLAG               */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               Check if thereˇs a rising / falling transition                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to get the rising / falling transition indicator flag               */       
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvPWM_GetCaptureIntStatus(uint8_t u8Capture, uint8_t u8IntType)
{   
    int32_t status;

    status = 0; 

    switch (u8Capture)
    {
        case DRVPWM_CAP0:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMA->CCR0.CRLRI0 : PWMA->CCR0.CFLRI0;
            break;
        case DRVPWM_CAP1:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMA->CCR0.CRLRI1 : PWMA->CCR0.CFLRI1;
            break;
        case DRVPWM_CAP2:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMA->CCR2.CRLRI2 : PWMA->CCR2.CFLRI2;
            break;
        case DRVPWM_CAP3:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMA->CCR2.CRLRI3 : PWMA->CCR2.CFLRI3;
            break;
        case DRVPWM_CAP4:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMB->CCR0.CRLRI0 : PWMB->CCR0.CFLRI0;
            break;
        case DRVPWM_CAP5:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMB->CCR0.CRLRI1 : PWMB->CCR0.CFLRI1;
            break;
        case DRVPWM_CAP6:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMB->CCR2.CRLRI2 : PWMB->CCR2.CFLRI2;
            break;
        case DRVPWM_CAP7:
            status = (u8IntType == DRVPWM_CAP_RISING_FLAG)? PWMB->CCR2.CRLRI3 : PWMB->CCR2.CFLRI3;
            break;
    }
    
    return status;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvPWM_ClearCaptureIntStatus                                                                  */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*               u8Capture      - [in]      DRVPWM_CAP0 / DRVPWM_CAP1 / DRVPWM_CAP2 / DRVPWM_CAP3          */
/*                                          DRVPWM_CAP4 / DRVPWM_CAP5 / DRVPWM_CAP6 / DRVPWM_CAP7          */
/*               u8IntType      - [in]      DRVPWM_CAP_RISING_FLAG/DRVPWM_CAP_FALLING_FLAG                 */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               Clear the rising / falling transition interrupt flag                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to clear the rising / falling transition indicator flag             */       
/*---------------------------------------------------------------------------------------------------------*/
void DrvPWM_ClearCaptureIntStatus(uint8_t u8Capture, uint8_t u8IntType)
{
    if (s_i32Option)
    { 
        switch (u8Capture)
        {
            case DRVPWM_CAP0:
                (u8IntType == DRVPWM_CAP_RISING_FLAG)? (outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & (CCR_MASK | BIT6))) : (outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & (CCR_MASK | BIT7)));
                break;
            case DRVPWM_CAP1:
                (u8IntType == DRVPWM_CAP_RISING_FLAG)? (outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & (CCR_MASK | BIT22))) : (outp32(&PWMA->CCR0, inp32(&PWMA->CCR0) & (CCR_MASK | BIT23)));
                break;
            case DRVPWM_CAP2:
                (u8IntType == DRVPWM_CAP_RISING_FLAG)? (outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT6))) : (outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT7)));
                break;
            case DRVPWM_CAP3:
                (u8IntType == DRVPWM_CAP_RISING_FLAG)? (outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT22))) : (outp32(&PWMA->CCR2, inp32(&PWMA->CCR2) & (CCR_MASK | BIT23)));
                break;

            case DRVPWM_CAP4:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -