Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/fatfs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PKG_NAME=fatfs
PKG_URL=https://github.com/MichelRottleuthner/FatFs_for_RIOT.git
PKG_VERSION=61fd6ae3815170bf7bf6121f33f1ef68c2b11599
PKG_LICENSE=BSD-1-Clause
MODULE_MAKEFILE := $(CURDIR)/Makefile.fatfs

.PHONY: all

all: git-download
@cp $(MODULE_MAKEFILE) $(PKG_BUILDDIR)/Makefile
"$(MAKE)" -C $(PKG_BUILDDIR)

include $(RIOTBASE)/pkg/pkg.mk
16 changes: 16 additions & 0 deletions pkg/fatfs/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ifneq (,$(filter fatfs_diskio_sdcard_spi,$(USEMODULE)))
USEMODULE += sdcard_spi
endif

ifneq (,$(filter fatfs,$(USEPKG)))
USEMODULE += fatfs_diskio_common
endif

include $(RIOTBASE)/boards/$(BOARD)/Makefile.features

#if periph_rtc is available use it. Otherwise use static timestamps
ifneq (, $(filter periph_rtc, $(FEATURES_PROVIDED)))
export CFLAGS+= -DFATFS_FFCONF_OPT_FS_NORTC=0
else
export CFLAGS+= -DFATFS_FFCONF_OPT_FS_NORTC=1
endif
3 changes: 3 additions & 0 deletions pkg/fatfs/Makefile.fatfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE=fatfs

include $(RIOTBASE)/Makefile.base
17 changes: 17 additions & 0 deletions pkg/fatfs/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INCLUDES += -I$(PKGDIRBASE)
INCLUDES += -I$(RIOTPKG)/fatfs/fatfs_diskio/common/include
DIRS += $(PKGDIRBASE)/fatfs

DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_diskio/common

ifneq (,$(filter fatfs_diskio_native,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_diskio/native
endif

ifneq (,$(filter fatfs_diskio_sdcard_spi,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_diskio/sdcard_spi
endif

ifeq ($(shell uname -s),Darwin)
CFLAGS += -Wno-empty-body
endif
3 changes: 3 additions & 0 deletions pkg/fatfs/fatfs_diskio/common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = fatfs_diskio_common

include $(RIOTBASE)/Makefile.base
51 changes: 51 additions & 0 deletions pkg/fatfs/fatfs_diskio/common/fatfs_diskio_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2016 Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup sys_fatfs_diskio
* @{
*
* @file
* @brief Implementation of common FatFs interface for native and sdcard_spi
* Based on low level disk I/O module example for FatFs by ChaN, 2016
*
* @author Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
*
* @}
*/

#include "fatfs/diskio.h" /* FatFs lower layer API */
#include "fatfs_diskio_common.h"
#include "time.h"
#include "stdint.h"

#if FATFS_FFCONF_OPT_FS_NORTC == 0
#include "periph/rtc.h"

DWORD get_fattime(void)
{
struct tm time;

rtc_get_time(&time);

/* bit 31:25 Year origin from 1980 (0..127) */
uint8_t year = time.tm_year + RTC_YEAR_OFFSET - FATFS_YEAR_OFFSET;
uint8_t month = time.tm_mon + 1; /* bit 24:21 month (1..12) */
uint8_t day_of_month = time.tm_mon + 1; /* bit 20:16 day (1..31) */
uint8_t hour = time.tm_hour; /* bit 15:11 hour (0..23) */
uint8_t minute = time.tm_min; /* bit 10:5 minute (0..59) */
uint8_t second = (time.tm_sec / 2); /* bit 4:0 second/2 (0..29) */

return year << FATFS_DISKIO_FATTIME_YEAR_OFFS |
month << FATFS_DISKIO_FATTIME_MON_OFFS |
day_of_month << FATFS_DISKIO_FATTIME_DAY_OFFS |
hour << FATFS_DISKIO_FATTIME_HH_OFFS |
minute << FATFS_DISKIO_FATTIME_MM_OFFS |
second;
}
#endif
45 changes: 45 additions & 0 deletions pkg/fatfs/fatfs_diskio/common/include/fatfs_diskio_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2016 Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup sys_fatfs_diskio
* @brief
* @{
*
* @brief Common defines for fatfs low-level diskio defines
* @author Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
*/

#ifndef FATFS_DISKIO_COMMON_H
#define FATFS_DISKIO_COMMON_H

#ifdef __cplusplus
extern "C" {
#endif

#include "fatfs/diskio.h" /* FatFs lower layer API */

#define RTC_YEAR_OFFSET (1900)
#define FATFS_YEAR_OFFSET (1980)

#define FIXED_BLOCK_SIZE (512)

#define FATFS_DISKIO_DSTASTUS_OK (0)

#define FATFS_DISKIO_FATTIME_YEAR_OFFS (25)
#define FATFS_DISKIO_FATTIME_MON_OFFS (21)
#define FATFS_DISKIO_FATTIME_DAY_OFFS (16)
#define FATFS_DISKIO_FATTIME_HH_OFFS (11)
#define FATFS_DISKIO_FATTIME_MM_OFFS (5)

#ifdef __cplusplus
}
#endif

#endif /* FATFS_DISKIO_COMMON_H */
/** @} */
7 changes: 7 additions & 0 deletions pkg/fatfs/fatfs_diskio/native/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MODULE = fatfs_diskio_native

FATFS_DISKIO_NATIVE_DEFAULT_FILE ?= \"riot_fatfs_disk.img\"

CFLAGS += -DFATFS_DISKIO_NATIVE_DEFAULT_FILE=$(FATFS_DISKIO_NATIVE_DEFAULT_FILE)

include $(RIOTBASE)/Makefile.base
Loading