mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
More FreeRTOS Stuff.
Added in the initial OpenPilot files. Added HooksTask. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@49 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
7b8b2155ec
commit
28e9081872
@ -56,6 +56,8 @@ OUTDIR = Build
|
||||
TARGET = OpenPilot
|
||||
|
||||
# Paths
|
||||
OPENPILOT = OpenPilot
|
||||
OPENPILOTINC = $(OPENPILOT)/inc
|
||||
PIOS = PiOS
|
||||
PIOSINC = $(PIOS)/inc
|
||||
PIOSSTM32F10X = $(PIOS)/STM32F10x
|
||||
@ -79,17 +81,20 @@ RTOSINCDIR = $(RTOSSRCDIR)/include
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
# use file-extension c for "c-only"-files
|
||||
|
||||
## OPENPILOT:
|
||||
SRC = $(OPENPILOT)/openpilot.c
|
||||
|
||||
## PIOS:
|
||||
SRC = $(PIOS)/pios.c
|
||||
SRC += $(PIOS)/pios.c
|
||||
|
||||
## PIOS Hardware (STM32F10x)
|
||||
SRC += $(PIOSSTM32F10X)/pios_sys.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_settings.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_led.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usart.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_irq.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_settings.c
|
||||
SRC += $(PIOSCOMMON)/pios_com.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
|
||||
@ -167,7 +172,9 @@ ASRCARM =
|
||||
|
||||
# List any extra directories to look for include files here.
|
||||
# Each directory must be seperated by a space.
|
||||
EXTRAINCDIRS = $(PIOS)
|
||||
EXTRAINCDIRS = $(OPENPILOT)
|
||||
EXTRAINCDIRS += $(OPENPILOTINC)
|
||||
EXTRAINCDIRS += $(PIOS)
|
||||
EXTRAINCDIRS += $(PIOSINC)
|
||||
EXTRAINCDIRS += $(PIOSSTM32F10X)
|
||||
EXTRAINCDIRS += $(PIOSCOMMON)
|
||||
|
47
flight/OpenPilot/inc/openpilot.h
Normal file
47
flight/OpenPilot/inc/openpilot.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file openpilot.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
|
||||
* @brief Main OpenPilot 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 OPENPILOT_H
|
||||
#define OPENPILOT_H
|
||||
|
||||
|
||||
/* PIOS Includes */
|
||||
#include "pios.h"
|
||||
|
||||
/* OpenPilot Includes */
|
||||
/* We use this to include all OpenPilot head files */
|
||||
|
||||
/* FreeRTOS Includes */
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <queue.h>
|
||||
|
||||
/* Function Prototypes */
|
||||
extern void OpenPilotInit(void);
|
||||
extern void vApplicationIdleHook(void);
|
||||
|
||||
|
||||
#endif /* OPENPILOT_H */
|
86
flight/OpenPilot/openpilot.c
Normal file
86
flight/OpenPilot/openpilot.c
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file openpilot.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
|
||||
* @brief Sets up ans runs main OpenPilot tasks.
|
||||
* @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
|
||||
*/
|
||||
|
||||
|
||||
/* OpenPilot Includes */
|
||||
#include "openpilot.h"
|
||||
|
||||
|
||||
/* Local Variables */
|
||||
static unsigned long ulIdleCycleCount = 0UL;
|
||||
|
||||
/* Local Functions */
|
||||
static void ServosTask(void *pvParameters);
|
||||
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
void OpenPilotInit(void)
|
||||
{
|
||||
xTaskCreate(ServosTask, (signed portCHAR *) "Servos", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Task to update servo positions at 50Hz
|
||||
*/
|
||||
static void ServosTask(void *pvParameters)
|
||||
{
|
||||
portTickType xLastWakeTime;
|
||||
|
||||
/* The xLastWakeTime variable needs to be initialized with the current tick count. */
|
||||
xLastWakeTime = xTaskGetTickCount();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
/* Update Servo positions */
|
||||
|
||||
|
||||
/* This task should execute exactly every 20 milliseconds or 50Hz
|
||||
There is no need to update the servos any faster than this */
|
||||
vTaskDelayUntil(&xLastWakeTime, (20 / portTICK_RATE_MS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Idle hook function
|
||||
*/
|
||||
void vApplicationIdleHook(void)
|
||||
{
|
||||
uint32_t IdleTimePercent = 0;
|
||||
|
||||
/* Called when the scheduler has no tasks to run */
|
||||
/* In here we could implement stats for FreeRTOS */
|
||||
|
||||
/* This can give a basic indication of how much time the system spends in idle */
|
||||
/* IdleTimePercent is the percentage of time spent in idle since the scheduler started */
|
||||
ulIdleCycleCount++;
|
||||
IdleTimePercent = ((ulIdleCycleCount / xTaskGetTickCount()) * 100);
|
||||
}
|
||||
|
@ -28,20 +28,15 @@
|
||||
/* Project Includes */
|
||||
#include "pios.h"
|
||||
|
||||
/* OpenPilot Includes */
|
||||
#include "openpilot.h"
|
||||
|
||||
/* FreeRTOS Includes */
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <queue.h>
|
||||
|
||||
/* Local Variables */
|
||||
static unsigned long ulIdleCycleCount = 0UL;
|
||||
/* Task Priorities */
|
||||
#define PRIORITY_TASK_HOOKS ( tskIDLE_PRIORITY + 3 )
|
||||
|
||||
/* Function Prototypes */
|
||||
void PiosMainTask(void *pvParameters);
|
||||
void SensorTask(void *pvParameters);
|
||||
void ServosTask(void *pvParameters);
|
||||
void vApplicationIdleHook(void);
|
||||
static void HooksTask(void *pvParameters);
|
||||
|
||||
|
||||
/**
|
||||
* Main function
|
||||
@ -51,12 +46,13 @@ int main()
|
||||
/* Setup Hardware */
|
||||
SysInit();
|
||||
|
||||
/* Start Main tasks. */
|
||||
xTaskCreate(PiosMainTask, (signed portCHAR *) "PiosMain", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
|
||||
xTaskCreate(SensorTask, (signed portCHAR *) "Sensor", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
|
||||
xTaskCreate(ServosTask, (signed portCHAR *) "Servos", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
|
||||
/* Initialise OpenPilot */
|
||||
OpenPilotInit();
|
||||
|
||||
/* *tart the task which calls the application hooks */
|
||||
xTaskCreate(HooksTask, (signed portCHAR *)"Hooks", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_HOOKS, NULL);
|
||||
|
||||
/* Start the scheduler. */
|
||||
/* Start the scheduler */
|
||||
vTaskStartScheduler();
|
||||
|
||||
/* If all is well we will never reach here as the scheduler will now be running. */
|
||||
@ -64,62 +60,25 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PiosMainTask
|
||||
*/
|
||||
void PiosMainTask(void *pvParameters)
|
||||
static void HooksTask(void *pvParameters)
|
||||
{
|
||||
portTickType xLastExecutionTime;
|
||||
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
// Initialise the xLastExecutionTime variable on task entry
|
||||
xLastExecutionTime = xTaskGetTickCount();
|
||||
|
||||
/**
|
||||
* SensorTask
|
||||
*/
|
||||
void SensorTask(void *pvParameters)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Task to update servo positions at 50Hz
|
||||
*/
|
||||
void ServosTask(void *pvParameters)
|
||||
{
|
||||
portTickType xLastWakeTime;
|
||||
|
||||
/* The xLastWakeTime variable needs to be initialized with the current tick count. */
|
||||
xLastWakeTime = xTaskGetTickCount();
|
||||
|
||||
for(;;)
|
||||
{
|
||||
/* Update Servo positions */
|
||||
while(1) {
|
||||
vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
|
||||
|
||||
/* Skip delay gap if we had to wait for more than 5 ticks to avoid */
|
||||
/* unnecessary repeats until xLastExecutionTime reached xTaskGetTickCount() again */
|
||||
portTickType xCurrentTickCount = xTaskGetTickCount();
|
||||
if(xLastExecutionTime < (xCurrentTickCount - 5)) {
|
||||
xLastExecutionTime = xCurrentTickCount;
|
||||
}
|
||||
|
||||
|
||||
/* This task should execute exactly every 20 milliseconds or 50Hz
|
||||
There is no need to update the servos any faster than this */
|
||||
vTaskDelayUntil(&xLastWakeTime, (20 / portTICK_RATE_MS));
|
||||
/* Check for incoming COM messages */
|
||||
COMReceiveHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Idle hook function
|
||||
*/
|
||||
void vApplicationIdleHook(void)
|
||||
{
|
||||
uint32_t IdleTimePercent = 0;
|
||||
|
||||
/* Called when the scheduler has no tasks to run */
|
||||
/* In here we could implement stats for FreeRTOS */
|
||||
|
||||
/* This can give a basic indication of how much time the system spends in idle */
|
||||
/* IdleTimePercent is the percentage of time spent in idle since the scheduler started */
|
||||
ulIdleCycleCount++;
|
||||
IdleTimePercent = ((ulIdleCycleCount / xTaskGetTickCount()) * 100);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user