系统时钟虽然很重要,但是并非所有系统都需要用到系统时钟

This commit is contained in:
nnhy 2015-07-28 15:18:15 +00:00
parent 302c8622af
commit 6a8c3da4d4
7 changed files with 20 additions and 9 deletions

View File

@ -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;
}

View File

@ -1,4 +1,5 @@
#include "Port.h"
#include "Time.h"
#if defined(STM32F1) || defined(STM32F4)
static const int PORT_IRQns[] = {

View File

@ -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;

View File

@ -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

2
Sys.h
View File

@ -141,7 +141,7 @@ extern TSys Sys; //创建一个全局的Sys对象 会在main函数之前执行
// 内存管理
#include "Memory.h"
#include "Time.h"
//#include "Time.h"
#include "Interrupt.h"
#endif //_Sys_H_

View File

@ -1,4 +1,5 @@
#include "Task.h"
#include "Time.h"
// 全局任务调度器
TaskScheduler Scheduler("系统");

View File

@ -1,4 +1,5 @@
#include "Thread.h"
#include "Time.h"
#include "Thread.h"
#include "Task.h"
//#define TH_DEBUG DEBUG