📄 91x_mc.c
字号:
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name : 91x_mc.c
* Author : MCD Application Team
* Version : V2.0
* Date : 12/07/2007
* Description : This file provides all the MC firmware functions.
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS
* A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Standard include ----------------------------------------------------------*/
#include "91x_mc.h"
#include "91x_scu.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#define MC_ODCS_Set 0x0001
#define MC_ODCS_Reset 0x00FE
#define MC_CMS_Set 0x0004
#define MC_CMS_Reset 0x00FB
#define MC_CPC_Set 0x0008
#define MC_CTC_Set 0x0010
#define MC_PCE_Set 0x0020
#define MC_PCE_Reset 0xFFDF
#define MC_TCE_Set 0x0040
#define MC_TCE_Reset 0x00BF
#define MC_DTE_Set 0x0080
#define MC_DTE_Reset 0x007F
#define MC_TCB_Set 0x0004
#define MC_TCB_Reset 0x00FB
#define MC_STC_Set 0x0008
#define MC_TES_Set 0x0010
#define MC_TES_Reset 0x00EF
#define MC_CCPT_Set 0x0020
#define MC_CCPT_Reset 0x005F
#define MC_DISEST_Set 0x0040
#define MC_DISEST_Reset 0x003F
#define MC_DTS_Set 0x0001
#define MC_DTS_Reset 0x00FE
#define MC_SDT_Set 0x0002
#define MC_C0SE_Set 0x0004
#define MC_C0SE_Reset 0x00FB
#define MC_CUSE_Set 0x0008
#define MC_CUSE_Reset 0x00F7
#define MC_CVSE_Set 0x0010
#define MC_CVSE_Reset 0x00EF
#define MC_CWSE_Set 0x0020
#define MC_CWSE_Reset 0x00D0
#define MC_RSE_Set 0x0040
#define MC_RSE_Reset 0x00BF
#define MC_GPI_Set 0x0080
#define MC_GPI_Reset 0x007F
#define MC_PUH_Set 0x0020
#define MC_PUH_Reset 0x005F
#define MC_PUL_Set 0x0010
#define MC_PUL_Reset 0x006F
#define MC_PVH_Set 0x0008
#define MC_PVH_Reset 0x0077
#define MC_PVL_Set 0x0004
#define MC_PVL_Reset 0x007B
#define MC_PWH_Set 0x0002
#define MC_PWH_Reset 0x007D
#define MC_PWL_Set 0x0001
#define MC_PWL_Reset 0x007E
#define MC_ODS_Set 0x0040
#define MC_ODS_Reset 0xFF3F
#define MC_ESC_Clear 0x4321
#define MC_PCR1_TIN_MASK 0xFFFC
#define MC_OPR_Mask 0x0040
#define MC_UDCS_Mask 0x0002
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************
* Function Name : MC_DeInit
* Description : Deinitializes MC peripheral registers to their default reset
* values.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void MC_DeInit(void)
{
/* MC peripheral is under Reset */
SCU_APBPeriphReset(__MC, ENABLE);
/* MC peripheral Reset off */
SCU_APBPeriphReset(__MC, DISABLE);
}
/*******************************************************************************
* Function Name : MC_Init
* Description : Initializes the MC peripheral according to the specified
* parameters in the MC_InitStruct .
* Input : IMC_InitStruct: pointer to a MC_InitTypeDef structure that
* contains the configuration information for the MC peripheral.
* Output : None
* Return : None
*******************************************************************************/
void MC_Init(MC_InitTypeDef* MC_InitStruct)
{
/* Select the operating Mode */
if(MC_InitStruct->MC_OperatingMode == MC_SoftwareOperating_Mode)
{
/* Select the Data transfer Mode */
MC->PCR2 |= MC_DTS_Set;
/* Enable the registers Software Data Transfer */
MC->PCR2 |= MC_C0SE_Set | MC_CUSE_Set | MC_CVSE_Set | MC_CWSE_Set
|MC_RSE_Set;
}
else
{
/* Select the Data transfer Mode */
MC->PCR2 &= MC_DTS_Reset;
/* Disable the registers Software Data Transfer */
MC->PCR2 &= MC_C0SE_Reset | MC_CUSE_Reset | MC_CVSE_Reset | MC_CWSE_Reset
|MC_RSE_Reset;
}
/* Select the MC PWM counter Mode */
if(MC_InitStruct->MC_PWMMode == MC_PWMZeroCentered_Mode)
{
MC->PCR0 |= MC_CMS_Set;
}
else
{
MC->PCR0 &= MC_CMS_Reset;
}
/* Set the MC PWM counter Prescaler */
MC->CPRS = MC_InitStruct->MC_Prescaler;
/* Set the MC PWM Period */
MC->CMP0 = MC_InitStruct->MC_Period;
/* Set the MC PWM Repetition counter */
MC->REP = MC_InitStruct->MC_RepetitionCounter;
/* Set the Tacho Compare value */
MC->TCMP = MC_InitStruct->MC_TachoPeriod;
/* Set the Tacho Prescaler value */
MC->TPRS = MC_InitStruct->MC_TachoPrescaler;
/* Set the MC Tacho Input Polarity */
MC->PCR1 = (MC->PCR1 & MC_PCR1_TIN_MASK) | MC_InitStruct->MC_TachoPolarity;
/* Set the MC PWM Forced State */
MC->OPR |= MC_ODS_Set;
MC->OPR = (MC->OPR & MC_OPR_Mask) | MC_InitStruct->MC_ForcedPWMState;
/* Select the Tacho Mode */
if(MC_InitStruct->MC_TachoMode == MC_TachoOneShot_Mode)
{
MC->PCR1 |= MC_TCB_Set;
}
else
{
MC->PCR1 &= MC_TCB_Reset;
}
/* Select the Tacho Event Mode */
if(MC_InitStruct->MC_TachoEvent_Mode == MC_TachoEvent_Software_Mode)
{
MC->PCR1 |= MC_TES_Set;
}
else
{
MC->PCR1 &= MC_TES_Reset;
}
/* Enable or disable the emergency input */
if(MC_InitStruct->MC_Emergency == MC_Emergency_Enable)
{
MC->PCR1 &= MC_DISEST_Reset;
}
else
{
MC->PCR1 |= MC_DISEST_Set;
}
/* Select the complementary Mode */
if(MC_InitStruct->MC_Complementary == MC_Complementary_Enable)
{
MC->DTG = MC_InitStruct->MC_DeadTime;
MC->PCR0 |= MC_ODCS_Set;
}
else
{
MC->PCR0 &= MC_ODCS_Reset;
}
/* Tacho Mode selection */
if(MC_InitStruct->MC_TachoMode == MC_TachoOneShot_Mode)
{
MC->PCR1 |= MC_TCB_Set;
}
else
{
MC->PCR1 &= MC_TCB_Reset;
}
switch(MC_InitStruct->MC_Channel)
{
/* Channel U configuration */
case MC_Channel_U:
{
MC->CMPU = MC_InitStruct->MC_PulseU;
if(MC_InitStruct->MC_PolarityUL == MC_Polarity_Inverted)
{
MC->PSR |= MC_PUL_Set;
}
else
{
MC->PSR &= MC_PUL_Reset;
}
if(MC_InitStruct->MC_PolarityUH == MC_Polarity_Inverted)
{
MC->PSR |= MC_PUH_Set;
}
else
{
MC->PSR &= MC_PUH_Reset;
}
break;
}
/* Channel V configuration */
case MC_Channel_V:
{
MC->CMPV = MC_InitStruct->MC_PulseV;
if(MC_InitStruct->MC_PolarityVL == MC_Polarity_Inverted)
{
MC->PSR |= MC_PVL_Set;
}
else
{
MC->PSR &= MC_PVL_Reset;
}
if(MC_InitStruct->MC_PolarityVH == MC_Polarity_Inverted)
{
MC->PSR |= MC_PVH_Set;
}
else
{
MC->PSR &= MC_PVH_Reset;
}
break;
}
/* Channel W configuration */
case MC_Channel_W:
{
MC->CMPW = MC_InitStruct->MC_PulseW;
if(MC_InitStruct->MC_PolarityWL == MC_Polarity_Inverted)
{
MC->PSR |= MC_PWL_Set;
}
else
{
MC->PSR &= MC_PWL_Reset;
}
if(MC_InitStruct->MC_PolarityWH == MC_Polarity_Inverted)
{
MC->PSR |= MC_PWH_Set;
}
else
{
MC->PSR &= MC_PWH_Reset;
}
break;
}
/* All Channel Configuration */
case MC_Channel_ALL:
{
MC->CMPU = MC_InitStruct->MC_PulseU;
MC->CMPV = MC_InitStruct->MC_PulseV;
MC->CMPW = MC_InitStruct->MC_PulseW;
if(MC_InitStruct->MC_PolarityUL == MC_Polarity_Inverted)
{
MC->PSR |= MC_PUL_Set;
}
else
{
MC->PSR &= MC_PUL_Reset;
}
if(MC_InitStruct->MC_PolarityUH == MC_Polarity_Inverted)
{
MC->PSR |= MC_PUH_Set;
}
else
{
MC->PSR &= MC_PUH_Reset;
}
if(MC_InitStruct->MC_PolarityVL == MC_Polarity_Inverted)
{
MC->PSR |= MC_PVL_Set;
}
else
{
MC->PSR &= MC_PVL_Reset;
}
if(MC_InitStruct->MC_PolarityVH == MC_Polarity_Inverted)
{
MC->PSR |= MC_PVH_Set;
}
else
{
MC->PSR &= MC_PVH_Reset;
}
if(MC_InitStruct->MC_PolarityWL == MC_Polarity_Inverted)
{
MC->PSR |= MC_PWL_Set;
}
else
{
MC->PSR &= MC_PWL_Reset;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -