主要三大对象的析构函数用不着

This commit is contained in:
nnhy 2015-08-19 02:49:55 +00:00
parent 577ec221b4
commit f372c5391b
6 changed files with 23 additions and 80 deletions

View File

@ -1,31 +1,7 @@
#include "Interrupt.h" #include "Interrupt.h"
// GD32全系列无法把向量表映射到RAMF103只能映射到Flash别的地方
/*#if defined(GD32)// || defined(STM32F4)
#define VEC_TABLE_ON_RAM 0
#else
#define VEC_TABLE_ON_RAM 1
#endif*/
/*
RAM中开辟中断向量表
128128使
使_Vectors作为真正的中断向量表使OnHandler作为中断处理函数
OnHandler内部获取中断号Vectors中保存的用户委托
*/
TInterrupt Interrupt; TInterrupt Interrupt;
// 真正的向量表 64k=0x10000
/*#if VEC_TABLE_ON_RAM
#ifdef STM32F0
__IO Func _Vectors[VectorySize] __attribute__((at(0x20000000)));
#else
// 84个中断向量向上取整到2整数倍也就是128128*4=512=0x200。CM3权威手册
__IO Func _Vectors[VectorySize] __attribute__((__aligned__(0x200)));
#endif
#endif*/
#define IS_IRQ(irq) (irq >= -16 && irq <= VectorySize - 16) #define IS_IRQ(irq) (irq >= -16 && irq <= VectorySize - 16)
void TInterrupt::Init() void TInterrupt::Init()
@ -44,33 +20,6 @@ void TInterrupt::Init()
NVIC->ICPR[2] = 0xFFFFFFFF; NVIC->ICPR[2] = 0xFFFFFFFF;
#endif #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 #ifdef STM32F4
/*SCB->AIRCR = (0x5FA << SCB_AIRCR_VECTKEY_Pos) // 解锁 /*SCB->AIRCR = (0x5FA << SCB_AIRCR_VECTKEY_Pos) // 解锁
| (7 << SCB_AIRCR_PRIGROUP_Pos); // 没有优先组位*/ | (7 << SCB_AIRCR_PRIGROUP_Pos); // 没有优先组位*/
@ -91,13 +40,12 @@ void TInterrupt::Init()
| SCB_SHCSR_BUSFAULTENA | SCB_SHCSR_BUSFAULTENA
| SCB_SHCSR_MEMFAULTENA; | SCB_SHCSR_MEMFAULTENA;
#endif #endif
//#endif
// 初始化EXTI中断线为默认值 // 初始化EXTI中断线为默认值
EXTI_DeInit(); EXTI_DeInit();
} }
TInterrupt::~TInterrupt() /*TInterrupt::~TInterrupt()
{ {
// 恢复中断向量表 // 恢复中断向量表
#if defined(STM32F1) || defined(STM32F4) #if defined(STM32F1) || defined(STM32F4)
@ -105,16 +53,13 @@ TInterrupt::~TInterrupt()
#else #else
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_Flash); SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_Flash);
#endif #endif
} }*/
bool TInterrupt::Activate(short irq, InterruptCallback isr, void* param) bool TInterrupt::Activate(short irq, InterruptCallback isr, void* param)
{ {
assert_param(IS_IRQ(irq)); assert_param(IS_IRQ(irq));
short irq2 = irq + 16; // exception = irq + 16 short irq2 = irq + 16; // exception = irq + 16
/*#if VEC_TABLE_ON_RAM
_Vectors[irq2] = UserHandler;
#endif*/
Vectors[irq2] = isr; Vectors[irq2] = isr;
Params[irq2] = param; Params[irq2] = param;
@ -229,8 +174,6 @@ bool TInterrupt::IsHandler() { return GetIPSR() & 0x01; }
void UserHandler() void UserHandler()
{ {
uint num = GetIPSR(); uint num = GetIPSR();
//if(num >= VectorySize) return;
//if(!Interrupt.Vectors[num]) return;
assert_param(num < VectorySize); assert_param(num < VectorySize);
assert_param(Interrupt.Vectors[num]); 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) __attribute__((section("SubHandler")));
void FAULT_SubHandler(uint* registers, uint exception) void FAULT_SubHandler(uint* registers, uint exception)
{ {
//uint exception = GetIPSR();
#ifdef STM32F0 #ifdef STM32F0
debug_printf("LR=0x%08x PC=0x%08x PSR=0x%08x\r\n", registers[5], registers[6], registers[7]); 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++) for(int i=0; i<=7; i++)

View File

@ -17,15 +17,12 @@ typedef void (*InterruptCallback)(ushort num, void* param);
// 中断管理类 // 中断管理类
class TInterrupt class TInterrupt
{ {
private:
//static uint GetIPSR(); // 获取中断号
//static void FaultHandler(); // 错误处理程序
public: public:
InterruptCallback Vectors[VectorySize]; // 对外的中断向量表 InterruptCallback Vectors[VectorySize]; // 对外的中断向量表
void* Params[VectorySize]; // 每一个中断向量对应的参数 void* Params[VectorySize]; // 每一个中断向量对应的参数
void Init(); // 初始化中断向量表 void Init(); // 初始化中断向量表
~TInterrupt(); //~TInterrupt();
// 注册中断函数(中断号,函数,参数) // 注册中断函数(中断号,函数,参数)
bool Activate(short irq, InterruptCallback isr, void* param = NULL); bool Activate(short irq, InterruptCallback isr, void* param = NULL);
@ -101,3 +98,11 @@ extern "C"
} }
#endif #endif
/*
RAM中开辟中断向量表
128128使
使_Vectors作为真正的中断向量表使OnHandler作为中断处理函数
OnHandler内部获取中断号Vectors中保存的用户委托
*/

View File

@ -215,10 +215,10 @@ TSys::TSys()
OnStart = NULL; OnStart = NULL;
} }
TSys::~TSys() /*TSys::~TSys()
{ {
if(OnStop) OnStop(); if(OnStop) OnStop();
} }*/
void ShowTime(void* param) void ShowTime(void* param)
{ {

18
Sys.h
View File

@ -66,11 +66,6 @@ typedef enum
// 判定指针是否在ROM区 // 判定指针是否在ROM区
#define IN_ROM_SECTION(p) ( (int)p < 0x20000000 ) #define IN_ROM_SECTION(p) ( (int)p < 0x20000000 )
// 列表集合
//#include "List.h"
//class TaskScheduler;
// 系统类 // 系统类
class TSys : Object class TSys : Object
{ {
@ -80,13 +75,14 @@ public:
COM_Def MessagePort;// 消息口默认0表示USART1 COM_Def MessagePort;// 消息口默认0表示USART1
bool IsGD; // 是否GD芯片 bool IsGD; // 是否GD芯片
char* Name; // 系统名称
ushort Code; // 产品代码
ushort Version; // 系统版本
char* Company; // 系统厂商
char* BuildTime; // 编译时间
uint Clock; // 系统时钟 uint Clock; // 系统时钟
uint CystalClock;// 晶振时钟 uint CystalClock;// 晶振时钟
char* Name; // 系统名称
char* Company; // 系统厂商
char* BuildTime; // 编译时间
ushort Code; // 产品代码
ushort Version; // 系统版本
byte ID[12]; // 芯片ID。 byte ID[12]; // 芯片ID。
ushort DevID; // MCU编码。低字设备版本高字子版本 ushort DevID; // MCU编码。低字设备版本高字子版本
ushort RevID; // MCU编码。低字设备版本高字子版本 ushort RevID; // MCU编码。低字设备版本高字子版本
@ -95,7 +91,7 @@ public:
ushort RAMSize; // 芯片RAM容量 ushort RAMSize; // 芯片RAM容量
TSys(); // 构造函数 TSys(); // 构造函数
~TSys(); // 析构函数 //~TSys(); // 析构函数
void InitClock(); // 初始化系统时钟 void InitClock(); // 初始化系统时钟
void Init(); // 初始化系统 void Init(); // 初始化系统

View File

@ -22,12 +22,12 @@ TTime::TTime()
_msUs = 0; _msUs = 0;
} }
TTime::~TTime() /*TTime::~TTime()
{ {
Interrupt.Deactivate(SysTick_IRQn); Interrupt.Deactivate(SysTick_IRQn);
// 关闭定时器 // 关闭定时器
SysTick->CTRL &= ~SYSTICK_ENABLE; SysTick->CTRL &= ~SYSTICK_ENABLE;
} }*/
void TTime::Init() void TTime::Init()
{ {

2
Time.h
View File

@ -27,7 +27,7 @@ public:
HardRTC* _RTC; HardRTC* _RTC;
TTime(); TTime();
~TTime(); //~TTime();
void UseRTC(); // 使用RTC必须在Init前调用 void UseRTC(); // 使用RTC必须在Init前调用
void Init(); void Init();