📄 bsp_clk.c
字号:
/*
* COPYRIGHT (c) Notifier 1993-2004, All Rights Reserved
*
* 描述: Clock支持包
* 基于uC/OS II的clk模块。
*
* 版本历史:
*
* 版本 作者 日期 修改内容
* 1.00 王璀 2006-02-14 创建
* 1.01 任学锋 2006-07-03 修改文件名,否则与bsp_clock重名。
*/
//==============================================================================
// 包含的头文件
//==============================================================================
#include <assert.h>
#include <time.h>
#include <string.h>
#include "system\sys_types.h"
#include "bsp\bsp_clock.h"
#include "clk.h"
//==============================================================================
// 本地宏及类型定义
//==============================================================================
//==============================================================================
// 内部函数声明
//==============================================================================
//==============================================================================
// 全局变量定义
//==============================================================================
//==============================================================================
// 内部变量定义
//==============================================================================
//==============================================================================
// 函数定义
//==============================================================================
#if BSP_CLOCK_TM_VALIDATE_EN > 0
//------------------------------------------------------------------------------
// 函数描述:验证并使struct tm类型的实例有效
// 用户构造一个struct tm类型的实例时,往往只能提供 年-月-日 时:分:秒 信息,而无法
// 直接得到Day Of Week,Day Of Year,Daylight Saving Time信息
// 使用本函数验证后,就能得到一个完整有效的struct tm类型的实例
STATUS//OK - 成功
//ERROR - 失败
//... - 用户定义的其它返回值
BspClockTmValidate
(
struct tm *a_pBrokenTime//时间
)
{
time_t calendarTime;
calendarTime = mktime(a_pBrokenTime);
if (calendarTime == -1)
{
return ERROR;
}
memcpy(a_pBrokenTime, localtime(&calendarTime), sizeof(struct tm));
return OK;
}
#endif
#if BSP_CLOCK_INIT_EN > 0
//------------------------------------------------------------------------------
// 函数描述:初始化CLOCK
STATUS//OK - 成功
//ERROR - 失败
//... - 用户定义的其它返回值
BspClockInit(void)
{
ClkInit();
return OK;
}
#endif
#if BSP_CLOCK_SET_EN > 0
//------------------------------------------------------------------------------
// 函数描述:写CLOCK状态
//------------------------------------------------------------------------------
// 函数描述:写CLOCK状态
STATUS//OK - 成功
//ERROR - 失败
//... - 用户定义的其它返回值
BspClockSet
(
INT8U a_id,//CLOCK的索引
struct tm *a_pBrokenTime//时间
)
{
struct tm brokenTime;
memcpy(&brokenTime, a_pBrokenTime, sizeof(struct tm));
if (BspClockTmValidate(&brokenTime) != OK)
{
return ERROR;
}
a_id = a_id;
//写入LPC2xxx的片内时钟
ClkSec = brokenTime.tm_sec;
ClkMin = brokenTime.tm_min;
ClkHr = brokenTime.tm_hour;
ClkDOW = brokenTime.tm_wday;
ClkDay = brokenTime.tm_mday;
ClkMonth = brokenTime.tm_mon;
ClkYear = brokenTime.tm_year + 1900;
return OK;
}
#endif
#if BSP_CLOCK_GET_EN > 0
//------------------------------------------------------------------------------
// 函数描述:读CLOCK状态
STATUS//OK - 成功
//ERROR - 失败
//... - 用户定义的其它返回值
BspClockGet
(
INT8U a_id,//CLOCK的索引
struct tm *a_pBrokenTime//时间
)
{
a_id = a_id;
//读取LPC2xxx的片内时钟
a_pBrokenTime->tm_sec = ClkSec;
a_pBrokenTime->tm_min = ClkMin;
a_pBrokenTime->tm_hour = ClkHr;
a_pBrokenTime->tm_wday = ClkDOW;
a_pBrokenTime->tm_mday = ClkDay;
a_pBrokenTime->tm_mon = ClkMonth;
a_pBrokenTime->tm_year = ClkYear - 1900;
if (BspClockTmValidate(a_pBrokenTime) != OK)
{
return ERROR;
}
return OK;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -