mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Fixed DELAY module. Now uses TIM2 and conforms to standard coding practices.
Added temporary flashing function as an easy way to know things are working. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@131 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
1320fc06be
commit
90f1fab5fe
@ -32,45 +32,43 @@
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the Timer used by PIOS_DELAY functions<BR>
|
||||
* Initialises 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 TIM7 for this on Hardware V1. Can be changed
|
||||
* with PIOS_DELAY_TIMER and PIOS_DELAY_TIMER_RCC the
|
||||
* board_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);
|
||||
/* 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);
|
||||
/* Time base configuration */
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
TIM_TimeBaseStructInit(&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);
|
||||
/* Enable counter */
|
||||
TIM_Cmd(PIOS_DELAY_TIMER, ENABLE);
|
||||
|
||||
return 0; // no error
|
||||
/* No error */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for a specific number of uS<BR>
|
||||
* Example:<BR>
|
||||
* \code
|
||||
* // wait for 500 uS
|
||||
* // Wait for 500 uS
|
||||
* PIOS_DELAY_Wait_uS(500);
|
||||
* \endcode
|
||||
* \param[in] uS delay (1..65535 microseconds)
|
||||
@ -78,10 +76,11 @@ int32_t PIOS_DELAY_Init(void)
|
||||
*/
|
||||
int32_t PIOS_DELAY_Wait_uS(uint16_t uS)
|
||||
{
|
||||
uint16_t start = PIOS_DELAY_TIMER->CNT;
|
||||
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 );
|
||||
/* Note that this event works on 16bit counter wrap-arounds */
|
||||
while((uint16_t)(PIOS_DELAY_TIMER->CNT - start) <= uS);
|
||||
|
||||
return 0; // no error
|
||||
/* No error */
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,7 +33,6 @@
|
||||
void NVIC_Configuration(void);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes all system peripherals
|
||||
*/
|
||||
|
@ -213,8 +213,8 @@
|
||||
//-------------------------
|
||||
// Delay Timer
|
||||
//-------------------------
|
||||
#define PIOS_DELAY_TIMER TIM7
|
||||
#define PIOS_DELAY_TIMER_RCC RCC_APB1Periph_TIM7
|
||||
#define PIOS_DELAY_TIMER TIM2
|
||||
#define PIOS_DELAY_TIMER_RCC RCC_APB1Periph_TIM2
|
||||
|
||||
//-------------------------
|
||||
// Master Clock
|
||||
|
@ -41,7 +41,8 @@ static uint32_t IdleTimePercent = 0;
|
||||
void vApplicationIdleHook(void);
|
||||
|
||||
/* Function Prototypes */
|
||||
void TestTask( void *pvParameters );
|
||||
void TestTask(void *pvParameters);
|
||||
void Flashy(void);
|
||||
|
||||
/**
|
||||
* Main function
|
||||
@ -56,6 +57,8 @@ int main()
|
||||
/* Delay system */
|
||||
PIOS_DELAY_Init();
|
||||
|
||||
Flashy();
|
||||
|
||||
/* Enables the SDCard */
|
||||
// PIOS_SDCARD_Init();
|
||||
|
||||
@ -80,11 +83,27 @@ int main()
|
||||
vTaskStartScheduler();
|
||||
|
||||
/* 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. */
|
||||
/* If we do get here, it will most likely be because we ran out of heap space. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
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++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestTask( void *pvParameters )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user