Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
sdLog.c File Reference
#include <string.h>
#include <stdlib.h>
#include <ch.h>
#include <hal.h>
#include <ff.h>
#include "modules/loggers/sdlog_chibios/sdLog.h"
#include "printf.h"
#include "mcu_periph/sdio.h"
#include <ctype.h>
Include dependency graph for sdLog.c:

Go to the source code of this file.

Macros

#define MIN(x, y)
#define MAX(x, y)
#define IS_POWER_OF_TWO(s)
#define FFCONF_DEF   _FATFS
#define SDLOG_WRITE_BUFFER_SIZE   (SDLOG_ALL_BUFFERS_SIZE/SDLOG_NUM_FILES)

Functions

static IN_SDMMC_DMA_SECTION (FATFS fatfs)
static int32_t uiGetIndexOfLogFile (const char *prefix, const char *fileName)
static SdioError flushWriteByteBuffer (const FileDes fd)
uint8_t sdLogGetFatfsResult (void)
static SdioError fatfsError (FRESULT rc)
 Keep the FatFS result of a failed start step.
SdioError sdLogInit (uint32_t *freeSpaceInKo)
 initialise sdLog
SdioError sdLogFinish (void)
 unmount filesystem
SdioError getFileName (const char *prefix, const char *directoryName, char *nextFileName, const size_t nameLength, const int indexOffset)
 get last used name for a pattern, then add offset and return valid filename
SdioError removeEmptyLogs (const char *directoryName, const char *prefix, const size_t sizeConsideredEmpty)
 remove spurious log file left on sd
SdioError sdLogWriteFile (const char *directoryName, const char *fileName, const uint8_t *data, const size_t len)
 write a whole file, if it does not exist yet

Variables

static FRESULT lastFatfsResult = FR_OK

Macro Definition Documentation

◆ FFCONF_DEF

#define FFCONF_DEF   _FATFS

Definition at line 52 of file sdLog.c.

◆ IS_POWER_OF_TWO

#define IS_POWER_OF_TWO ( s)
Value:
((s) && !((s) & ((s) - 1)))
static uint32_t s

Definition at line 44 of file sdLog.c.

◆ MAX

#define MAX ( x,
y )
Value:
(((x) > (y)) ? (x) : (y))

Definition at line 42 of file sdLog.c.

Referenced by getFileName().

◆ MIN

#define MIN ( x,
y )
Value:
(((x) < (y)) ? (x) : (y))

Definition at line 39 of file sdLog.c.

Referenced by getFileName(), rxInit(), and sdLogWriteFile().

◆ SDLOG_WRITE_BUFFER_SIZE

#define SDLOG_WRITE_BUFFER_SIZE   (SDLOG_ALL_BUFFERS_SIZE/SDLOG_NUM_FILES)

Definition at line 71 of file sdLog.c.

Function Documentation

◆ fatfsError()

SdioError fatfsError ( FRESULT rc)
static

Keep the FatFS result of a failed start step.

Most boards have no card detect pin, so a missing card is only seen when it cannot be read.

Definition at line 236 of file sdLog.c.

References lastFatfsResult, SDLOG_FATFS_ERROR, and SDLOG_NOCARD.

Referenced by getFileName(), and sdLogInit().

Here is the caller graph for this function:

◆ flushWriteByteBuffer()

SdioError flushWriteByteBuffer ( const FileDes fd)
inlinestatic

References fd.

◆ getFileName()

SdioError getFileName ( const char * prefix,
const char * directoryName,
char * nextFileName,
const size_t nameLength,
const int indexOffset )

get last used name for a pattern, then add offset and return valid filename

for log file, you often have a pattern and a version. To retreive last file for reading, call function with indexOffset=0. To get next available file for writing, call function with indexOffset=1 This function is available even without thread login facility : even if SDLOG_XXX macro are zeroed

Parameters
[in]prefix: the pattern for the file : example LOG_
[in]directoryName: root directory where to find file
[out]nextFileName: file with path ready to be used for f_open system call
[in]nameLength: length of previous buffer
[in]indexOffset: use 0 to retrieve last existent filename, 1 for next filename
Returns
status (always check status)

Definition at line 776 of file sdLog.c.

References chsnprintf(), dir, fatfsError(), MAX, MIN, NUMBERFMF, NUMBERMAX, SDLOG_LOGNUM_ERROR, SDLOG_OK, and uiGetIndexOfLogFile().

Here is the call graph for this function:

◆ IN_SDMMC_DMA_SECTION()

IN_SDMMC_DMA_SECTION ( FATFS fatfs)
static

References fd.

◆ removeEmptyLogs()

SdioError removeEmptyLogs ( const char * directoryName,
const char * prefix,
const size_t sizeConsideredEmpty )

remove spurious log file left on sd

when tuning firmware, log files are created at each tries, and we consider that empty or nearly empty log are of no value this function remove log file whose size is less than a given value

Parameters
[in]prefix: the pattern for the file : example LOG_
[in]directoryName: root directory where to find file
[in]sizeConsideredEmpty: file whose size is less or equal to that value will be removed
Returns
status (always check status)

Definition at line 837 of file sdLog.c.

References dir, SDLOG_FATFS_ERROR, SDLOG_FATFS_NOENT, and SDLOG_OK.

Referenced by thd_startlog().

Here is the caller graph for this function:

◆ sdLogFinish()

SdioError sdLogFinish ( void )

unmount filesystem

unmount filesystem, free sdio peripheral This function is available even without thread login facility : even if SDLOG_XXX macro are zeroed

Returns
status (always check status)

Definition at line 307 of file sdLog.c.

References SDLOG_FATFS_ERROR, and SDLOG_OK.

Referenced by sdlog_chibios_finish().

Here is the caller graph for this function:

◆ sdLogGetFatfsResult()

uint8_t sdLogGetFatfsResult ( void )

Definition at line 227 of file sdLog.c.

References lastFatfsResult.

Referenced by sdlog_start_failed().

Here is the caller graph for this function:

◆ sdLogInit()

SdioError sdLogInit ( uint32_t * freeSpaceInKo)

initialise sdLog

init sdio peripheral, verify sdCard is inserted, check and mount filesystem, launch worker thread This function is available even without thread login facility : even if SDLOG_XXX macro are zeroed

Parameters
[out]freeSpaceInKo: if pointer in nonnull, return free space on filesystem
Returns
status (always check status)

Definition at line 245 of file sdLog.c.

References FALSE, fatfsError(), HEAP_DEFAULT, lastFatfsResult, msgqueue_init(), sdio_connect(), sdio_disconnect(), SDLOG_NOCARD, SDLOG_NUM_FILES, SDLOG_OK, SDLOG_QUEUE_BUCKETS, and SDLOG_WAS_LAUNCHED.

Referenced by thd_startlog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sdLogWriteFile()

SdioError sdLogWriteFile ( const char * directoryName,
const char * fileName,
const uint8_t * data,
const size_t len )

write a whole file, if it does not exist yet

the file is written under a temporary name and renamed when complete, so it is never left partially written. The status of the logs is not changed.

Parameters
[in]directoryName: directory of the file, created if needed
[in]fileName: name of the file
[in]data: content of the file (may be in flash)
[in]len: length of the content
Returns
status (always check status)

Definition at line 882 of file sdLog.c.

References chsnprintf(), MIN, SDLOG_FATFS_ERROR, SDLOG_FSFULL, SDLOG_INTERNAL_ERROR, and SDLOG_OK.

Referenced by thd_startlog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uiGetIndexOfLogFile()

int32_t uiGetIndexOfLogFile ( const char * prefix,
const char * fileName )
static

Definition at line 948 of file sdLog.c.

Referenced by getFileName().

Here is the caller graph for this function:

Variable Documentation

◆ lastFatfsResult

FRESULT lastFatfsResult = FR_OK
static

Definition at line 225 of file sdLog.c.

Referenced by fatfsError(), sdLogGetFatfsResult(), and sdLogInit().