BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
platform/exp430f5529/fatfs/main.c
#include <bsp430/clock.h>
#include <bsp430/serial.h>
#include <stdio.h>
/* msp430.h headers define DIR which will conflict with the structure
* definition from FatFS. */
#undef DIR
#include "diskio.h"
#include "ff.h"
/* Get definitions for FATFS_IS_PRE_R0_10 and other flags that
* accommodate API changes. */
#include "ff_compat.h"
char buffer[1024];
void main ()
{
unsigned int reset_flags;
unsigned long reset_causes;
int rv;
FATFS fso;
DIR dir_obj;
FILINFO finfo;
{
unsigned int sysrstiv;
/* Record all the reset causes */
reset_causes = 0;
while (0 != ((sysrstiv = uiBSP430sysSYSRSTGenerator_ni(&reset_flags)))) {
reset_causes |= 1UL << (sysrstiv / 2);
}
}
cprintf("\nBUILD " __DATE__ " " __TIME__ "\n");
cprintf("FatFS Revision ID: %lu\n", (unsigned long)_FATFS);
cprintf("System reset bitmask %lx; causes:\n", reset_causes);
{
int bit = 0;
while (bit < (8 * sizeof(reset_causes))) {
if (reset_causes & (1UL << bit)) {
}
++bit;
}
}
cputtext("System reset included:");
if (reset_flags & BSP430_SYS_FLAG_SYSRST_BOR) {
cputtext(" BOR");
}
if (reset_flags & BSP430_SYS_FLAG_SYSRST_LPM5WU) {
cputtext(" LPM5WU");
}
if (reset_flags & BSP430_SYS_FLAG_SYSRST_POR) {
cputtext(" POR");
}
if (reset_flags & BSP430_SYS_FLAG_SYSRST_PUC) {
cputtext(" PUC");
}
cputchar('\n');
cprintf("Set core voltage gets %d\n", rv);
#if (FATFS_IS_PRE_R0_10 - 0)
rv = f_mount(0, &fso);
#else /* Pre R0.10 */
rv = f_mount(&fso, "", 1);
#endif /* Pre R0.10 */
cprintf("mount gets %d\n", rv);
if (FR_OK == rv) {
rv = f_opendir(&dir_obj, "/");
cprintf("opendir gets %d\n", rv);
}
while (FR_OK == rv) {
rv = f_readdir(&dir_obj, &finfo);
if (FR_OK != rv) {
break;
}
if (0 == finfo.fname[0]) {
break;
}
cprintf("%s %lu %u %u %#x\n", finfo.fname, finfo.fsize, finfo.fdate, finfo.ftime, finfo.fattrib);
}
{
FIL fil_obj;
/* Append a boot log message to the file BOOT.LOG. NB: This had
* failed with version combinations prior to FatFs 0.9b and BSP430
* 20130427. */
rv = f_open(&fil_obj, "0:BOOT.LOG", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
cprintf("Boot log open returned %d\n", rv);
if (FR_OK == rv) {
UINT nbytes = -1;
rv = f_read(&fil_obj, buffer, sizeof(buffer), &nbytes);
cprintf("Read boot log %u got %d with %u read\n",
(unsigned int)sizeof(buffer), rv, nbytes);
if (0 == rv) {
buffer[nbytes] = 0;
cputs("Contents:");
cputs(buffer);
}
rv = f_lseek(&fil_obj, f_size(&fil_obj));
cprintf("Seek to end got %d\n", rv);
if (FR_OK == rv) {
int nb = snprintf(buffer, sizeof(buffer), "Booted build " __DATE__ " " __TIME__ "\n");
UINT nw;
rv = f_write(&fil_obj, buffer, nb, &nw);
cprintf("write %u got %d nw %u\n", nb, rv, nw);
}
f_close(&fil_obj);
}
}
#if (FATFS_IS_PRE_R0_10 - 0)
f_mount(0, NULL);
#else /* Pre R0.10 */
f_mount(NULL, NULL, 1);
#endif /* Pre R0.10 */
cprintf("Exiting application\n");
}