重构BSP架构
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
#include "Bsp.h"
|
||||
|
||||
INTERRUPT_ST Interrupt[INTERRUPT_NUM];
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数初始化为空
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note 初始化系统中断
|
||||
* @example void
|
||||
*/
|
||||
void SystemInterruptInit(void)
|
||||
{
|
||||
//设定系统中断组
|
||||
NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||
//清空结构体
|
||||
for (uint8_t i = 0;i < INTERRUPT_NUM;i++)
|
||||
{
|
||||
Interrupt[i].CallBack = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数注册
|
||||
* @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||
* @retval void
|
||||
* @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||
* @example void
|
||||
*/
|
||||
void InterruptRegister(uint32_t Irqn, void(*Func)(uint32_t))
|
||||
{
|
||||
Interrupt[Irqn].CallBack = Func;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断NVIC配置
|
||||
* @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||
* @retval void
|
||||
* @note 设定一个中断的优先级
|
||||
* @example void
|
||||
*/
|
||||
void InterruptSetLevel(uint32_t Vector, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭中断
|
||||
* @param Vector:中断号
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void InterruptDisable(uint32_t Vector)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Vector;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
void USART1_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(USART1, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(USART1, USART_FLAG_ORE);
|
||||
}
|
||||
(*Interrupt[USART1_IRQn].CallBack)((uint32_t)USART1);
|
||||
}
|
||||
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(USART2, USART_FLAG_ORE);
|
||||
}
|
||||
(*Interrupt[USART2_IRQn].CallBack)((uint32_t)USART2);
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(USART3, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(USART3, USART_FLAG_ORE);
|
||||
}
|
||||
(*Interrupt[USART3_IRQn].CallBack)((uint32_t)USART3);
|
||||
}
|
||||
|
||||
|
||||
void USART4_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(UART4, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(UART4, USART_FLAG_ORE);
|
||||
}
|
||||
(*Interrupt[UART4_IRQn].CallBack)((uint32_t)UART4);
|
||||
}
|
||||
|
||||
void USART5_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(UART5, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(UART5, USART_FLAG_ORE);
|
||||
}
|
||||
(*Interrupt[UART5_IRQn].CallBack)((uint32_t)UART5);
|
||||
}
|
||||
Reference in New Issue
Block a user