Browse Source
Boot-time event logging implementation (#536)
Boot-time event logging implementation (#536)
* Initial cut on boot-time event logging * More verbose PWM init logging; more verbose HMC5883 error logging * Disable NMEA GPS on CC3D due to flash size issuesmaster
Konstantin Sharlaimov
8 years ago
committed by
GitHub
11 changed files with 388 additions and 18 deletions
-
1Makefile
-
25src/main/drivers/compass_hmc5883l.c
-
133src/main/drivers/logging.c
-
42src/main/drivers/logging.h
-
55src/main/drivers/logging_codes.h
-
47src/main/drivers/pwm_mapping.c
-
49src/main/io/serial_cli.c
-
32src/main/main.c
-
14src/main/sensors/initialisation.c
-
6src/main/target/CC3D/target.h
-
2src/main/target/common.h
@ -0,0 +1,133 @@ |
|||
/* |
|||
* This file is part of Cleanflight. |
|||
* |
|||
* Cleanflight is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Cleanflight is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
#include <string.h> |
|||
|
|||
#include "platform.h" |
|||
|
|||
#ifdef BOOTLOG |
|||
|
|||
#include "logging.h" |
|||
#include "system.h" |
|||
|
|||
#define MAX_BOOTLOG_ENTRIES 64 |
|||
|
|||
static bootLogEntry_t events[MAX_BOOTLOG_ENTRIES]; |
|||
static int eventCount; |
|||
static bool eventOverflow; |
|||
|
|||
#ifdef BOOTLOG_DESCRIPTIONS |
|||
static const char * eventDescription[BOOT_EVENT_CODE_COUNT] = { |
|||
[BOOT_EVENT_CONFIG_LOADED] = "CONFIG_LOADED", |
|||
[BOOT_EVENT_SYSTEM_INIT_DONE] = "SYSTEM_INIT_DONE", |
|||
[BOOT_EVENT_PWM_INIT_DONE] = "PWM_INIT_DONE", |
|||
[BOOT_EVENT_EXTRA_BOOT_DELAY] = "EXTRA_BOOT_DELAY", |
|||
[BOOT_EVENT_SENSOR_INIT_DONE] = "SENSOR_INIT_DONE", |
|||
[BOOT_EVENT_GPS_INIT_DONE] = "GPS_INIT_DONE", |
|||
[BOOT_EVENT_LEDSTRIP_INIT_DONE] = "LEDSTRIP_INIT_DONE", |
|||
[BOOT_EVENT_TELEMETRY_INIT_DONE] = "TELEMETRY_INIT_DONE", |
|||
[BOOT_EVENT_SYSTEM_READY] = "SYSTEM_READY", |
|||
[BOOT_EVENT_GYRO_DETECTION] = "GYRO_DETECTION", |
|||
[BOOT_EVENT_ACC_DETECTION] = "ACC_DETECTION", |
|||
[BOOT_EVENT_BARO_DETECTION] = "BARO_DETECTION", |
|||
[BOOT_EVENT_MAG_DETECTION] = "MAG_DETECTION", |
|||
[BOOT_EVENT_RANGEFINDER_DETECTION] = "RANGEFINDER_DETECTION", |
|||
[BOOT_EVENT_MAG_INIT_FAILED] = "MAG_INIT_FAILED", |
|||
[BOOT_EVENT_HMC5883L_READ_FAILED] = "HMC5883L_READ_FAILED", |
|||
[BOOT_EVENT_HMC5883L_SATURATION] = "HMC5883L_SATURATION", |
|||
[BOOT_EVENT_TIMER_CH_SKIPPED] = "TIMER_CHANNEL_SKIPPED", |
|||
[BOOT_EVENT_TIMER_CH_MAPPED] = "TIMER_CHANNEL_MAPPED" |
|||
}; |
|||
|
|||
const char * getBootlogEventDescription(bootLogEventCode_e eventCode) |
|||
{ |
|||
if (eventCode < BOOT_EVENT_CODE_COUNT) { |
|||
return eventDescription[eventCode]; |
|||
} |
|||
else { |
|||
return NULL; |
|||
} |
|||
} |
|||
#endif |
|||
|
|||
void initBootlog(void) |
|||
{ |
|||
memset(events, 0, sizeof(events)); |
|||
eventCount = 0; |
|||
eventOverflow = false; |
|||
} |
|||
|
|||
int getBootlogEventCount(void) |
|||
{ |
|||
return eventCount; |
|||
} |
|||
|
|||
bootLogEntry_t * getBootlogEvent(int index) |
|||
{ |
|||
if (index <= eventCount) { |
|||
return &events[index]; |
|||
} |
|||
else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
static void addBootlogEntry(bootLogEntry_t * event) |
|||
{ |
|||
if (eventCount >= MAX_BOOTLOG_ENTRIES) { |
|||
eventOverflow = true; |
|||
return; |
|||
} |
|||
|
|||
memcpy(&events[eventCount], event, sizeof(bootLogEntry_t)); |
|||
events[eventCount].timestamp = millis(); |
|||
|
|||
eventCount++; |
|||
} |
|||
|
|||
void addBootlogEvent2(bootLogEventCode_e eventCode, uint16_t eventFlags) |
|||
{ |
|||
bootLogEntry_t event; |
|||
event.eventCode = eventCode; |
|||
event.eventFlags = eventFlags; |
|||
addBootlogEntry(&event); |
|||
} |
|||
|
|||
void addBootlogEvent4(bootLogEventCode_e eventCode, uint16_t eventFlags, uint32_t param1, uint32_t param2) |
|||
{ |
|||
bootLogEntry_t event; |
|||
event.eventCode = eventCode; |
|||
event.eventFlags = eventFlags | BOOT_EVENT_FLAGS_PARAM32; |
|||
event.params.u32[0] = param1; |
|||
event.params.u32[1] = param2; |
|||
addBootlogEntry(&event); |
|||
} |
|||
|
|||
void addBootlogEvent6(bootLogEventCode_e eventCode, uint16_t eventFlags, uint16_t param1, uint16_t param2, uint16_t param3, uint16_t param4) |
|||
{ |
|||
bootLogEntry_t event; |
|||
event.eventCode = eventCode; |
|||
event.eventFlags = eventFlags | BOOT_EVENT_FLAGS_PARAM16; |
|||
event.params.u16[0] = param1; |
|||
event.params.u16[1] = param2; |
|||
event.params.u16[2] = param3; |
|||
event.params.u16[3] = param4; |
|||
addBootlogEntry(&event); |
|||
} |
|||
#endif |
@ -0,0 +1,42 @@ |
|||
/* |
|||
* This file is part of Cleanflight. |
|||
* |
|||
* Cleanflight is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Cleanflight is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef BOOTLOG |
|||
|
|||
#include "logging_codes.h" |
|||
|
|||
typedef struct bootLogEntry_s { |
|||
uint32_t timestamp; |
|||
uint16_t eventCode; |
|||
uint16_t eventFlags; |
|||
union { |
|||
uint16_t u16[4]; |
|||
uint32_t u32[2]; |
|||
} params; |
|||
} bootLogEntry_t; |
|||
|
|||
void initBootlog(void); |
|||
int getBootlogEventCount(void); |
|||
bootLogEntry_t * getBootlogEvent(int index); |
|||
const char * getBootlogEventDescription(bootLogEventCode_e eventCode); |
|||
void addBootlogEvent2(bootLogEventCode_e eventCode, bootLogFlags_e eventFlags); |
|||
void addBootlogEvent4(bootLogEventCode_e eventCode, bootLogFlags_e eventFlags, uint32_t param1, uint32_t param2); |
|||
void addBootlogEvent6(bootLogEventCode_e eventCode, bootLogFlags_e eventFlags, uint16_t param1, uint16_t param2, uint16_t param3, uint16_t param4); |
|||
|
|||
#endif |
@ -0,0 +1,55 @@ |
|||
/* |
|||
* This file is part of Cleanflight. |
|||
* |
|||
* Cleanflight is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* Cleanflight is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef BOOTLOG |
|||
|
|||
typedef enum { |
|||
BOOT_EVENT_FLAGS_NONE = 0, |
|||
BOOT_EVENT_FLAGS_WARNING = 1 << 0, |
|||
BOOT_EVENT_FLAGS_ERROR = 1 << 1, |
|||
|
|||
BOOT_EVENT_FLAGS_PARAM16 = 1 << 14, |
|||
BOOT_EVENT_FLAGS_PARAM32 = 1 << 15 |
|||
} bootLogFlags_e; |
|||
|
|||
typedef enum { |
|||
BOOT_EVENT_CONFIG_LOADED = 0, |
|||
BOOT_EVENT_SYSTEM_INIT_DONE = 1, |
|||
BOOT_EVENT_PWM_INIT_DONE = 2, |
|||
BOOT_EVENT_EXTRA_BOOT_DELAY = 3, |
|||
BOOT_EVENT_SENSOR_INIT_DONE = 4, |
|||
BOOT_EVENT_GPS_INIT_DONE = 5, |
|||
BOOT_EVENT_LEDSTRIP_INIT_DONE = 6, |
|||
BOOT_EVENT_TELEMETRY_INIT_DONE = 7, |
|||
BOOT_EVENT_SYSTEM_READY = 8, |
|||
BOOT_EVENT_GYRO_DETECTION = 9, |
|||
BOOT_EVENT_ACC_DETECTION = 10, |
|||
BOOT_EVENT_BARO_DETECTION = 11, |
|||
BOOT_EVENT_MAG_DETECTION = 12, |
|||
BOOT_EVENT_RANGEFINDER_DETECTION = 13, |
|||
BOOT_EVENT_MAG_INIT_FAILED = 14, |
|||
BOOT_EVENT_HMC5883L_READ_FAILED = 15, |
|||
BOOT_EVENT_HMC5883L_SATURATION = 16, |
|||
BOOT_EVENT_TIMER_CH_SKIPPED = 17, // 1 - MAX_MOTORS exceeded, 2 - MAX_SERVOS exceeded, 3 - feature clash |
|||
BOOT_EVENT_TIMER_CH_MAPPED = 18, // 0 - PPM, 1 - PWM, 2 - MOTOR, 3 - SERVO |
|||
|
|||
BOOT_EVENT_CODE_COUNT |
|||
} bootLogEventCode_e; |
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue