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"
|
|
|
|
|
2009-12-02 12:07:56 +01:00
|
|
|
/* OpenPilot Includes */
|
2009-12-11 19:48:48 +01:00
|
|
|
#include <openpilot.h>
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 12:07:56 +01:00
|
|
|
/* Task Priorities */
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2009-12-02 22:49:31 +01:00
|
|
|
/* Local Variables */
|
|
|
|
static uint32_t ulIdleCycleCount = 0;
|
|
|
|
static uint32_t IdleTimePercent = 0;
|
|
|
|
|
2009-12-04 21:33:18 +01:00
|
|
|
/* Global Functions */
|
|
|
|
void vApplicationIdleHook(void);
|
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/* Function Prototypes */
|
2010-01-21 00:48:04 +01:00
|
|
|
void TickTask(void *pvParameters);
|
2010-01-20 09:16:35 +01:00
|
|
|
void Flashy(void);
|
2010-01-21 00:48:04 +01:00
|
|
|
void SysTick_Handler(void);
|
2009-12-23 08:39:34 +01:00
|
|
|
|
2009-12-02 07:44:53 +01:00
|
|
|
/**
|
|
|
|
* Main function
|
|
|
|
*/
|
2009-11-28 10:28:11 +01:00
|
|
|
int main()
|
|
|
|
{
|
2009-12-21 04:57:30 +01:00
|
|
|
|
|
|
|
/* Brings up System using CMSIS functions,
|
2009-12-22 20:32:47 +01:00
|
|
|
enables the LEDs. */
|
2009-12-08 03:13:21 +01:00
|
|
|
PIOS_SYS_Init();
|
2009-12-22 20:32:47 +01:00
|
|
|
|
2009-12-24 03:51:20 +01:00
|
|
|
/* Delay system */
|
|
|
|
PIOS_DELAY_Init();
|
2009-12-23 11:34:26 +01:00
|
|
|
|
2009-12-22 20:32:47 +01:00
|
|
|
/* Enables the SDCard */
|
2010-01-21 00:48:04 +01:00
|
|
|
PIOS_SDCARD_Init();
|
|
|
|
|
|
|
|
/* Call LoadSettings which populates System Vars
|
2009-12-21 05:07:29 +01:00
|
|
|
so the rest of the hardware can be configured. */
|
2010-01-21 00:48:04 +01:00
|
|
|
//PIOS_Settings_Load();
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
|
|
|
|
}
|
2009-12-21 05:07:29 +01:00
|
|
|
|
2009-12-21 04:57:30 +01:00
|
|
|
/* Com ports init */
|
2009-12-22 06:08:59 +01:00
|
|
|
// PIOS_COM_Init();
|
2009-12-21 04:57:30 +01:00
|
|
|
|
|
|
|
/* Analog to digi init */
|
2009-12-22 06:08:59 +01:00
|
|
|
// PIOS_ADC_Init();
|
2009-12-02 22:49:31 +01:00
|
|
|
|
2009-12-21 04:57:30 +01:00
|
|
|
/* Initialise OpenPilot application */
|
2009-12-22 06:08:59 +01:00
|
|
|
// OpenPilotInit();
|
2009-12-23 08:14:52 +01:00
|
|
|
|
2009-12-24 03:51:20 +01:00
|
|
|
|
|
|
|
/* Create a FreeRTOS task */
|
2010-01-21 00:48:04 +01:00
|
|
|
xTaskCreate(TickTask, (signed portCHAR *) "Test", configMINIMAL_STACK_SIZE , NULL, 2, NULL);
|
2009-12-24 03:51:20 +01:00
|
|
|
|
2009-12-21 04:57:30 +01:00
|
|
|
/* Start the FreeRTOS scheduler */
|
2009-12-02 07:44:53 +01:00
|
|
|
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. */
|
2010-01-20 09:16:35 +01:00
|
|
|
/* If we do get here, it will most likely be because we ran out of heap space. */
|
2009-12-02 07:44:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2009-11-28 10:28:11 +01:00
|
|
|
|
2010-01-20 09:16:35 +01:00
|
|
|
void Flashy(void)
|
|
|
|
{
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
/* Setup the LEDs to Alternate */
|
|
|
|
PIOS_LED_On(LED1);
|
|
|
|
PIOS_LED_Off(LED2);
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
PIOS_LED_Toggle(LED1);
|
|
|
|
PIOS_LED_Toggle(LED2);
|
|
|
|
for(int i = 0; i < 1000000; i++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-24 03:51:20 +01:00
|
|
|
|
2010-01-21 00:48:04 +01:00
|
|
|
void TickTask(void *pvParameters)
|
2009-11-28 10:28:11 +01:00
|
|
|
{
|
2010-01-21 00:48:04 +01:00
|
|
|
const portTickType xDelay = 10 / portTICK_RATE_MS;
|
2009-12-23 08:14:52 +01:00
|
|
|
|
2010-01-21 00:48:04 +01:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
PIOS_LED_Toggle(LED2);
|
|
|
|
vTaskDelay(xDelay);
|
|
|
|
}
|
2009-12-02 22:49:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Idle hook function
|
|
|
|
*/
|
|
|
|
void vApplicationIdleHook(void)
|
|
|
|
{
|
|
|
|
/* Called when the scheduler has no tasks to run */
|
2009-12-15 13:17:11 +01:00
|
|
|
|
2009-12-02 22:49:31 +01:00
|
|
|
/* In here we could implement full stats for FreeRTOS
|
|
|
|
Although this would need us to enable stats in FreeRTOS
|
|
|
|
which is *very* costly. With the function below we can
|
|
|
|
either print it out or just watch the variable using JTAG */
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
/* For example a value of 75 would mean we are spending 75% of FreeRTOS Cycles in idle */
|
|
|
|
ulIdleCycleCount++;
|
|
|
|
IdleTimePercent = ((ulIdleCycleCount / xTaskGetTickCount()) * 100);
|
|
|
|
}
|
2009-12-15 13:17:11 +01:00
|
|
|
|