串口和中断写完
This commit is contained in:
+120
-114
@@ -1,114 +1,120 @@
|
||||
// #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);
|
||||
// }
|
||||
#include "Bsp.h"
|
||||
|
||||
#define IRQ_NULL ((void *)0)
|
||||
|
||||
IRQ_MAP_T IRQ_PERIPH[IRQ_NUM] = {0x00};
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数初始化为空
|
||||
* @note 初始化系统中断
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void IrqInit(void)
|
||||
{
|
||||
//设定系统中断组
|
||||
NVIC_PriorityGroupConfig(NVIC_GROUP_LEVEL);
|
||||
for (uint8_t i = 0; i < IRQ_NUM; i++) {
|
||||
IRQ_PERIPH[i].IrqCallback = IRQ_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断回调函数注册
|
||||
* @note 将外部传入的函数地址关联到INTERRUPT_ST表中
|
||||
* @param Vector:中断号 void(*Func)(uint32_t):回调函数
|
||||
* @retval void
|
||||
*/
|
||||
void IrqRegister(unsigned int Irq, void(*Func)(void *Param))
|
||||
{
|
||||
IRQ_PERIPH[Irq].IrqCallback = Func;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 中断NVIC配置
|
||||
* @note 设定一个中断的优先级
|
||||
* @param Vector:中断号 NvicPrePriority:主优先级 NvicSubPriority:抢占优先级
|
||||
* @retval void
|
||||
*/
|
||||
void IrqConfig(uint32_t Irq, uint8_t NvicPrePriority, uint8_t NvicSubPriority)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NvicPrePriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = NvicSubPriority;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭中断
|
||||
* @note void
|
||||
* @param Vector:中断号
|
||||
* @retval void
|
||||
*/
|
||||
void IrqDisable(uint32_t Irq)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = Irq;
|
||||
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(COM0->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM0->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM0->Periph.Irqn].IrqCallback(COM0);
|
||||
}
|
||||
}
|
||||
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM1->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM1->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM1->Periph.Irqn].IrqCallback(COM1);
|
||||
}
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM2->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM2->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM2->Periph.Irqn].IrqCallback(COM1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void USART4_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM3->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM3->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM3->Periph.Irqn].IrqCallback(COM3);
|
||||
}
|
||||
}
|
||||
|
||||
void USART5_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetFlagStatus(COM4->Periph.UartId, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ClearFlag(COM4->Periph.UartId, USART_FLAG_ORE);
|
||||
}
|
||||
if (IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback != IRQ_NULL) {
|
||||
IRQ_PERIPH[COM4->Periph.Irqn].IrqCallback(COM4);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user