Skip to content

Commit 8746a2a

Browse files
JordanYatesnashif
authored andcommitted
tests: fs: fat_fs_api: add timestamp integration
Add an example implementation of `get_fattime` to the API tests. Also ensure that `FS_FATFS_EXTRA_NATIVE_API` compiles in a test. Signed-off-by: Jordan Yates <[email protected]>
1 parent a1d6f80 commit 8746a2a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tests/subsys/fs/fat_fs_api/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ CONFIG_DISK_DRIVER_FLASH=y
66
CONFIG_ZTEST=y
77
CONFIG_FLASH=y
88
CONFIG_FLASH_MAP=y
9+
10+
# Demonstrate filesystem time integration
11+
CONFIG_FS_FATFS_HAS_RTC=y

tests/subsys/fs/fat_fs_api/prj_lfn.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CONFIG_FILE_SYSTEM_MKFS=y
33
CONFIG_LOG=y
44
CONFIG_FAT_FILESYSTEM_ELM=y
55
CONFIG_FS_FATFS_LFN=y
6+
CONFIG_FS_FATFS_EXTRA_NATIVE_API=y
67
CONFIG_DISK_DRIVER_FLASH=y
78
CONFIG_ZTEST=y
89
CONFIG_FLASH=y

tests/subsys/fs/fat_fs_api/src/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8+
#include <time.h>
89

910
#include "test_fat.h"
1011
void test_fs_open_flags(void);
1112
const char *test_fs_open_flags_file_path = FATFS_MNTP"/the_file.txt";
1213

14+
/* Time integration for filesystem */
15+
DWORD get_fattime(void)
16+
{
17+
time_t unix_time = time(NULL);
18+
struct tm *cal;
19+
20+
/* Convert to calendar time */
21+
cal = localtime(&unix_time);
22+
23+
/* From http://elm-chan.org/fsw/ff/doc/fattime.html */
24+
return (DWORD)(cal->tm_year - 80) << 25 | (DWORD)(cal->tm_mon + 1) << 21 |
25+
(DWORD)cal->tm_mday << 16 | (DWORD)cal->tm_hour << 11 | (DWORD)cal->tm_min << 5 |
26+
(DWORD)cal->tm_sec >> 1;
27+
}
28+
1329
static void *fat_fs_basic_setup(void)
1430
{
1531
fs_file_t_init(&filep);

0 commit comments

Comments
 (0)