From 18ad56d4ed5d80be1e02b39e46d9772e2f1edd82 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Sun, 24 Nov 2013 15:40:32 +0100 Subject: [PATCH] removed identical files from pios/posix (use files from common instead) --- flight/pios/posix/pios_debuglog.c | 224 --------------- flight/pios/posix/pios_dosfs_logfs.c | 261 ------------------ .../targets/boards/simposix/firmware/Makefile | 2 + 3 files changed, 2 insertions(+), 485 deletions(-) delete mode 100644 flight/pios/posix/pios_debuglog.c delete mode 100644 flight/pios/posix/pios_dosfs_logfs.c diff --git a/flight/pios/posix/pios_debuglog.c b/flight/pios/posix/pios_debuglog.c deleted file mode 100644 index d87b655af..000000000 --- a/flight/pios/posix/pios_debuglog.c +++ /dev/null @@ -1,224 +0,0 @@ -/** - ****************************************************************************** - * @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; - memset(buffer->Data, 0xff, sizeof(buffer->Data)); - 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(); - memset(buffer->Data, 0xff, sizeof(buffer->Data)); - 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 - * @param[out] free slots in filesystem - * @param[out] used slots in filesystem - */ -void PIOS_DEBUGLOG_Info(uint16_t *flight, uint16_t *entry, uint16_t *free, uint16_t *used) -{ - if (flight) { - *flight = flightnum; - } - if (entry) { - *entry = lognum; - } - struct PIOS_FLASHFS_Stats stats = { 0, 0 }; - PIOS_FLASHFS_GetStats(pios_user_fs_id, &stats); - if (free) { - *free = stats.num_free_slots; - } - if (used) { - *used = stats.num_active_slots; - } -} - -/** - * @brief Format entire flash memory!!! - */ -void PIOS_DEBUGLOG_Format(void) -{ - mutexlock(); - PIOS_FLASHFS_Format(pios_user_fs_id); - lognum = 0; - flightnum = 0; - mutexunlock(); -} - -/** - * @} - * @} - */ diff --git a/flight/pios/posix/pios_dosfs_logfs.c b/flight/pios/posix/pios_dosfs_logfs.c deleted file mode 100644 index 0b627e542..000000000 --- a/flight/pios/posix/pios_dosfs_logfs.c +++ /dev/null @@ -1,261 +0,0 @@ -/** - ****************************************************************************** - * @file pios_dosfs_logfs.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @brief Log Structured Filesystem wrapper implemented using dosfs - *****************************************************************************/ -/* - * 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 - */ - - -#include "pios.h" - -#ifdef PIOS_USE_SETTINGS_ON_SDCARD - -#include - -#if defined(PIOS_INCLUDE_FREERTOS) -static xSemaphoreHandle mutex = 0; -#endif - -struct flashfs_logfs_cfg; - - -/** - * Get an 8 character (plus extension) filename for the object. - * @param[in] obj The object handle. - * @param[in] instId The instance ID - * @param[in] file Filename string pointer -- must be 14 bytes long and allocated - */ -static void objectFilename(uint32_t obj_id, uint16_t obj_inst_id, uint8_t *filename) -{ - uint32_t prefix = obj_id + (obj_inst_id / 256) * 16; // put upper 8 bit of instance id into object id modification, - // skip least sig nibble since that is used for meta object id - uint8_t suffix = obj_inst_id & 0xff; - - snprintf((char *)filename, 13, "%08X.o%02X", prefix, suffix); -} - - -/** - * @brief Initialize the flash object setting FS - * @return 0 if success, -1 if failure - */ -int32_t PIOS_FLASHFS_Logfs_Init(__attribute__((unused)) uintptr_t *fs_id, __attribute__((unused)) const struct flashfs_logfs_cfg *cfg, __attribute__((unused)) const struct pios_flash_driver *driver, __attribute__((unused)) uintptr_t flash_id) -{ -#if defined(PIOS_INCLUDE_FREERTOS) - if (!mutex) { - mutex = xSemaphoreCreateRecursiveMutex(); - } -#endif - return 0; -} - -int32_t PIOS_FLASHFS_Logfs_Destroy(__attribute__((unused)) uintptr_t fs_id) -{ - // stub, only wrapper for dosfs, does not need destroying - return 0; -} - -/********************************** - * - * Provide a PIOS_FLASHFS_* driver - * - *********************************/ -#include "pios_flashfs.h" /* API for flash filesystem */ - -/** - * @brief Saves one object instance to the filesystem - * @param[in] fs_id The filesystem to use for this action - * @param[in] obj UAVObject ID of the object to save - * @param[in] obj_inst_id The instance number of the object being saved - * @param[in] obj_data Contents of the object being saved - * @param[in] obj_size Size of the object being saved - * @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 failure to delete any previous versions of the object - * @retval -4 if filesystem is entirely full and garbage collection won't help - * @retval -5 if garbage collection failed - * @retval -6 if filesystem is full even after garbage collection should have freed space - * @retval -7 if writing the new object to the filesystem failed - */ -int32_t PIOS_FLASHFS_ObjSave(__attribute__((unused)) uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size) -{ - FILEINFO file; - uint8_t filename[14]; - - if (PIOS_SDCARD_IsMounted() == 0) { - return -1; - } - - // Lock - -#if defined(PIOS_INCLUDE_FREERTOS) - xSemaphoreTakeRecursive(mutex, portMAX_DELAY); -#endif - - // Get filename - objectFilename(obj_id, obj_inst_id, filename); - - // Open file - if (PIOS_FOPEN_WRITE(filename, file)) { -#if defined(PIOS_INCLUDE_FREERTOS) - xSemaphoreGiveRecursive(mutex); -#endif - return -2; - } - // Append object - uint32_t bytes_written = 0; - PIOS_FWRITE(&file, obj_data, obj_size, &bytes_written); - - // Done, close file and unlock - PIOS_FCLOSE(file); -#if defined(PIOS_INCLUDE_FREERTOS) - xSemaphoreGiveRecursive(mutex); -#endif - - if (bytes_written != obj_size) { - return -7; - } - - return 0; -} - -/** - * @brief Load one object instance from the filesystem - * @param[in] fs_id The filesystem to use for this action - * @param[in] obj UAVObject ID of the object to load - * @param[in] obj_inst_id The instance of the object to load - * @param[in] obj_data Buffer to hold the contents of the loaded object - * @param[in] obj_size Size of the object to be loaded - * @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_FLASHFS_ObjLoad(__attribute__((unused)) uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id, uint8_t *obj_data, uint16_t obj_size) -{ - FILEINFO file; - uint8_t filename[14]; - - // Check for file system availability - if (PIOS_SDCARD_IsMounted() == 0) { - return -1; - } - -#if defined(PIOS_INCLUDE_FREERTOS) - // Lock - xSemaphoreTakeRecursive(mutex, portMAX_DELAY); -#endif - // Get filename - objectFilename(obj_id, obj_inst_id, filename); - - // Open file - if (PIOS_FOPEN_READ(filename, file)) { -#if defined(PIOS_INCLUDE_FREERTOS) - xSemaphoreGiveRecursive(mutex); -#endif - return -1; - } - // Load object - uint32_t bytes_read = 0; - uint32_t result = PIOS_FREAD(&file, obj_data, obj_size, &bytes_read); - - // Done, close file and unlock - PIOS_FCLOSE(file); -#if defined(PIOS_INCLUDE_FREERTOS) - xSemaphoreGiveRecursive(mutex); -#endif - if (result != 0) { - return -1; - } - return 0; -} - -/** - * @brief Delete one instance of an object from the filesystem - * @param[in] fs_id The filesystem to use for this action - * @param[in] obj UAVObject ID of the object to delete - * @param[in] obj_inst_id The instance of the object to delete - * @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 failed to delete the object from the filesystem - */ -int32_t PIOS_FLASHFS_ObjDelete(__attribute__((unused)) uintptr_t fs_id, uint32_t obj_id, uint16_t obj_inst_id) -{ - uint8_t filename[14]; - - // Check for file system availability - if (PIOS_SDCARD_IsMounted() == 0) { - return -1; - } -#if defined(PIOS_INCLUDE_FREERTOS) - // Lock - xSemaphoreTakeRecursive(mutex, portMAX_DELAY); -#endif - // Get filename - objectFilename(obj_id, obj_inst_id, filename); - - // Delete file - PIOS_FUNLINK(filename); - - // Done -#if defined(PIOS_INCLUDE_FREERTOS) - xSemaphoreGiveRecursive(mutex); -#endif - return 0; -} - -/** - * @brief Erases all filesystem arenas and activate the first arena - * @param[in] fs_id The filesystem to use for this action - * @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 failed to erase all arenas - * @retval -4 if failed to activate arena 0 - * @retval -5 if failed to mount arena 0 - */ -int32_t PIOS_FLASHFS_Format(__attribute__((unused)) uintptr_t fs_id) -{ - /* stub - not implemented */ - return -1; -} - -/** - * @brief Returs stats for the filesystems - * @param[in] fs_id The filesystem to use for this action - * @return 0 if success or error code - * @retval -1 if fs_id is not a valid filesystem instance - */ -int32_t PIOS_FLASHFS_GetStats(__attribute__((unused)) uintptr_t fs_id, __attribute__((unused)) struct PIOS_FLASHFS_Stats *stats) -{ - /* stub - not implemented */ - return 0; -} - -#endif /* PIOS_USE_SETTINGS_ON_SDCARD */ - -/** - * @} - * @} - */ diff --git a/flight/targets/boards/simposix/firmware/Makefile b/flight/targets/boards/simposix/firmware/Makefile index ed04e470f..c9d719334 100644 --- a/flight/targets/boards/simposix/firmware/Makefile +++ b/flight/targets/boards/simposix/firmware/Makefile @@ -98,6 +98,8 @@ SRC += $(MATHLIB)/sin_lookup.c SRC += $(MATHLIB)/pid.c SRC += $(PIOSCORECOMMON)/pios_task_monitor.c +SRC += $(PIOSCORECOMMON)/pios_dosfs_logfs.c +SRC += $(PIOSCORECOMMON)/pios_debuglog.c ## PIOS Hardware include $(PIOS)/posix/library.mk