系统时钟虽然很重要,但是并非所有系统都需要用到系统时钟
This commit is contained in:
parent
302c8622af
commit
6a8c3da4d4
|
@ -323,6 +323,10 @@ SmartIRQ::~SmartIRQ()
|
||||||
__set_PRIMASK(_state);
|
__set_PRIMASK(_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*================================ 锁 ================================*/
|
||||||
|
|
||||||
|
#include "Time.h"
|
||||||
|
|
||||||
// 智能锁。初始化时锁定一个整数,销毁时解锁
|
// 智能锁。初始化时锁定一个整数,销毁时解锁
|
||||||
Lock::Lock(int& ref)
|
Lock::Lock(int& ref)
|
||||||
{
|
{
|
||||||
|
@ -356,10 +360,11 @@ bool Lock::Wait(int us)
|
||||||
int& ref = *_ref;
|
int& ref = *_ref;
|
||||||
// 等待超时时间
|
// 等待超时时间
|
||||||
TimeWheel tw(0, 0, us);
|
TimeWheel tw(0, 0, us);
|
||||||
|
tw.Sleep = 1;
|
||||||
while(ref > 0)
|
while(ref > 0)
|
||||||
{
|
{
|
||||||
// 延迟一下,释放CPU使用权
|
// 延迟一下,释放CPU使用权
|
||||||
Sys.Sleep(1);
|
//Sys.Sleep(1);
|
||||||
if(tw.Expired()) return false;
|
if(tw.Expired()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
Port.cpp
1
Port.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "Port.h"
|
#include "Port.h"
|
||||||
|
#include "Time.h"
|
||||||
|
|
||||||
#if defined(STM32F1) || defined(STM32F4)
|
#if defined(STM32F1) || defined(STM32F4)
|
||||||
static const int PORT_IRQns[] = {
|
static const int PORT_IRQns[] = {
|
||||||
|
|
|
@ -241,17 +241,20 @@ bool SerialPort::OnWrite(const byte* buf, uint size)
|
||||||
uint SerialPort::OnRead(byte* buf, uint size)
|
uint SerialPort::OnRead(byte* buf, uint size)
|
||||||
{
|
{
|
||||||
// 在100ms内接收数据
|
// 在100ms内接收数据
|
||||||
uint msTimeout = 1;
|
//uint msTimeout = 1;
|
||||||
TimeWheel tw(0, msTimeout);
|
//TimeWheel tw(0, msTimeout);
|
||||||
uint count = 0; // 收到的字节数
|
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)
|
if(USART_GetFlagStatus(_port, USART_FLAG_RXNE) != RESET)
|
||||||
{
|
{
|
||||||
*buf++ = (byte)USART_ReceiveData(_port);
|
*buf++ = (byte)USART_ReceiveData(_port);
|
||||||
count++;
|
count++;
|
||||||
tw.Reset(0, msTimeout);
|
//tw.Reset(0, msTimeout);
|
||||||
|
msTimeout = 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
|
4
Sys.cpp
4
Sys.cpp
|
@ -245,6 +245,8 @@ void TSys::InitClock()
|
||||||
Clock = clock.SYSCLK_Frequency;
|
Clock = clock.SYSCLK_Frequency;
|
||||||
SystemCoreClock = Clock;
|
SystemCoreClock = Clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TSys::Init(void)
|
void TSys::Init(void)
|
||||||
|
@ -253,8 +255,6 @@ void TSys::Init(void)
|
||||||
|
|
||||||
// 必须在系统主频率确定以后再初始化时钟
|
// 必须在系统主频率确定以后再初始化时钟
|
||||||
Time.Init();
|
Time.Init();
|
||||||
|
|
||||||
Inited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|
2
Sys.h
2
Sys.h
|
@ -141,7 +141,7 @@ extern TSys Sys; //创建一个全局的Sys对象 会在main函数之前执行
|
||||||
// 内存管理
|
// 内存管理
|
||||||
#include "Memory.h"
|
#include "Memory.h"
|
||||||
|
|
||||||
#include "Time.h"
|
//#include "Time.h"
|
||||||
#include "Interrupt.h"
|
#include "Interrupt.h"
|
||||||
|
|
||||||
#endif //_Sys_H_
|
#endif //_Sys_H_
|
||||||
|
|
1
Task.cpp
1
Task.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
#include "Time.h"
|
||||||
|
|
||||||
// 全局任务调度器
|
// 全局任务调度器
|
||||||
TaskScheduler Scheduler("系统");
|
TaskScheduler Scheduler("系统");
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "Thread.h"
|
#include "Time.h"
|
||||||
|
#include "Thread.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
|
||||||
//#define TH_DEBUG DEBUG
|
//#define TH_DEBUG DEBUG
|
||||||
|
|
Loading…
Reference in New Issue