From 44e5b22e261643baf5cdb7bb570edb01a6bc36b4 Mon Sep 17 00:00:00 2001 From: Stone Date: Sat, 18 Jun 2016 08:12:52 +0000 Subject: [PATCH] =?UTF-8?q?=E4=B8=A5=E6=A0=BC=E8=A6=81=E6=B1=82=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E6=8E=92=E9=99=A4=E7=BC=96=E8=AF=91=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config.cpp | 6 ++--- Core/Buffer.cpp | 4 +-- Core/Queue.cpp | 15 ++++++++--- Core/Stream.cpp | 2 +- Device/Power.cpp | 4 +-- Drivers/Enc28j60.cpp | 2 +- Drivers/Esp8266/Esp8266.cpp | 2 +- Drivers/W5500.cpp | 6 ++--- Kernel/Interrupt.cpp | 14 ++++++++-- Kernel/Sys.cpp | 30 +++++++++++++++++---- Kernel/Task.cpp | 54 ++++++++++++++++++++++++++++++------- Kernel/Thread.cpp | 4 +-- Kernel/Time.cpp | 18 +++++++++---- Kernel/Z_Debug.cpp | 28 ++++++++++++------- Net/Ethernet.h | 9 +------ Net/IPAddress.cpp | 2 +- TinyNet/TinyServer.cpp | 2 +- TokenNet/TokenMessage.cpp | 2 +- 18 files changed, 145 insertions(+), 59 deletions(-) diff --git a/Config.cpp b/Config.cpp index f4f3d425..385e6be9 100644 --- a/Config.cpp +++ b/Config.cpp @@ -235,7 +235,7 @@ const void* Config::New(int size) const // 实在没办法,最后划分一个新的区块。这里判断一下空间是否足够 if(Size && (uint)cfg + sizeof(ConfigBlock) + size > Address + Size) { - debug_printf("Config::New 0x%08X + %d + %d 配置区(0x%08X, %d)空间不足\r\n", cfg, sizeof(ConfigBlock), size, Address, Size); + debug_printf("Config::New 0x%p + %d + %d 配置区(0x%p, %d)空间不足\r\n", cfg, sizeof(ConfigBlock), size, (byte*)Address, Size); return nullptr; } @@ -293,7 +293,7 @@ bool Config::RemoveAll() const }*/ #if CFG_DEBUG - debug_printf("Config::RemoveAll (0x%08X, %d) \r\n", Address, Size); + debug_printf("Config::RemoveAll (0x%p, %d) \r\n", (byte*)Address, Size); #endif ByteArray bs((byte)0xFF, Size); @@ -438,7 +438,7 @@ void ConfigBase::Save() const auto pt = Cfg.Set(_Name, bs); if(pt) - debug_printf("成功 0x%08X \r\n", pt); + debug_printf("成功 0x%p \r\n", pt); else debug_printf("失败\r\n"); } diff --git a/Core/Buffer.cpp b/Core/Buffer.cpp index 851a2d61..10ac180f 100644 --- a/Core/Buffer.cpp +++ b/Core/Buffer.cpp @@ -119,7 +119,7 @@ int Buffer::Copy(int destIndex, const void* src, int len) // 不指定长度,又没有剩余量,无法拷贝 if(remain <= 0) { - debug_printf("Buffer::Copy (0x%08X, %d) <= (%d, 0x%08X, %d) \r\n", _Arr, _Length, destIndex, src, len); + debug_printf("Buffer::Copy (0x%p, %d) <= (%d, 0x%p, %d) \r\n", _Arr, _Length, destIndex, src, len); assert(false, "Buffer::Copy 未指明要拷贝的长度"); return 0; @@ -133,7 +133,7 @@ int Buffer::Copy(int destIndex, const void* src, int len) // 子类可能在这里扩容 if(!SetLength(destIndex + len)) { - debug_printf("Buffer::Copy (0x%08X, %d) <= (%d, 0x%08X, %d) \r\n", _Arr, _Length, destIndex, src, len); + debug_printf("Buffer::Copy (0x%p, %d) <= (%d, 0x%p, %d) \r\n", _Arr, _Length, destIndex, src, len); assert(false, "Buffer::Copy 缓冲区太小"); len = remain; diff --git a/Core/Queue.cpp b/Core/Queue.cpp index 8f68af66..cf73fb4b 100644 --- a/Core/Queue.cpp +++ b/Core/Queue.cpp @@ -39,7 +39,11 @@ void Queue::Clear() } #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif void Queue::Push(byte dat) @@ -79,8 +83,13 @@ byte Queue::Pop() return dat; } -#pragma arm section code - +#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) { /* diff --git a/Core/Stream.cpp b/Core/Stream.cpp index fa0772eb..8aed9107 100644 --- a/Core/Stream.cpp +++ b/Core/Stream.cpp @@ -56,7 +56,7 @@ bool Stream::CheckRemain(uint count) if(count > remain) { if(CanResize) - debug_printf("数据流 0x%08X 剩余容量 (%d - %d) = %d 不足 %d ,无法扩容!\r\n", this, _Capacity, _Position, remain, count); + debug_printf("数据流 0x%p 剩余容量 (%d - %d) = %d 不足 %d ,无法扩容!\r\n", this, _Capacity, _Position, remain, count); else assert(false, "无法扩容"); diff --git a/Device/Power.cpp b/Device/Power.cpp index 0b203322..a6fdfb37 100644 --- a/Device/Power.cpp +++ b/Device/Power.cpp @@ -38,7 +38,7 @@ void Power::Standby(uint msTime) auto pwr = (Power*)_powers[i]; if(pwr) { - debug_printf("Power::LowPower 0x%08X\r\n", pwr); + debug_printf("Power::LowPower 0x%p\r\n", pwr); pwr->ChangePower(msTime); } } @@ -52,7 +52,7 @@ void Power::Standby(uint msTime) // 各模块向系统注册低功耗句柄,供系统进入低功耗前调用 void Power::AddPower(Power* power) { - debug_printf("Power::AddPower 0x%08X\r\n", power); + debug_printf("Power::AddPower 0x%p\r\n", power); _powers.Add(power); } diff --git a/Drivers/Enc28j60.cpp b/Drivers/Enc28j60.cpp index 2eb8023a..0d6c3b40 100644 --- a/Drivers/Enc28j60.cpp +++ b/Drivers/Enc28j60.cpp @@ -753,7 +753,7 @@ bool Enc28j60::OnWrite(const Buffer& bs) WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS); // 等待发送完成 times = 1000; - while((ReadReg(ECON1) & ECON1_TXRTS) && --times > 0); + while(((ReadReg(ECON1) & ECON1_TXRTS) && --times) > 0) { } /* 如果数据包发送完成或因错误/ 取消而中止发送,ECON1.TXRTS 位会被清零,一个7 字节的发送状态向量将被写入由ETXND + 1 指向的单元, diff --git a/Drivers/Esp8266/Esp8266.cpp b/Drivers/Esp8266/Esp8266.cpp index 10d9b800..6657ceaf 100644 --- a/Drivers/Esp8266/Esp8266.cpp +++ b/Drivers/Esp8266/Esp8266.cpp @@ -271,7 +271,7 @@ String Esp8266::Send(const String& cmd, cstring expect, cstring expect2, uint ms #if NET_DEBUG // 只有AT指令显示日志 - if(!cmd.StartsWith("AT") || expect && expect[0] == '>') EnableLog = false; + if(!cmd.StartsWith("AT") || (expect && expect[0] == '>')) EnableLog = false; if(EnableLog) { we.Command = &cmd; diff --git a/Drivers/W5500.cpp b/Drivers/W5500.cpp index 98b56e32..4de8f092 100644 --- a/Drivers/W5500.cpp +++ b/Drivers/W5500.cpp @@ -652,7 +652,7 @@ void W5500::Register(byte Index, HardSocket* handler) { if(Index >= 8) return; - net_printf("W5500::Register %d 0x%08X\r\n", Index, handler); + net_printf("W5500::Register %d 0x%p\r\n", Index, handler); _sockets[Index] = handler; } @@ -1126,8 +1126,8 @@ bool HardSocket::OnOpen() while(!tw.Expired()) { sr = ReadStatus(); - if(Protocol == ProtocolType::Tcp && sr == SOCK_INIT - || Protocol == ProtocolType::Udp && sr == SOCK_UDP) + if((Protocol == ProtocolType::Tcp && sr == SOCK_INIT) + || (Protocol == ProtocolType::Udp && sr == SOCK_UDP)) { rs = true; break; diff --git a/Kernel/Interrupt.cpp b/Kernel/Interrupt.cpp index f9c30bf3..e000dc37 100644 --- a/Kernel/Interrupt.cpp +++ b/Kernel/Interrupt.cpp @@ -40,7 +40,11 @@ bool TInterrupt::Deactivate(short irq) } #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif void TInterrupt::Process(uint num) const @@ -80,7 +84,13 @@ SmartIRQ::~SmartIRQ() TInterrupt::GlobalEnable(); } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif /*================================ 锁 ================================*/ diff --git a/Kernel/Sys.cpp b/Kernel/Sys.cpp index f9bf4f0d..cb76d1b5 100644 --- a/Kernel/Sys.cpp +++ b/Kernel/Sys.cpp @@ -26,7 +26,11 @@ extern uint __microlib_freelist_initialised; #endif #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif TSys::TSys() @@ -49,7 +53,13 @@ TSys::TSys() Started = false; } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif void ShowTime(void* param) { @@ -112,8 +122,12 @@ void TSys::RemoveTask(uint& taskid) const taskid = 0; } -#if !defined(TINY) && defined(STM32F0) && defined(DEBUG) - #pragma arm section code = "SectionForSys" +#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 @@ -262,7 +276,13 @@ void TSys::Delay(uint us) const } #endif -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif /****************系统跟踪****************/ diff --git a/Kernel/Task.cpp b/Kernel/Task.cpp index 0516e95c..ebe4f934 100644 --- a/Kernel/Task.cpp +++ b/Kernel/Task.cpp @@ -35,7 +35,11 @@ Task::~Task() } #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif bool Task::Execute(UInt64 now) @@ -116,7 +120,13 @@ bool Task::CheckTime(UInt64 end, bool isSleep) return Event || Times > 0; } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif // 显示状态 void Task::ShowStatus() @@ -137,7 +147,11 @@ void Task::ShowStatus() } #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif // 全局任务调度器 @@ -158,7 +172,13 @@ Task& Task::Current() return *(Scheduler()->Current); } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif TaskScheduler::TaskScheduler(cstring name) { @@ -216,7 +236,7 @@ uint TaskScheduler::Add(Action func, void* param, int dueTime, int period, cstri Count++; #if DEBUG - debug_printf("%s::添加%d %s First=%dms Period=%dms 0x%08x\r\n", Name, task->ID, name, dueTime, period, func); + debug_printf("%s::添加%d %s First=%dms Period=%dms 0x%p\r\n", Name, task->ID, name, dueTime, period, func); #endif return task->ID; @@ -231,7 +251,7 @@ void TaskScheduler::Remove(uint taskid) auto task = (Task*)_Tasks[i]; if(task->ID == taskid) { - debug_printf("%s::删除%d %s 0x%08x\r\n", Name, task->ID, task->Name, task->Callback); + debug_printf("%s::删除%d %s 0x%p\r\n", Name, task->ID, task->Name, task->Callback); // 清零ID,实现重用 task->ID = 0; @@ -328,7 +348,13 @@ void TaskScheduler::Execute(uint msMax, bool& cancel) } } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif // 显示状态 void TaskScheduler::ShowStatus() @@ -358,7 +384,11 @@ void TaskScheduler::ShowStatus() } #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif Task* TaskScheduler::operator[](int taskid) @@ -372,4 +402,10 @@ Task* TaskScheduler::operator[](int taskid) return nullptr; } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index b9126ab1..f79b8b67 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -39,7 +39,7 @@ Thread::Thread(Action callback, void* state, uint stackSize) ID = ++g_ID; if(g_ID >= 0xFFFF) g_ID = 0; - debug_printf("Thread::Create %d 0x%08x StackSize=0x%04x", ID, callback, stackSize); + debug_printf("Thread::Create %d 0x%p StackSize=0x%04x", ID, callback, stackSize); Name = nullptr; @@ -54,7 +54,7 @@ Thread::Thread(Action callback, void* state, uint stackSize) uint* p = new uint[stackSize]; Stack = p; StackTop = Stack + stackSize; - debug_printf(" Stack=(0x%08x, 0x%08x)", Stack, StackTop); + debug_printf(" Stack=(0x%p, 0x%p)", Stack, StackTop); debug_printf("\r\n"); // 默认状态就绪 diff --git a/Kernel/Time.cpp b/Kernel/Time.cpp index 64aadb82..49d222dc 100644 --- a/Kernel/Time.cpp +++ b/Kernel/Time.cpp @@ -51,10 +51,12 @@ void TTime::SetTime(UInt64 seconds) if(OnSave) OnSave(); } -#pragma arm section code - #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif void TTime::Sleep(uint ms, bool* running) const @@ -76,7 +78,7 @@ void TTime::Sleep(uint ms, bool* running) const } } // 睡眠时间太短 - if(!ms || running != nullptr && !*running) return; + if(!ms || (running && !*running)) return; uint me = Current() + ms; @@ -119,7 +121,13 @@ void TTime::Delay(uint us) const } } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif /************************************************ TimeWheel ************************************************/ diff --git a/Kernel/Z_Debug.cpp b/Kernel/Z_Debug.cpp index cb841376..7e31cae6 100644 --- a/Kernel/Z_Debug.cpp +++ b/Kernel/Z_Debug.cpp @@ -17,7 +17,11 @@ #if DEBUG #if !defined(TINY) && defined(STM32F0) - #pragma arm section code = "SectionForSys" + #if defined(__CC_ARM) + #pragma arm section code = "SectionForSys" + #elif defined(__GNUC__) + __attribute__((section("SectionForSys"))) + #endif #endif #if MEM_DEBUG @@ -37,7 +41,7 @@ void free_(void* p) { byte* bs = (byte*)p; bs -= 4; - if(!(bs[0] == 'S' && bs[1] == 'M')) mem_printf("p=0x%08x bs[0]=%c bs[1]=%c\r\n", p, bs[0], bs[1]); + if(!(bs[0] == 'S' && bs[1] == 'M')) mem_printf("p=0x%p bs[0]=%c bs[1]=%c\r\n", p, bs[0], bs[1]); assert(bs[0] == 'S' && bs[1] == 'M', "正在释放不是本系统申请的内存!"); free(bs); @@ -67,7 +71,7 @@ void* operator new(uint size) mem_printf("malloc failed! size=%d ", size); else { - mem_printf("0x%08x ", p); + mem_printf("0x%p ", p); // 如果堆只剩下64字节,则报告失败,要求用户扩大堆空间以免不测 //uint end = (uint)&__heap_limit; //uint end = __get_PSP(); @@ -97,7 +101,7 @@ void* operator new[](uint size) mem_printf("malloc failed! size=%d ", size); else { - mem_printf("0x%08x ", p); + mem_printf("0x%p ", p); // 如果堆只剩下64字节,则报告失败,要求用户扩大堆空间以免不测 //uint end = (uint)&__heap_limit; //uint end = __get_PSP(); @@ -108,11 +112,11 @@ void* operator new[](uint size) return p; } -void operator delete(void* p) +void operator delete(void* p) noexcept { assert_ptr(p); - mem_printf(" delete 0x%08x ", p); + mem_printf(" delete 0x%p ", p); if(p) { SmartIRQ irq; @@ -120,11 +124,11 @@ void operator delete(void* p) } } -void operator delete[](void* p) +void operator delete[](void* p) noexcept { assert_ptr(p); - mem_printf(" delete[] 0x%08x ", p); + mem_printf(" delete[] 0x%p ", p); if(p) { SmartIRQ irq; @@ -132,7 +136,13 @@ void operator delete[](void* p) } } -#pragma arm section code +#if !defined(TINY) && defined(STM32F0) + #if defined(__CC_ARM) + #pragma arm section code + #elif defined(__GNUC__) + __attribute__((section(""))) + #endif +#endif #ifdef USE_FULL_ASSERT diff --git a/Net/Ethernet.h b/Net/Ethernet.h index c6cb770b..87ae3fa9 100644 --- a/Net/Ethernet.h +++ b/Net/Ethernet.h @@ -177,14 +177,7 @@ typedef struct _TCP_HEADER void Init(bool recursion = false) { -#if (defined (__GNUC__)) -#pragma GCC diagnostic ignored "-Woverflow" -#endif - Length = (byte)sizeof(this[0]); - //Length = (byte)0x14; -#if (defined (__GNUC__)) -#pragma GCC diagnostic warning "-Woverflow" -#endif + Length = sizeof(this[0]) >> 2; reserved_1 = 0; reserved_2 = 0; diff --git a/Net/IPAddress.cpp b/Net/IPAddress.cpp index d1c5e162..5c6993c0 100644 --- a/Net/IPAddress.cpp +++ b/Net/IPAddress.cpp @@ -64,7 +64,7 @@ IPAddress IPAddress::Parse(const String& ipstr) // 标准地址第一个不能是0,唯一的Any例外已经在前面处理 int v = item.ToInt(); - if(v < 0 || v > 255 || i == 0 && v == 0) break; + if(v < 0 || v > 255 || (i == 0 && v == 0)) break; ip[i] = (byte)v; diff --git a/TinyNet/TinyServer.cpp b/TinyNet/TinyServer.cpp index b5d6e41b..b40b1d94 100644 --- a/TinyNet/TinyServer.cpp +++ b/TinyNet/TinyServer.cpp @@ -278,7 +278,7 @@ bool TinyServer::OnJoin(const TinyMessage& msg) // 从1开始派ID id = 1; - while(DevMgmt.FindDev(++id) != nullptr && id < 0xFF); + while(DevMgmt.FindDev(++id) != nullptr && id < 0xFF) { } debug_printf("发现节点设备 0x%04X ,为其分配 0x%02X\r\n", dm.Kind, id); if(id == 0xFF) return false; diff --git a/TokenNet/TokenMessage.cpp b/TokenNet/TokenMessage.cpp index b309e967..c866d454 100644 --- a/TokenNet/TokenMessage.cpp +++ b/TokenNet/TokenMessage.cpp @@ -63,7 +63,7 @@ void TokenMessage::Write(Stream& ms) const assert_ptr(this); byte tmp = Code | (Reply << 7); - if(!Reply && OneWay || Reply && Error) tmp |= (1 << 6); + if((!Reply && OneWay) || (Reply && Error)) tmp |= (1 << 6); ms.Write(tmp); ms.Write(Seq); ms.WriteArray(Buffer(Data, Length));