系统关键性代码链接到固件开头,主要规避GD32F130C8后32k特别慢的问题
This commit is contained in:
parent
95714310ef
commit
d7ff86fc37
|
@ -22,15 +22,8 @@ void Queue::Clear()
|
|||
_size = 0;
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void Queue::Enqueue(byte dat)
|
||||
// 关键性代码,放到开头
|
||||
INROOT void Queue::Enqueue(byte dat)
|
||||
{
|
||||
int total = _s.Capacity();
|
||||
if(!total) _s.SetLength(64);
|
||||
|
@ -47,7 +40,7 @@ void Queue::Enqueue(byte dat)
|
|||
ExitCritical();
|
||||
}
|
||||
|
||||
byte Queue::Dequeue()
|
||||
INROOT byte Queue::Dequeue()
|
||||
{
|
||||
if(_size == 0) return 0;
|
||||
|
||||
|
@ -70,13 +63,6 @@ byte Queue::Dequeue()
|
|||
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)
|
||||
{
|
||||
int total = _s.Capacity();
|
||||
|
|
|
@ -24,4 +24,11 @@ void assert_failed2(const char* msg, const char* file, unsigned int line);
|
|||
|
||||
#endif
|
||||
|
||||
// 关键性代码放到开头
|
||||
#if !defined(TINY)
|
||||
#define INROOT __attribute__((section(".InRoot")))
|
||||
#else
|
||||
#define INROOT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,15 +39,8 @@ bool TInterrupt::Deactivate(short irq)
|
|||
return OnDeactivate(irq);
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void TInterrupt::Process(uint num) const
|
||||
// 关键性代码,放到开头
|
||||
INROOT void TInterrupt::Process(uint num) const
|
||||
{
|
||||
auto& inter = Interrupt;
|
||||
//assert_param(num < VectorySize);
|
||||
|
@ -80,7 +73,7 @@ void TInterrupt::Halt()
|
|||
/******************************** SmartIRQ ********************************/
|
||||
|
||||
// 智能IRQ,初始化时备份,销毁时还原
|
||||
SmartIRQ::SmartIRQ(bool enable)
|
||||
INROOT SmartIRQ::SmartIRQ(bool enable)
|
||||
{
|
||||
_state = TInterrupt::GlobalState();
|
||||
if(enable)
|
||||
|
@ -89,7 +82,7 @@ SmartIRQ::SmartIRQ(bool enable)
|
|||
TInterrupt::GlobalDisable();
|
||||
}
|
||||
|
||||
SmartIRQ::~SmartIRQ()
|
||||
INROOT SmartIRQ::~SmartIRQ()
|
||||
{
|
||||
//__set_PRIMASK(_state);
|
||||
if(_state)
|
||||
|
@ -98,14 +91,6 @@ SmartIRQ::~SmartIRQ()
|
|||
TInterrupt::GlobalEnable();
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/******************************** Lock ********************************/
|
||||
|
||||
#include "TTime.h"
|
||||
|
|
|
@ -16,15 +16,8 @@ struct HandlerRemap StrBoot __attribute__((at(0x2000fff0)));
|
|||
#define BIT(x) (1 << (x))
|
||||
#endif
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TSys::TSys()
|
||||
// 关键性代码,放到开头
|
||||
INROOT TSys::TSys()
|
||||
{
|
||||
Config = nullptr;
|
||||
|
||||
|
@ -44,14 +37,6 @@ TSys::TSys()
|
|||
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)
|
||||
{
|
||||
InitClock();
|
||||
|
@ -106,15 +91,8 @@ void TSys::RemoveTask(uint& taskid) const
|
|||
taskid = 0;
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const
|
||||
// 关键性代码,放到开头
|
||||
INROOT bool TSys::SetTask(uint taskid, bool enable, int msNextTime) const
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -223,14 +201,6 @@ void TSys::Delay(uint us) const
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************系统日志****************/
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
|
@ -44,6 +44,13 @@ void assert_failed2(cstring msg, cstring file, unsigned int line);
|
|||
|
||||
#endif
|
||||
|
||||
// 关键性代码放到开头
|
||||
#if !defined(TINY)
|
||||
#define INROOT __attribute__((section(".InRoot")))
|
||||
#else
|
||||
#define INROOT
|
||||
#endif
|
||||
|
||||
#if defined(BOOT) || defined(APP)
|
||||
struct HandlerRemap
|
||||
{
|
||||
|
|
|
@ -36,15 +36,8 @@ void Task::Init()
|
|||
MaxDeepth = 1;
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool Task::Execute(UInt64 now)
|
||||
// 关键性代码,放到开头
|
||||
INROOT bool Task::Execute(UInt64 now)
|
||||
{
|
||||
TS(Name);
|
||||
|
||||
|
@ -92,7 +85,7 @@ bool Task::Execute(UInt64 now)
|
|||
}
|
||||
|
||||
// 设置任务的开关状态,同时运行指定任务最近一次调度的时间,0表示马上调度
|
||||
void Task::Set(bool enable, int msNextTime)
|
||||
INROOT void Task::Set(bool enable, int msNextTime)
|
||||
{
|
||||
Enable = enable;
|
||||
|
||||
|
@ -103,7 +96,7 @@ void Task::Set(bool enable, int msNextTime)
|
|||
if(enable) Scheduler()->SkipSleep();
|
||||
}
|
||||
|
||||
bool Task::CheckTime(UInt64 end, bool isSleep)
|
||||
INROOT bool Task::CheckTime(UInt64 end, bool isSleep)
|
||||
{
|
||||
if(Deepth >= MaxDeepth) return false;
|
||||
|
||||
|
@ -136,24 +129,16 @@ TaskScheduler* Task::Scheduler()
|
|||
return &_sc;
|
||||
}
|
||||
|
||||
Task* Task::Get(int taskid)
|
||||
INROOT Task* Task::Get(int taskid)
|
||||
{
|
||||
return (*Scheduler())[taskid];
|
||||
}
|
||||
|
||||
Task& Task::Current()
|
||||
INROOT Task& Task::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()
|
||||
{
|
||||
|
@ -319,16 +304,9 @@ void TaskScheduler::Stop()
|
|||
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");
|
||||
|
||||
|
@ -385,7 +363,7 @@ void TaskScheduler::Execute(uint msMax, bool& cancel)
|
|||
_SkipSleep = false;
|
||||
}
|
||||
|
||||
uint TaskScheduler::ExecuteForWait(uint msMax, bool& cancel)
|
||||
INROOT uint TaskScheduler::ExecuteForWait(uint msMax, bool& cancel)
|
||||
{
|
||||
auto& dp = Deepth;
|
||||
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;
|
||||
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()
|
||||
{
|
||||
|
|
|
@ -23,10 +23,6 @@
|
|||
#define STACK_SAVE_Size (8 << 2) // 0x20 = 32
|
||||
#endif
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
Thread::Thread(Action callback, void* state, uint stackSize)
|
||||
{
|
||||
SmartIRQ irq; // 关闭全局中断
|
||||
|
|
|
@ -56,15 +56,8 @@ void TTime::SetTime(UInt64 sec)
|
|||
if(OnSave) OnSave();
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void TTime::Sleep(int ms, bool* running) const
|
||||
// 关键性代码,放到开头
|
||||
INROOT void TTime::Sleep(int ms, bool* running) const
|
||||
{
|
||||
// 睡眠时间太短
|
||||
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;
|
||||
|
@ -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"
|
||||
{
|
||||
// 获取系统启动后经过的毫秒数
|
||||
|
|
|
@ -50,9 +50,8 @@ void TInterrupt::GlobalEnable() { __enable_irq(); }
|
|||
void TInterrupt::GlobalDisable(){ __disable_irq(); }
|
||||
bool TInterrupt::GlobalState() { return __get_PRIMASK(); }
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
// 关键性代码,放到开头
|
||||
INROOT
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
__ASM uint GetIPSR()
|
||||
|
|
|
@ -12,19 +12,14 @@
|
|||
#define mem_printf(format, ...)
|
||||
#endif
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#if defined(__CC_ARM)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#elif defined(__GNUC__)
|
||||
__attribute__((section("SectionForSys")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#pragma arm section rwdata = ".InRoot"
|
||||
// 全局堆
|
||||
Heap* _Heap = nullptr;
|
||||
|
||||
// 关键性代码,放到开头
|
||||
|
||||
extern "C" {
|
||||
void* malloc(uint size)
|
||||
INROOT void* malloc(uint size)
|
||||
{
|
||||
// 初始化全局堆
|
||||
if(!_Heap)
|
||||
|
@ -52,7 +47,7 @@ extern "C" {
|
|||
return p;
|
||||
}
|
||||
|
||||
void free(void* p)
|
||||
INROOT void free(void* p)
|
||||
{
|
||||
#if MEM_DEBUG
|
||||
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);
|
||||
|
||||
|
@ -89,7 +84,7 @@ void* operator new(uint size)
|
|||
return p;
|
||||
}
|
||||
|
||||
void* operator new[](uint size)
|
||||
INROOT void* operator new[](uint size)
|
||||
{
|
||||
mem_printf(" new size[]: %d ", size);
|
||||
// 内存大小向4字节对齐
|
||||
|
@ -111,7 +106,7 @@ void* operator new[](uint size)
|
|||
return p;
|
||||
}
|
||||
|
||||
void operator delete(void* p) noexcept
|
||||
INROOT void operator delete(void* p) noexcept
|
||||
{
|
||||
mem_printf(" delete 0x%p ", 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);
|
||||
if(p)
|
||||
|
@ -131,8 +126,8 @@ void operator delete[](void* p) noexcept
|
|||
}
|
||||
}
|
||||
|
||||
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); }
|
||||
INROOT void operator delete[](void* p, uint size) noexcept { operator delete[](p); }
|
||||
|
||||
void assert_failed2(cstring msg, cstring file, unsigned int line)
|
||||
{
|
||||
|
|
|
@ -135,11 +135,8 @@ void SerialPort::OnWrite2()
|
|||
USART_ITConfig((USART_TypeDef*)State, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
void SerialPort::OnTxHandler()
|
||||
// 关键性代码,放到开头
|
||||
INROOT void SerialPort::OnTxHandler()
|
||||
{
|
||||
if(!Tx.Empty())
|
||||
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 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_PE) != RESET) USART_ClearFlag(st, USART_FLAG_PE);*/
|
||||
}
|
||||
|
||||
#pragma arm section code
|
||||
|
|
|
@ -47,11 +47,8 @@ static int _Index; // MCU在型号表中的索引
|
|||
|
||||
#endif
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
_force_inline void InitHeapStack(uint top)
|
||||
// 关键性代码,放到开头
|
||||
INROOT _force_inline void InitHeapStack(uint top)
|
||||
{
|
||||
uint* p = (uint*)__get_MSP();
|
||||
|
||||
|
@ -66,7 +63,7 @@ _force_inline void InitHeapStack(uint top)
|
|||
}
|
||||
|
||||
// 获取JTAG编号,ST是0x041,GD是0x7A3
|
||||
uint16_t Get_JTAG_ID()
|
||||
INROOT uint16_t Get_JTAG_ID()
|
||||
{
|
||||
if( *( uint8_t *)( 0xE00FFFE8 ) & 0x08 )
|
||||
{
|
||||
|
@ -77,7 +74,7 @@ uint16_t Get_JTAG_ID()
|
|||
return 0;
|
||||
}
|
||||
|
||||
void TSys::OnInit()
|
||||
INROOT void TSys::OnInit()
|
||||
{
|
||||
#ifdef STM32F0
|
||||
Clock = 48000000;
|
||||
|
@ -147,8 +144,6 @@ void TSys::OnInit()
|
|||
#endif
|
||||
}
|
||||
|
||||
#pragma arm section code
|
||||
|
||||
void TSys::InitClock()
|
||||
{
|
||||
#ifndef TINY
|
||||
|
@ -185,17 +180,12 @@ void TSys::SetStackTop(uint addr)
|
|||
__set_MSP(addr);
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0) && defined(DEBUG)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
bool TSys::CheckMemory() const
|
||||
// 关键性代码,放到开头
|
||||
INROOT bool TSys::CheckMemory() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma arm section code
|
||||
|
||||
#if DEBUG
|
||||
typedef struct
|
||||
{
|
||||
|
@ -321,13 +311,13 @@ void TSys::OnStart()
|
|||
|
||||
/******************************** 临界区 ********************************/
|
||||
|
||||
void EnterCritical() { __disable_irq(); }
|
||||
void ExitCritical() { __enable_irq(); }
|
||||
INROOT void EnterCritical() { __disable_irq(); }
|
||||
INROOT void ExitCritical() { __enable_irq(); }
|
||||
|
||||
/******************************** REV ********************************/
|
||||
|
||||
uint _REV(uint value) { return __REV(value); }
|
||||
ushort _REV16(ushort value) { return __REV16(value); }
|
||||
INROOT uint _REV(uint value) { return __REV(value); }
|
||||
INROOT ushort _REV16(ushort value) { return __REV16(value); }
|
||||
|
||||
/******************************** 调试日志 ********************************/
|
||||
|
||||
|
|
|
@ -25,11 +25,7 @@
|
|||
#define STACK_SAVE_Size (8 << 2) // 0x20 = 32
|
||||
#endif
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
void Thread::CheckStack()
|
||||
INROOT void Thread::CheckStack()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
uint p = __get_PSP();
|
||||
|
@ -47,7 +43,7 @@ void Thread::CheckStack()
|
|||
}
|
||||
|
||||
// 系统线程调度开始
|
||||
void Thread::OnSchedule()
|
||||
INROOT void Thread::OnSchedule()
|
||||
{
|
||||
// 使用双栈。每个线程有自己的栈,属于PSP,中断专用MSP
|
||||
if(__get_CONTROL() != 2)
|
||||
|
@ -73,7 +69,7 @@ extern "C"
|
|||
extern uint* newStack; // 新的线程栈
|
||||
|
||||
#ifdef STM32F0
|
||||
__asm void PendSV_Handler()
|
||||
INROOT __asm void PendSV_Handler()
|
||||
{
|
||||
IMPORT curStack
|
||||
IMPORT newStack
|
||||
|
@ -123,7 +119,7 @@ PendSV_NoSave // 此时整个上下文已经被保存
|
|||
BX LR // 中断返回将恢复上下文
|
||||
}
|
||||
#else
|
||||
__asm void PendSV_Handler()
|
||||
INROOT __asm void PendSV_Handler()
|
||||
{
|
||||
IMPORT curStack
|
||||
IMPORT newStack
|
||||
|
@ -167,25 +163,25 @@ PendSV_NoSave // 此时整个上下文已经被保存
|
|||
#endif
|
||||
|
||||
// 切换线程,马上切换时间片给下一个线程
|
||||
bool Thread::CheckPend()
|
||||
INROOT bool Thread::CheckPend()
|
||||
{
|
||||
// 如果有挂起的切换,则不再切换。否则切换时需要保存的栈会出错
|
||||
return SCB->ICSR & SCB_ICSR_PENDSVSET_Msk;
|
||||
}
|
||||
|
||||
void Thread::OnSwitch()
|
||||
INROOT void Thread::OnSwitch()
|
||||
{
|
||||
// 触发PendSV异常,引发上下文切换
|
||||
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
|
||||
}
|
||||
|
||||
void Thread::OnInit()
|
||||
INROOT void Thread::OnInit()
|
||||
{
|
||||
Interrupt.SetPriority(PendSV_IRQn, 0xFF);
|
||||
}
|
||||
|
||||
// 每个线程结束时执行该方法,销毁线程
|
||||
void Thread::OnEnd()
|
||||
INROOT void Thread::OnEnd()
|
||||
{
|
||||
//SmartIRQ irq; // 关闭全局中断,确保销毁成功
|
||||
__disable_irq();
|
||||
|
|
|
@ -89,14 +89,11 @@ void TTime::Init()
|
|||
TIM_Cmd(tim, ENABLE);
|
||||
}
|
||||
|
||||
#if !defined(TINY) && defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
#if defined(STM32F0) || defined(GD32F150) || defined(STM32F4)
|
||||
#define SysTick_CTRL_COUNTFLAG SysTick_CTRL_COUNTFLAG_Msk
|
||||
#endif
|
||||
void TTime::OnHandler(ushort num, void* param)
|
||||
// 关键性代码,放到开头
|
||||
INROOT void TTime::OnHandler(ushort num, void* param)
|
||||
{
|
||||
auto timer = (TIM_TypeDef*)param;
|
||||
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;
|
||||
}
|
||||
|
||||
// 当前毫秒数
|
||||
UInt64 TTime::Current() const
|
||||
INROOT UInt64 TTime::Current() const
|
||||
{
|
||||
uint cnt = g_Timers[Index]->CNT;
|
||||
#if ! (defined(STM32F0) || defined(GD32F150))
|
||||
|
@ -134,7 +131,5 @@ UInt64 TTime::Current() const
|
|||
return Milliseconds + cnt;
|
||||
}
|
||||
|
||||
uint TTime::TicksToUs(uint ticks) const { return !ticks ? 0 : (ticks / gTicks); }
|
||||
uint TTime::UsToTicks(uint us) const { return !us ? 0 : (us * gTicks); }
|
||||
|
||||
#pragma arm section code
|
||||
INROOT uint TTime::TicksToUs(uint ticks) const { return !ticks ? 0 : (ticks / gTicks); }
|
||||
INROOT uint TTime::UsToTicks(uint us) const { return !us ? 0 : (us * gTicks); }
|
||||
|
|
|
@ -31,9 +31,6 @@ void TInterrupt::OnInit() const
|
|||
}
|
||||
|
||||
#if !defined(TINY)
|
||||
#if defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
|
|
@ -71,9 +71,6 @@ void TInterrupt::DecodePriority (uint priority, uint priorityGroup, uint* pPreem
|
|||
#endif
|
||||
|
||||
#if !defined(TINY)
|
||||
#if defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
|
|
@ -71,9 +71,6 @@ void TInterrupt::DecodePriority (uint priority, uint priorityGroup, uint* pPreem
|
|||
#endif
|
||||
|
||||
#if !defined(TINY)
|
||||
#if defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
|
|
@ -71,9 +71,6 @@ void TInterrupt::DecodePriority (uint priority, uint priorityGroup, uint* pPreem
|
|||
#endif
|
||||
|
||||
#if !defined(TINY)
|
||||
#if defined(STM32F0)
|
||||
#pragma arm section code = "SectionForSys"
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue