mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 06:39:01 +08:00
Add FAT date/time stamp
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4008 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -4173,6 +4173,11 @@ build
|
||||
If you are willing to live with some non-standard, short long file names, then define this value.
|
||||
A good choice would be the same value as selected for CONFIG_NAME_MAX which will limit the visibility of longer file names anyway.
|
||||
</li>
|
||||
<li>
|
||||
<code>CONFIG_FS_FATTIME</code>: Support FAT date and time.
|
||||
NOTE: There is not much sense in supporting FAT date and time unless you have a hardware RTC
|
||||
or other way to get the time and date.
|
||||
</li>
|
||||
<li>
|
||||
<code>CONFIG_FS_NXFFS</code>: Enable NuttX FLASH file system (NXFF) support.
|
||||
</li>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/armv7-m/nvic.h
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -396,7 +396,7 @@
|
||||
#define NVIC_SYSTICK_RELOAD_SHIFT 0 /* Bits 23-0: Timer reload value */
|
||||
#define NVIC_SYSTICK_RELOAD_MASK (0x00ffffff << NVIC_SYSTICK_RELOAD_SHIFT)
|
||||
|
||||
/* SysTick current value registe (SYSTICK_CURRENT) */
|
||||
/* SysTick current value register (SYSTICK_CURRENT) */
|
||||
|
||||
#define NVIC_SYSTICK_CURRENT_SHIFT 0 /* Bits 23-0: Timer current value */
|
||||
#define NVIC_SYSTICK_CURRENT_MASK (0x00ffffff << NVIC_SYSTICK_RELOAD_SHIFT)
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
||||
* Author: Uros Platise <uros.platise@isotel.eu>
|
||||
*
|
||||
* With extensions, modifications by:
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregroy Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -337,7 +342,7 @@ static int stm32_rtc_interrupt(int irq, void *context)
|
||||
int up_rtcinitialize(void)
|
||||
{
|
||||
/* Set access to the peripheral, enable the backup domain (BKP) and the lower power
|
||||
* extern 32,768Hz LSE oscillator.
|
||||
* extern 32,768Hz (Low-Speed External, LSE) oscillator.
|
||||
*/
|
||||
|
||||
stm32_pwr_enablebkp();
|
||||
|
||||
@@ -578,6 +578,9 @@ defconfig -- This is a configuration file similar to the Linux
|
||||
define this value. A good choice would be the same value as
|
||||
selected for CONFIG_NAME_MAX which will limit the visibility
|
||||
of longer file names anyway.
|
||||
CONFIG_FS_FATTIME: Support FAT date and time. NOTE: There is not
|
||||
much sense in supporting FAT date and time unless you have a
|
||||
hardware RTC or other way to get the time and date.
|
||||
CONFIG_FS_NXFFS: Enable NuttX FLASH file system (NXFF) support.
|
||||
CONFIG_NXFFS_ERASEDSTATE: The erased state of FLASH.
|
||||
This must have one of the values of 0xff or 0x00.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* fs/fat/fs_fat32attrib.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
+69
-4
@@ -2,7 +2,7 @@
|
||||
* fs/fat/fs_fat32util.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References:
|
||||
* Microsoft FAT documentation
|
||||
@@ -50,6 +50,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <semaphore.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@@ -371,7 +372,7 @@ void fat_semgive(struct fat_mountpt_s *fs)
|
||||
/****************************************************************************
|
||||
* Name: fat_systime2fattime
|
||||
*
|
||||
* Desciption: Get the system time convertto a time and and date suitble
|
||||
* Desciption: Get the system time convert to a time and and date suitble
|
||||
* for writing into the FAT FS.
|
||||
*
|
||||
* TIME in LS 16-bits:
|
||||
@@ -379,7 +380,7 @@ void fat_semgive(struct fat_mountpt_s *fs)
|
||||
* Bits 5-10 = minutes (0-59)
|
||||
* Bits 11-15 = hours (0-23)
|
||||
* DATE in MS 16-bits
|
||||
* Bits 0:4 = Day of month (0-31)
|
||||
* Bits 0:4 = Day of month (1-31)
|
||||
* Bits 5:8 = Month of year (1-12)
|
||||
* Bits 9:15 = Year from 1980 (0-127 representing 1980-2107)
|
||||
*
|
||||
@@ -387,6 +388,46 @@ void fat_semgive(struct fat_mountpt_s *fs)
|
||||
|
||||
uint32_t fat_systime2fattime(void)
|
||||
{
|
||||
/* Unless you have a hardware RTC or some other to get accurate time, then
|
||||
* there is no reason to support FAT time.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_FS_FATTIME
|
||||
struct timespec ts;
|
||||
struct tm tm;
|
||||
int ret;
|
||||
|
||||
/* Get the current time in seconds and nanoseconds */
|
||||
|
||||
ret = clock_settime(CLOCK_REALTIME, &ts);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* Break done the seconds in date and time units */
|
||||
|
||||
if (gmtime_r((FAR const time_t *)&ts.tv_sec, &tm) != NULL)
|
||||
{
|
||||
/* FAT can only represent dates since 1980. struct tm can
|
||||
* represent dates since 1900.
|
||||
*/
|
||||
|
||||
if (tm.tm_year >= 80)
|
||||
{
|
||||
uint16_t fattime;
|
||||
uint16_t fatdate;
|
||||
|
||||
fattime = (tm.tm_sec >> 1) & 0x001f; /* Bits 0-4: 2 second count (0-29) */
|
||||
fattime |= (tm.tm_min << 5) & 0x07e0; /* Bits 5-10: minutes (0-59) */
|
||||
fattime |= (tm.tm_hour << 11) & 0xf800; /* Bits 11-15: hours (0-23) */
|
||||
|
||||
fatdate = tm.tm_mday & 0x001f; /* Bits 0-4: Day of month (1-31) */
|
||||
fatdate |= ((tm.tm_mon+1) << 5) & 0x01e0; /* Bits 5-8: Month of year (1-12) */
|
||||
fatdate |= ((tm.tm_year-80) << 9) & 0xfe00; /* Bits 9-15: Year from 1980 */
|
||||
|
||||
return (uint32_t)fatdate << 16 | (uint32_t)fattime;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -400,7 +441,7 @@ uint32_t fat_systime2fattime(void)
|
||||
* Bits 5-10 = minutes (0-59)
|
||||
* Bits 11-15 = hours (0-23)
|
||||
* 16-bit FAT date:
|
||||
* Bits 0:4 = Day of month (0-31)
|
||||
* Bits 0:4 = Day of month (1-31)
|
||||
* Bits 5:8 = Month of year (1-12)
|
||||
* Bits 9:15 = Year from 1980 (0-127 representing 1980-2107)
|
||||
*
|
||||
@@ -408,7 +449,31 @@ uint32_t fat_systime2fattime(void)
|
||||
|
||||
time_t fat_fattime2systime(uint16_t fattime, uint16_t fatdate)
|
||||
{
|
||||
/* Unless you have a hardware RTC or some other to get accurate time, then
|
||||
* there is no reason to support FAT time.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_FS_FATTIME
|
||||
struct tm tm;
|
||||
unsigned int tmp;
|
||||
|
||||
/* Break out the date and time */
|
||||
|
||||
tm.tm_sec = (fatdate & 0x001f) << 1; /* Bits 0-4: 2 second count (0-29) */
|
||||
tm.tm_min = (fatdate & 0x07e0) >> 5; /* Bits 5-10: minutes (0-59) */
|
||||
tm.tm_hour = (fatdate & 0xf800) >> 11; /* Bits 11-15: hours (0-23) */
|
||||
|
||||
tm.tm_mday = (fatdate & 0x001f); /* Bits 0-4: Day of month (1-31) */
|
||||
tmp = ((fatdate & 0x01e0) >> 5); /* Bits 5-8: Month of year (1-12) */
|
||||
tm.tm_mon = tmp > 0 ? tmp-1 : 0;
|
||||
tm.tm_year = ((fatdate & 0xfe00) >> 9) + 80; /* Bits 9-15: Year from 1980 */
|
||||
|
||||
/* Then convert the broken out time into seconds since the epoch */
|
||||
|
||||
return mktime(&tm);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/time.h
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
* include/time.h
|
||||
*
|
||||
* Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -154,8 +154,8 @@ 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 *timer);
|
||||
EXTERN struct tm *gmtime_r(const time_t *timer, struct tm *result);
|
||||
EXTERN FAR struct tm *gmtime(FAR const time_t *timer);
|
||||
EXTERN FAR struct tm *gmtime_r(FAR const time_t *timer, FAR 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);
|
||||
|
||||
@@ -302,7 +302,7 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct tm *gmtime_r(const time_t *timer, struct tm *result)
|
||||
FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result)
|
||||
{
|
||||
time_t epoch;
|
||||
time_t jdn;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* sched/clock_gettime.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* sched/clock_settime.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <nuttx/rtc.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user