2009-11-28 10:28:11 +01:00
|
|
|
/**
|
2009-11-29 11:03:08 +01:00
|
|
|
******************************************************************************
|
2009-11-28 12:07:38 +01:00
|
|
|
*
|
2009-11-29 11:03:08 +01:00
|
|
|
* @file pios.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
|
|
|
|
* @brief Sets up main tasks, tickhook, and contains the Main function.
|
|
|
|
* - It all starts from here!
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
2009-11-29 13:38:42 +01:00
|
|
|
*
|
2009-11-29 11:03:08 +01:00
|
|
|
*****************************************************************************/
|
2009-11-28 10:28:11 +01:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
|
|
|
|
/* FreeRTOS Includes */
|
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
|
|
|
#include <queue.h>
|
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/* Local Variables */
|
|
|
|
static unsigned long ulIdleCycleCount = 0UL;
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/* Function Prototypes */
|
|
|
|
void PiosMainTask(void *pvParameters);
|
|
|
|
void SensorTask(void *pvParameters);
|
|
|
|
void ServosTask(void *pvParameters);
|
|
|
|
void vApplicationIdleHook(void);
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/**
|
|
|
|
* Main function
|
|
|
|
*/
|
2009-11-28 10:28:11 +01:00
|
|
|
int main()
|
|
|
|
{
|
2009-12-02 07:44:53 +01:00
|
|
|
/* Setup Hardware */
|
|
|
|
SysInit();
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/* 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);
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/* Start the scheduler. */
|
|
|
|
vTaskStartScheduler();
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/* If all is well we will never reach here as the scheduler will now be running. */
|
|
|
|
/* If we do get here, it will most likley be because we ran out of heap space. */
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-28 10:28:11 +01:00
|
|
|
|
|
|
|
|
2009-11-29 08:15:59 +01:00
|
|
|
/**
|
2009-12-02 07:44:53 +01:00
|
|
|
* PiosMainTask
|
2009-11-29 08:15:59 +01:00
|
|
|
*/
|
2009-12-02 07:44:53 +01:00
|
|
|
void PiosMainTask(void *pvParameters)
|
2009-11-28 10:28:11 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-29 08:15:59 +01:00
|
|
|
/**
|
2009-12-02 07:44:53 +01:00
|
|
|
* SensorTask
|
2009-11-29 08:15:59 +01:00
|
|
|
*/
|
2009-12-02 07:44:53 +01:00
|
|
|
void SensorTask(void *pvParameters)
|
2009-11-28 10:28:11 +01:00
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/**
|
|
|
|
* 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 */
|
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
2009-11-28 10:28:11 +01:00
|
|
|
|