From 7116f2a986ac893d84a9fadfc682e8e83dacae3b Mon Sep 17 00:00:00 2001 From: nnhy Date: Thu, 22 Oct 2015 01:25:29 +0000 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Debug.cpp | 16 +-------------- Interrupt.cpp | 13 +++++++----- Sys.cpp | 55 +++++---------------------------------------------- Sys.h | 8 -------- Task.cpp | 1 - Thread.cpp | 4 +--- Time.cpp | 2 +- 7 files changed, 16 insertions(+), 83 deletions(-) diff --git a/Debug.cpp b/Debug.cpp index 4f192b38..f80671a3 100644 --- a/Debug.cpp +++ b/Debug.cpp @@ -103,22 +103,10 @@ void operator delete[](void* p) #ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval : None - */ void assert_failed(uint8_t* file, uint32_t line) { - /* User can add his own implementation to report the file name and line number, - ex: debug_printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /*if(_printf_sp) */debug_printf("Assert Failed! Line %d, %s\r\n", line, file); + debug_printf("Assert Failed! Line %d, %s\r\n", line, file); - if(Sys.OnStop) Sys.OnStop(); - - /* Infinite loop */ while (1) { } } @@ -126,8 +114,6 @@ void assert_failed(const char* msg, uint8_t* file, uint32_t line) { debug_printf("%s Line %d, %s\r\n", msg, line, file); - if(Sys.OnStop) Sys.OnStop(); - while (1) { } } diff --git a/Interrupt.cpp b/Interrupt.cpp index ec81700b..50afc156 100644 --- a/Interrupt.cpp +++ b/Interrupt.cpp @@ -1,4 +1,5 @@ #include "Interrupt.h" +#include "SerialPort.h" TInterrupt Interrupt; @@ -216,11 +217,13 @@ extern "C" } #endif - if(!Sys.OnError || Sys.OnError(exception)) - { - if(Sys.OnStop) Sys.OnStop(); - while(true); - } +#if DEBUG + ShowFault(exception); + + SerialPort* sp = SerialPort::GetMessagePort(); + if(sp) sp->Flush(); +#endif + while(true); } __asm void FaultHandler() __attribute__((section("SubHandler"))); diff --git a/Sys.cpp b/Sys.cpp index 7ec032e5..10dc36f6 100644 --- a/Sys.cpp +++ b/Sys.cpp @@ -1,7 +1,6 @@ #include "Sys.h" #include "Time.h" -#include "SerialPort.h" TSys Sys; TTime Time; @@ -16,6 +15,10 @@ extern uint __microlib_freelist_initialised; #define BIT(x) (1 << (x)) #endif +#ifndef TINY +static int _Index; // MCU在型号表中的索引 +#endif + #ifdef STM32F1 char MemNames[] = "468BCDEFGIK"; uint MemSizes[] = { 16, 32, 64, 128, 256, 384, 512, 768, 1024, 2048, 3072 }; @@ -103,26 +106,6 @@ uint16_t Get_JTAG_ID() return 0; } -bool SysError(uint code) -{ - debug_printf("系统错误!0x%02x\r\n", code); - -#if DEBUG - ShowFault(code); - - SerialPort* sp = SerialPort::GetMessagePort(); - if(sp) sp->Flush(); -#endif - - return true; -} - -void SysStop() -{ - debug_printf("系统停止!\r\n"); - //while(true); -} - TSys::TSys() { #ifdef STM32F0 @@ -185,18 +168,8 @@ TSys::TSys() InitHeapStack(StackTop()); #endif - StartTime = 0; - OnTick = NULL; OnSleep = NULL; -#if DEBUG - OnError = SysError; - OnStop = SysStop; -#else - OnError = 0; - OnStop = 0; -#endif - #ifdef STM32F1 // 关闭JTAG仿真接口,只打开SW仿真。 RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // 打开时钟 @@ -214,14 +187,8 @@ TSys::TSys() #endif Started = false; - OnStart = NULL; } -/*TSys::~TSys() -{ - if(OnStop) OnStop(); -}*/ - void ShowTime(void* param) { debug_printf("\r"); @@ -282,9 +249,6 @@ typedef struct void TSys::ShowInfo() { #if DEBUG - // 刚刚初始化完成的时间 - ulong initedTime = Time.Current(); - byte* ver = (byte*)&Version; debug_printf("%s::%s Code:%04X ", Company, Name, Code); debug_printf("Ver:%x.%x Build:%s\r\n", *ver++, *ver++, BuildTime); @@ -390,8 +354,6 @@ void TSys::ShowInfo() debug_printf("Time : "); Time.Now().Show(true); - // 系统启动时间 - debug_printf("Start: %dms (Inited: %dms)\r\n", (uint)(Time.Current() - StartTime), (uint)(initedTime - StartTime)); debug_printf("Support: http://www.NewLifeX.com\r\n"); debug_printf("\r\n"); @@ -458,14 +420,7 @@ void TSys::Start() #if DEBUG //AddTask(ShowTime, NULL, 2000000, 2000000); #endif - if(OnStart) - { - // 设置重载值,让其每1ms重载一次 - //Time.SetMax(1000); - OnStart(); - } - else - Task::Scheduler()->Start(); + Task::Scheduler()->Start(); } void TimeSleep(uint us) diff --git a/Sys.h b/Sys.h index c9a70d4e..6c9626cc 100644 --- a/Sys.h +++ b/Sys.h @@ -88,7 +88,6 @@ public: ushort RAMSize; // 芯片RAM容量 TSys(); // 构造函数 - //~TSys(); // 析构函数 void InitClock(); // 初始化系统时钟 void Init(); // 初始化系统 @@ -96,8 +95,6 @@ public: uint HeapBase(); // 堆起始地址,前面是静态分配内存 uint StackTop(); // 栈顶,后面是初始化不清零区域 - ulong StartTime; // 启动时间,微秒 - Func OnTick; void Sleep(uint ms); // 毫秒级延迟 void Delay(uint us); // 微秒级延迟 typedef void (*FuncU32)(uint param); @@ -106,10 +103,6 @@ public: bool CheckMemory(); void Reset(); // 重启系统 - bool (*OnError)(uint code); // 系统出错时引发,返回值决定是否停止系统 - Func OnStop; -private: - int _Index; // MCU在型号表中的索引 public: // 创建任务,返回任务编号。dueTime首次调度时间ms,period调度间隔ms,-1表示仅处理一次 @@ -122,7 +115,6 @@ public: bool Started; void Start(); // 开始系统大循环 - Func OnStart; }; extern TSys Sys; //创建一个全局的Sys对象 会在main函数之前执行构造函数(!!!!!) diff --git a/Task.cpp b/Task.cpp index a2eaea7c..5810930d 100644 --- a/Task.cpp +++ b/Task.cpp @@ -226,7 +226,6 @@ void TaskScheduler::Execute(uint msMax) { ulong now = Time.Current(); ulong end = now + msMax; - now -= Sys.StartTime; // 当前时间。减去系统启动时间,避免修改系统时间后导致调度停摆 ulong min = UInt64_Max; // 最小时间,这个时间就会有任务到来 TimeCost tc; diff --git a/Thread.cpp b/Thread.cpp index ef794357..1a0f0d69 100644 --- a/Thread.cpp +++ b/Thread.cpp @@ -420,7 +420,7 @@ void Thread::Schedule() //SmartIRQ irq; __disable_irq(); - Sys.OnTick = OnTick; + //Sys.OnTick = OnTick; Sys.OnSleep = OnSleep; // 先切换好了才换栈,因为里面有很多层调用,不确定新栈空间是否足够 @@ -651,8 +651,6 @@ void Thread::Init() Main = main; Interrupt.SetPriority(PendSV_IRQn, 0xFF); - - Sys.OnStart = Schedule; } // 每个线程结束时执行该方法,销毁线程 diff --git a/Time.cpp b/Time.cpp index 479527ac..1c178cb9 100644 --- a/Time.cpp +++ b/Time.cpp @@ -137,7 +137,7 @@ void TTime::OnHandler(ushort num, void* param) // 定期保存Ticks到后备RTC寄存器 if(Time.OnSave) Time.OnSave(); - if(Sys.OnTick) Sys.OnTick(); + //if(Sys.OnTick) Sys.OnTick(); } // 当前滴答时钟