From f372c5391b84684ac199752634c7308bccf54f73 Mon Sep 17 00:00:00 2001 From: nnhy Date: Wed, 19 Aug 2015 02:49:55 +0000 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E8=A6=81=E4=B8=89=E5=A4=A7=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9A=84=E6=9E=90=E6=9E=84=E5=87=BD=E6=95=B0=E7=94=A8?= =?UTF-8?q?=E4=B8=8D=E7=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interrupt.cpp | 62 ++------------------------------------------------- Interrupt.h | 13 +++++++---- Sys.cpp | 4 ++-- Sys.h | 18 ++++++--------- Time.cpp | 4 ++-- Time.h | 2 +- 6 files changed, 23 insertions(+), 80 deletions(-) diff --git a/Interrupt.cpp b/Interrupt.cpp index 6df1c776..1c2b0a4a 100644 --- a/Interrupt.cpp +++ b/Interrupt.cpp @@ -1,31 +1,7 @@ #include "Interrupt.h" -// GD32全系列无法把向量表映射到RAM,F103只能映射到Flash别的地方 -/*#if defined(GD32)// || defined(STM32F4) - #define VEC_TABLE_ON_RAM 0 -#else - #define VEC_TABLE_ON_RAM 1 -#endif*/ - -/* -完全接管中断,在RAM中开辟中断向量表,做到随时可换。 -由于中断向量表要求128对齐,这里多分配128字节,找到对齐点后给向量表使用 - -为了增强中断函数处理,我们使用_Vectors作为真正的中断向量表,全部使用OnHandler作为中断处理函数。 -然后在OnHandler内部获取中断号,再调用Vectors中保存的用户委托,并向它传递中断号和参数。 -*/ TInterrupt Interrupt; -// 真正的向量表 64k=0x10000 -/*#if VEC_TABLE_ON_RAM -#ifdef STM32F0 - __IO Func _Vectors[VectorySize] __attribute__((at(0x20000000))); -#else - // 84个中断向量,向上取整到2整数倍也就是128,128*4=512=0x200。CM3权威手册 - __IO Func _Vectors[VectorySize] __attribute__((__aligned__(0x200))); -#endif -#endif*/ - #define IS_IRQ(irq) (irq >= -16 && irq <= VectorySize - 16) void TInterrupt::Init() @@ -44,33 +20,6 @@ void TInterrupt::Init() NVIC->ICPR[2] = 0xFFFFFFFF; #endif -/*#if VEC_TABLE_ON_RAM - memset((void*)_Vectors, 0, VectorySize << 2); - _Vectors[2] = (Func)&FaultHandler; // NMI - _Vectors[3] = (Func)&FaultHandler; // Hard Fault - _Vectors[4] = (Func)&FaultHandler; // MMU Fault - _Vectors[5] = (Func)&FaultHandler; // Bus Fault - _Vectors[6] = (Func)&FaultHandler; // Usage Fault - _Vectors[11] = (Func)&FaultHandler; // SVC - _Vectors[12] = (Func)&FaultHandler; // Debug - _Vectors[14] = (Func)&FaultHandler; // PendSV - _Vectors[15] = (Func)&FaultHandler; // Systick - -#if defined(STM32F1) || defined(STM32F4) - __DMB(); // 确保中断表已经被写入 - - SCB->AIRCR = (0x5FA << SCB_AIRCR_VECTKEY_Pos) // 解锁 - | (7 << SCB_AIRCR_PRIGROUP_Pos); // 没有优先组位 - //SCB->VTOR = (uint)_Vectors; // 向量表基地址 - NVIC_SetVectorTable(NVIC_VectTab_RAM, (uint)((byte*)_Vectors - SRAM_BASE)); - assert_param(SCB->VTOR == (uint)_Vectors); -#else - // Enable the SYSCFG peripheral clock - RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE); - // Remap SRAM at 0x00000000 - SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM); -#endif -#else*/ #ifdef STM32F4 /*SCB->AIRCR = (0x5FA << SCB_AIRCR_VECTKEY_Pos) // 解锁 | (7 << SCB_AIRCR_PRIGROUP_Pos); // 没有优先组位*/ @@ -91,13 +40,12 @@ void TInterrupt::Init() | SCB_SHCSR_BUSFAULTENA | SCB_SHCSR_MEMFAULTENA; #endif -//#endif // 初始化EXTI中断线为默认值 EXTI_DeInit(); } -TInterrupt::~TInterrupt() +/*TInterrupt::~TInterrupt() { // 恢复中断向量表 #if defined(STM32F1) || defined(STM32F4) @@ -105,16 +53,13 @@ TInterrupt::~TInterrupt() #else SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_Flash); #endif -} +}*/ bool TInterrupt::Activate(short irq, InterruptCallback isr, void* param) { assert_param(IS_IRQ(irq)); short irq2 = irq + 16; // exception = irq + 16 -/*#if VEC_TABLE_ON_RAM - _Vectors[irq2] = UserHandler; -#endif*/ Vectors[irq2] = isr; Params[irq2] = param; @@ -229,8 +174,6 @@ bool TInterrupt::IsHandler() { return GetIPSR() & 0x01; } void UserHandler() { uint num = GetIPSR(); - //if(num >= VectorySize) return; - //if(!Interrupt.Vectors[num]) return; assert_param(num < VectorySize); assert_param(Interrupt.Vectors[num]); @@ -254,7 +197,6 @@ extern "C" void FAULT_SubHandler(uint* registers, uint exception) __attribute__((section("SubHandler"))); void FAULT_SubHandler(uint* registers, uint exception) { - //uint exception = GetIPSR(); #ifdef STM32F0 debug_printf("LR=0x%08x PC=0x%08x PSR=0x%08x\r\n", registers[5], registers[6], registers[7]); for(int i=0; i<=7; i++) diff --git a/Interrupt.h b/Interrupt.h index a0e304d0..fd82e5f3 100644 --- a/Interrupt.h +++ b/Interrupt.h @@ -17,15 +17,12 @@ typedef void (*InterruptCallback)(ushort num, void* param); // 中断管理类 class TInterrupt { -private: - //static uint GetIPSR(); // 获取中断号 - //static void FaultHandler(); // 错误处理程序 public: InterruptCallback Vectors[VectorySize]; // 对外的中断向量表 void* Params[VectorySize]; // 每一个中断向量对应的参数 void Init(); // 初始化中断向量表 - ~TInterrupt(); + //~TInterrupt(); // 注册中断函数(中断号,函数,参数) bool Activate(short irq, InterruptCallback isr, void* param = NULL); @@ -101,3 +98,11 @@ extern "C" } #endif + +/* +完全接管中断,在RAM中开辟中断向量表,做到随时可换。 +由于中断向量表要求128对齐,这里多分配128字节,找到对齐点后给向量表使用 + +为了增强中断函数处理,我们使用_Vectors作为真正的中断向量表,全部使用OnHandler作为中断处理函数。 +然后在OnHandler内部获取中断号,再调用Vectors中保存的用户委托,并向它传递中断号和参数。 +*/ diff --git a/Sys.cpp b/Sys.cpp index c2f838cb..8aa615cd 100644 --- a/Sys.cpp +++ b/Sys.cpp @@ -215,10 +215,10 @@ TSys::TSys() OnStart = NULL; } -TSys::~TSys() +/*TSys::~TSys() { if(OnStop) OnStop(); -} +}*/ void ShowTime(void* param) { diff --git a/Sys.h b/Sys.h index faa3551b..3d279c7e 100644 --- a/Sys.h +++ b/Sys.h @@ -66,11 +66,6 @@ typedef enum // 判定指针是否在ROM区 #define IN_ROM_SECTION(p) ( (int)p < 0x20000000 ) -// 列表集合 -//#include "List.h" - -//class TaskScheduler; - // 系统类 class TSys : Object { @@ -80,13 +75,14 @@ public: COM_Def MessagePort;// 消息口,默认0表示USART1 bool IsGD; // 是否GD芯片 - char* Name; // 系统名称 - ushort Code; // 产品代码 - ushort Version; // 系统版本 - char* Company; // 系统厂商 - char* BuildTime; // 编译时间 uint Clock; // 系统时钟 uint CystalClock;// 晶振时钟 + + char* Name; // 系统名称 + char* Company; // 系统厂商 + char* BuildTime; // 编译时间 + ushort Code; // 产品代码 + ushort Version; // 系统版本 byte ID[12]; // 芯片ID。 ushort DevID; // MCU编码。低字设备版本,高字子版本 ushort RevID; // MCU编码。低字设备版本,高字子版本 @@ -95,7 +91,7 @@ public: ushort RAMSize; // 芯片RAM容量 TSys(); // 构造函数 - ~TSys(); // 析构函数 + //~TSys(); // 析构函数 void InitClock(); // 初始化系统时钟 void Init(); // 初始化系统 diff --git a/Time.cpp b/Time.cpp index 43117dc2..6a0c6f54 100644 --- a/Time.cpp +++ b/Time.cpp @@ -22,12 +22,12 @@ TTime::TTime() _msUs = 0; } -TTime::~TTime() +/*TTime::~TTime() { Interrupt.Deactivate(SysTick_IRQn); // 关闭定时器 SysTick->CTRL &= ~SYSTICK_ENABLE; -} +}*/ void TTime::Init() { diff --git a/Time.h b/Time.h index 8335f0e4..826c3cf2 100644 --- a/Time.h +++ b/Time.h @@ -27,7 +27,7 @@ public: HardRTC* _RTC; TTime(); - ~TTime(); + //~TTime(); void UseRTC(); // 使用RTC,必须在Init前调用 void Init();