mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-04-10 02:02:21 +02: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
|
* This is called from pios.c as part of the main() function
|
||||||
* at system start up.
|
* 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
|
* \return < 0 if initialisation failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
int32_t PIOS_DELAY_Init(void)
|
int32_t PIOS_DELAY_Init(void)
|
||||||
{
|
{
|
||||||
// enable timer clock
|
/* Enable timer clock */
|
||||||
if( PIOS_DELAY_TIMER_RCC == RCC_APB2Periph_TIM1 || PIOS_DELAY_TIMER_RCC == RCC_APB2Periph_TIM8 )
|
if(PIOS_DELAY_TIMER_RCC == RCC_APB2Periph_TIM1 || PIOS_DELAY_TIMER_RCC == RCC_APB2Periph_TIM8) {
|
||||||
RCC_APB2PeriphClockCmd(PIOS_DELAY_TIMER_RCC, ENABLE);
|
RCC_APB2PeriphClockCmd(PIOS_DELAY_TIMER_RCC, ENABLE);
|
||||||
else
|
} else {
|
||||||
RCC_APB1PeriphClockCmd(PIOS_DELAY_TIMER_RCC, ENABLE);
|
RCC_APB1PeriphClockCmd(PIOS_DELAY_TIMER_RCC, ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
// time base configuration
|
/* Time base configuration */
|
||||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||||
TIM_TimeBaseStructure.TIM_Period = 65535; // maximum value
|
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||||
TIM_TimeBaseStructure.TIM_Prescaler = 72-1; // for 1 uS accuracy fixed to 72Mhz
|
TIM_TimeBaseStructure.TIM_Period = 65535; // maximum value
|
||||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
TIM_TimeBaseStructure.TIM_Prescaler = 72-1; // for 1 uS accuracy fixed to 72Mhz
|
||||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||||
TIM_TimeBaseInit(PIOS_DELAY_TIMER, &TIM_TimeBaseStructure);
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||||
|
TIM_TimeBaseInit(PIOS_DELAY_TIMER, &TIM_TimeBaseStructure);
|
||||||
|
|
||||||
// enable counter
|
/* Enable counter */
|
||||||
TIM_Cmd(PIOS_DELAY_TIMER, ENABLE);
|
TIM_Cmd(PIOS_DELAY_TIMER, ENABLE);
|
||||||
|
|
||||||
return 0; // no error
|
/* No error */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for a specific number of uS<BR>
|
* Waits for a specific number of uS<BR>
|
||||||
* Example:<BR>
|
* Example:<BR>
|
||||||
* \code
|
* \code
|
||||||
* // wait for 500 uS
|
* // Wait for 500 uS
|
||||||
* PIOS_DELAY_Wait_uS(500);
|
* PIOS_DELAY_Wait_uS(500);
|
||||||
* \endcode
|
* \endcode
|
||||||
* \param[in] uS delay (1..65535 microseconds)
|
* \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)
|
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
|
/* Note that this event works on 16bit counter wrap-arounds */
|
||||||
while( (uint16_t)(PIOS_DELAY_TIMER->CNT - start) <= uS );
|
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);
|
void NVIC_Configuration(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all system peripherals
|
* Initializes all system peripherals
|
||||||
*/
|
*/
|
||||||
|
@ -213,8 +213,8 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
// Delay Timer
|
// Delay Timer
|
||||||
//-------------------------
|
//-------------------------
|
||||||
#define PIOS_DELAY_TIMER TIM7
|
#define PIOS_DELAY_TIMER TIM2
|
||||||
#define PIOS_DELAY_TIMER_RCC RCC_APB1Periph_TIM7
|
#define PIOS_DELAY_TIMER_RCC RCC_APB1Periph_TIM2
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
// Master Clock
|
// Master Clock
|
||||||
|
@ -41,7 +41,8 @@ static uint32_t IdleTimePercent = 0;
|
|||||||
void vApplicationIdleHook(void);
|
void vApplicationIdleHook(void);
|
||||||
|
|
||||||
/* Function Prototypes */
|
/* Function Prototypes */
|
||||||
void TestTask( void *pvParameters );
|
void TestTask(void *pvParameters);
|
||||||
|
void Flashy(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function
|
* Main function
|
||||||
@ -56,6 +57,8 @@ int main()
|
|||||||
/* Delay system */
|
/* Delay system */
|
||||||
PIOS_DELAY_Init();
|
PIOS_DELAY_Init();
|
||||||
|
|
||||||
|
Flashy();
|
||||||
|
|
||||||
/* Enables the SDCard */
|
/* Enables the SDCard */
|
||||||
// PIOS_SDCARD_Init();
|
// PIOS_SDCARD_Init();
|
||||||
|
|
||||||
@ -80,11 +83,27 @@ int main()
|
|||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
/* If all is well we will never reach here as the scheduler will now be running. */
|
/* 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;
|
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 )
|
void TestTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user