diff --git a/flight/OpenPilot/System/inc/FreeRTOSConfig.h b/flight/OpenPilot/System/inc/FreeRTOSConfig.h index c2a07fa67..6336639a4 100644 --- a/flight/OpenPilot/System/inc/FreeRTOSConfig.h +++ b/flight/OpenPilot/System/inc/FreeRTOSConfig.h @@ -75,7 +75,7 @@ NVIC value of 255. */ #if defined(DEBUG) #define configGENERATE_RUN_TIME_STATS 1 #define INCLUDE_uxTaskGetRunTime 1 -#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() PIOS_RTC_Start() +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() PIOS_RTC_Init() // Note: Using the tick count defeats the purpose here, need some timer on the scale of 10khz #define portGET_RUN_TIME_COUNTER_VALUE() PIOS_RTC_Counter() #endif diff --git a/flight/OpenPilot/System/pios_board.c b/flight/OpenPilot/System/pios_board.c index ccbf8fced..57605ad9d 100644 --- a/flight/OpenPilot/System/pios_board.c +++ b/flight/OpenPilot/System/pios_board.c @@ -1049,6 +1049,7 @@ void PIOS_Board_Init(void) { #if defined(PIOS_INCLUDE_SPEKTRUM) /* SPEKTRUM init must come before comms */ + PIOS_RTC_Init(); // Spektrum uses RTC to check for frame failures PIOS_SPEKTRUM_Init(); if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) { diff --git a/flight/PiOS/STM32F10x/Libraries/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h b/flight/PiOS/STM32F10x/Libraries/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h index 81839c07f..caee2a839 100755 --- a/flight/PiOS/STM32F10x/Libraries/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h +++ b/flight/PiOS/STM32F10x/Libraries/FreeRTOS/Source/portable/GCC/ARM_CM3/portmacro.h @@ -138,7 +138,7 @@ extern void vPortYieldFromISR( void ); extern void vPortEnterCritical( void ); extern void vPortExitCritical( void ); -void PIOS_RTC_Start(); +void PIOS_RTC_Init(); uint32_t PIOS_RTC_Counter(); #define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK() diff --git a/flight/PiOS/STM32F10x/pios_rtc.c b/flight/PiOS/STM32F10x/pios_rtc.c index 0a950e913..1f1769621 100644 --- a/flight/PiOS/STM32F10x/pios_rtc.c +++ b/flight/PiOS/STM32F10x/pios_rtc.c @@ -33,7 +33,11 @@ #if defined(PIOS_INCLUDE_RTC) -void PIOS_RTC_Start() +#ifndef PIOS_RTC_PRESCALAR +#define PIOS_RTC_PRESCALAR 0 +#endif + +void PIOS_RTC_Init() { RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR, ENABLE); @@ -44,7 +48,7 @@ void PIOS_RTC_Start() RTC_WaitForLastTask(); RTC_WaitForSynchro(); RTC_WaitForLastTask(); - RTC_SetPrescaler(0); // counting at 8e6 / 128 + RTC_SetPrescaler(PIOS_RTC_PRESCALAR); // counting at 8e6 / 128 RTC_WaitForLastTask(); RTC_SetCounter(0); RTC_WaitForLastTask(); @@ -55,6 +59,15 @@ uint32_t PIOS_RTC_Counter() return RTC_GetCounter(); } +float PIOS_RTC_Rate() +{ + return (float) (8e6 / 128) / (1 + PIOS_RTC_PRESCALAR); +} + +float PIOS_RTC_MsPerTick() +{ + return 1000.0f / PIOS_RTC_Rate(); +} #endif diff --git a/flight/PiOS/inc/pios_rtc.h b/flight/PiOS/inc/pios_rtc.h index c9ad5661f..0c9183d00 100644 --- a/flight/PiOS/inc/pios_rtc.h +++ b/flight/PiOS/inc/pios_rtc.h @@ -31,8 +31,10 @@ #define PIOS_SERVO_H /* Public Functions */ -extern void PIOS_RTC_Start(); +extern void PIOS_RTC_Init(); extern uint32_t PIOS_RTC_Counter(); +extern float PIOS_RTC_Rate(); +extern float PIOS_RTC_MsPerTick(); #endif /* PIOS_SERVO_H */