39#define MIN(x , y)  (((x) < (y)) ? (x) : (y)) 
   42#define MAX(x , y)  (((x) > (y)) ? (x) : (y)) 
   44#define IS_POWER_OF_TWO(s) ((s) && !((s) & ((s) - 1))) 
   46#ifndef SDLOG_NUM_FILES 
   47#error  SDLOG_NUM_FILES should be defined in mcuconf.h 
   52#define  FFCONF_DEF _FATFS 
   56#error  upgrade FATFS to 0.14 at least 
   58#if FF_FS_LOCK != 0 && FF_FS_LOCK < SDLOG_NUM_FILES 
   59#error  if FF_FS_LOCK is not zero, it should be equal of superior to SDLOG_NUM_FILES 
   63#ifndef  SDLOG_ALL_BUFFERS_SIZE 
   64#error SDLOG_ALL_BUFFERS_SIZE should be defined in mcuconf.h 
   67#if  SDLOG_ALL_BUFFERS_SIZE > 65536 
   68#error constraint 512 <=  SDLOG_ALL_BUFFERS_SIZE <= 65536 not meet 
   71#define SDLOG_WRITE_BUFFER_SIZE (SDLOG_ALL_BUFFERS_SIZE/SDLOG_NUM_FILES) 
   73#ifndef SDLOG_MAX_MESSAGE_LEN 
   74#error  SDLOG_MAX_MESSAGE_LENshould be defined in mcuconf.h 
   77#ifndef SDLOG_QUEUE_BUCKETS 
   78#error  SDLOG_QUEUE_BUCKETS should be defined in mcuconf.h 
   81#if FF_FS_REENTRANT == 0 
   82#warning "FF_FS_REENTRANT = 0 in ffconf.h DO NOT open close file during log" 
   85#if SDLOG_WRITE_BUFFER_SIZE < 512 
   86#error SDLOG_ALL_BUFFERS_SIZE / SDLOG_NUM_FILES cannot be < 512 
   89#if (!(IS_POWER_OF_TWO (SDLOG_WRITE_BUFFER_SIZE))) 
   90#error SDLOG_ALL_BUFFERS_SIZE / SDLOG_NUM_FILES should be a POWER OF 2 
   93#ifdef SDLOG_NEED_QUEUE 
  127#define IN_SDMMC_DMA_SECTION(x) IN_SDMMC_SECTION(x) 
  128#define IN_SDMMC_DMA_SECTION_CLEAR(x) IN_SDMMC_SECTION_CLEAR(x) 
  129#define IN_SDMMC_DMA_SECTION_NOINIT(x) IN_SDMMC_SECTION_NOINIT(x) 
  131#define IN_SDMMC_DMA_SECTION(x) IN_DMA_SECTION(x) 
  132#define IN_SDMMC_DMA_SECTION_CLEAR(x) IN_DMA_SECTION_CLEAR(x) 
  133#define IN_SDMMC_DMA_SECTION_NOINIT(x) IN_DMA_SECTION_NOINIT(x) 
  152#define WRITE_BYTE_CACHE_SIZE 15  
  178    .fil = {{0}}, .inUse = 
false, .tagAtClose = 
false,
 
  179    .writeByteCache = 
NULL, .writeByteSeek = 0
 
  200#define LOG_MESSAGE_PREBUF_LEN (SDLOG_MAX_MESSAGE_LEN+sizeof(LogMessage)) 
  206#ifdef SDLOG_NEED_QUEUE 
  208static size_t logRawLen(
const size_t len);
 
  237#ifdef SDLOG_NEED_QUEUE 
  269#ifdef SDLOG_NEED_QUEUE 
 
  305#ifdef SDLOG_NEED_QUEUE 
  355  if (
flush == 
false) {
 
  435#define FD_CHECK(fd)  if ((fd < 0) || (fd >= SDLOG_NUM_FILES) \ 
  436                          || (fileDes[fd].inUse == false))    \ 
  437                        return SDLOG_FATFS_ERROR 
  470  lm->op.fd = 
fd & 0x1f;
 
  508  lm->op.fd = 
fd & 0x1f;
 
  528  lm->op.fd = 
fd & 0x1f;
 
  572  lm->op.fd = 
fd & 0x1f;
 
  603  return  sdb->lm->mess + 
sdb->offset;
 
  618  return sdb->len - 
sdb->offset;
 
  637  sdb->lm->op.fd = 
fd & 0x1f;
 
  670    lm->op.fd = 
fd & 0x1f;
 
  695#define WA_LOG_BASE_SIZE 1024 
  784    if (
rc != 
FR_OK || 
fno.fname[0] ==  0) { 
break; } 
 
  787    if (
fno.fname[0] == 
'.') { 
continue; }
 
 
  829    if (
rc != 
FR_OK || 
fno.fname[0] ==  0) { 
break; } 
 
  831    if (
fno.fname[0] == 
'.') { 
continue; }
 
 
  897#ifdef SDLOG_NEED_QUEUE 
  971      switch (
lm->op.fcntl) {
 
 1019              if (
fileDes[
lm->op.fd].autoFlushPeriod) {
 
 1052static size_t logRawLen(
const size_t len)
 
static THD_WORKING_AREA(wa_thd_spi1, SPI_THREAD_STACK_SIZE)
static const float offset[]
void chvsnprintf(char *buffer, size_t size, const char *fmt, va_list ap)
void chsnprintf(char *buffer, size_t size, const char *fmt,...)
#define CH_CFG_ST_FREQUENCY
System tick frequency.
#define SDLOG_MAX_MESSAGE_LEN
#define SDLOG_QUEUE_BUCKETS
int32_t msgqueue_pop_timeout(MsgQueue *que, void **msgPtr, const systime_t timout)
receive message specifying timeout
int32_t msgqueue_send(MsgQueue *que, void *msg, const uint16_t msgLen, const MsgQueueUrgency urgency)
send a buffer previously allocated by msgqueue_malloc_before_send
int32_t msgqueue_pop(MsgQueue *que, void **msgPtr)
wait then receive message
void msgqueue_init(MsgQueue *que, tlsf_memory_heap_t *heap, msg_t *mb_buf, const cnt_t mb_size)
initialise MsgQueue
int32_t msgqueue_copy_send(MsgQueue *que, const void *msg, const uint16_t msgLen, const MsgQueueUrgency urgency)
send a buffer NOT previously allocated
Mini printf-like functionality.
Specific RAM section for DMA usage on F7.
#define IN_STD_SECTION_CLEAR(var)
SdioError sdLogFinish(void)
unmount filesystem
SdioError removeEmptyLogs(const char *directoryName, const char *prefix, const size_t sizeConsideredEmpty)
remove spurious log file left on sd
static int32_t uiGetIndexOfLogFile(const char *prefix, const char *fileName)
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 sdLogInit(uint32_t *freeSpaceInKo)
initialise sdLog
static SdioError flushWriteByteBuffer(const FileDes fd)
static IN_SDMMC_DMA_SECTION(FATFS fatfs)
#define SDLOG_WRITE_BUFFER_SIZE
struct _SdLogBuffer SdLogBuffer
arch independent SDIO API
bool sdio_connect(SDCDriver *sdc)
Connect a SD card on SDIO peripheral.
bool sdio_disconnect(SDCDriver *sdc)
Disconnect a SD card on SDIO peripheral.
void tlsf_free_r(tlsf_memory_heap_t *heap, void *ptr)
void * tlsf_malloc_r(tlsf_memory_heap_t *heap, size_t bytes)
void tlsf_stat_r(tlsf_memory_heap_t *heap, struct tlsf_stat_t *stat)
void * tlsf_realloc_r(tlsf_memory_heap_t *heap, void *ptr, size_t bytes)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.