mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 07:28:38 +08:00
Add rtc.h header file
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3493 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
75661bee13
commit
f96fb2fa03
7 changed files with 54 additions and 39 deletions
|
@ -2092,9 +2092,9 @@ static int fat_stat(struct inode *mountpt, const char *relpath, struct stat *buf
|
|||
{
|
||||
struct fat_mountpt_s *fs;
|
||||
struct fat_dirinfo_s dirinfo;
|
||||
uint16_t date;
|
||||
uint16_t fatdate;
|
||||
uint16_t date2;
|
||||
uint16_t time;
|
||||
uint16_t fattime;
|
||||
uint8_t attribute;
|
||||
int ret;
|
||||
|
||||
|
@ -2174,12 +2174,12 @@ static int fat_stat(struct inode *mountpt, const char *relpath, struct stat *buf
|
|||
|
||||
/* Times */
|
||||
|
||||
date = DIR_GETWRTDATE(dirinfo.fd_entry);
|
||||
time = DIR_GETWRTTIME(dirinfo.fd_entry);
|
||||
buf->st_mtime = fat_fattime2systime(time, date);
|
||||
fatdate = DIR_GETWRTDATE(dirinfo.fd_entry);
|
||||
fattime = DIR_GETWRTTIME(dirinfo.fd_entry);
|
||||
buf->st_mtime = fat_fattime2systime(fattime, fatdate);
|
||||
|
||||
date2 = DIR_GETLASTACCDATE(dirinfo.fd_entry);
|
||||
if (date == date2)
|
||||
if (fatdate == date2)
|
||||
{
|
||||
buf->st_atime = buf->st_mtime;
|
||||
}
|
||||
|
@ -2188,9 +2188,9 @@ static int fat_stat(struct inode *mountpt, const char *relpath, struct stat *buf
|
|||
buf->st_atime = fat_fattime2systime(0, date2);
|
||||
}
|
||||
|
||||
date = DIR_GETCRDATE(dirinfo.fd_entry);
|
||||
time = DIR_GETCRTIME(dirinfo.fd_entry);
|
||||
buf->st_ctime = fat_fattime2systime(time, date);
|
||||
fatdate = DIR_GETCRDATE(dirinfo.fd_entry);
|
||||
fattime = DIR_GETCRTIME(dirinfo.fd_entry);
|
||||
buf->st_ctime = fat_fattime2systime(fattime, fatdate);
|
||||
|
||||
ret = OK;
|
||||
|
||||
|
|
|
@ -1895,8 +1895,8 @@ int fat_dirtruncate(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo)
|
|||
int fat_dircreate(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo)
|
||||
{
|
||||
uint8_t *direntry;
|
||||
uint32_t time;
|
||||
int ret;
|
||||
uint32_t fattime;
|
||||
int ret;
|
||||
|
||||
/* Set up the directory entry */
|
||||
|
||||
|
@ -1924,11 +1924,11 @@ int fat_dircreate(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo)
|
|||
/* ARCHIVE attribute, write time, creation time */
|
||||
DIR_PUTATTRIBUTES(dirinfo->fd_entry, FATATTR_ARCHIVE);
|
||||
|
||||
time = fat_systime2fattime();
|
||||
DIR_PUTWRTTIME(dirinfo->fd_entry, time & 0xffff);
|
||||
DIR_PUTCRTIME(dirinfo->fd_entry, time & 0xffff);
|
||||
DIR_PUTWRTDATE(dirinfo->fd_entry, time >> 16);
|
||||
DIR_PUTCRDATE(dirinfo->fd_entry, time >> 16);
|
||||
fattime = fat_systime2fattime();
|
||||
DIR_PUTWRTTIME(dirinfo->fd_entry, fattime & 0xffff);
|
||||
DIR_PUTCRTIME(dirinfo->fd_entry, fattime & 0xffff);
|
||||
DIR_PUTWRTDATE(dirinfo->fd_entry, fattime >> 16);
|
||||
DIR_PUTCRDATE(dirinfo->fd_entry, fattime >> 16);
|
||||
|
||||
fs->fs_dirty = true;
|
||||
return OK;
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __SYS_MMAN_H
|
||||
#define __SYS_MMAN_H
|
||||
#ifndef __INCLUDE_SYS_TIME_H
|
||||
#define __INCLUDE_SYS_TIME_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
|
@ -71,4 +71,4 @@ EXTERN int gettimeofday(struct timeval *tp, FAR void *tzp);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SYS_MMAN_H */
|
||||
#endif /* __INCLUDE_SYS_TIME_H */
|
||||
|
|
|
@ -179,6 +179,10 @@ typedef int16_t blksize_t;
|
|||
typedef unsigned int socklen_t;
|
||||
typedef uint16_t sa_family_t;
|
||||
|
||||
/* Used for system times in clock ticks */
|
||||
|
||||
typedef uint32_t clock_t;
|
||||
|
||||
/* The type useconds_t shall be an unsigned integer type capable of storing
|
||||
* values at least in the range [0, 1000000]. The type suseconds_t shall be
|
||||
* a signed integer type capable of storing values at least in the range
|
||||
|
|
|
@ -49,15 +49,22 @@
|
|||
* Pre-processor Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/* Clock tick of the system (frequency Hz). The default value is 100Hz, but this
|
||||
* default setting can be overridden by defining the clock interval in
|
||||
* milliseconds as CONFIG_MSEC_PER_TICK in the board configuration file.
|
||||
/* Clock tick of the system (frequency Hz).
|
||||
*
|
||||
* NOTE: This symbolic name CLK_TCK has been removed from the standard. It is
|
||||
* replaced with CLOCKS_PER_SEC. Both are defined here.
|
||||
*
|
||||
* The default value is 100Hz, but this default setting can be overridden by
|
||||
* defining the clock interval in milliseconds as CONFIG_MSEC_PER_TICK in the
|
||||
* board configuration file.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_MSEC_PER_TICK
|
||||
# define CLK_TCK (1000/CONFIG_MSEC_PER_TICK)
|
||||
# define CLK_TCK (1000/CONFIG_MSEC_PER_TICK)
|
||||
# define CLOCKS_PER_SEC (1000/CONFIG_MSEC_PER_TICK)
|
||||
#else
|
||||
# define CLK_TCK (100)
|
||||
# define CLK_TCK (100)
|
||||
# define CLOCKS_PER_SEC (100)
|
||||
#endif
|
||||
|
||||
/* This is the only clock_id supported by the "Clock and Timer
|
||||
|
@ -141,15 +148,19 @@ extern "C" {
|
|||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
EXTERN clock_t clock(void);
|
||||
|
||||
EXTERN int clock_settime(clockid_t clockid, const struct timespec *tp);
|
||||
EXTERN int clock_gettime(clockid_t clockid, struct timespec *tp);
|
||||
EXTERN int clock_getres(clockid_t clockid, struct timespec *res);
|
||||
|
||||
EXTERN time_t mktime(const struct tm *tp);
|
||||
EXTERN struct tm *gmtime(const time_t *clock);
|
||||
EXTERN struct tm *gmtime_r(const time_t *clock, struct tm *result);
|
||||
EXTERN struct tm *gmtime(const time_t *timer);
|
||||
EXTERN struct tm *gmtime_r(const time_t *timer, struct tm *result);
|
||||
EXTERN size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
|
||||
|
||||
EXTERN time_t time(time_t *tloc);
|
||||
|
||||
EXTERN int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid);
|
||||
EXTERN int timer_delete(timer_t timerid);
|
||||
EXTERN int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value,
|
||||
|
|
|
@ -85,9 +85,9 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct tm *gmtime(const time_t *clock)
|
||||
struct tm *gmtime(const time_t *timer)
|
||||
{
|
||||
static struct tm tm;
|
||||
return gmtime_r(clock, &tm);
|
||||
return gmtime_r(timer, &tm);
|
||||
}
|
||||
|
||||
|
|
|
@ -296,9 +296,9 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct tm *gmtime_r(const time_t *clock, struct tm *result)
|
||||
struct tm *gmtime_r(const time_t *timer, struct tm *result)
|
||||
{
|
||||
time_t time;
|
||||
time_t epoch;
|
||||
time_t jdn;
|
||||
int year;
|
||||
int month;
|
||||
|
@ -309,21 +309,21 @@ struct tm *gmtime_r(const time_t *clock, struct tm *result)
|
|||
|
||||
/* Get the seconds since the EPOCH */
|
||||
|
||||
time = *clock;
|
||||
sdbg("clock=%d\n", (int)time);
|
||||
epoch = *timer;
|
||||
sdbg("timer=%d\n", (int)epoch);
|
||||
|
||||
/* Convert to days, hours, minutes, and seconds since the EPOCH */
|
||||
|
||||
jdn = time / SEC_PER_DAY;
|
||||
time -= SEC_PER_DAY * jdn;
|
||||
jdn = epoch / SEC_PER_DAY;
|
||||
epoch -= SEC_PER_DAY * jdn;
|
||||
|
||||
hour = time / SEC_PER_HOUR;
|
||||
time -= SEC_PER_HOUR * hour;
|
||||
hour = epoch / SEC_PER_HOUR;
|
||||
epoch -= SEC_PER_HOUR * hour;
|
||||
|
||||
min = time / SEC_PER_MIN;
|
||||
time -= SEC_PER_MIN * min;
|
||||
min = epoch / SEC_PER_MIN;
|
||||
epoch -= SEC_PER_MIN * min;
|
||||
|
||||
sec = time;
|
||||
sec = epoch;
|
||||
|
||||
sdbg("hour=%d min=%d sec=%d\n",
|
||||
(int)hour, (int)min, (int)sec);
|
||||
|
|
Loading…
Reference in a new issue