1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Delay module.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@118 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
dankers 2009-12-24 02:51:20 +00:00 committed by dankers
parent 6c2d90cd11
commit 282cf5c43e
5 changed files with 132 additions and 14 deletions

View File

@ -89,6 +89,7 @@ SRC += $(PIOS)/pios.c
## PIOS Hardware (STM32F10x) ## PIOS Hardware (STM32F10x)
SRC += $(PIOSSTM32F10X)/pios_sys.c SRC += $(PIOSSTM32F10X)/pios_sys.c
SRC += $(PIOSSTM32F10X)/pios_led.c SRC += $(PIOSSTM32F10X)/pios_led.c
SRC += $(PIOSSTM32F10X)/pios_delay.c
SRC += $(PIOSSTM32F10X)/pios_usart.c SRC += $(PIOSSTM32F10X)/pios_usart.c
SRC += $(PIOSSTM32F10X)/pios_irq.c SRC += $(PIOSSTM32F10X)/pios_irq.c
SRC += $(PIOSSTM32F10X)/pios_adc.c SRC += $(PIOSSTM32F10X)/pios_adc.c

View File

@ -0,0 +1,87 @@
/**
******************************************************************************
*
* @file pios_delay.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
* @brief Delay Functions
* - Provides a micro-second granular delay using a TIM
* @see The GNU Public License (GPL) Version 3
* @defgroup PIOS_DELAY Delay 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
*/
/* Project Includes */
#include "pios.h"
/**
* Initializes the Timer used by PIOS_DELAY functions<BR>
* This is called from pios.c as part of the main() function
* at system start up.
*
* We use TIM8 for this on Hardware V1. Can be changed
* with PIOS_DELAY_TIMER and PIOS_DELAY_TIMER_RCC the
* pios_config.h file.
*
* \return < 0 if initialisation failed
*/
int32_t PIOS_DELAY_Init(void)
{
// enable timer clock
if( PIOS_DELAY_TIMER_RCC == RCC_APB2Periph_TIM1 || PIOS_DELAY_TIMER_RCC == RCC_APB2Periph_TIM8 )
RCC_APB2PeriphClockCmd(PIOS_DELAY_TIMER_RCC, ENABLE);
else
RCC_APB1PeriphClockCmd(PIOS_DELAY_TIMER_RCC, ENABLE);
// time base configuration
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 65535; // maximum value
TIM_TimeBaseStructure.TIM_Prescaler = 72-1; // for 1 uS accuracy fixed to 72Mhz
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(PIOS_DELAY_TIMER, &TIM_TimeBaseStructure);
// enable counter
TIM_Cmd(PIOS_DELAY_TIMER, ENABLE);
return 0; // no error
}
/**
* Waits for a specific number of uS<BR>
* Example:<BR>
* \code
* // wait for 500 uS
* PIOS_DELAY_Wait_uS(500);
* \endcode
* \param[in] uS delay (1..65535 microseconds)
* \return < 0 on errors
*/
int32_t PIOS_DELAY_Wait_uS(uint16_t uS)
{
uint16_t start = PIOS_DELAY_TIMER->CNT;
// note that this event works on 16bit counter wrap-arounds
while( (uint16_t)(PIOS_DELAY_TIMER->CNT - start) <= uS );
return 0; // no error
}

View File

@ -0,0 +1,35 @@
/**
******************************************************************************
*
* @file pios_settings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2009.
* @brief Settings 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 PIOS_DELAY_H
#define PIOS_DELAY_H
/* Public Functions */
extern int32_t PIOS_DELAY_Init(void);
extern int32_t PIOS_DELAY_Wait_uS(uint16_t uS);
#endif /* PIOS_DELAY_H */

View File

@ -42,7 +42,6 @@ void vApplicationIdleHook(void);
/* Function Prototypes */ /* Function Prototypes */
void TestTask( void *pvParameters ); void TestTask( void *pvParameters );
void DiskTask( void *pvParameters );
/** /**
* Main function * Main function
@ -54,8 +53,8 @@ int main()
enables the LEDs. */ enables the LEDs. */
PIOS_SYS_Init(); PIOS_SYS_Init();
xTaskCreate( TestTask, ( signed portCHAR * ) "Test", configMINIMAL_STACK_SIZE , NULL, 2, NULL ); /* Delay system */
xTaskCreate( DiskTask, ( signed portCHAR * ) "Disk", configMINIMAL_STACK_SIZE , NULL, 4, NULL ); PIOS_DELAY_Init();
/* Enables the SDCard */ /* Enables the SDCard */
// PIOS_SDCARD_Init(); // PIOS_SDCARD_Init();
@ -73,6 +72,10 @@ int main()
/* Initialise OpenPilot application */ /* Initialise OpenPilot application */
// OpenPilotInit(); // OpenPilotInit();
/* Create a FreeRTOS task */
xTaskCreate( TestTask, ( signed portCHAR * ) "Test", configMINIMAL_STACK_SIZE , NULL, 2, NULL );
/* Start the FreeRTOS scheduler */ /* Start the FreeRTOS scheduler */
vTaskStartScheduler(); vTaskStartScheduler();
@ -81,6 +84,8 @@ int main()
return 0; return 0;
} }
void TestTask( void *pvParameters ) void TestTask( void *pvParameters )
{ {
const portTickType xDelay = 500 / portTICK_RATE_MS; const portTickType xDelay = 500 / portTICK_RATE_MS;
@ -93,17 +98,6 @@ const portTickType xDelay = 500 / portTICK_RATE_MS;
} }
void DiskTask( void *pvParameters )
{
const portTickType xDelay = 10 / portTICK_RATE_MS;
while(1)
{
disk_timerproc();
vTaskDelay(xDelay);
}
}
/** /**
* Idle hook function * Idle hook function

View File

@ -53,6 +53,7 @@
/* PIOS Hardware Includes (STM32F10x) */ /* PIOS Hardware Includes (STM32F10x) */
#include <pios_board.h> #include <pios_board.h>
#include <pios_sys.h> #include <pios_sys.h>
#include <pios_delay.h>
#include <pios_led.h> #include <pios_led.h>
#include <pios_sdcard.h> #include <pios_sdcard.h>
#include <pios_usart.h> #include <pios_usart.h>