中断向量表由平台实现,减少核心系统对芯片的依赖
This commit is contained in:
parent
d7ff86fc37
commit
fd612d1054
|
@ -2,25 +2,16 @@
|
||||||
|
|
||||||
#include "Interrupt.h"
|
#include "Interrupt.h"
|
||||||
|
|
||||||
TInterrupt Interrupt;
|
extern InterruptCallback Vectors[]; // 对外的中断向量表
|
||||||
|
extern void* Params[]; // 每一个中断向量对应的参数
|
||||||
|
|
||||||
//#define IS_IRQ(irq) (irq >= -16 && irq <= VectorySize - 16)
|
TInterrupt Interrupt;
|
||||||
|
|
||||||
void TInterrupt::Init() const
|
void TInterrupt::Init() const
|
||||||
{
|
{
|
||||||
OnInit();
|
OnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*TInterrupt::~TInterrupt()
|
|
||||||
{
|
|
||||||
// 恢复中断向量表
|
|
||||||
#if defined(STM32F1) || defined(STM32F4)
|
|
||||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0);
|
|
||||||
#else
|
|
||||||
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_Flash);
|
|
||||||
#endif
|
|
||||||
}*/
|
|
||||||
|
|
||||||
bool TInterrupt::Activate(short irq, InterruptCallback isr, void* param)
|
bool TInterrupt::Activate(short irq, InterruptCallback isr, void* param)
|
||||||
{
|
{
|
||||||
short irq2 = irq + 16; // exception = irq + 16
|
short irq2 = irq + 16; // exception = irq + 16
|
||||||
|
@ -42,10 +33,8 @@ bool TInterrupt::Deactivate(short irq)
|
||||||
// 关键性代码,放到开头
|
// 关键性代码,放到开头
|
||||||
INROOT void TInterrupt::Process(uint num) const
|
INROOT void TInterrupt::Process(uint num) const
|
||||||
{
|
{
|
||||||
auto& inter = Interrupt;
|
//auto& inter = Interrupt;
|
||||||
//assert_param(num < VectorySize);
|
if(!Vectors[num]) return;
|
||||||
//assert_param(Interrupt.Vectors[num]);
|
|
||||||
if(!inter.Vectors[num]) return;
|
|
||||||
|
|
||||||
// 内存检查
|
// 内存检查
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -53,8 +42,8 @@ INROOT void TInterrupt::Process(uint num) const
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 找到应用层中断委托并调用
|
// 找到应用层中断委托并调用
|
||||||
auto isr = (InterruptCallback)inter.Vectors[num];
|
auto isr = (InterruptCallback)Vectors[num];
|
||||||
void* param = (void*)inter.Params[num];
|
void* param = (void*)Params[num];
|
||||||
isr(num - 16, param);
|
isr(num - 16, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,28 +4,12 @@
|
||||||
// 中断委托(中断号,参数)
|
// 中断委托(中断号,参数)
|
||||||
typedef void (*InterruptCallback)(ushort num, void* param);
|
typedef void (*InterruptCallback)(ushort num, void* param);
|
||||||
|
|
||||||
#ifdef STM32F1
|
|
||||||
#define VectorySize 84
|
|
||||||
#elif defined(STM32F0)
|
|
||||||
#define VectorySize 48
|
|
||||||
#elif defined(GD32F150)
|
|
||||||
#define VectorySize 64
|
|
||||||
#elif defined(STM32F4)
|
|
||||||
#define VectorySize (86 + 16 + 1)
|
|
||||||
#else
|
|
||||||
#define VectorySize 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//VectorySize 64 未考证
|
//VectorySize 64 未考证
|
||||||
// 中断管理类
|
// 中断管理类
|
||||||
class TInterrupt
|
class TInterrupt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InterruptCallback Vectors[VectorySize]; // 对外的中断向量表
|
|
||||||
void* Params[VectorySize]; // 每一个中断向量对应的参数
|
|
||||||
|
|
||||||
void Init() const; // 初始化中断向量表
|
void Init() const; // 初始化中断向量表
|
||||||
//~TInterrupt();
|
|
||||||
|
|
||||||
void Process(uint num) const;
|
void Process(uint num) const;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,21 @@
|
||||||
|
|
||||||
#define IS_IRQ(irq) (irq >= -16 && irq <= VectorySize - 16)
|
#define IS_IRQ(irq) (irq >= -16 && irq <= VectorySize - 16)
|
||||||
|
|
||||||
|
#ifdef STM32F1
|
||||||
|
#define VectorySize 84
|
||||||
|
#elif defined(STM32F0)
|
||||||
|
#define VectorySize 48
|
||||||
|
#elif defined(GD32F150)
|
||||||
|
#define VectorySize 64
|
||||||
|
#elif defined(STM32F4)
|
||||||
|
#define VectorySize (86 + 16 + 1)
|
||||||
|
#else
|
||||||
|
#define VectorySize 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
InterruptCallback Vectors[VectorySize]; // 对外的中断向量表
|
||||||
|
void* Params[VectorySize]; // 每一个中断向量对应的参数
|
||||||
|
|
||||||
bool TInterrupt::OnActivate(short irq)
|
bool TInterrupt::OnActivate(short irq)
|
||||||
{
|
{
|
||||||
assert_param(IS_IRQ(irq));
|
assert_param(IS_IRQ(irq));
|
||||||
|
|
|
@ -20,13 +20,7 @@ ArpSocket::ArpSocket(TinyIP* tip) : TinySocket(tip, IP_NONE)
|
||||||
{
|
{
|
||||||
//Type = IP_NONE;
|
//Type = IP_NONE;
|
||||||
|
|
||||||
#ifdef STM32F0
|
Count = 8;
|
||||||
Count = 4;
|
|
||||||
#elif defined(STM32F1)
|
|
||||||
Count = 16;
|
|
||||||
#elif defined(STM32F4)
|
|
||||||
Count = 64;
|
|
||||||
#endif
|
|
||||||
_Arps = nullptr;
|
_Arps = nullptr;
|
||||||
|
|
||||||
Enable = true;
|
Enable = true;
|
||||||
|
|
Loading…
Reference in New Issue