📄 75x_tb.c
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : 75x_tb.c
* Author : MCD Application Team
* Date First Issued : 03/10/2006 : V0.1
* Description : This file provides all the TB software functions.
********************************************************************************
* History:
* 03/10/2006 : V0.1
********************************************************************************
* 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.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "75x_tb.h"
#include "75x_mrcc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#define TB_IT_Enable_Mask 0x7FFF
#define TB_IT_Clear_Mask 0x7FFF
#define TB_IC_Enable 0x0004
#define TB_ICPolarity_Set 0x0008
#define TB_ICPolarity_Reset 0xFFF7
#define TB_UFS_Reset 0xFFFE
#define TB_UFS_Set 0x0001
/* TB debug state */
#define TB_DBGC_Set 0x0400
#define TB_DBGC_Reset 0xFB7F
/* TB counter state */
#define TB_COUNTER_Reset 0x0002
#define TB_COUNTER_Start 0x0004
#define TB_COUNTER_Stop 0xFFFB
#define TB_SMS_EXTCLK_Set 0x0008
#define TB_SMS_RESETCLK_Set 0x0000
/* TB Slave Mode Enable Set/Reset value */
#define TB_SME_Reset 0x731B
#define TB_SME_Set 0x0004
/* TB Trigger Selection value */
#define TB_TS_IC1_Set 0x0200
/* TB SCR Masks bit */
#define TB_SlaveModeSelection_Mask 0x7307
#define TB_TriggerSelection_Mask 0x701F
#define TB_InternalTriggerSelection_Mask 0x031F
/* Reset Register Masks */
#define TB_Prescaler_Reset_Mask 0x0000
#define TB_CounterMode_Mask 0xFF8F
#define TB_AutoReload_Reset_Mask 0xFFFF
#define TB_ICAPolarity_Reset_Mask 0x0008
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************
* Function Name : TB_DeInit
* Description : Deinitializes the TB peripheral registers to their default
* reset values.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TB_DeInit(void)
{
/* Enters and exits the TB peripheral to and from reset */
MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TB,ENABLE);
MRCC_PeripheralSWResetConfig(MRCC_Peripheral_TB,DISABLE);
}
/*******************************************************************************
* Function Name : TB_Init
* Description : Initializes TB peripheral according to the specified
* parameters in the TB_InitStruct.
* Input : TB_InitStruct: pointer to a TB_InitTypeDef structure that
* contains the configuration information for the TB peripheral.
* Output : None
* Return : None
*******************************************************************************/
void TB_Init(TB_InitTypeDef* TB_InitStruct)
{
/* Set the TB prescaler value */
TB->PSC = TB_InitStruct->TB_Prescaler;
/* Set the TB period value */
TB->ARR = TB_InitStruct->TB_AutoReload;
/* Set the corresponding counter mode */
TB->CR = (TB->CR & TB_CounterMode_Mask) | TB_InitStruct->TB_CounterMode;
/* Set the corresponding clock source */
if(TB_InitStruct->TB_ClockSource == TB_ClockSource_CKRTC)
{
TB->SCR &= TB_SME_Reset & TB_SlaveModeSelection_Mask & TB_TriggerSelection_Mask;
TB->SCR |= TB_SMS_EXTCLK_Set | TB_SME_Set | TB_TS_IC1_Set;
}
else
{
TB->SCR &= TB_SME_Reset & TB_SlaveModeSelection_Mask & TB_TriggerSelection_Mask;
}
if(TB_InitStruct->TB_Mode == TB_Mode_IC)
{
/* Set the corresponding value in TB SCR register */
TB->SCR &= TB_SME_Reset & TB_SlaveModeSelection_Mask & TB_TriggerSelection_Mask;
TB->SCR |= TB_SMS_RESETCLK_Set | TB_SME_Set | TB_TS_IC1_Set;
/* Set the IC1 enable bit */
TB->IMCR |= TB_IC_Enable;
/* Set the input signal polarity */
if (TB_InitStruct->TB_ICAPolarity == TB_ICAPolarity_Falling)
{
TB->IMCR |= TB_ICPolarity_Set;
}
else
{
TB->IMCR &= TB_ICPolarity_Reset;
}
}
}
/*******************************************************************************
* Function Name : TB_StructInit
* Description : Fills each TB_InitStruct member with its default value
* Input : TB_InitStruct : pointer to a TB_InitTypeDef structure which
* will be initialized.
* Output : None
* Return : None
*******************************************************************************/
void TB_StructInit(TB_InitTypeDef *TB_InitStruct)
{
TB_InitStruct->TB_Mode = TB_Mode_Timing;
TB_InitStruct->TB_ClockSource = TB_ClockSource_CKTIM;
TB_InitStruct->TB_CounterMode = TB_CounterMode_Up;
TB_InitStruct->TB_ICAPolarity = TB_ICAPolarity_Rising;
TB_InitStruct->TB_Prescaler = TB_Prescaler_Reset_Mask;
TB_InitStruct->TB_AutoReload = TB_AutoReload_Reset_Mask;
}
/*******************************************************************************
* Function Name : TB_Cmd
* Description : Enables or disables the TB peripheral.
* Input : Newstate: new state of the TB peripheral. This parameter can
* be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TB_Cmd(FunctionalState Newstate)
{
if(Newstate == ENABLE)
{
TB->CR |= TB_COUNTER_Start;
}
else
{
TB->CR &= TB_COUNTER_Stop;
}
}
/*******************************************************************************
* Function Name : TB_ITConfig
* Description : Enables or disables the specified TB interrupt.
* Input : - TB_IT: specifies the TB interrupt sources to be enabled or
* disabled.
* This parameter can be any combination of the following values:
* - TB_IT_Update: TB Update interrupt
* - TB_IT_GlobalUpdate: TB Global Update interrupt
* - TB_IT_IC: TB Input Capture interrupt
* - Newstate: new state of the specified TB interrupts.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TB_ITConfig(u16 TB_IT, FunctionalState Newstate)
{
u16 TB_IT_Enable = 0;
TB_IT_Enable = TB_IT & TB_IT_Enable_Mask;
if(Newstate == ENABLE)
{
/* Update interrupt global source: overflow/undeflow, counter reset operation
or slave mode controller in reset mode */
if ((TB_IT & TB_IT_GlobalUpdate) == TB_IT_GlobalUpdate)
{
TB->CR &= TB_UFS_Reset;
}
/* Update interrupt source: counter overflow/underflow */
else if ((TB_IT & TB_IT_Update) == TB_IT_Update)
{
TB->CR |= TB_UFS_Set;
}
/* Select and enable the interrupts requests */
TB->RSR |= TB_IT_Enable;
TB->RER |= TB_IT_Enable;
}
/* Disable the interrupts requests */
else
{
TB->RSR &= ~TB_IT_Enable;
TB->RER &= ~TB_IT_Enable;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -