mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Some fixes in debuglog to compile and run on all firmware platforms
This commit is contained in:
parent
243e261411
commit
6031200aea
201
flight/pios/common/pios_debuglog.c
Normal file
201
flight/pios/common/pios_debuglog.c
Normal file
@ -0,0 +1,201 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
* @defgroup PIOS_DEBUGLOG Flash log debugging Functions
|
||||
* @brief Debugging functionality
|
||||
* @{
|
||||
*
|
||||
* @file pios_debuglog.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013.
|
||||
* @brief Debugging Functions
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "debuglogentry.h"
|
||||
|
||||
// global definitions
|
||||
|
||||
|
||||
// Global variables
|
||||
extern uintptr_t pios_user_fs_id; // flash filesystem for logging
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
static xSemaphoreHandle mutex = 0;
|
||||
#define mutexlock() xSemaphoreTakeRecursive(mutex, portMAX_DELAY)
|
||||
#define mutexunlock() xSemaphoreGiveRecursive(mutex)
|
||||
#else
|
||||
#define mutexlock()
|
||||
#define mutexunlock()
|
||||
#endif
|
||||
|
||||
static bool logging_enabled = false;
|
||||
static uint16_t flightnum = 0;
|
||||
static uint16_t lognum = 0;
|
||||
static DebugLogEntryData *buffer = 0;
|
||||
#if !defined(PIOS_INCLUDE_FREERTOS)
|
||||
static DebugLogEntryData staticbuffer;
|
||||
#endif
|
||||
|
||||
/* Private Function Prototypes */
|
||||
|
||||
/**
|
||||
* @brief Initialize the log facility
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Initialize()
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (!mutex) {
|
||||
mutex = xSemaphoreCreateRecursiveMutex();
|
||||
buffer = pvPortMalloc(sizeof(DebugLogEntryData));
|
||||
}
|
||||
#else
|
||||
buffer = &staticbuffer;
|
||||
#endif
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
mutexlock();
|
||||
lognum = 0;
|
||||
flightnum = 0;
|
||||
while (PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
flightnum++;
|
||||
}
|
||||
mutexunlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables or Disables logging globally
|
||||
* @param[in] enable or disable logging
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Enable(uint8_t enabled)
|
||||
{
|
||||
logging_enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a debug log entry with a uavobject
|
||||
* @param[in] objectid
|
||||
* @param[in] instanceid
|
||||
* @param[in] instanceid
|
||||
* @param[in] size of object
|
||||
* @param[in] data buffer
|
||||
*/
|
||||
void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8_t *data)
|
||||
{
|
||||
if (!logging_enabled || !buffer) {
|
||||
return;
|
||||
}
|
||||
mutexlock();
|
||||
buffer->Flight = flightnum;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
buffer->FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
#else
|
||||
buffer->FlightTime = 0;
|
||||
#endif
|
||||
buffer->Type = DEBUGLOGENTRY_TYPE_UAVOBJECT;
|
||||
buffer->ObjectID = objid;
|
||||
buffer->InstanceID = instid;
|
||||
if (size > sizeof(buffer->Data)) {
|
||||
size = sizeof(buffer->Data);
|
||||
}
|
||||
buffer->Size = size;
|
||||
memcpy(buffer->Data, data, size);
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
lognum++;
|
||||
}
|
||||
mutexunlock();
|
||||
}
|
||||
/**
|
||||
* @brief Write a debug log entry with text
|
||||
* @param[in] format - as in printf
|
||||
* @param[in] variable arguments for printf
|
||||
* @param...
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Printf(char *format, ...)
|
||||
{
|
||||
if (!logging_enabled || !buffer) {
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
mutexlock();
|
||||
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
|
||||
buffer->Flight = flightnum;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
buffer->FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
#else
|
||||
buffer->FlightTime = 0;
|
||||
#endif
|
||||
buffer->Entry = lognum;
|
||||
buffer->Type = DEBUGLOGENTRY_TYPE_TEXT;
|
||||
buffer->ObjectID = 0;
|
||||
buffer->InstanceID = 0;
|
||||
buffer->Size = strlen((const char *)buffer->Data);
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
lognum++;
|
||||
}
|
||||
mutexunlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Load one object instance from the filesystem
|
||||
* @param[out] buffer where to store the uavobject
|
||||
* @param[in] log entry from which flight
|
||||
* @param[in] log entry sequence number
|
||||
* @return 0 if success or error code
|
||||
* @retval -1 if fs_id is not a valid filesystem instance
|
||||
* @retval -2 if failed to start transaction
|
||||
* @retval -3 if object not found in filesystem
|
||||
* @retval -4 if object size in filesystem does not exactly match buffer size
|
||||
* @retval -5 if reading the object data from flash fails
|
||||
*/
|
||||
int32_t PIOS_DEBUGLOG_Read(void *mybuffer, uint16_t flight, uint16_t inst)
|
||||
{
|
||||
PIOS_Assert(mybuffer);
|
||||
return PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flight * 256, inst, (uint8_t *)mybuffer, sizeof(DebugLogEntryData));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieve run time info of logging system
|
||||
* @param[out] current flight number
|
||||
* @param[out] next entry number
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
||||
{
|
||||
if (flight) {
|
||||
*flight = flightnum;
|
||||
}
|
||||
if (entry) {
|
||||
*entry = lognum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -41,7 +41,7 @@ void PIOS_DEBUGLOG_Initialize();
|
||||
* @brief Enables or Disables logging globally
|
||||
* @param[in] enable or disable logging
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Enable(bool enabled);
|
||||
void PIOS_DEBUGLOG_Enable(uint8_t enabled);
|
||||
|
||||
/**
|
||||
* @brief Write a debug log entry with a uavobject
|
||||
|
@ -69,6 +69,7 @@
|
||||
/* #define DEBUG_LEVEL 0 */
|
||||
/* #define PIOS_ENABLE_DEBUG_PINS */
|
||||
#include <pios_debug.h>
|
||||
#include <pios_debuglog.h>
|
||||
|
||||
/* PIOS common functions */
|
||||
#include <pios_crc.h>
|
||||
|
@ -51,7 +51,10 @@ static xSemaphoreHandle mutex = 0;
|
||||
static bool logging_enabled = false;
|
||||
static uint16_t flightnum = 0;
|
||||
static uint16_t lognum = 0;
|
||||
static DebugLogEntryData buffer;
|
||||
static DebugLogEntryData *buffer = 0;
|
||||
#if !defined(PIOS_INCLUDE_FREERTOS)
|
||||
static DebugLogEntryData staticbuffer;
|
||||
#endif
|
||||
|
||||
/* Private Function Prototypes */
|
||||
|
||||
@ -62,13 +65,19 @@ void PIOS_DEBUGLOG_Initialize()
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
if (!mutex) {
|
||||
mutex = xSemaphoreCreateRecursiveMutex();
|
||||
mutex = xSemaphoreCreateRecursiveMutex();
|
||||
buffer = pvPortMalloc(sizeof(DebugLogEntryData));
|
||||
}
|
||||
#else
|
||||
buffer = &staticbuffer;
|
||||
#endif
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
mutexlock();
|
||||
lognum = 0;
|
||||
flightnum = 0;
|
||||
while (PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)&buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
while (PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
flightnum++;
|
||||
}
|
||||
mutexunlock();
|
||||
@ -79,7 +88,7 @@ void PIOS_DEBUGLOG_Initialize()
|
||||
* @brief Enables or Disables logging globally
|
||||
* @param[in] enable or disable logging
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Enable(bool enabled)
|
||||
void PIOS_DEBUGLOG_Enable(uint8_t enabled)
|
||||
{
|
||||
logging_enabled = enabled;
|
||||
}
|
||||
@ -94,26 +103,26 @@ void PIOS_DEBUGLOG_Enable(bool enabled)
|
||||
*/
|
||||
void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8_t *data)
|
||||
{
|
||||
if (!logging_enabled) {
|
||||
if (!logging_enabled || !buffer) {
|
||||
return;
|
||||
}
|
||||
mutexlock();
|
||||
buffer.Flight = flightnum;
|
||||
buffer->Flight = flightnum;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
buffer.FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
buffer->FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
#else
|
||||
buffer.FlightTime = 0;
|
||||
buffer->FlightTime = 0;
|
||||
#endif
|
||||
buffer.Type = DEBUGLOGENTRY_TYPE_UAVOBJECT;
|
||||
buffer.ObjectID = objid;
|
||||
buffer.InstanceID = instid;
|
||||
buffer.Size = size;
|
||||
uint16_t t = 0;
|
||||
for (; t < size && t < sizeof(buffer.Data); t++) {
|
||||
buffer.Data[t] = data[t];
|
||||
buffer->Type = DEBUGLOGENTRY_TYPE_UAVOBJECT;
|
||||
buffer->ObjectID = objid;
|
||||
buffer->InstanceID = instid;
|
||||
if (size > sizeof(buffer->Data)) {
|
||||
size = sizeof(buffer->Data);
|
||||
}
|
||||
buffer->Size = size;
|
||||
memcpy(buffer->Data, data, size);
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)&buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
lognum++;
|
||||
}
|
||||
mutexunlock();
|
||||
@ -126,26 +135,26 @@ void PIOS_DEBUGLOG_UAVObject(uint32_t objid, uint16_t instid, size_t size, uint8
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Printf(char *format, ...)
|
||||
{
|
||||
if (!logging_enabled) {
|
||||
if (!logging_enabled || !buffer) {
|
||||
return;
|
||||
}
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
mutexlock();
|
||||
vsnprintf((char *)buffer.Data, sizeof(buffer.Data), (char *)format, args);
|
||||
buffer.Flight = flightnum;
|
||||
vsnprintf((char *)buffer->Data, sizeof(buffer->Data), (char *)format, args);
|
||||
buffer->Flight = flightnum;
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
buffer.FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
buffer->FlightTime = xTaskGetTickCount() * portTICK_RATE_MS;
|
||||
#else
|
||||
buffer.FlightTime = 0;
|
||||
buffer->FlightTime = 0;
|
||||
#endif
|
||||
buffer.Entry = lognum;
|
||||
buffer.Type = DEBUGLOGENTRY_TYPE_TEXT;
|
||||
buffer.ObjectID = 0;
|
||||
buffer.InstanceID = 0;
|
||||
buffer.Size = strlen((const char *)buffer.Data);
|
||||
buffer->Entry = lognum;
|
||||
buffer->Type = DEBUGLOGENTRY_TYPE_TEXT;
|
||||
buffer->ObjectID = 0;
|
||||
buffer->InstanceID = 0;
|
||||
buffer->Size = strlen((const char *)buffer->Data);
|
||||
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)&buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
if (PIOS_FLASHFS_ObjSave(pios_user_fs_id, flightnum * 256, lognum, (uint8_t *)buffer, sizeof(DebugLogEntryData)) == 0) {
|
||||
lognum++;
|
||||
}
|
||||
mutexunlock();
|
||||
@ -164,16 +173,16 @@ void PIOS_DEBUGLOG_Printf(char *format, ...)
|
||||
* @retval -4 if object size in filesystem does not exactly match buffer size
|
||||
* @retval -5 if reading the object data from flash fails
|
||||
*/
|
||||
int32_t PIOS_DEBUGLOG_Read(void *buffer, uint16_t flight, uint16_t inst)
|
||||
int32_t PIOS_DEBUGLOG_Read(void *mybuffer, uint16_t flight, uint16_t inst)
|
||||
{
|
||||
PIOS_Assert(buffer);
|
||||
return PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flight * 256, inst, (uint8_t *)buffer, sizeof(DebugLogEntryData));
|
||||
PIOS_Assert(mybuffer);
|
||||
return PIOS_FLASHFS_ObjLoad(pios_user_fs_id, flight * 256, inst, (uint8_t *)mybuffer, sizeof(DebugLogEntryData));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieve run time info of logging system
|
||||
* @param[out] buffer where to store the uavobject
|
||||
* @param[in] log entry from which flight
|
||||
* @param[out] current flight number
|
||||
* @param[out] next entry number
|
||||
*/
|
||||
void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry)
|
||||
{
|
||||
|
@ -81,6 +81,7 @@ SRC += $(PIOSCOMMON)/pios_com_msg.c
|
||||
SRC += $(PIOSCOMMON)/pios_crc.c
|
||||
SRC += $(PIOSCOMMON)/pios_flashfs_logfs.c
|
||||
SRC += $(PIOSCOMMON)/pios_flash_jedec.c
|
||||
SRC += $(PIOSCOMMON)/pios_debuglog.c
|
||||
SRC += $(PIOSCOMMON)/pios_rcvr.c
|
||||
SRC += $(PIOSCOMMON)/pios_rfm22b.c
|
||||
SRC += $(PIOSCOMMON)/pios_rfm22b_com.c
|
||||
|
Loading…
x
Reference in New Issue
Block a user