📄 dmclock.c
字号:
/* $id:dmClock.c V1.0 2001/09/5 */
/******************************************************************************
* This source code has been made available to you by CORETEK on
* AS-IS.Anyone receiving this source is licensed under
* CORETEK copyrights to use it in any way he or she deems fit,including
* copying it,modifying it,compiling it,and redistributing it either with
* or without modifictions.
*
*
* Any person who transfers this source code or any derivative work must
* include the CORETEK copyright notice, this paragraph,and the preceding
* two paragraphs in the transferred software.
*
*
* COPYRIGHT CORETEK CORPORATION 2001
* LICENSED MATERIAL - PROGRAM PROPERTY OF CORETEK
*****************************************************************************/
/******************************************************************************
*
* FILE: dmClock.c
*
* MODULE: DM
*
* PURPOSE: Three function definitions for set, obtain, and continually update
* the current date and time.
*
* AUTHOR(S):Zhang Yumin
*
* GROUP:TOOL_GROUP
*
* DATE CREATED:2001/09/05
*
* REFERENCE DOCUMENT ID:
*
* MODIFICATIONS:
* Date user Name Description
* 2001/09/05 Zhang Yumin Create this file
*
*********************************************************************************/
#include "dmLibio.h"
#include "dmClock.h"
/*
* Handle used to set the RTC time.
*/
T_VOID ( *fnDM_ClockRtcSet)(T_DM_TimeOfDay tod);
T_VOID ( *fnDM_ClockRtcGet)(T_DM_TimeOfDay *tod);
T_DM_StatusCode( *fnDM_ClockAnnounce)(T_DM_ClockAnnounce);
/********************************************************************
* FUNCTION: fnDM_ClockGet
*
* PURPOSE: This directive returns the current date and time.
* (External function)
* PARAMETERS:
*
* Input: option -which value to return
* time_buffer -pointer to output buffer (a time and date
* structure or an interval)
* Output: time_buffer - output filled in
* InOut: None
*
* Return value: Upon successful completion, a value of 0 is returned.
* Otherwise, a value of -1 is returned and the global
* integer variable errno is set to indicate the error.
*
* Reentrant: No
********************************************************************/
T_WORD fnDM_ClockGet(
T_DM_ClockGetOptions option,
T_VOID *time_buffer
)
{
T_DM_StatusCode status;
T_WORD rc;
if((fnDM_ClockRtcGet)&&
( option == DM_CLOCK_GET_TOD
||option == DM_CLOCK_GET_SECONDS_SINCE_EPOCH
||option == DM_CLOCK_GET_TIME_VALUE
||option == DM_CLOCK_GET_SECONDS_SINCE_BOOT)&&
(((T_UWORD)fnDM_ClockRtcGet)!= ((T_UWORD)0x1)))
{
T_UWORD ticks;
T_DM_TimeOfDay tod;
ticks = fnDM_TodCurTicks();
/*
* Get the RTC time and set the TOD,
* but the RTC not return the ticks,
* so we preserve the current ticks first.
* After return from RTC we resume the
* current ticks.
*/
(*fnDM_ClockRtcGet)(&tod);
tod.ticks = ticks;
fnDM_TodSet(&tod);
}
status = fnDM_TodGet(option,time_buffer);
rc = fnDM_StatusToErrno(status);
if(rc!=0)
{
errno = rc;
return -1;
}
return 0;
}
/********************************************************************
* FUNCTION: fnDM_ClockSet
*
* PURPOSE: This directive sets the date and time for this node.
* (External function)
* PARAMETERS:
*
* Input: time_buffer -pointer to the time and date structure
* Output: None
* InOut: None
*
* Return value: DM_SUCCESSFUL - if successful
* error code - if unsuccessful
* Reentrant: No
********************************************************************/
T_WORD fnDM_ClockSet(
T_DM_TimeOfDay *time_buffer
)
{
T_DM_StatusCode status;
T_WORD rc;
if((fnDM_ClockRtcSet)&& (((T_UWORD)fnDM_ClockRtcSet)!= ((T_UWORD)0x1)))
(*fnDM_ClockRtcSet)(*time_buffer);
status = fnDM_TodSet(time_buffer);
rc = fnDM_StatusToErrno(status);
if(rc!=0)
{
errno = rc;
return -1;
}
return 0;
}
/********************************************************************
* FUNCTION: fnDM_ClockTimerTicks
*
* PURPOSE: This directive notifies the executve that a tick has
* occurred.When the tick occurs the time manager updates
* and maintains the calendar time, timeslicing, and any
* timeout delays.
* PARAMETERS:
*
* Input: None
* Output: None
* InOut: None
*
* Return value: None
* Reentrant: No
********************************************************************/
T_VOID fnDM_ClockTimerTicks()
{
if(fnDM_ClockAnnounce)
(*fnDM_ClockAnnounce)(DM_ANNOUNCE_TICK);
inlDM_TodTickleTicks();
if((!fnDM_ClockRtcSet))
fnDM_TodTickle();
//printk("Timer is running!\n");
}
/********************************************************************
* FUNCTION: fnDM_ClockRtcTicks
*
* PURPOSE: This directive notifies the executve that a tick has
* occurred.When the tick occurs the time manager updates
* and maintains the calendar time, timeslicing, and any
* timeout delays.
* PARAMETERS:
*
* Input: None
* Output: None
* InOut: None
*
* Return value: None
* Reentrant: No
********************************************************************/
T_VOID fnDM_ClockRtcTicks()
{
if(fnDM_ClockAnnounce)
(*fnDM_ClockAnnounce)(DM_ANNOUNCE_TICK);
inlDM_TodTickleTicks();
//printk("RTC is running!\n");
}
/********************************************************************
* FUNCTION: fnDM_ClockSecondInterrupt
*
* PURPOSE: This directive notifies the executve that a tick has
* occurred.When the tick occurs the time manager updates
* and maintains the calendar time, timeslicing, and any
* timeout delays.
* PARAMETERS:
*
* Input: None
* Output: None
* InOut: None
*
* Return value: None
* Reentrant: No
********************************************************************/
T_VOID fnDM_ClockSecondInterrupt()
{
inlDM_TodSecondInterrupt();
if(fnDM_ClockAnnounce)
(*fnDM_ClockAnnounce)(DM_ANNOUNCE_SECOND);
}
/********************************************************************
* FUNCTION: fnDM_ClockSecondInterrupt
*
* PURPOSE: This directive notifies the executve that a tick has
* occurred.When the tick occurs the time manager updates
* and maintains the calendar time, timeslicing, and any
* timeout delays.
* PARAMETERS:
*
* Input: None
* Output: None
* InOut: None
*
* Return value: DM_SUCCESSFUL - always succeeds
* DM_INVALID_CLOCK - if invalid arguments!
* Reentrant: No
********************************************************************/
T_DM_StatusCode fnDM_ClockRefresh(T_DM_TOD_Control *the_tod)
{
return fnDM_TodSet(the_tod);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -