系统关键性代码链接到固件开头,主要规避GD32F130C8后32k特别慢的问题

This commit is contained in:
大石头X2 2017-02-18 10:57:55 +08:00
parent 95714310ef
commit d7ff86fc37
18 changed files with 84 additions and 220 deletions

View File

@ -22,15 +22,8 @@ void Queue::Clear()
_size = 0; _size = 0;
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM) INROOT void Queue::Enqueue(byte dat)
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
void Queue::Enqueue(byte dat)
{ {
int total = _s.Capacity(); int total = _s.Capacity();
if(!total) _s.SetLength(64); if(!total) _s.SetLength(64);
@ -47,7 +40,7 @@ void Queue::Enqueue(byte dat)
ExitCritical(); ExitCritical();
} }
byte Queue::Dequeue() INROOT byte Queue::Dequeue()
{ {
if(_size == 0) return 0; if(_size == 0) return 0;
@ -70,13 +63,6 @@ byte Queue::Dequeue()
return dat; return dat;
} }
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
uint Queue::Write(const Buffer& bs) uint Queue::Write(const Buffer& bs)
{ {
int total = _s.Capacity(); int total = _s.Capacity();

View File

@ -24,4 +24,11 @@ void assert_failed2(const char* msg, const char* file, unsigned int line);
#endif #endif
// 关键性代码放到开头
#if !defined(TINY)
#define INROOT __attribute__((section(".InRoot")))
#else
#define INROOT
#endif
#endif #endif

View File

@ -39,15 +39,8 @@ bool TInterrupt::Deactivate(short irq)
return OnDeactivate(irq); return OnDeactivate(irq);
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM) INROOT void TInterrupt::Process(uint num) const
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
void TInterrupt::Process(uint num) const
{ {
auto& inter = Interrupt; auto& inter = Interrupt;
//assert_param(num < VectorySize); //assert_param(num < VectorySize);
@ -80,7 +73,7 @@ void TInterrupt::Halt()
/******************************** SmartIRQ ********************************/ /******************************** SmartIRQ ********************************/
// 智能IRQ初始化时备份销毁时还原 // 智能IRQ初始化时备份销毁时还原
SmartIRQ::SmartIRQ(bool enable) INROOT SmartIRQ::SmartIRQ(bool enable)
{ {
_state = TInterrupt::GlobalState(); _state = TInterrupt::GlobalState();
if(enable) if(enable)
@ -89,7 +82,7 @@ SmartIRQ::SmartIRQ(bool enable)
TInterrupt::GlobalDisable(); TInterrupt::GlobalDisable();
} }
SmartIRQ::~SmartIRQ() INROOT SmartIRQ::~SmartIRQ()
{ {
//__set_PRIMASK(_state); //__set_PRIMASK(_state);
if(_state) if(_state)
@ -98,14 +91,6 @@ SmartIRQ::~SmartIRQ()
TInterrupt::GlobalEnable(); TInterrupt::GlobalEnable();
} }
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
/******************************** Lock ********************************/ /******************************** Lock ********************************/
#include "TTime.h" #include "TTime.h"

View File

@ -16,15 +16,8 @@ struct HandlerRemap StrBoot __attribute__((at(0x2000fff0)));
#define BIT(x) (1 << (x)) #define BIT(x) (1 << (x))
#endif #endif
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM) INROOT TSys::TSys()
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
TSys::TSys()
{ {
Config = nullptr; Config = nullptr;
@ -44,14 +37,6 @@ TSys::TSys()
Started = false; Started = false;
} }
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
void TSys::Init(void) void TSys::Init(void)
{ {
InitClock(); InitClock();
@ -106,15 +91,8 @@ void TSys::RemoveTask(uint& taskid) const
taskid = 0; taskid = 0;
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM) INROOT bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const
{ {
if(!taskid) return false; if(!taskid) return false;
@ -127,7 +105,7 @@ bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const
} }
// 改变任务周期 // 改变任务周期
bool TSys::SetTaskPeriod(uint taskid, int period) const INROOT bool TSys::SetTaskPeriod(uint taskid, int period) const
{ {
if(!taskid) return false; if(!taskid) return false;
@ -167,11 +145,11 @@ void TSys::Reboot(int msDelay) const
} }
// 系统启动后的毫秒数 // 系统启动后的毫秒数
UInt64 TSys::Ms() const { return Time.Current(); } INROOT UInt64 TSys::Ms() const { return Time.Current(); }
// 系统绝对当前时间,秒 // 系统绝对当前时间,秒
uint TSys::Seconds() const { return Time.Seconds + Time.BaseSeconds; } INROOT uint TSys::Seconds() const { return Time.Seconds + Time.BaseSeconds; }
void TSys::Sleep(uint ms) const INROOT void TSys::Sleep(uint ms) const
{ {
// 优先使用线程级睡眠 // 优先使用线程级睡眠
if(OnSleep) if(OnSleep)
@ -196,7 +174,7 @@ void TSys::Sleep(uint ms) const
} }
} }
void TSys::Delay(uint us) const INROOT void TSys::Delay(uint us) const
{ {
// 如果延迟微秒数太大,则使用线程级睡眠 // 如果延迟微秒数太大,则使用线程级睡眠
if(OnSleep && us >= 2000) if(OnSleep && us >= 2000)
@ -223,14 +201,6 @@ void TSys::Delay(uint us) const
} }
#endif #endif
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
/****************系统日志****************/ /****************系统日志****************/
#include <stdarg.h> #include <stdarg.h>

View File

@ -44,6 +44,13 @@ void assert_failed2(cstring msg, cstring file, unsigned int line);
#endif #endif
// 关键性代码放到开头
#if !defined(TINY)
#define INROOT __attribute__((section(".InRoot")))
#else
#define INROOT
#endif
#if defined(BOOT) || defined(APP) #if defined(BOOT) || defined(APP)
struct HandlerRemap struct HandlerRemap
{ {

View File

@ -36,15 +36,8 @@ void Task::Init()
MaxDeepth = 1; MaxDeepth = 1;
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM) INROOT bool Task::Execute(UInt64 now)
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
bool Task::Execute(UInt64 now)
{ {
TS(Name); TS(Name);
@ -92,7 +85,7 @@ bool Task::Execute(UInt64 now)
} }
// 设置任务的开关状态同时运行指定任务最近一次调度的时间0表示马上调度 // 设置任务的开关状态同时运行指定任务最近一次调度的时间0表示马上调度
void Task::Set(bool enable, int msNextTime) INROOT void Task::Set(bool enable, int msNextTime)
{ {
Enable = enable; Enable = enable;
@ -103,7 +96,7 @@ void Task::Set(bool enable, int msNextTime)
if(enable) Scheduler()->SkipSleep(); if(enable) Scheduler()->SkipSleep();
} }
bool Task::CheckTime(UInt64 end, bool isSleep) INROOT bool Task::CheckTime(UInt64 end, bool isSleep)
{ {
if(Deepth >= MaxDeepth) return false; if(Deepth >= MaxDeepth) return false;
@ -136,24 +129,16 @@ TaskScheduler* Task::Scheduler()
return &_sc; return &_sc;
} }
Task* Task::Get(int taskid) INROOT Task* Task::Get(int taskid)
{ {
return (*Scheduler())[taskid]; return (*Scheduler())[taskid];
} }
Task& Task::Current() INROOT Task& Task::Current()
{ {
return *(Scheduler()->Current); return *(Scheduler()->Current);
} }
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
// 显示状态 // 显示状态
void Task::ShowStatus() void Task::ShowStatus()
{ {
@ -319,16 +304,9 @@ void TaskScheduler::Stop()
Running = false; Running = false;
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
// 执行一次循环。指定最大可用时间 // 执行一次循环。指定最大可用时间
void TaskScheduler::Execute(uint msMax, bool& cancel) INROOT void TaskScheduler::Execute(uint msMax, bool& cancel)
{ {
TS("Task::Execute"); TS("Task::Execute");
@ -385,7 +363,7 @@ void TaskScheduler::Execute(uint msMax, bool& cancel)
_SkipSleep = false; _SkipSleep = false;
} }
uint TaskScheduler::ExecuteForWait(uint msMax, bool& cancel) INROOT uint TaskScheduler::ExecuteForWait(uint msMax, bool& cancel)
{ {
auto& dp = Deepth; auto& dp = Deepth;
if(dp >= MaxDeepth) return 0; if(dp >= MaxDeepth) return 0;
@ -418,20 +396,12 @@ uint TaskScheduler::ExecuteForWait(uint msMax, bool& cancel)
} }
// 跳过最近一次睡眠,马上开始下一轮循环 // 跳过最近一次睡眠,马上开始下一轮循环
void TaskScheduler::SkipSleep() INROOT void TaskScheduler::SkipSleep()
{ {
_SkipSleep = true; _SkipSleep = true;
Sleeping = false; Sleeping = false;
} }
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
// 显示状态 // 显示状态
void TaskScheduler::ShowStatus() void TaskScheduler::ShowStatus()
{ {

View File

@ -23,10 +23,6 @@
#define STACK_SAVE_Size (8 << 2) // 0x20 = 32 #define STACK_SAVE_Size (8 << 2) // 0x20 = 32
#endif #endif
#if !defined(TINY) && defined(STM32F0)
#pragma arm section code = "SectionForSys"
#endif
Thread::Thread(Action callback, void* state, uint stackSize) Thread::Thread(Action callback, void* state, uint stackSize)
{ {
SmartIRQ irq; // 关闭全局中断 SmartIRQ irq; // 关闭全局中断

View File

@ -56,15 +56,8 @@ void TTime::SetTime(UInt64 sec)
if(OnSave) OnSave(); if(OnSave) OnSave();
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#if defined(__CC_ARM) INROOT void TTime::Sleep(int ms, bool* running) const
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
void TTime::Sleep(int ms, bool* running) const
{ {
// 睡眠时间太短 // 睡眠时间太短
if(ms <= 0) return; if(ms <= 0) return;
@ -97,7 +90,7 @@ void TTime::Sleep(int ms, bool* running) const
} }
} }
void TTime::Delay(int us) const INROOT void TTime::Delay(int us) const
{ {
// 睡眠时间太短 // 睡眠时间太短
if(us <= 0) return; if(us <= 0) return;
@ -129,14 +122,6 @@ void TTime::Delay(int us) const
} }
} }
#if !defined(TINY) && defined(STM32F0)
#if defined(__CC_ARM)
#pragma arm section code
#elif defined(__GNUC__)
__attribute__((section("")))
#endif
#endif
extern "C" extern "C"
{ {
// 获取系统启动后经过的毫秒数 // 获取系统启动后经过的毫秒数

View File

@ -50,9 +50,8 @@ void TInterrupt::GlobalEnable() { __enable_irq(); }
void TInterrupt::GlobalDisable(){ __disable_irq(); } void TInterrupt::GlobalDisable(){ __disable_irq(); }
bool TInterrupt::GlobalState() { return __get_PRIMASK(); } bool TInterrupt::GlobalState() { return __get_PRIMASK(); }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#pragma arm section code = "SectionForSys" INROOT
#endif
#if defined ( __CC_ARM ) #if defined ( __CC_ARM )
__ASM uint GetIPSR() __ASM uint GetIPSR()

View File

@ -12,19 +12,14 @@
#define mem_printf(format, ...) #define mem_printf(format, ...)
#endif #endif
#if !defined(TINY) && defined(STM32F0) #pragma arm section rwdata = ".InRoot"
#if defined(__CC_ARM)
#pragma arm section code = "SectionForSys"
#elif defined(__GNUC__)
__attribute__((section("SectionForSys")))
#endif
#endif
// 全局堆 // 全局堆
Heap* _Heap = nullptr; Heap* _Heap = nullptr;
// 关键性代码,放到开头
extern "C" { extern "C" {
void* malloc(uint size) INROOT void* malloc(uint size)
{ {
// 初始化全局堆 // 初始化全局堆
if(!_Heap) if(!_Heap)
@ -52,7 +47,7 @@ extern "C" {
return p; return p;
} }
void free(void* p) INROOT void free(void* p)
{ {
#if MEM_DEBUG #if MEM_DEBUG
byte* bs = (byte*)p; byte* bs = (byte*)p;
@ -66,7 +61,7 @@ extern "C" {
} }
} }
void* operator new(uint size) INROOT void* operator new(uint size)
{ {
mem_printf(" new size: %d ", size); mem_printf(" new size: %d ", size);
@ -89,7 +84,7 @@ void* operator new(uint size)
return p; return p;
} }
void* operator new[](uint size) INROOT void* operator new[](uint size)
{ {
mem_printf(" new size[]: %d ", size); mem_printf(" new size[]: %d ", size);
// 内存大小向4字节对齐 // 内存大小向4字节对齐
@ -111,7 +106,7 @@ void* operator new[](uint size)
return p; return p;
} }
void operator delete(void* p) noexcept INROOT void operator delete(void* p) noexcept
{ {
mem_printf(" delete 0x%p ", p); mem_printf(" delete 0x%p ", p);
if(p) if(p)
@ -121,7 +116,7 @@ void operator delete(void* p) noexcept
} }
} }
void operator delete[](void* p) noexcept INROOT void operator delete[](void* p) noexcept
{ {
mem_printf(" delete[] 0x%p ", p); mem_printf(" delete[] 0x%p ", p);
if(p) if(p)
@ -131,8 +126,8 @@ void operator delete[](void* p) noexcept
} }
} }
void operator delete(void* p, uint size) noexcept { operator delete(p); } INROOT void operator delete(void* p, uint size) noexcept { operator delete(p); }
void operator delete[](void* p, uint size) noexcept { operator delete[](p); } INROOT void operator delete[](void* p, uint size) noexcept { operator delete[](p); }
void assert_failed2(cstring msg, cstring file, unsigned int line) void assert_failed2(cstring msg, cstring file, unsigned int line)
{ {

View File

@ -135,11 +135,8 @@ void SerialPort::OnWrite2()
USART_ITConfig((USART_TypeDef*)State, USART_IT_TXE, ENABLE); USART_ITConfig((USART_TypeDef*)State, USART_IT_TXE, ENABLE);
} }
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#pragma arm section code = "SectionForSys" INROOT void SerialPort::OnTxHandler()
#endif
void SerialPort::OnTxHandler()
{ {
if(!Tx.Empty()) if(!Tx.Empty())
USART_SendData((USART_TypeDef*)State, (ushort)Tx.Dequeue()); USART_SendData((USART_TypeDef*)State, (ushort)Tx.Dequeue());
@ -151,7 +148,7 @@ void SerialPort::OnTxHandler()
} }
} }
void SerialPort::OnRxHandler() INROOT void SerialPort::OnRxHandler()
{ {
// 串口接收中断必须以极快的速度完成,否则会出现丢数据的情况 // 串口接收中断必须以极快的速度完成,否则会出现丢数据的情况
// 判断缓冲区足够最小值以后才唤醒任务,减少时间消耗 // 判断缓冲区足够最小值以后才唤醒任务,减少时间消耗
@ -169,7 +166,7 @@ void SerialPort::OnRxHandler()
} }
// 真正的串口中断函数 // 真正的串口中断函数
void SerialPort::OnHandler(ushort num, void* param) INROOT void SerialPort::OnHandler(ushort num, void* param)
{ {
auto sp = (SerialPort*)param; auto sp = (SerialPort*)param;
auto st = (USART_TypeDef*)sp->State; auto st = (USART_TypeDef*)sp->State;
@ -192,5 +189,3 @@ void SerialPort::OnHandler(ushort num, void* param)
if(USART_GetFlagStatus(st, USART_FLAG_FE) != RESET) USART_ClearFlag(st, USART_FLAG_FE); if(USART_GetFlagStatus(st, USART_FLAG_FE) != RESET) USART_ClearFlag(st, USART_FLAG_FE);
if(USART_GetFlagStatus(st, USART_FLAG_PE) != RESET) USART_ClearFlag(st, USART_FLAG_PE);*/ if(USART_GetFlagStatus(st, USART_FLAG_PE) != RESET) USART_ClearFlag(st, USART_FLAG_PE);*/
} }
#pragma arm section code

View File

@ -47,11 +47,8 @@ static int _Index; // MCU在型号表中的索引
#endif #endif
#if !defined(TINY) && defined(STM32F0) // 关键性代码,放到开头
#pragma arm section code = "SectionForSys" INROOT _force_inline void InitHeapStack(uint top)
#endif
_force_inline void InitHeapStack(uint top)
{ {
uint* p = (uint*)__get_MSP(); uint* p = (uint*)__get_MSP();
@ -66,7 +63,7 @@ _force_inline void InitHeapStack(uint top)
} }
// 获取JTAG编号ST是0x041GD是0x7A3 // 获取JTAG编号ST是0x041GD是0x7A3
uint16_t Get_JTAG_ID() INROOT uint16_t Get_JTAG_ID()
{ {
if( *( uint8_t *)( 0xE00FFFE8 ) & 0x08 ) if( *( uint8_t *)( 0xE00FFFE8 ) & 0x08 )
{ {
@ -77,7 +74,7 @@ uint16_t Get_JTAG_ID()
return 0; return 0;
} }
void TSys::OnInit() INROOT void TSys::OnInit()
{ {
#ifdef STM32F0 #ifdef STM32F0
Clock = 48000000; Clock = 48000000;
@ -147,8 +144,6 @@ void TSys::OnInit()
#endif #endif
} }
#pragma arm section code
void TSys::InitClock() void TSys::InitClock()
{ {
#ifndef TINY #ifndef TINY
@ -185,17 +180,12 @@ void TSys::SetStackTop(uint addr)
__set_MSP(addr); __set_MSP(addr);
} }
#if !defined(TINY) && defined(STM32F0) && defined(DEBUG) // 关键性代码,放到开头
#pragma arm section code = "SectionForSys" INROOT bool TSys::CheckMemory() const
#endif
bool TSys::CheckMemory() const
{ {
return true; return true;
} }
#pragma arm section code
#if DEBUG #if DEBUG
typedef struct typedef struct
{ {
@ -321,13 +311,13 @@ void TSys::OnStart()
/******************************** 临界区 ********************************/ /******************************** 临界区 ********************************/
void EnterCritical() { __disable_irq(); } INROOT void EnterCritical() { __disable_irq(); }
void ExitCritical() { __enable_irq(); } INROOT void ExitCritical() { __enable_irq(); }
/******************************** REV ********************************/ /******************************** REV ********************************/
uint _REV(uint value) { return __REV(value); } INROOT uint _REV(uint value) { return __REV(value); }
ushort _REV16(ushort value) { return __REV16(value); } INROOT ushort _REV16(ushort value) { return __REV16(value); }
/******************************** 调试日志 ********************************/ /******************************** 调试日志 ********************************/

View File

@ -25,11 +25,7 @@
#define STACK_SAVE_Size (8 << 2) // 0x20 = 32 #define STACK_SAVE_Size (8 << 2) // 0x20 = 32
#endif #endif
#if !defined(TINY) && defined(STM32F0) INROOT void Thread::CheckStack()
#pragma arm section code = "SectionForSys"
#endif
void Thread::CheckStack()
{ {
#ifdef DEBUG #ifdef DEBUG
uint p = __get_PSP(); uint p = __get_PSP();
@ -47,7 +43,7 @@ void Thread::CheckStack()
} }
// 系统线程调度开始 // 系统线程调度开始
void Thread::OnSchedule() INROOT void Thread::OnSchedule()
{ {
// 使用双栈。每个线程有自己的栈属于PSP中断专用MSP // 使用双栈。每个线程有自己的栈属于PSP中断专用MSP
if(__get_CONTROL() != 2) if(__get_CONTROL() != 2)
@ -73,7 +69,7 @@ extern "C"
extern uint* newStack; // 新的线程栈 extern uint* newStack; // 新的线程栈
#ifdef STM32F0 #ifdef STM32F0
__asm void PendSV_Handler() INROOT __asm void PendSV_Handler()
{ {
IMPORT curStack IMPORT curStack
IMPORT newStack IMPORT newStack
@ -123,7 +119,7 @@ PendSV_NoSave // 此时整个上下文已经被保存
BX LR // 中断返回将恢复上下文 BX LR // 中断返回将恢复上下文
} }
#else #else
__asm void PendSV_Handler() INROOT __asm void PendSV_Handler()
{ {
IMPORT curStack IMPORT curStack
IMPORT newStack IMPORT newStack
@ -167,25 +163,25 @@ PendSV_NoSave // 此时整个上下文已经被保存
#endif #endif
// 切换线程,马上切换时间片给下一个线程 // 切换线程,马上切换时间片给下一个线程
bool Thread::CheckPend() INROOT bool Thread::CheckPend()
{ {
// 如果有挂起的切换,则不再切换。否则切换时需要保存的栈会出错 // 如果有挂起的切换,则不再切换。否则切换时需要保存的栈会出错
return SCB->ICSR & SCB_ICSR_PENDSVSET_Msk; return SCB->ICSR & SCB_ICSR_PENDSVSET_Msk;
} }
void Thread::OnSwitch() INROOT void Thread::OnSwitch()
{ {
// 触发PendSV异常引发上下文切换 // 触发PendSV异常引发上下文切换
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
} }
void Thread::OnInit() INROOT void Thread::OnInit()
{ {
Interrupt.SetPriority(PendSV_IRQn, 0xFF); Interrupt.SetPriority(PendSV_IRQn, 0xFF);
} }
// 每个线程结束时执行该方法,销毁线程 // 每个线程结束时执行该方法,销毁线程
void Thread::OnEnd() INROOT void Thread::OnEnd()
{ {
//SmartIRQ irq; // 关闭全局中断,确保销毁成功 //SmartIRQ irq; // 关闭全局中断,确保销毁成功
__disable_irq(); __disable_irq();

View File

@ -89,14 +89,11 @@ void TTime::Init()
TIM_Cmd(tim, ENABLE); TIM_Cmd(tim, ENABLE);
} }
#if !defined(TINY) && defined(STM32F0)
#pragma arm section code = "SectionForSys"
#endif
#if defined(STM32F0) || defined(GD32F150) || defined(STM32F4) #if defined(STM32F0) || defined(GD32F150) || defined(STM32F4)
#define SysTick_CTRL_COUNTFLAG SysTick_CTRL_COUNTFLAG_Msk #define SysTick_CTRL_COUNTFLAG SysTick_CTRL_COUNTFLAG_Msk
#endif #endif
void TTime::OnHandler(ushort num, void* param) // 关键性代码,放到开头
INROOT void TTime::OnHandler(ushort num, void* param)
{ {
auto timer = (TIM_TypeDef*)param; auto timer = (TIM_TypeDef*)param;
if(!timer) return; if(!timer) return;
@ -119,13 +116,13 @@ void TTime::OnHandler(ushort num, void* param)
} }
// 当前滴答时钟 // 当前滴答时钟
uint TTime::CurrentTicks() const INROOT uint TTime::CurrentTicks() const
{ {
return SysTick->LOAD - SysTick->VAL; return SysTick->LOAD - SysTick->VAL;
} }
// 当前毫秒数 // 当前毫秒数
UInt64 TTime::Current() const INROOT UInt64 TTime::Current() const
{ {
uint cnt = g_Timers[Index]->CNT; uint cnt = g_Timers[Index]->CNT;
#if ! (defined(STM32F0) || defined(GD32F150)) #if ! (defined(STM32F0) || defined(GD32F150))
@ -134,7 +131,5 @@ UInt64 TTime::Current() const
return Milliseconds + cnt; return Milliseconds + cnt;
} }
uint TTime::TicksToUs(uint ticks) const { return !ticks ? 0 : (ticks / gTicks); } INROOT uint TTime::TicksToUs(uint ticks) const { return !ticks ? 0 : (ticks / gTicks); }
uint TTime::UsToTicks(uint us) const { return !us ? 0 : (us * gTicks); } INROOT uint TTime::UsToTicks(uint us) const { return !us ? 0 : (us * gTicks); }
#pragma arm section code

View File

@ -31,9 +31,6 @@ void TInterrupt::OnInit() const
} }
#if !defined(TINY) #if !defined(TINY)
#if defined(STM32F0)
#pragma arm section code = "SectionForSys"
#endif
extern "C" extern "C"
{ {

View File

@ -71,9 +71,6 @@ void TInterrupt::DecodePriority (uint priority, uint priorityGroup, uint* pPreem
#endif #endif
#if !defined(TINY) #if !defined(TINY)
#if defined(STM32F0)
#pragma arm section code = "SectionForSys"
#endif
extern "C" extern "C"
{ {

View File

@ -71,9 +71,6 @@ void TInterrupt::DecodePriority (uint priority, uint priorityGroup, uint* pPreem
#endif #endif
#if !defined(TINY) #if !defined(TINY)
#if defined(STM32F0)
#pragma arm section code = "SectionForSys"
#endif
extern "C" extern "C"
{ {

View File

@ -71,9 +71,6 @@ void TInterrupt::DecodePriority (uint priority, uint priorityGroup, uint* pPreem
#endif #endif
#if !defined(TINY) #if !defined(TINY)
#if defined(STM32F0)
#pragma arm section code = "SectionForSys"
#endif
extern "C" extern "C"
{ {