📄 stm32f10x_nvic.c
字号:
}
/*******************************************************************************
* 函数名称: NVIC_SetVectorTable
* 功能描述: 设置向量表的位置和偏移量.
* 输入参数: (1)NVIC_VectTab:指定中断向量表在RAM还是在FLASH存储器中.
* 这个参数可以取下面的值之一:
* - NVIC_VectTab_RAM
* - NVIC_VectTab_FLASH
* (2)Offset:向量表的基址偏移,这个值一定要比0x0100高.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset)
{
/* Check the parameters [检查参数]*/
assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
assert_param(IS_NVIC_OFFSET(Offset));
SCB->VTOR = NVIC_VectTab | (Offset & (u32)0x1FFFFF80);
}
/*******************************************************************************
* 函数名称: NVIC_GenerateSystemReset
* 功能描述: 生成一个系统复位.
* 输入参数: 无
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_GenerateSystemReset(void)
{
SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32)0x04;
}
/*******************************************************************************
* 函数名称: NVIC_GenerateCoreReset
* 功能描述: 生成一个核(Core+NVIC)复位.
* 输入参数: 无
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_GenerateCoreReset(void)
{
SCB->AIRCR = AIRCR_VECTKEY_MASK | (u32)0x01;
}
/*******************************************************************************
* 函数名称: NVIC_SystemLPConfig
* 功能描述: 选择系统进入低功耗模式的条件。
* 输入参数: (1)LowPowerMode:系统为进入低功耗模式的新模式.
* 这个参数可以取下面的值之一:
* - NVIC_LP_SEVONPEND
* - NVIC_LP_SLEEPDEEP
* - NVIC_LP_SLEEPONEXIT
* (2)NewState:LP条件的新状态.这个参数可以是:ENABLE或DISABLE.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_SystemLPConfig(u8 LowPowerMode, FunctionalState NewState)
{
/* Check the parameters [检查参数]*/
assert_param(IS_NVIC_LP(LowPowerMode));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
SCB->SCR |= LowPowerMode;
}
else
{
SCB->SCR &= (u32)(~(u32)LowPowerMode);
}
}
/*******************************************************************************
* 函数名称: NVIC_SystemHandlerConfig
* 功能描述: 使能或关闭指定的系统处理程序。
* 输入参数: (1)SystemHandler:系统处理程序有效或无效..
* 这个参数可以取下面的值之一:
* - SystemHandler_MemoryManage
* - SystemHandler_BusFault
* - SystemHandler_UsageFault
* (2)NewState:指定系统处理程序的新状态.这个参数可以是:ENABLE或DISABLE.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_SystemHandlerConfig(u32 SystemHandler, FunctionalState NewState)
{
u32 tmpreg = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_CONFIG_SYSTEM_HANDLER(SystemHandler));
assert_param(IS_FUNCTIONAL_STATE(NewState));
tmpreg = (u32)0x01 << (SystemHandler & (u32)0x1F);
if (NewState != DISABLE)
{
SCB->SHCSR |= tmpreg;
}
else
{
SCB->SHCSR &= ~tmpreg;
}
}
/*******************************************************************************
* 函数名称: NVIC_SystemHandlerPriorityConfig
* 功能描述: 配置指定系统处理程序的优先级。
* 输入参数: (1)SystemHandler:使能或关闭系统处理程序.
* 这个参数可以取下面的值之一:
* - SystemHandler_MemoryManage
* - SystemHandler_BusFault
* - SystemHandler_UsageFault
* - SystemHandler_SVCall
* - SystemHandler_DebugMonitor
* - SystemHandler_PSV
* - SystemHandler_SysTick
* (2)SystemHandlerPreemptionPriority:指定系统处理程序的新的优先级组.
* (3)SystemHandlerSubPriority:指定系统处理程序的新子优先级.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_SystemHandlerPriorityConfig(u32 SystemHandler, u8 SystemHandlerPreemptionPriority,
u8 SystemHandlerSubPriority)
{
u32 tmp1 = 0x00, tmp2 = 0xFF, handlermask = 0x00;
u32 tmppriority = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_PRIORITY_SYSTEM_HANDLER(SystemHandler));
assert_param(IS_NVIC_PREEMPTION_PRIORITY(SystemHandlerPreemptionPriority));
assert_param(IS_NVIC_SUB_PRIORITY(SystemHandlerSubPriority));
tmppriority = (0x700 - (SCB->AIRCR & (u32)0x700))>> 0x08;
tmp1 = (0x4 - tmppriority);
tmp2 = tmp2 >> tmppriority;
tmppriority = (u32)SystemHandlerPreemptionPriority << tmp1;
tmppriority |= SystemHandlerSubPriority & tmp2;
tmppriority = tmppriority << 0x04;
tmp1 = SystemHandler & (u32)0xC0;
tmp1 = tmp1 >> 0x06;
tmp2 = (SystemHandler >> 0x08) & (u32)0x03;
tmppriority = tmppriority << (tmp2 * 0x08);
handlermask = (u32)0xFF << (tmp2 * 0x08);
SCB->SHPR[tmp1] &= ~handlermask;
SCB->SHPR[tmp1] |= tmppriority;
}
/*******************************************************************************
* 函数名称: NVIC_GetSystemHandlerPendingBitStatus
* 功能描述: 检查指定系统处理程序挂起位设置与否。
* 输入参数: SystemHandler:要检查的系统处理程序挂起位.
* 这个参数可以取下面的值之一:
* - SystemHandler_MemoryManage
* - SystemHandler_BusFault
* - SystemHandler_SVCall
* 输出参数: 无
* 返回参数: 系统处理程序挂起位的新状态(SET or RESET).
*******************************************************************************/
ITStatus NVIC_GetSystemHandlerPendingBitStatus(u32 SystemHandler)
{
ITStatus bitstatus = RESET;
u32 tmp = 0x00, tmppos = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_GET_PENDING_SYSTEM_HANDLER(SystemHandler));
tmppos = (SystemHandler >> 0x0A);
tmppos &= (u32)0x0F;
tmppos = (u32)0x01 << tmppos;
tmp = SCB->SHCSR & tmppos;
if (tmp == tmppos)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
/*******************************************************************************
* 函数名称: NVIC_SetSystemHandlerPendingBit
* 功能描述: 设置系统处理程序挂起位。
* 输入参数: SystemHandler:要设置的系统处理程序挂起位.
* 这个参数可以取下面的值之一:
* - SystemHandler_NMI
* - SystemHandler_PSV
* - SystemHandler_SysTick
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_SetSystemHandlerPendingBit(u32 SystemHandler)
{
u32 tmp = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_SET_PENDING_SYSTEM_HANDLER(SystemHandler));
/* Get the System Handler pending bit position [取得系统处理程序挂起位位置]*/
tmp = SystemHandler & (u32)0x1F;
/* Set the corresponding System Handler pending bit [置位相应的系统处理程序挂起位]*/
SCB->ICSR |= ((u32)0x01 << tmp);
}
/*******************************************************************************
* 函数名称: NVIC_ClearSystemHandlerPendingBit
* 功能描述: 清除系统处理程序挂起位。
* 输入参数: SystemHandler:要复位的系统处理程序挂起位.
* 这个参数可以取下面的值之一:
* - SystemHandler_PSV
* - SystemHandler_SysTick
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void NVIC_ClearSystemHandlerPendingBit(u32 SystemHandler)
{
u32 tmp = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_CLEAR_SYSTEM_HANDLER(SystemHandler));
/* Get the System Handler pending bit position [取得系统处理程序挂起位位置]*/
tmp = SystemHandler & (u32)0x1F;
/* Clear the corresponding System Handler pending bit [清除相应的系统处理程序挂起位]*/
SCB->ICSR |= ((u32)0x01 << (tmp - 0x01));
}
/*******************************************************************************
* 函数名称: NVIC_GetSystemHandlerActiveBitStatus
* 功能描述: 检查指定系统处理程序活动位设置与否。
* 输入参数: SystemHandler:要检查的系统处理程序活动位.
* 这个参数可以取下面的值之一:
* - SystemHandler_MemoryManage
* - SystemHandler_BusFault
* - SystemHandler_UsageFault
* - SystemHandler_SVCall
* - SystemHandler_DebugMonitor
* - SystemHandler_PSV
* - SystemHandler_SysTick
* 输出参数: 无
* 返回参数: 系统处理程序活动位的新状态(SET or RESET).
*******************************************************************************/
ITStatus NVIC_GetSystemHandlerActiveBitStatus(u32 SystemHandler)
{
ITStatus bitstatus = RESET;
u32 tmp = 0x00, tmppos = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_GET_ACTIVE_SYSTEM_HANDLER(SystemHandler));
tmppos = (SystemHandler >> 0x0E) & (u32)0x0F;
tmppos = (u32)0x01 << tmppos;
tmp = SCB->SHCSR & tmppos;
if (tmp == tmppos)
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}
/*******************************************************************************
* 函数名称: NVIC_GetFaultHandlerSources
* 功能描述: 返回系统处理程序故障源.
* 输入参数: SystemHandler:将要返回故障源的系统处理程序
* 这个参数可以取下面的值之一:
* - SystemHandler_HardFault
* - SystemHandler_MemoryManage
* - SystemHandler_BusFault
* - SystemHandler_UsageFault
* - SystemHandler_DebugMonitor
* 输出参数: 无
* 返回参数: 故障处理程序源.
*******************************************************************************/
u32 NVIC_GetFaultHandlerSources(u32 SystemHandler)
{
u32 faultsources = 0x00;
u32 tmpreg = 0x00, tmppos = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_FAULT_SOURCE_SYSTEM_HANDLER(SystemHandler));
tmpreg = (SystemHandler >> 0x12) & (u32)0x03;
tmppos = (SystemHandler >> 0x14) & (u32)0x03;
if (tmpreg == 0x00)
{
faultsources = SCB->HFSR;
}
else if (tmpreg == 0x01)
{
faultsources = SCB->CFSR >> (tmppos * 0x08);
if (tmppos != 0x02)
{
faultsources &= (u32)0x0F;
}
else
{
faultsources &= (u32)0xFF;
}
}
else
{
faultsources = SCB->DFSR;
}
return faultsources;
}
/*******************************************************************************
* 函数名称: NVIC_GetFaultAddress
* 功能描述: 返回生成故障处理程序位置的地址.
* 输入参数: SystemHandler:将要返回故障地址的系统处理程序.
* 这个参数可以取下面的值之一:
* - SystemHandler_MemoryManage
* - SystemHandler_BusFault
* 输出参数: 无
* 返回参数: Fault address.
*******************************************************************************/
u32 NVIC_GetFaultAddress(u32 SystemHandler)
{
u32 faultaddress = 0x00;
u32 tmp = 0x00;
/* Check the parameters [检查参数]*/
assert_param(IS_FAULT_ADDRESS_SYSTEM_HANDLER(SystemHandler));
tmp = (SystemHandler >> 0x16) & (u32)0x01;
if (tmp == 0x00)
{
faultaddress = SCB->MMFAR;
}
else
{
faultaddress = SCB->BFAR;
}
return faultaddress;
}
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -