1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Flight/Alarms Implemented Alarms library, now checking for stack overflow, out of memory, event and other errors (see the SystemAlarms object). All modules will be reporting their alarms using this library.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@554 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-04-27 01:55:28 +00:00 committed by vassilis
parent d04983a6a5
commit 8c11a03129
41 changed files with 537 additions and 97 deletions

View File

@ -115,6 +115,7 @@ SRC += $(MODGPS)/GPS.c $(MODGPS)/buffer.c
## OPENPILOT:
SRC += $(OPSYSTEM)/openpilot.c
SRC += $(OPSYSTEM)/op_logging.c
SRC += $(OPSYSTEM)/alarms.c
SRC += $(OPUAVTALK)/uavtalk.c
SRC += $(OPUAVOBJ)/uavobjectmanager.c
SRC += $(OPUAVOBJ)/uavobjectsinit.c

View File

@ -44,6 +44,7 @@
*
*/
#include "openpilot.h"
#include "examplemodevent.h"
#include "exampleobject1.h" // object the module will listen for updates (input)
#include "exampleobject2.h" // object the module will update (output)

View File

@ -44,6 +44,7 @@
*
*/
#include "openpilot.h"
#include "examplemodperiodic.h"
#include "exampleobject2.h" // object that will be updated by the module
#include "examplesettings.h" // object holding module settings

View File

@ -43,6 +43,7 @@
* http://www.openpilot.org/OpenPilot_Application_Architecture
*/
#include "openpilot.h"
#include "examplemodthread.h"
#include "exampleobject1.h" // object the module will listen for updates (input)
#include "exampleobject2.h" // object the module will update (output)

View File

@ -26,8 +26,6 @@
#ifndef EXAMPLEMODEVENT_H
#define EXAMPLEMODEVENT_H
#include "openpilot.h"
int32_t ExampleModEventInitialize();
#endif // EXAMPLEMODEVENT_H

View File

@ -26,8 +26,6 @@
#ifndef EXAMPLEMODPERIODIC_H
#define EXAMPLEMODPERIODIC_H
#include "openpilot.h"
int32_t ExampleModPeriodicInitialize();
#endif // EXAMPLEMODPERIODIC_H

View File

@ -26,8 +26,6 @@
#ifndef EXAMPLEMODTHREAD_H
#define EXAMPLEMODTHREAD_H
#include "openpilot.h"
int32_t ExampleModThreadInitialize();
#endif // EXAMPLEMODTHREAD_H

View File

@ -26,8 +26,6 @@
#ifndef SYSTEMMOD_H
#define SYSTEMMOD_H
#include "openpilot.h"
int32_t SystemModInitialize(void);
#endif // SYSTEMMOD_H

View File

@ -24,6 +24,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "systemmod.h"
#include "settingspersistence.h"
#include "systemstats.h"
@ -36,16 +37,23 @@
#define STACK_SIZE configMINIMAL_STACK_SIZE
#define TASK_PRIORITY (tskIDLE_PRIORITY+3)
#define HEAP_LIMIT_WARNING 4000
#define HEAP_LIMIT_CRITICAL 1000
#define CPULOAD_LIMIT_WARNING 80
#define CPULOAD_LIMIT_CRITICAL 95
// Private types
// Private variables
static uint32_t idleCounter;
static uint32_t idleCounterClear;
static xTaskHandle systemTaskHandle;
static int32_t stackOverflow;
// Private functions
static void objectUpdatedCb(UAVObjEvent* ev);
static void updateStats();
static void updateSystemAlarms();
static void systemTask(void* parameters);
/**
@ -54,6 +62,8 @@ static void systemTask(void* parameters);
*/
int32_t SystemModInitialize(void)
{
// Initialize vars
stackOverflow = 0;
// Create system task
xTaskCreate(systemTask, (signed char*)"System", STACK_SIZE, NULL, TASK_PRIORITY, &systemTaskHandle);
return 0;
@ -83,9 +93,22 @@ static void systemTask(void* parameters)
// Update the system statistics
updateStats();
// Flash the LED
// Update the system alarms
updateSystemAlarms();
// Flash system alive the LED
PIOS_LED_Toggle(LED1);
// Flash the error LED if an alarm is set
if ( AlarmsHasWarnings() )
{
PIOS_LED_Toggle(LED2);
}
else
{
PIOS_LED_Off(LED2);
}
// Wait until next period
vTaskDelayUntil(&lastSysTime, SYSTEM_UPDATE_PERIOD_MS / portTICK_RATE_MS);
}
@ -132,6 +155,79 @@ static void updateStats()
SystemStatsSet(&stats);
}
/**
* Update system alarms
*/
static void updateSystemAlarms()
{
SystemStatsData stats;
UAVObjStats objStats;
EventStats evStats;
SystemStatsGet(&stats);
// Check heap
if ( stats.HeapRemaining < HEAP_LIMIT_CRITICAL )
{
AlarmsSet(SYSTEMALARMS_ALARM_OUTOFMEMORY, SYSTEMALARMS_ALARM_CRITICAL);
}
else if ( stats.HeapRemaining < HEAP_LIMIT_WARNING )
{
AlarmsSet(SYSTEMALARMS_ALARM_OUTOFMEMORY, SYSTEMALARMS_ALARM_WARNING);
}
else
{
AlarmsClear(SYSTEMALARMS_ALARM_OUTOFMEMORY);
}
// Check CPU load
if ( stats.CPULoad > CPULOAD_LIMIT_CRITICAL )
{
AlarmsSet(SYSTEMALARMS_ALARM_CPUOVERLOAD, SYSTEMALARMS_ALARM_CRITICAL);
}
else if ( stats.CPULoad > CPULOAD_LIMIT_WARNING )
{
AlarmsSet(SYSTEMALARMS_ALARM_CPUOVERLOAD, SYSTEMALARMS_ALARM_WARNING);
}
else
{
AlarmsClear(SYSTEMALARMS_ALARM_CPUOVERLOAD);
}
// Check for stack overflow
if ( stackOverflow == 1 )
{
AlarmsSet(SYSTEMALARMS_ALARM_STACKOVERFLOW, SYSTEMALARMS_ALARM_CRITICAL);
}
else
{
AlarmsClear(SYSTEMALARMS_ALARM_STACKOVERFLOW);
}
// Check for SD card
if ( POIS_SDCARD_IsMounted() == 0 )
{
AlarmsSet(SYSTEMALARMS_ALARM_SDCARD, SYSTEMALARMS_ALARM_WARNING);
}
else
{
AlarmsClear(SYSTEMALARMS_ALARM_SDCARD);
}
// Check for event errors
UAVObjGetStats(&objStats);
EventGetStats(&evStats);
UAVObjClearStats();
EventClearStats();
if ( objStats.eventErrors > 0 || evStats.eventErrors > 0 )
{
AlarmsSet(SYSTEMALARMS_ALARM_EVENTSYSTEM, SYSTEMALARMS_ALARM_WARNING);
}
else
{
AlarmsClear(SYSTEMALARMS_ALARM_EVENTSYSTEM);
}
}
/**
* Called by the RTOS when the CPU is idle, used to measure the CPU idle time.
*/
@ -154,6 +250,6 @@ void vApplicationIdleHook(void)
*/
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
{
stackOverflow = 1;
}

View File

@ -203,6 +203,16 @@ static void processObjEvent(UAVObjEvent* ev)
txErrors = 0;
txRetries = 0;
FlightTelemetryStatsSet(&stats);
// Update the telemetry alarm
if ( stats.Connected == FLIGHTTELEMETRYSTATS_CONNECTED_TRUE )
{
AlarmsClear(SYSTEMALARMS_ALARM_TELEMETRY);
}
else
{
AlarmsSet(SYSTEMALARMS_ALARM_TELEMETRY, SYSTEMALARMS_ALARM_ERROR);
}
}
// This is an object update, handle based on event type
else

View File

@ -0,0 +1,181 @@
/**
******************************************************************************
*
* @file alarms.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Library for setting and clearing system alarms
* @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
*/
#include "openpilot.h"
#include "alarms.h"
// Private constants
// Private types
// Private variables
static xSemaphoreHandle lock;
// Private functions
static int32_t hasSeverity(SystemAlarmsAlarmOptions severity);
/**
* Initialize the alarms library
*/
int32_t AlarmsInitialize(void)
{
lock = xSemaphoreCreateRecursiveMutex();
AlarmsClearAll();
return 0;
}
/**
* Set an alarm
* @param alarm The system alarm to be modified
* @param severity The alarm severity
* @return 0 if success, -1 if an error
*/
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
{
SystemAlarmsData alarms;
uint8_t changed;
// Check that this is a valid alarm
if (alarm >= SYSTEMALARMS_ALARM_NUMELEM)
{
return -1;
}
// Lock
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
// Read alarm and update its severity only if it was changed
SystemAlarmsGet(&alarms);
if ( alarms.Alarm[alarm] != severity )
{
alarms.Alarm[alarm] = severity;
SystemAlarmsSet(&alarms);
SystemAlarmsUpdated(); // force telemetry update since the alarm was changed
}
// Release lock
xSemaphoreGiveRecursive(lock);
return 0;
}
/**
* Get an alarm
* @param alarm The system alarm to be read
* @return Alarm severity
*/
SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm)
{
SystemAlarmsData alarms;
// Check that this is a valid alarm
if (alarm >= SYSTEMALARMS_ALARM_NUMELEM)
{
return 0;
}
// Read alarm
SystemAlarmsGet(&alarms);
return alarms.Alarm[alarm];
}
/**
* Clear an alarm
* @param alarm The system alarm to be modified
* @return 0 if success, -1 if an error
*/
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
{
return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK);
}
/**
* Clear all alarms
*/
void AlarmsClearAll()
{
uint32_t n;
for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n)
{
AlarmsClear(n);
}
}
/**
* Check if there are any alarms with the given or higher severity
* @return 0 if no alarms are found, 1 if at least one alarm is found
*/
int32_t AlarmsHasWarnings()
{
return hasSeverity(SYSTEMALARMS_ALARM_WARNING);
}
/**
* Check if there are any alarms with error or higher severity
* @return 0 if no alarms are found, 1 if at least one alarm is found
*/
int32_t AlarmsHasErrors()
{
return hasSeverity(SYSTEMALARMS_ALARM_ERROR);
};
/**
* Check if there are any alarms with critical or higher severity
* @return 0 if no alarms are found, 1 if at least one alarm is found
*/
int32_t AlarmsHasCritical()
{
return hasSeverity(SYSTEMALARMS_ALARM_CRITICAL);
};
/**
* Check if there are any alarms with the given or higher severity
* @return 0 if no alarms are found, 1 if at least one alarm is found
*/
static int32_t hasSeverity(SystemAlarmsAlarmOptions severity)
{
SystemAlarmsData alarms;
uint32_t n;
// Lock
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
// Read alarms
SystemAlarmsGet(&alarms);
// Go through alarms and check if any are of the given severity or higher
for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n)
{
if ( alarms.Alarm[n] >= severity)
{
xSemaphoreGiveRecursive(lock);
return 1;
}
}
// If this point is reached then no alarms found
xSemaphoreGiveRecursive(lock);
return 0;
}

View File

@ -0,0 +1,40 @@
/**
******************************************************************************
*
* @file alarms.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Include file of the alarm library
* @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
*/
#ifndef ALARMS_H
#define ALARMS_H
#include "systemalarms.h"
int32_t AlarmsInitialize(void);
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity);
SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm);
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm);
void AlarmsClearAll();
int32_t AlarmsHasWarnings();
int32_t AlarmsHasErrors();
int32_t AlarmsHasCritical();
#endif // ALARMS_H

View File

@ -31,16 +31,13 @@
/* PIOS Includes */
#include <pios.h>
/* OpenPilot Includes */
#include <op_config.h>
#include <op_logging.h>
/* UAVObjects */
/* OpenPilot Libraries */
#include "op_config.h"
#include "op_logging.h"
#include "utlist.h"
#include "uavobjectmanager.h"
#include "eventdispatcher.h"
#include "utlist.h"
/* UAVTalk */
#include "alarms.h"
#include "uavtalk.h"
/* Global Functions */

View File

@ -59,8 +59,7 @@ void OP_ADC_NotifyChange(uint32_t pin, uint32_t pin_value);
int main()
{
/* NOTE: Do NOT modify the following start-up sequence */
/* Any new initialization functions should be added in */
/* OpenPilotInit() */
/* Any new initialization functions should be added in OpenPilotInit() */
/* Brings up System using CMSIS functions, enables the LEDs. */
PIOS_SYS_Init();
@ -95,64 +94,40 @@ void OpenPilotInit()
/* SPI Init */
PIOS_SPI_Init();
/* Enables the SDCard */
/* Enable and mount the SDCard */
PIOS_SDCARD_Init();
/* Wait for SD card for ever */
for(;;)
{
/* Check if we have an SD Card with the correct settings files on it */
if(!PIOS_SDCARD_MountFS(0)) {
/* Found one without errors */
break;
}
/* SD Card not found, flash for 1 second */
PIOS_LED_On(LED1);
PIOS_LED_On(LED2);
for(uint32_t i = 0; i < 10; i++) {
PIOS_LED_Toggle(LED2);
PIOS_DELAY_WaitmS(100);
}
}
PIOS_SDCARD_MountFS(0);
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
UAVObjectsInitializeAll();
/* Com ports init */
/* Initialize the alarms library */
AlarmsInitialize();
/* Initialize the PiOS library */
PIOS_COM_Init();
/* Initialise servo outputs */
PIOS_Servo_Init();
/* Analog to digital converter initialise */
PIOS_ADC_Init();
PIOS_GPIO_Init();
//PIOS_PPM_Init();
PIOS_PWM_Init();
PIOS_USB_Init(0);
PIOS_I2C_Init();
PIOS_Servo_SetHz(50, 450);
/* Create a FreeRTOS task */
//xTaskCreate(TaskTesting, (signed portCHAR *)"TaskTesting", configMINIMAL_STACK_SIZE , NULL, 4, NULL);
//xTaskCreate(TaskServos, (signed portCHAR *)"Servos", configMINIMAL_STACK_SIZE , NULL, 3, NULL);
//xTaskCreate(TaskSDCard, (signed portCHAR *)"SDCard", configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 2), NULL);
/* Initialize modules */
TelemetryInitialize();
ExampleModPeriodicInitialize();
//ExampleModThreadInitialize();
//ExampleModEventInitialize();
GpsInitialize();
/* Create test tasks */
//xTaskCreate(TaskTesting, (signed portCHAR *)"TaskTesting", configMINIMAL_STACK_SIZE , NULL, 4, NULL);
//xTaskCreate(TaskServos, (signed portCHAR *)"Servos", configMINIMAL_STACK_SIZE , NULL, 3, NULL);
//xTaskCreate(TaskSDCard, (signed portCHAR *)"SDCard", configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 2), NULL);
}
static void TaskTesting(void *pvParameters)

View File

@ -60,6 +60,7 @@ static PeriodicObjectList* objList;
static xQueueHandle queue;
static xTaskHandle eventTaskHandle;
static xSemaphoreHandle mutex;
static EventStats stats;
// Private functions
static int32_t processPeriodicUpdates();
@ -74,8 +75,9 @@ static int32_t eventPeriodicUpdate(UAVObjEvent* ev, UAVObjEventCallback cb, xQue
*/
int32_t EventDispatcherInitialize()
{
// Initialize list
// Initialize variables
objList = NULL;
memset(&stats, 0, sizeof(EventStats));
// Create mutex
mutex = xSemaphoreCreateRecursiveMutex();
@ -92,6 +94,27 @@ int32_t EventDispatcherInitialize()
return 0;
}
/**
* Get the statistics counters
* @param[out] statsOut The statistics counters will be copied there
*/
void EventGetStats(EventStats* statsOut)
{
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
memcpy(statsOut, &stats, sizeof(EventStats));
xSemaphoreGiveRecursive(mutex);
}
/**
* Clear the statistics counters
*/
void EventClearStats()
{
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
memset(&stats, 0, sizeof(EventStats));
xSemaphoreGiveRecursive(mutex);
}
/**
* Dispatch an event by invoking the supplied callback. The function
* returns imidiatelly, the callback is invoked from the event task.
@ -312,7 +335,10 @@ static int32_t processPeriodicUpdates()
// Push event to queue, if one
if ( objEntry->evInfo.queue != 0)
{
xQueueSend(objEntry->evInfo.queue, &objEntry->evInfo.ev, 0); // do not block if queue is full
if ( xQueueSend(objEntry->evInfo.queue, &objEntry->evInfo.ev, 0) != pdTRUE ) // do not block if queue is full
{
++stats.eventErrors;
}
}
}
// Update minimum delay

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "exampleobject1.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "exampleobject2.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "examplesettings.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "flighttelemetrystats.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "gcstelemetrystats.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "gpsobject.h"
// Private variables

View File

@ -27,9 +27,17 @@
#define EVENTDISPATCHER_H
// Public types
/**
* Event dispatcher statistics
*/
typedef struct {
uint32_t eventErrors;
} EventStats;
// Public functions
int32_t EventDispatcherInitialize();
void EventGetStats(EventStats* statsOut);
void EventClearStats();
int32_t EventCallbackDispatch(UAVObjEvent* ev, UAVObjEventCallback cb);
int32_t EventPeriodicCallbackCreate(UAVObjEvent* ev, UAVObjEventCallback cb, int32_t periodMs);
int32_t EventPeriodicCallbackUpdate(UAVObjEvent* ev, UAVObjEventCallback cb, int32_t periodMs);

View File

@ -32,8 +32,6 @@
#ifndef EXAMPLEOBJECT1_H
#define EXAMPLEOBJECT1_H
#include "openpilot.h"
// Object constants
#define EXAMPLEOBJECT1_OBJID 3852936276U
#define EXAMPLEOBJECT1_NAME "ExampleObject1"
@ -69,7 +67,17 @@ typedef struct {
} __attribute__((packed)) ExampleObject1Data;
// Enumeration types
// Field information
// Field Field1 information
// Field Field2 information
// Field Field3 information
// Field Field4 information
/* Number of elements for field Field4 */
#define EXAMPLEOBJECT1_FIELD4_NUMELEM 4
// Field Field5 information
// Field Field6 information
// Field Field7 information
// Field Field8 information
/* Enumeration options for field Field8 */
typedef enum { EXAMPLEOBJECT1_FIELD8_OPTION1=0, EXAMPLEOBJECT1_FIELD8_OPTION2=1, } ExampleObject1Field8Options;

View File

@ -32,8 +32,6 @@
#ifndef EXAMPLEOBJECT2_H
#define EXAMPLEOBJECT2_H
#include "openpilot.h"
// Object constants
#define EXAMPLEOBJECT2_OBJID 2743296914U
#define EXAMPLEOBJECT2_NAME "ExampleObject2"
@ -65,7 +63,13 @@ typedef struct {
} __attribute__((packed)) ExampleObject2Data;
// Enumeration types
// Field information
// Field Field1 information
// Field Field2 information
// Field Field3 information
// Field Field4 information
/* Number of elements for field Field4 */
#define EXAMPLEOBJECT2_FIELD4_NUMELEM 4
// Generic interface functions

View File

@ -32,8 +32,6 @@
#ifndef EXAMPLESETTINGS_H
#define EXAMPLESETTINGS_H
#include "openpilot.h"
// Object constants
#define EXAMPLESETTINGS_OBJID 1640607828U
#define EXAMPLESETTINGS_NAME "ExampleSettings"
@ -64,7 +62,10 @@ typedef struct {
} __attribute__((packed)) ExampleSettingsData;
// Enumeration types
// Field information
// Field UpdatePeriod information
// Field StepSize information
// Field StepDirection information
/* Enumeration options for field StepDirection */
typedef enum { EXAMPLESETTINGS_STEPDIRECTION_UP=0, EXAMPLESETTINGS_STEPDIRECTION_DOWN=1, } ExampleSettingsStepDirectionOptions;

View File

@ -32,8 +32,6 @@
#ifndef FLIGHTTELEMETRYSTATS_H
#define FLIGHTTELEMETRYSTATS_H
#include "openpilot.h"
// Object constants
#define FLIGHTTELEMETRYSTATS_OBJID 766280320U
#define FLIGHTTELEMETRYSTATS_NAME "FlightTelemetryStats"
@ -67,9 +65,15 @@ typedef struct {
} __attribute__((packed)) FlightTelemetryStatsData;
// Enumeration types
// Field information
// Field Connected information
/* Enumeration options for field Connected */
typedef enum { FLIGHTTELEMETRYSTATS_CONNECTED_TRUE=0, FLIGHTTELEMETRYSTATS_CONNECTED_FALSE=1, } FlightTelemetryStatsConnectedOptions;
// Field TxDataRate information
// Field RxDataRate information
// Field TxFailures information
// Field RxFailures information
// Field TxRetries information
// Generic interface functions

View File

@ -32,8 +32,6 @@
#ifndef GCSTELEMETRYSTATS_H
#define GCSTELEMETRYSTATS_H
#include "openpilot.h"
// Object constants
#define GCSTELEMETRYSTATS_OBJID 607270704U
#define GCSTELEMETRYSTATS_NAME "GCSTelemetryStats"
@ -67,9 +65,15 @@ typedef struct {
} __attribute__((packed)) GCSTelemetryStatsData;
// Enumeration types
// Field information
// Field Connected information
/* Enumeration options for field Connected */
typedef enum { GCSTELEMETRYSTATS_CONNECTED_TRUE=0, GCSTELEMETRYSTATS_CONNECTED_FALSE=1, } GCSTelemetryStatsConnectedOptions;
// Field TxDataRate information
// Field RxDataRate information
// Field TxFailures information
// Field RxFailures information
// Field TxRetries information
// Generic interface functions

View File

@ -32,8 +32,6 @@
#ifndef GPSOBJECT_H
#define GPSOBJECT_H
#include "openpilot.h"
// Object constants
#define GPSOBJECT_OBJID 4217926642U
#define GPSOBJECT_NAME "GpsObject"
@ -66,7 +64,12 @@ typedef struct {
} __attribute__((packed)) GpsObjectData;
// Enumeration types
// Field information
// Field Latitude information
// Field Longitude information
// Field Altitude information
// Field Satellites information
// Field Updates information
// Generic interface functions

View File

@ -32,8 +32,6 @@
#ifndef SETTINGSPERSISTENCE_H
#define SETTINGSPERSISTENCE_H
#include "openpilot.h"
// Object constants
#define SETTINGSPERSISTENCE_OBJID 3652432370U
#define SETTINGSPERSISTENCE_NAME "SettingsPersistence"
@ -62,7 +60,8 @@ typedef struct {
} __attribute__((packed)) SettingsPersistenceData;
// Enumeration types
// Field information
// Field Operation information
/* Enumeration options for field Operation */
typedef enum { SETTINGSPERSISTENCE_OPERATION_LOAD=0, SETTINGSPERSISTENCE_OPERATION_SAVE=1, } SettingsPersistenceOperationOptions;

View File

@ -32,10 +32,8 @@
#ifndef SYSTEMALARMS_H
#define SYSTEMALARMS_H
#include "openpilot.h"
// Object constants
#define SYSTEMALARMS_OBJID 2311311912U
#define SYSTEMALARMS_OBJID 2311311458U
#define SYSTEMALARMS_NAME "SystemAlarms"
#define SYSTEMALARMS_ISSINGLEINST 1
#define SYSTEMALARMS_ISSETTINGS 0
@ -58,15 +56,18 @@
// Object data
typedef struct {
uint8_t Alarm[4];
uint8_t Alarm[6];
} __attribute__((packed)) SystemAlarmsData;
// Enumeration types
// Field information
// Field Alarm information
/* Enumeration options for field Alarm */
typedef enum { SYSTEMALARMS_ALARM_NONE=0, SYSTEMALARMS_ALARM_WARNING=1, SYSTEMALARMS_ALARM_ERROR=2, SYSTEMALARMS_ALARM_CRITICAL=3, } SystemAlarmsAlarmOptions;
typedef enum { SYSTEMALARMS_ALARM_OK=0, SYSTEMALARMS_ALARM_WARNING=1, SYSTEMALARMS_ALARM_ERROR=2, SYSTEMALARMS_ALARM_CRITICAL=3, } SystemAlarmsAlarmOptions;
/* Array element names for field Alarm */
typedef enum { SYSTEMALARMS_ALARM_OUTOFMEMORY=0, SYSTEMALARMS_ALARM_STACKOVERFLOW=1, SYSTEMALARMS_ALARM_CPUOVERLOAD=2, SYSTEMALARMS_ALARM_EVENTSYSTEM=3, } SystemAlarmsAlarmElem;
typedef enum { SYSTEMALARMS_ALARM_OUTOFMEMORY=0, SYSTEMALARMS_ALARM_STACKOVERFLOW=1, SYSTEMALARMS_ALARM_CPUOVERLOAD=2, SYSTEMALARMS_ALARM_EVENTSYSTEM=3, SYSTEMALARMS_ALARM_SDCARD=4, SYSTEMALARMS_ALARM_TELEMETRY=5, } SystemAlarmsAlarmElem;
/* Number of elements for field Alarm */
#define SYSTEMALARMS_ALARM_NUMELEM 6
// Generic interface functions

View File

@ -32,8 +32,6 @@
#ifndef SYSTEMSTATS_H
#define SYSTEMSTATS_H
#include "openpilot.h"
// Object constants
#define SYSTEMSTATS_OBJID 680908530U
#define SYSTEMSTATS_NAME "SystemStats"
@ -64,7 +62,10 @@ typedef struct {
} __attribute__((packed)) SystemStatsData;
// Enumeration types
// Field information
// Field FlightTime information
// Field HeapRemaining information
// Field CPULoad information
// Generic interface functions

View File

@ -88,7 +88,16 @@ typedef struct {
*/
typedef void (*UAVObjEventCallback)(UAVObjEvent* ev);
/**
* Event manager statistics
*/
typedef struct {
uint32_t eventErrors;
} UAVObjStats;
int32_t UAVObjInitialize();
void UAVObjGetStats(UAVObjStats* statsOut);
void UAVObjClearStats();
UAVObjHandle UAVObjRegister(uint32_t id, const char* name, int32_t isMetaobject, int32_t isSingleInstance,
int32_t isSettings, uint32_t numBytes);
UAVObjHandle UAVObjGetByID(uint32_t id);

View File

@ -32,8 +32,6 @@
#ifndef $(NAMEUC)_H
#define $(NAMEUC)_H
#include "openpilot.h"
// Object constants
#define $(NAMEUC)_OBJID $(OBJID)U
#define $(NAMEUC)_NAME "$(NAME)"
@ -61,8 +59,8 @@ typedef struct {
$(DATAFIELDS)
} __attribute__((packed)) $(NAME)Data;
// Enumeration types
$(DATAENUM)
// Field information
$(DATAFIELDINFO)
// Generic interface functions
int32_t $(NAME)Initialize();

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "settingspersistence.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "systemalarms.h"
// Private variables

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "systemstats.h"
// Private variables

View File

@ -80,6 +80,7 @@ static int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCa
static ObjectList* objList;
static xSemaphoreHandle mutex;
static UAVObjMetadata defMetadata;
static UAVObjStats stats;
/**
* Initialize the object manager
@ -88,8 +89,9 @@ static UAVObjMetadata defMetadata;
*/
int32_t UAVObjInitialize()
{
// Initialize object list
// Initialize variables
objList = NULL;
memset(&stats, 0, sizeof(UAVObjStats));
// Create mutex
mutex = xSemaphoreCreateRecursiveMutex();
@ -110,6 +112,27 @@ int32_t UAVObjInitialize()
return 0;
}
/**
* Get the statistics counters
* @param[out] statsOut The statistics counters will be copied there
*/
void UAVObjGetStats(UAVObjStats* statsOut)
{
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
memcpy(statsOut, &stats, sizeof(UAVObjStats));
xSemaphoreGiveRecursive(mutex);
}
/**
* Clear the statistics counters
*/
void UAVObjClearStats()
{
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
memset(&stats, 0, sizeof(UAVObjStats));
xSemaphoreGiveRecursive(mutex);
}
/**
* Register and new object in the object manager.
* \param[in] id Unique object ID
@ -459,6 +482,12 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file)
ObjectList* objEntry;
ObjectInstList* instEntry;
// Check for file system availability
if ( POIS_SDCARD_IsMounted() == 0 )
{
return -1;
}
// Lock
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
@ -510,6 +539,12 @@ int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
FILEINFO file;
ObjectList* objEntry;
// Check for file system availability
if ( POIS_SDCARD_IsMounted() == 0 )
{
return -1;
}
// Lock
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
@ -551,6 +586,12 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
uint16_t instId;
UAVObjHandle obj;
// Check for file system availability
if ( POIS_SDCARD_IsMounted() == 0 )
{
return -1;
}
// Lock
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
@ -626,6 +667,12 @@ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId)
UAVObjHandle loadedObj;
ObjectList* loadedObjEntry;
// Check for file system availability
if ( POIS_SDCARD_IsMounted() == 0 )
{
return -1;
}
// Lock
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
@ -983,7 +1030,7 @@ void UAVObjUpdated(UAVObjHandle obj)
void UAVObjInstanceUpdated(UAVObjHandle obj, uint16_t instId)
{
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
sendEvent((ObjectList*)obj, instId, EV_UPDATED);
sendEvent((ObjectList*)obj, instId, EV_UPDATED_MANUAL);
xSemaphoreGiveRecursive(mutex);
}
@ -1030,12 +1077,18 @@ static int32_t sendEvent(ObjectList* obj, uint16_t instId, UAVObjEventType event
// Send to queue if a valid queue is registered
if (eventEntry->queue != 0)
{
xQueueSend(eventEntry->queue, &msg, 0); // do not wait if queue is full
if ( xQueueSend(eventEntry->queue, &msg, 0) != pdTRUE ) // will not block
{
++stats.eventErrors;
}
}
// Invoke callback (from event task) if a valid one is registered
if (eventEntry->cb != 0)
{
EventCallbackDispatch(&msg, eventEntry->cb); // invoke callback from the event task
if ( EventCallbackDispatch(&msg, eventEntry->cb) != pdTRUE ) // invoke callback from the event task, will not block
{
++stats.eventErrors;
}
}
}
}

View File

@ -29,6 +29,7 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "openpilot.h"
#include "$(NAMELC).h"
// Private variables

View File

@ -87,6 +87,7 @@ uint8_t PIOS_SDCARD_Sector[SECTOR_SIZE];
#define CT_SDC (CT_SD1|CT_SD2)
#define CT_BLOCK 0x08
static uint8_t CardType;
static int32_t sdcard_mounted;
/**
* Initialises SPI pins and peripheral to access MMC/SD Card
@ -96,6 +97,9 @@ static uint8_t CardType;
int32_t PIOS_SDCARD_Init(void)
{
SDCARD_MUTEX_TAKE;
sdcard_mounted = 0;
/* Ensure that fast pin drivers are activated */
PIOS_SPI_IO_Init(PIOS_SDCARD_SPI, PIOS_SPI_PIN_DRIVER_STRONG);
@ -804,6 +808,16 @@ int32_t PIOS_SDCARD_StartupLog(void)
return 0;
}
/**
* Check if the SD card has been mounted
* @return 0 if no
* @return 1 if yes
*/
int32_t POIS_SDCARD_IsMounted()
{
return sdcard_mounted;
}
/**
* Mounts the file system
* param[in] CreateStartupLog 1 = True, 0 = False
@ -845,6 +859,7 @@ int32_t PIOS_SDCARD_MountFS(uint32_t CreateStartupLog)
}
/* No errors */
sdcard_mounted = 1;
return 0;
}

View File

@ -32,7 +32,7 @@
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 0
#define configUSE_ALTERNATIVE_API 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configQUEUE_REGISTRY_SIZE 10

View File

@ -99,6 +99,7 @@ extern int32_t PIOS_SDCARD_CIDRead(SDCARDCidTypeDef *cid);
extern int32_t PIOS_SDCARD_CSDRead(SDCARDCsdTypeDef *csd);
extern int32_t PIOS_SDCARD_StartupLog(void);
extern int32_t POIS_SDCARD_IsMounted();
extern int32_t PIOS_SDCARD_MountFS(uint32_t StartupLog);
extern int32_t PIOS_SDCARD_GetFree(void);