Merge pull request #1939 from bthebaudeau/re-mote-sd-fat
Add global SD/MMC and FAT support, with RE-Mote as an example
This commit is contained in:
commit
bd3f8fa3c5
44 changed files with 39692 additions and 98 deletions
12
examples/fat/Makefile
Normal file
12
examples/fat/Makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
|
||||
CONTIKI = ../..
|
||||
|
||||
all: example-fat
|
||||
|
||||
CONTIKI_WITH_RIME = 1
|
||||
|
||||
ifeq ($(TARGET), zoul)
|
||||
BOARD ?= remote-revb
|
||||
endif
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
2
examples/fat/Makefile.target
Normal file
2
examples/fat/Makefile.target
Normal file
|
@ -0,0 +1,2 @@
|
|||
TARGET = zoul
|
||||
BOARD ?= remote-revb
|
6
examples/fat/README.md
Normal file
6
examples/fat/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
FAT File System Example
|
||||
=======================
|
||||
|
||||
Supported Hardware (tested or known to work)
|
||||
--------------------------------------------
|
||||
* Zoul: RE-Mote revision B
|
96
examples/fat/example-fat.c
Normal file
96
examples/fat/example-fat.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Benoît Thébaudeau <benoit@wsystem.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Example demonstrating how to use the FAT file system.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "ff.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(example_fat_process, "FAT example");
|
||||
AUTOSTART_PROCESSES(&example_fat_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define TEST_FILENAME "test.txt"
|
||||
#define TEST_LINE "Hello world!"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(example_fat_process, ev, data)
|
||||
{
|
||||
static FATFS FatFs; /* Work area (file system object) for logical drive */
|
||||
FIL fil; /* File object */
|
||||
char line[82]; /* Line buffer */
|
||||
FRESULT fr; /* FatFs return code */
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
printf("FAT example\n");
|
||||
|
||||
/* Register work area to the default drive */
|
||||
f_mount(&FatFs, "", 0);
|
||||
|
||||
printf("Writing \"%s\" to \"%s\"\n", TEST_LINE, TEST_FILENAME);
|
||||
|
||||
/* Create the test file */
|
||||
fr = f_open(&fil, TEST_FILENAME, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
if(fr) {
|
||||
printf("f_open() error: %d\n", fr);
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
/* Write the test line */
|
||||
f_printf(&fil, "%s\n", TEST_LINE);
|
||||
|
||||
/* Close the file */
|
||||
f_close(&fil);
|
||||
|
||||
printf("Reading back \"%s\":\n\n", TEST_FILENAME);
|
||||
|
||||
/* Open the test file */
|
||||
fr = f_open(&fil, TEST_FILENAME, FA_READ);
|
||||
if(fr) {
|
||||
printf("f_open() error: %d\n", fr);
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
/* Read all the lines and display them */
|
||||
while(f_gets(line, sizeof(line), &fil)) {
|
||||
printf(line);
|
||||
}
|
||||
|
||||
/* Close the file */
|
||||
f_close(&fil);
|
||||
|
||||
printf("\nDone\n");
|
||||
|
||||
PROCESS_END();
|
||||
}
|
41
examples/fat/project-conf.h
Normal file
41
examples/fat/project-conf.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if CONTIKI_TARGET_ZOUL
|
||||
#define RTC_CONF_INIT 1
|
||||
#define RTC_CONF_SET_FROM_SYS 1
|
||||
#endif
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -4,9 +4,6 @@ CONTIKI_PROJECT = test-power-mgmt
|
|||
|
||||
BOARD ?= remote-revb
|
||||
|
||||
# Works in Linux and probably on OSX too (RTCC example)
|
||||
CFLAGS = -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\""
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../../../..
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
#define BROADCAST_CHANNEL 129
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
#define RTC_CONF_INIT 1
|
||||
#define RTC_CONF_SET_FROM_SYS 1
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,10 +59,6 @@ static struct etimer et;
|
|||
/* RE-Mote revision B, low-power PIC version */
|
||||
#define PM_EXPECTED_VERSION 0x20
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef DATE
|
||||
#define DATE "Unknown"
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define TEST_LEDS_FAIL leds_off(LEDS_ALL); \
|
||||
leds_on(LEDS_RED); \
|
||||
PROCESS_EXIT();
|
||||
|
@ -80,7 +76,6 @@ PROCESS_THREAD(test_remote_pm, ev, data)
|
|||
static uint8_t aux;
|
||||
static uint16_t voltage;
|
||||
static uint32_t cycles;
|
||||
static char *next;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
|
@ -162,38 +157,13 @@ PROCESS_THREAD(test_remote_pm, ev, data)
|
|||
/* Configure the RTCC to schedule a "hard" restart of the shutdown mode,
|
||||
* waking up from a RTCC interrupt to the low-power PIC
|
||||
*/
|
||||
printf("PM: System date: %s\n", DATE);
|
||||
if(strcmp("Unknown", DATE) == 0) {
|
||||
printf("PM: could not retrieve date from system\n");
|
||||
printf("PM\n");
|
||||
|
||||
if(rtcc_get_time_date(simple_td) == AB08_ERROR) {
|
||||
printf("PM: Couldn't read time and date\n");
|
||||
TEST_LEDS_FAIL;
|
||||
}
|
||||
|
||||
/* Configure RTC and return structure with all parameters */
|
||||
rtcc_init();
|
||||
|
||||
/* Configure the RTC with the current values */
|
||||
simple_td->weekdays = (uint8_t)strtol(DATE, &next, 10);
|
||||
simple_td->day = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->months = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->years = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->hours = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->minutes = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->seconds = (uint8_t)strtol(next, NULL, 10);
|
||||
|
||||
simple_td->miliseconds = 0;
|
||||
simple_td->mode = RTCC_24H_MODE;
|
||||
simple_td->century = RTCC_CENTURY_20XX;
|
||||
|
||||
if(rtcc_set_time_date(simple_td) == AB08_ERROR) {
|
||||
printf("PM: Time and date configuration failed\n");
|
||||
TEST_LEDS_FAIL;
|
||||
} else {
|
||||
if(rtcc_get_time_date(simple_td) == AB08_ERROR) {
|
||||
printf("PM: Couldn't read time and date\n");
|
||||
TEST_LEDS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printf("PM: Configured time: ");
|
||||
rtcc_print(RTCC_PRINT_DATE_DEC);
|
||||
|
||||
|
|
|
@ -3,9 +3,6 @@ CONTIKI_PROJECT = test-rtcc
|
|||
|
||||
TARGET = zoul
|
||||
|
||||
# Works in Linux and probably on OSX too (RTCC example)
|
||||
CFLAGS = -DDATE="\"`date +"%02u %02d %02m %02y %02H %02M %02S"`\""
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../../../..
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
#define RTC_CONF_INIT 1
|
||||
#define RTC_CONF_SET_FROM_SYS 1
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -55,10 +55,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef DATE
|
||||
#define DATE "Unknown"
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LOOP_PERIOD 60L
|
||||
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
|
||||
#define TEST_ALARM_SECOND 15
|
||||
|
@ -109,58 +105,13 @@ rtcc_interrupt_callback(uint8_t value)
|
|||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_remote_rtcc_process, ev, data)
|
||||
{
|
||||
static char *next;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Alternatively for test only, undefine DATE and define on your own as
|
||||
* #define DATE "07 06 12 15 16 00 00"
|
||||
* Also note that if you restart the node at a given time, it will use the
|
||||
* already defined DATE, so if you want to update the device date/time you
|
||||
* need to reflash the node
|
||||
*/
|
||||
|
||||
/* Get the system date in the following format: wd dd mm yy hh mm ss */
|
||||
printf("RE-Mote RTC test, system date: %s\n", DATE);
|
||||
|
||||
/* Sanity check */
|
||||
if(strcmp("Unknown", DATE) == 0) {
|
||||
printf("Fail: could not retrieve date from system\n");
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
/* Configure RTC and return structure with all parameters */
|
||||
rtcc_init();
|
||||
printf("RE-Mote RTC test\n");
|
||||
|
||||
/* Map interrupt callback handler */
|
||||
RTCC_REGISTER_INT1(rtcc_interrupt_callback);
|
||||
|
||||
/* Configure the RTC with the current values */
|
||||
simple_td->weekdays = (uint8_t)strtol(DATE, &next, 10);
|
||||
simple_td->day = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->months = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->years = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->hours = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->minutes = (uint8_t)strtol(next, &next, 10);
|
||||
simple_td->seconds = (uint8_t)strtol(next, NULL, 10);
|
||||
|
||||
/* Don't care about the milliseconds... */
|
||||
simple_td->miliseconds = 0;
|
||||
|
||||
/* This example relies on 24h mode */
|
||||
simple_td->mode = RTCC_24H_MODE;
|
||||
|
||||
/* And to simplify the configuration, it relies it will be executed in the
|
||||
* present century
|
||||
*/
|
||||
simple_td->century = RTCC_CENTURY_20XX;
|
||||
|
||||
/* Set the time and date */
|
||||
if(rtcc_set_time_date(simple_td) == AB08_ERROR) {
|
||||
printf("Fail: Time and date not configured\n");
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
/* Wait a bit */
|
||||
etimer_set(&et, (CLOCK_SECOND * 2));
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue