diff --git a/Interrupt.cpp b/Interrupt.cpp index 1a70fc2b..3e4f281d 100644 --- a/Interrupt.cpp +++ b/Interrupt.cpp @@ -323,6 +323,10 @@ SmartIRQ::~SmartIRQ() __set_PRIMASK(_state); } +/*================================ 锁 ================================*/ + +#include "Time.h" + // 智能锁。初始化时锁定一个整数,销毁时解锁 Lock::Lock(int& ref) { @@ -356,10 +360,11 @@ bool Lock::Wait(int us) int& ref = *_ref; // 等待超时时间 TimeWheel tw(0, 0, us); + tw.Sleep = 1; while(ref > 0) { // 延迟一下,释放CPU使用权 - Sys.Sleep(1); + //Sys.Sleep(1); if(tw.Expired()) return false; } diff --git a/Port.cpp b/Port.cpp index 579b6da4..d1aa98d3 100644 --- a/Port.cpp +++ b/Port.cpp @@ -1,4 +1,5 @@ #include "Port.h" +#include "Time.h" #if defined(STM32F1) || defined(STM32F4) static const int PORT_IRQns[] = { diff --git a/SerialPort.cpp b/SerialPort.cpp index 4fd57f87..94ee3459 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -241,17 +241,20 @@ bool SerialPort::OnWrite(const byte* buf, uint size) uint SerialPort::OnRead(byte* buf, uint size) { // 在100ms内接收数据 - uint msTimeout = 1; - TimeWheel tw(0, msTimeout); + //uint msTimeout = 1; + //TimeWheel tw(0, msTimeout); uint count = 0; // 收到的字节数 - while(count < size && !tw.Expired()) + //while(count < size && !tw.Expired()) + uint msTimeout = 1000; + while(count < size && msTimeout-- > 0) { // 轮询接收寄存器,收到数据则放入缓冲区 if(USART_GetFlagStatus(_port, USART_FLAG_RXNE) != RESET) { *buf++ = (byte)USART_ReceiveData(_port); count++; - tw.Reset(0, msTimeout); + //tw.Reset(0, msTimeout); + msTimeout = 1000; } } return count; diff --git a/Sys.cpp b/Sys.cpp index 4e4135c8..5aa326d6 100644 --- a/Sys.cpp +++ b/Sys.cpp @@ -245,6 +245,8 @@ void TSys::InitClock() Clock = clock.SYSCLK_Frequency; SystemCoreClock = Clock; } + + Inited = true; } void TSys::Init(void) @@ -253,8 +255,6 @@ void TSys::Init(void) // 必须在系统主频率确定以后再初始化时钟 Time.Init(); - - Inited = true; } #if DEBUG diff --git a/Sys.h b/Sys.h index 5452fdc2..5695c72f 100644 --- a/Sys.h +++ b/Sys.h @@ -141,7 +141,7 @@ extern TSys Sys; //创建一个全局的Sys对象 会在main函数之前执行 // 内存管理 #include "Memory.h" -#include "Time.h" +//#include "Time.h" #include "Interrupt.h" #endif //_Sys_H_ diff --git a/Task.cpp b/Task.cpp index e35c4736..35cd5f2e 100644 --- a/Task.cpp +++ b/Task.cpp @@ -1,4 +1,5 @@ #include "Task.h" +#include "Time.h" // 全局任务调度器 TaskScheduler Scheduler("系统"); diff --git a/Thread.cpp b/Thread.cpp index 9734465f..e7da5223 100644 --- a/Thread.cpp +++ b/Thread.cpp @@ -1,4 +1,5 @@ -#include "Thread.h" +#include "Time.h" +#include "Thread.h" #include "Task.h" //#define TH_DEBUG DEBUG