45#define GPS_LEAP_SECONDS 18
48#ifndef SDLOG_START_DELAY
49#if INS_EKF2_LOG_INPUTS
51#define SDLOG_START_DELAY 2
53#define SDLOG_START_DELAY 30
56#if INS_EKF2_LOG_INPUTS && SDLOG_START_DELAY > 5
57PRINT_CONFIG_MSG(
"INS_EKF2_LOG_INPUTS: the EKF2 only starts after the SD log is open (SDLOG_START_DELAY), set it low")
61#ifndef SDLOG_AUTO_FLUSH_PERIOD
62#define SDLOG_AUTO_FLUSH_PERIOD 10
66#ifndef SDLOG_CONTIGUOUS_STORAGE_MEM
67#define SDLOG_CONTIGUOUS_STORAGE_MEM 50
71#ifndef SDLOG_ENABLE_LOWBAT_FLUSH
72#define SDLOG_ENABLE_LOWBAT_FLUSH TRUE
76#if (!defined USE_ADC_WATCHDOG) || (USE_ADC_WATCHDOG == 0)
77#error sdlog_chibios need USE_ADC_WATCHDOG in order to properly close files when power is unplugged
86#define SDLOG_CONF TRUE
89#include "generated/aircraft_conf.h"
106static __attribute__((noreturn))
void thd_startlog(
void *arg);
114#if FLIGHTRECORDER_SDLOG
115static const char FLIGHTRECORDER_LOG_NAME[] =
"fr_";
116static const char FR_LOG_DIR[] =
"FLIGHT_RECORDER";
117FileDes flightRecorderLogFile = -1;
142#ifdef SDLOG_PREFLIGHT_ERROR
153#if PERIODIC_TELEMETRY
162 static uint32_t reported_errors = 0;
163 static bool start_reported =
false;
166 if (errors != reported_errors) {
168 reported_errors = errors;
174 }
else if (start_error !=
SDLOG_OK) {
181 start_reported =
true;
189 pprz_msg_send_INFO_MSG(trans,
dev, AC_ID, strlen(
msg),
msg);
203 size = strlen(filenames);
205 pprz_msg_send_LOGGER_STATUS(trans,
dev, AC_ID, &
status, &errno, &used, size, filenames);
228 sdLogSeekBufferFromSDB(sdb, 1);
234 memcpy(sdLogGetBufferFromSDB(sdb), data, len);
235 sdLogSeekBufferFromSDB(sdb, len);
241 sdLogWriteSDB(*(
p->file), sdb);
252 sdlog->
device.periph = (
void *)(sdlog);
265#if PERIODIC_TELEMETRY
277 chThdCreateStatic(wa_thd_startlog,
sizeof(wa_thd_startlog),
292#if FF_FS_REENTRANT == 0
293 sdLogCloseAllLogs(flush);
300#if FLIGHTRECORDER_SDLOG
301 flightRecorderLogFile = -1;
307#if defined(SDLOG_BAT_ADC) && defined(SDLOG_BAT_CHAN)
311#if SDLOG_ENABLE_LOWBAT_FLUSH
313static __attribute__((noreturn))
void thd_bat_survey(
void *arg);
314static void powerOutageIsr(
void);
315event_source_t powerOutageSource;
316event_listener_t powerOutageListener;
318#define DefaultAdcOfVoltage(voltage) ((uint32_t) (voltage/(DefaultVoltageOfAdc(1))))
319static const uint16_t V_ALERT = DefaultAdcOfVoltage(5.5f);
325static void powerOutageIsr(
void)
327 chEvtBroadcastI(&powerOutageSource);
330static void thd_bat_survey(
void *arg)
333 chRegSetThreadName(
"battery survey");
334 chEvtRegister(&powerOutageSource, &powerOutageListener, 1);
335 chThdSleepMilliseconds(2000);
339 chEvtWaitOne(EVENT_MASK(1));
375 chRegSetThreadName(
"start log");
376 char tmpFilename[32];
382 chThdSleepSeconds(20000);
403#if FLIGHTRECORDER_SDLOG
405 err = sdLogOpenLog(&flightRecorderLogFile, FR_LOG_DIR, FLIGHTRECORDER_LOG_NAME,
420#if defined(SDLOG_BAT_ADC) && defined(SDLOG_BAT_CHAN) && SDLOG_ENABLE_LOWBAT_FLUSH
422 chEvtObjectInit(&powerOutageSource);
423 chThdCreateStatic(wa_thd_bat_survey,
sizeof(wa_thd_bat_survey),
424 NORMALPRIO + 2, thd_bat_survey, NULL);
433 bool in_error = !
sdOk;
439 chThdSleepMilliseconds(
sdOk ==
true ? 1000 : 200);
458#if HAL_USE_RTC && USE_GPS
462 if (chVTGetSystemTime() - timestamp > TIME_S2I(5)) {
463 timestamp = chVTGetSystemTime();
466 const uint32_t unixToGpsEpoch = 315964800;
469 gmtime_r(&univTime, &time_tm);
472 rtcConvertStructTmToDateTime(&time_tm, 0, &date);
473 rtcSetTime(&RTCD1, &date);
483 uint8_t ac_id = pprzlink_get_DL_INFO_MSG_UP_ac_id(buf);
484 if(ac_id != AC_ID && ac_id != 0xFF) {
487 uint8_t fd = pprzlink_get_DL_INFO_MSG_UP_fd(buf);
489 uint8_t len = pprzlink_get_INFO_MSG_UP_msg_length(buf);
arch independent ADC (Analog to Digital Converter) API
#define SDLOG_USB_VBUS_PIN
#define SDLOG_USB_VBUS_PORT
static THD_WORKING_AREA(wa_thd_spi1, SPI_THREAD_STACK_SIZE)
static struct uart_periph * dev
struct GpsState gps
global GPS state
Device independent GPS code (interface).
void chsnprintf(char *buffer, size_t size, const char *fmt,...)
void mcu_reboot(enum reboot_state_t reboot_state)
Reboot the MCU.
void mcu_energy_save(void)
Save energy for performing operations on shutdown Used for example to shutdown SD-card logging.
@ MCU_REBOOT_POWEROFF
Poweroff the device.
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer).
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
arch independent LED (Light Emitting Diodes) API
static FILE * pprzLogFile
Arch independent mcu ( Micro Controller Unit ) utilities.
static uint8_t null_byte_function(struct SuperbitRF *p)
static int null_function(struct SuperbitRF *p)
void preflight_error(struct preflight_result_t *result, const char *fmt,...)
Register a preflight error used inside the preflight checking functions.
void preflight_success(struct preflight_result_t *result, const char *fmt,...)
Register a preflight success used inside the preflight checking functions.
void preflight_warning(struct preflight_result_t *result, const char *fmt,...)
Register a preflight warning used inside the preflight checking functions.
void preflight_check_register(struct preflight_check_t *check, preflight_check_f func)
Register a preflight check and add it to the linked list.
Mini printf-like functionality.
#define IN_DMA_SECTION(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
SdioError sdLogInit(uint32_t *freeSpaceInKo)
initialise sdLog
uint8_t sdLogGetFatfsResult(void)
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
struct _SdLogBuffer SdLogBuffer
#define LOG_APPEND_TAG_AT_CLOSE_DISABLED
#define LOG_PREALLOCATION_DISABLED
static void sdlog_send(struct chibios_sdlog *p, long fd)
static int null_function(struct chibios_sdlog *p)
static enum @167037365353014241033154007315025330016177123070 chibios_sdlog_status
sdlog status
static volatile uint8_t sdlog_start_fatfs
static volatile SdioError sdlog_conf_error
Result of writing the configuration, reported to the GCS.
static void send_sdlog_status(struct transport_tx *trans, struct link_device *dev)
static volatile SdioError sdlog_start_error
static int sdlog_check_free_space(struct chibios_sdlog *p, long *fd, uint16_t len)
void logger_log_msg_up(uint8_t *buf)
static volatile uint32_t sdlog_error_events
static void thd_startlog(void *arg)
#define SDLOG_AUTO_FLUSH_PERIOD
static void sdlog_report_status(struct transport_tx *trans, struct link_device *dev)
Tell the GCS in words why the logger does not run (no SD card, card full, ...): at the start and ever...
static const char PPRZ_LOG_DIR[]
static volatile SdioError sdlog_error_cause
void sdlog_chibios_finish(const bool flush)
static void sdlog_transmit(struct chibios_sdlog *p, long fd, uint8_t byte)
static void sdlog_start_failed(const char *step, SdioError err)
Keep why the start failed (the first failing step only).
#define SDLOG_START_DELAY
static char NO_FILE_NAME[]
static const char PPRZ_LOG_NAME[]
#define SDLOG_CONTIGUOUS_STORAGE_MEM
void chibios_sdlog_init(struct chibios_sdlog *sdlog, FileDes *file)
init chibios_sdlog structure
static char chibios_sdlog_filenames[68]
sdlog filenames
static uint8_t null_byte_function(struct chibios_sdlog *p)
static void sdlog_transmit_buffer(struct chibios_sdlog *p, long fd, uint8_t *data, uint16_t len)
void sdlog_chibios_init(void)
static const char * sdlog_start_step
#define DEST_INFO_MSG_PPRZLOG
#define DEST_INFO_MSG_ALL
struct link_device device
Generic device interface.
static const char * sdlog_error_string(SdioError error)
Human readable cause of a logger error, for the messages to the GCS.
SdioError sdLogWriteByte(const FileDes fd, const uint8_t value)
SdioError sdLogGetStorageStatus(void)
SdioError sdLogWriteRaw(const FileDes fd, const uint8_t *buffer, const size_t len)
size_t sdLogGetNbBytesWrittenToStorage(void)
volatile uint32_t nb_sec
full seconds since startup
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Dynamic memory allocation based on TLSF library.
void usbStorageStartPolling(void)
bool usbStorageIsItRunning(void)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.