44 #ifndef SDLOG_START_DELAY
45 #define SDLOG_START_DELAY 30
49 #if (!defined USE_ADC_WATCHDOG) || (USE_ADC_WATCHDOG == 0)
50 #error sdlog_chibios need USE_ADC_WATCHDOG in order to properly close files when power is unplugged
53 #define DefaultAdcOfVoltage(voltage) ((uint32_t) (voltage/(DefaultVoltageOfAdc(1))))
62 static __attribute__((noreturn)) void
thd_startlog(
void *arg);
80 #if FLIGHTRECORDER_SDLOG
81 static const char FLIGHTRECORDER_LOG_NAME[] =
"fr_";
82 static const char FR_LOG_DIR[] =
"FLIGHT_RECORDER";
83 FileDes flightRecorderLogFile = -1;
105 sdLogSeekBufferFromSDB(sdb, 1);
111 memcpy(sdLogGetBufferFromSDB(sdb), data, len);
112 sdLogSeekBufferFromSDB(sdb, len);
118 sdLogWriteSDB(*(p->
file), sdb);
121 static int null_function(
struct chibios_sdlog *
p __attribute__((unused))) {
return 0; }
128 sdlog->
device.periph = (
void *)(sdlog);
144 chThdCreateStatic(wa_thd_startlog,
sizeof(wa_thd_startlog),
151 if (pprzLogFile != -1) {
152 sdLogCloseAllLogs(flush);
155 #if FLIGHTRECORDER_SDLOG
156 flightRecorderLogFile = 0;
164 chRegSetThreadName(
"start log");
170 chThdSleepSeconds (20000);
186 #if FLIGHTRECORDER_SDLOG
188 if (sdLogOpenLog (&flightRecorderLogFile, FR_LOG_DIR, FLIGHTRECORDER_LOG_NAME,
false) !=
SDLOG_OK)
195 chEvtObjectInit (&powerOutageSource);
196 chThdCreateStatic (wa_thd_bat_survey,
sizeof(wa_thd_bat_survey),
205 chThdSleepMilliseconds (
sdOk ==
true ? 1000 : 200);
211 if (chVTGetSystemTime() - timestamp > 5000) {
212 timestamp = chVTGetSystemTime();
215 const uint32_t unixToGpsEpoch = 315964800;
217 time_t univTime = ((
gps.
week * 7 * 24 * 3600) + (
gps.
tow/1000)) + unixToGpsEpoch;
218 gmtime_r(&univTime, &time_tm);
221 rtcConvertStructTmToDateTime(&time_tm, 0, &date);
222 rtcSetTime(&RTCD1, &date);
234 chRegSetThreadName (
"battery survey");
235 chEvtRegister(&powerOutageSource, &powerOutageListener, 1);
236 chThdSleepMilliseconds (2000);
241 chEvtWaitOne(EVENT_MASK(1));
245 chThdSleepMilliseconds (TIME_INFINITE);
255 chEvtBroadcastI(&powerOutageSource);
262 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
263 PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
SdioError sdLogFinish(void)
unmount filesystem
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)
static void systemDeepSleep(void)
static const uint16_t V_ALERT
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
SdioError sdLogInit(uint32_t *freeSpaceInKo)
initialise sdLog
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
static int null_function(struct chibios_sdlog *p)
#define DefaultAdcOfVoltage(voltage)
#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 sdlog_transmit(struct chibios_sdlog *p, long fd, uint8_t byte)
void sdlog_chibios_finish(bool flush)
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)