1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-15 07:29:15 +01:00

Added OpenPilot Logging functions, tasks.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@55 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
gussy 2009-12-04 20:33:18 +00:00 committed by gussy
parent 67540d1c26
commit 4e4b50e187
6 changed files with 163 additions and 10 deletions

View File

@ -82,7 +82,8 @@ RTOSINCDIR = $(RTOSSRCDIR)/include
# use file-extension c for "c-only"-files
## OPENPILOT:
SRC = $(OPENPILOT)/openpilot.c
SRC = $(OPENPILOT)/openpilot.c
SRC += $(OPENPILOT)/op_logging.c
## PIOS:
SRC += $(PIOS)/pios.c

View File

@ -0,0 +1,45 @@
/**
******************************************************************************
*
* @file op_logging.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
* @brief OpenPilot Logging Functions header.
* @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 OP_LOGGING_H
#define OP_LOGGING_H
/* Defines */
#define OP_LOGGING_TASK_PRI ( tskIDLE_PRIORITY + 5 )
/* Type Definitions */
typedef enum {FLIGHT_LOG, RC_LOG} LogTypeTypeDef;
typedef struct {
LogTypeTypeDef Type;
char *Message;
} LogTypeDef;
/* Function Prototypes */
extern void OP_Logging_Init(void);
#endif /* OP_LOGGING_H */

View File

@ -32,18 +32,14 @@
#include "pios.h"
/* OpenPilot Includes */
/* We use this to include all OpenPilot head files */
#include "op_logging.h"
/* FreeRTOS Includes */
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
/* Function Prototypes */
/* Global Functions */
extern void OpenPilotInit(void);
extern void vApplicationIdleHook(void);
/* Hooks */
extern void ADCNotifyChange(uint32_t pin, uint32_t pin_value);
#endif /* OPENPILOT_H */

View File

@ -0,0 +1,100 @@
/**
******************************************************************************
*
* @file op_logging.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
* @brief OpenPilot Logging Functions
* @see The GNU Public License (GPL) Version 3
* @defgroup OP_LOGGING Logging Functions
* @{
*
*****************************************************************************/
/*
* 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
*/
/* OpenPilot Includes */
#include "openpilot.h"
/* Global Variables */
xQueueHandle xLoggingQueue;
/* Local Variables */
static uint8_t FlightLogFilename[128];
/* Local Functions */
static void OP_Logging_MicroSDGateKeeperTask(void *pvParameters);
/**
* Main function
*/
void OP_Logging_Init(void)
{
uint16_t FileCount;
FILINFO DummyFileInfo;
/* This is a crude way to file the next avaiable number avaiable */
/* The proper way would be to use folders with dates, we will get to that later */
for(FileCount = 0; FileCount < 65536; FileCount++) {
sprintf((char *)FlightLogFilename, "Flight_Log_%d.txt", FileCount);
if(f_stat((char *)FlightLogFilename, &DummyFileInfo) != FR_OK) {
/* We have come to a file that doesn't extist */
break;
}
}
/* Start the gatekeeper task */
xTaskCreate(OP_Logging_MicroSDGateKeeperTask, (signed portCHAR *) "Logging_MicroSDGateKeeperTask", configMINIMAL_STACK_SIZE, NULL, OP_LOGGING_TASK_PRI, NULL);
}
/**
* Task to handle the MicroSD log que
*/
void OP_Logging_MicroSDGateKeeperTask(void *pvParameters)
{
FIL File;
LogTypeDef pcMessageToLog;
for(;;) {
xQueueReceive(xLoggingQueue, &pcMessageToLog, portMAX_DELAY);
/* We don't want this take to get pre-empted, so enter critical state */
/* If we do get pre-empted we face corrupting the MicroSD filesystem */
taskENTER_CRITICAL();
/* Open the correct log file */
switch(pcMessageToLog.Type) {
case FLIGHT_LOG:
f_open(&File, (char *)FlightLogFilename, FA_OPEN_EXISTING);
break;
case RC_LOG:
break;
}
/* Write the stuff */
f_puts(pcMessageToLog.Message, &File);
/* Sync the MicroSD Card */
f_sync(&File);
/* Close the file */
f_close(&File);
/* Exit the critical stage */
taskEXIT_CRITICAL();
}
}

View File

@ -29,7 +29,7 @@
/* Local Variables */
static uint16_t adc_pin_values[4];
//static uint16_t adc_pin_values[4];
/* Local Functions */
static void ServosTask(void *pvParameters);
@ -40,6 +40,10 @@ static void ServosTask(void *pvParameters);
*/
void OpenPilotInit(void)
{
/* Initialise Logging */
OP_Logging_Init();
xTaskCreate(ServosTask, (signed portCHAR *) "Servos", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
@ -66,11 +70,14 @@ static void ServosTask(void *pvParameters)
}
}
/**
* This hook is called every time the
*/
/* Do we really need to use this callback stuff for analog changes?? We should just use PIOS_ADC_PinGet()
void ADCNotifyChange(uint32_t pin, uint32_t pin_value)
{
/* All we really need to do here is store the values in a local array. */
// All we really need to do here is store the values in a local array.
adc_pin_values[pin] = (uint16_t) pin_value;
}
*/

View File

@ -38,6 +38,10 @@
static uint32_t ulIdleCycleCount = 0;
static uint32_t IdleTimePercent = 0;
/* Global Functions */
void vApplicationIdleHook(void);
/* Function Prototypes */
static void HooksTask(void *pvParameters);
@ -84,7 +88,7 @@ static void HooksTask(void *pvParameters)
}
/* Check for ADC pin changes, call ADCNotifyChange on each pin change */
ADCHandler(ADCNotifyChange);
//ADCHandler(ADCNotifyChange);
/* Check for incoming COM messages */
COMReceiveHandler();