46 #ifndef SDLOG_START_DELAY
47 #define SDLOG_START_DELAY 30
51 #ifndef SDLOG_AUTO_FLUSH_PERIOD
52 #define SDLOG_AUTO_FLUSH_PERIOD 10
56 #ifndef SDLOG_CONTIGUOUS_STORAGE_MEM
57 #define SDLOG_CONTIGUOUS_STORAGE_MEM 50
60 #if (!defined USE_ADC_WATCHDOG) || (USE_ADC_WATCHDOG == 0)
61 #error sdlog_chibios need USE_ADC_WATCHDOG in order to properly close files when power is unplugged
64 #define DefaultAdcOfVoltage(voltage) ((uint32_t) (voltage/(DefaultVoltageOfAdc(1))))
73 static __attribute__((noreturn)) void
thd_startlog(
void *arg);
90 #if FLIGHTRECORDER_SDLOG
91 static const char FLIGHTRECORDER_LOG_NAME[] =
"fr_";
92 static const char FR_LOG_DIR[] =
"FLIGHT_RECORDER";
93 FileDes flightRecorderLogFile = -1;
108 #if PERIODIC_TELEMETRY
115 pprz_msg_send_LOGGER_STATUS(trans, dev, AC_ID, &status, &errno, &used, strlen(chibios_sdlog_filenames), chibios_sdlog_filenames);
138 sdLogSeekBufferFromSDB(sdb, 1);
144 memcpy(sdLogGetBufferFromSDB(sdb), data, len);
145 sdLogSeekBufferFromSDB(sdb, len);
151 sdLogWriteSDB(*(p->
file), sdb);
154 static int null_function(
struct chibios_sdlog *
p __attribute__((unused))) {
return 0; }
162 sdlog->
device.periph = (
void *)(sdlog);
175 #if PERIODIC_TELEMETRY
183 chThdCreateStatic(wa_thd_startlog,
sizeof(wa_thd_startlog),
190 if (pprzLogFile != -1) {
202 #if FF_FS_REENTRANT == 0
203 sdLogCloseAllLogs(flush);
210 #if FLIGHTRECORDER_SDLOG
211 flightRecorderLogFile = 0;
220 chRegSetThreadName(
"start log");
221 char tmpFilename[32];
227 chThdSleepSeconds(20000);
245 chsnprintf(chibios_sdlog_filenames,
sizeof(chibios_sdlog_filenames),
"%s", tmpFilename);
246 #if FLIGHTRECORDER_SDLOG
248 if (sdLogOpenLog(&flightRecorderLogFile, FR_LOG_DIR, FLIGHTRECORDER_LOG_NAME,
253 chsnprintf(chibios_sdlog_filenames,
sizeof(chibios_sdlog_filenames),
", %s", tmpFilename);
259 chEvtObjectInit(&powerOutageSource);
260 chThdCreateStatic(wa_thd_bat_survey,
sizeof(wa_thd_bat_survey),
273 chThdSleepMilliseconds(
sdOk ==
true ? 1000 : 200);
274 if (sdLogGetStorageStatus() !=
SDLOG_OK) {
282 #if HAL_USE_RTC && USE_GPS
286 if (chVTGetSystemTime() - timestamp > 5000) {
287 timestamp = chVTGetSystemTime();
290 const uint32_t unixToGpsEpoch = 315964800;
292 time_t univTime = ((
gps.
week * 7 * 24 * 3600) + (
gps.
tow / 1000)) + unixToGpsEpoch;
293 gmtime_r(&univTime, &time_tm);
296 rtcConvertStructTmToDateTime(&time_tm, 0, &date);
297 rtcSetTime(&RTCD1, &date);
309 chRegSetThreadName(
"battery survey");
310 chEvtRegister(&powerOutageSource, &powerOutageListener, 1);
311 chThdSleepMilliseconds(2000);
315 chEvtWaitOne(EVENT_MASK(1));
320 chThdSleep(TIME_INFINITE);
330 chEvtBroadcastI(&powerOutageSource);
SdioError sdLogFinish(void)
unmount filesystem
#define LOG_APPEND_TAG_AT_CLOSE_DISABLED
Mini printf-like functionality.
static void thd_bat_survey(void *arg)
static THD_WORKING_AREA(wa_thd_startlog, 2048)
event_listener_t powerOutageListener
static void thd_startlog(void *arg)
void sdlog_chibios_finish(const bool flush)
Periodic telemetry system header (includes downlink utility and generated code).
static const uint16_t V_ALERT
void chsnprintf(char *buffer, size_t size, const char *fmt,...)
struct link_device device
Generic device interface.
static const char PPRZ_LOG_NAME[]
static const char PPRZ_LOG_DIR[]
static void powerOutageIsr(void)
arch independent ADC (Analog to Digital Converter) API
#define LOG_PREALLOCATION_DISABLED
SdioError sdLogInit(uint32_t *freeSpaceInKo)
initialise sdLog
#define SDLOG_AUTO_FLUSH_PERIOD
static enum @293 chibios_sdlog_status
sdlog status
static char chibios_sdlog_filenames[68]
sdlog filenames
void WEAK mcu_periph_energy_save(void)
Call board specific energy saving Can be necessary for closing on power off.
static uint8_t null_byte_function(struct chibios_sdlog *p)
Dynamic memory allocation based on TLSF library.
static int sdlog_check_free_space(struct chibios_sdlog *p, long *fd, uint16_t len)
event_source_t powerOutageSource
uint32_t tow
GPS time of week in ms.
Device independent GPS code (interface)
void usbStorageStartPolling(void)
SdioError removeEmptyLogs(const char *directoryName, const char *prefix, const size_t sizeConsideredEmpty)
remove spurious log file left on sd
#define DefaultPeriodic
Set default periodic telemetry.
static void mcu_deep_sleep(void)
Put MCU into deep sleep mode.
static int null_function(struct chibios_sdlog *p)
#define DefaultAdcOfVoltage(voltage)
static const struct usb_device_descriptor dev
Arch independent mcu ( Micro Controller Unit ) utilities.
#define SDLOG_CONTIGUOUS_STORAGE_MEM
#define SDLOG_START_DELAY
void chibios_sdlog_init(struct chibios_sdlog *sdlog, FileDes *file)
init chibios_sdlog structure
arch independent LED (Light Emitting Diodes) API
bool usbStorageIsItRunning(void)
static void send_sdlog_status(struct transport_tx *trans, struct link_device *dev)
static void sdlog_transmit(struct chibios_sdlog *p, long fd, uint8_t byte)
static void sdlog_send(struct chibios_sdlog *p, long fd)
struct _SdLogBuffer SdLogBuffer
struct GpsState gps
global GPS state
static void sdlog_transmit_buffer(struct chibios_sdlog *p, long fd, uint8_t *data, uint16_t len)
void sdlog_chibios_init(void)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.