1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-11 19:24:10 +01:00

bl: alternate stopwatch for small bootloaders

The small bootloaders (CC and PipX) are out of flash space
so their stopwatch implementation has been swapped out for
one based on the DELAY clock that takes about 500 bytes less
of code space.

Identical functionality is preserved.
This commit is contained in:
Stacey Sheldon 2011-07-29 13:50:46 -04:00
parent a3888ecd48
commit 8b0415d905
6 changed files with 53 additions and 46 deletions

View File

@ -94,8 +94,6 @@ DOXYGENDIR = ../Doc/Doxygen
SRC += $(OPSYSTEM)/main.c SRC += $(OPSYSTEM)/main.c
SRC += $(OPSYSTEM)/pios_board.c SRC += $(OPSYSTEM)/pios_board.c
SRC += $(OPSYSTEM)/op_dfu.c SRC += $(OPSYSTEM)/op_dfu.c
SRC += $(FLIGHTLIB)/stopwatch.c
## PIOS Hardware (STM32F10x) ## PIOS Hardware (STM32F10x)
SRC += $(PIOSSTM32F10X)/pios_sys.c SRC += $(PIOSSTM32F10X)/pios_sys.c
@ -139,7 +137,6 @@ SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
SRC += $(STMSPDSRCDIR)/misc.c SRC += $(STMSPDSRCDIR)/misc.c

View File

@ -28,7 +28,6 @@
/* Bootloader Includes */ /* Bootloader Includes */
#include <pios.h> #include <pios.h>
#include <pios_board_info.h> #include <pios_board_info.h>
#include "stopwatch.h"
#include "op_dfu.h" #include "op_dfu.h"
#include "usb_lib.h" #include "usb_lib.h"
#include "pios_iap.h" #include "pios_iap.h"
@ -47,9 +46,9 @@ pFunction Jump_To_Application;
uint32_t JumpAddress; uint32_t JumpAddress;
/// LEDs PWM /// LEDs PWM
uint32_t period1 = 50; // *100 uS -> 5 mS uint32_t period1 = 5000; // 5 mS
uint32_t sweep_steps1 = 100; // * 5 mS -> 500 mS uint32_t sweep_steps1 = 100; // * 5 mS -> 500 mS
uint32_t period2 = 50; // *100 uS -> 5 mS uint32_t period2 = 5000; // 5 mS
uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS
@ -70,7 +69,6 @@ uint8_t processRX();
void jump_to_app(); void jump_to_app();
#define BLUE LED1 #define BLUE LED1
#define LED_PWM_TIMER TIM1
int main() { int main() {
PIOS_SYS_Init(); PIOS_SYS_Init();
if (BSL_HOLD_STATE == 0) if (BSL_HOLD_STATE == 0)
@ -93,13 +91,17 @@ int main() {
DeviceState = DFUidle; DeviceState = DFUidle;
else else
DeviceState = BLidle; DeviceState = BLidle;
STOPWATCH_Init(100, LED_PWM_TIMER);
} else } else
JumpToApp = TRUE; JumpToApp = TRUE;
STOPWATCH_Reset(LED_PWM_TIMER); uint32_t stopwatch = 0;
uint32_t prev_ticks = PIOS_DELAY_GetuS();
while (TRUE) { while (TRUE) {
/* Update the stopwatch */
uint32_t elapsed_ticks = PIOS_DELAY_GetuSSince(prev_ticks);
prev_ticks += elapsed_ticks;
stopwatch += elapsed_ticks;
if (JumpToApp == TRUE) if (JumpToApp == TRUE)
jump_to_app(); jump_to_app();
@ -107,19 +109,19 @@ int main() {
case Last_operation_Success: case Last_operation_Success:
case uploadingStarting: case uploadingStarting:
case DFUidle: case DFUidle:
period1 = 50; period1 = 5000;
sweep_steps1 = 100; sweep_steps1 = 100;
PIOS_LED_Off(BLUE); PIOS_LED_Off(BLUE);
period2 = 0; period2 = 0;
break; break;
case uploading: case uploading:
period1 = 50; period1 = 5000;
sweep_steps1 = 100; sweep_steps1 = 100;
period2 = 25; period2 = 2500;
sweep_steps2 = 50; sweep_steps2 = 50;
break; break;
case downloading: case downloading:
period1 = 25; period1 = 2500;
sweep_steps1 = 50; sweep_steps1 = 50;
PIOS_LED_Off(BLUE); PIOS_LED_Off(BLUE);
period2 = 0; period2 = 0;
@ -130,14 +132,14 @@ int main() {
period2 = 0; period2 = 0;
break; break;
default://error default://error
period1 = 50; period1 = 5000;
sweep_steps1 = 100; sweep_steps1 = 100;
period2 = 50; period2 = 5000;
sweep_steps2 = 100; sweep_steps2 = 100;
} }
if (period1 != 0) { if (period1 != 0) {
if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet(LED_PWM_TIMER))) if (LedPWM(period1, sweep_steps1, stopwatch))
PIOS_LED_On(BLUE); PIOS_LED_On(BLUE);
else else
PIOS_LED_Off(BLUE); PIOS_LED_Off(BLUE);
@ -145,16 +147,16 @@ int main() {
PIOS_LED_On(BLUE); PIOS_LED_On(BLUE);
if (period2 != 0) { if (period2 != 0) {
if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet(LED_PWM_TIMER))) if (LedPWM(period2, sweep_steps2, stopwatch))
PIOS_LED_On(BLUE); PIOS_LED_On(BLUE);
else else
PIOS_LED_Off(BLUE); PIOS_LED_Off(BLUE);
} else } else
PIOS_LED_Off(BLUE); PIOS_LED_Off(BLUE);
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100) if (stopwatch > 50 * 1000 * 1000)
STOPWATCH_Reset(LED_PWM_TIMER); stopwatch = 0;
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState if ((stopwatch > 6 * 1000 * 1000) && (DeviceState
== BLidle)) == BLidle))
JumpToApp = TRUE; JumpToApp = TRUE;

View File

@ -94,8 +94,6 @@ DOXYGENDIR = ../Doc/Doxygen
SRC += $(OPSYSTEM)/main.c SRC += $(OPSYSTEM)/main.c
SRC += $(OPSYSTEM)/pios_board.c SRC += $(OPSYSTEM)/pios_board.c
SRC += $(OPSYSTEM)/op_dfu.c SRC += $(OPSYSTEM)/op_dfu.c
SRC += $(FLIGHTLIB)/stopwatch.c
## PIOS Hardware (STM32F10x) ## PIOS Hardware (STM32F10x)
SRC += $(PIOSSTM32F10X)/pios_sys.c SRC += $(PIOSSTM32F10X)/pios_sys.c
@ -138,7 +136,6 @@ SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c
SRC += $(STMSPDSRCDIR)/misc.c SRC += $(STMSPDSRCDIR)/misc.c

View File

@ -28,7 +28,6 @@
/* Bootloader Includes */ /* Bootloader Includes */
#include <pios.h> #include <pios.h>
#include <pios_board_info.h> #include <pios_board_info.h>
#include "stopwatch.h"
#include "op_dfu.h" #include "op_dfu.h"
#include "usb_lib.h" #include "usb_lib.h"
#include "pios_iap.h" #include "pios_iap.h"
@ -47,9 +46,9 @@ pFunction Jump_To_Application;
uint32_t JumpAddress; uint32_t JumpAddress;
/// LEDs PWM /// LEDs PWM
uint32_t period1 = 50; // *100 uS -> 5 mS uint32_t period1 = 5000; // 5 mS
uint32_t sweep_steps1 = 100; // * 5 mS -> 500 mS uint32_t sweep_steps1 = 100; // * 5 mS -> 500 mS
uint32_t period2 = 50; // *100 uS -> 5 mS uint32_t period2 = 5000; // 5 mS
uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS
@ -71,7 +70,6 @@ void jump_to_app();
#define BLUE LED1 #define BLUE LED1
#define RED LED4 #define RED LED4
#define LED_PWM_TIMER TIM3
int main() { int main() {
/* NOTE: Do NOT modify the following start-up sequence */ /* NOTE: Do NOT modify the following start-up sequence */
/* Any new initialization functions should be added in OpenPilotInit() */ /* Any new initialization functions should be added in OpenPilotInit() */
@ -98,35 +96,37 @@ int main() {
DeviceState = DFUidle; DeviceState = DFUidle;
else else
DeviceState = BLidle; DeviceState = BLidle;
STOPWATCH_Init(100, LED_PWM_TIMER);
} else } else
JumpToApp = TRUE; JumpToApp = TRUE;
STOPWATCH_Reset(LED_PWM_TIMER); uint32_t stopwatch = 0;
uint32_t prev_ticks = PIOS_DELAY_GetuS();
while (TRUE) { while (TRUE) {
/* Update the stopwatch */
uint32_t elapsed_ticks = PIOS_DELAY_GetuSSince(prev_ticks);
prev_ticks += elapsed_ticks;
stopwatch += elapsed_ticks;
if (JumpToApp == TRUE) if (JumpToApp == TRUE)
jump_to_app(); jump_to_app();
//pwm_period = 50; // *100 uS -> 5 mS
//pwm_sweep_steps =100; // * 5 mS -> 500 mS
switch (DeviceState) { switch (DeviceState) {
case Last_operation_Success: case Last_operation_Success:
case uploadingStarting: case uploadingStarting:
case DFUidle: case DFUidle:
period1 = 50; period1 = 5000;
sweep_steps1 = 100; sweep_steps1 = 100;
PIOS_LED_Off(RED); PIOS_LED_Off(RED);
period2 = 0; period2 = 0;
break; break;
case uploading: case uploading:
period1 = 50; period1 = 5000;
sweep_steps1 = 100; sweep_steps1 = 100;
period2 = 25; period2 = 2500;
sweep_steps2 = 50; sweep_steps2 = 50;
break; break;
case downloading: case downloading:
period1 = 25; period1 = 2500;
sweep_steps1 = 50; sweep_steps1 = 50;
PIOS_LED_Off(RED); PIOS_LED_Off(RED);
period2 = 0; period2 = 0;
@ -137,14 +137,14 @@ int main() {
period2 = 0; period2 = 0;
break; break;
default://error default://error
period1 = 50; period1 = 5000;
sweep_steps1 = 100; sweep_steps1 = 100;
period2 = 50; period2 = 5000;
sweep_steps2 = 100; sweep_steps2 = 100;
} }
if (period1 != 0) { if (period1 != 0) {
if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet(LED_PWM_TIMER))) if (LedPWM(period1, sweep_steps1, stopwatch))
PIOS_LED_On(BLUE); PIOS_LED_On(BLUE);
else else
PIOS_LED_Off(BLUE); PIOS_LED_Off(BLUE);
@ -152,16 +152,16 @@ int main() {
PIOS_LED_On(BLUE); PIOS_LED_On(BLUE);
if (period2 != 0) { if (period2 != 0) {
if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet(LED_PWM_TIMER))) if (LedPWM(period2, sweep_steps2, stopwatch))
PIOS_LED_On(RED); PIOS_LED_On(RED);
else else
PIOS_LED_Off(RED); PIOS_LED_Off(RED);
} else } else
PIOS_LED_Off(RED); PIOS_LED_Off(RED);
if (STOPWATCH_ValueGet(LED_PWM_TIMER) > 100 * 50 * 100) if (stopwatch > 50 * 1000 * 1000)
STOPWATCH_Reset(LED_PWM_TIMER); stopwatch = 0;
if ((STOPWATCH_ValueGet(LED_PWM_TIMER) > 60000) && (DeviceState if ((stopwatch > 6 * 1000 * 1000) && (DeviceState
== BLidle)) == BLidle))
JumpToApp = TRUE; JumpToApp = TRUE;

View File

@ -116,7 +116,7 @@ int32_t PIOS_DELAY_WaituS(uint32_t uS)
* // Wait for 500 mS * // Wait for 500 mS
* PIOS_DELAY_Wait_mS(500); * PIOS_DELAY_Wait_mS(500);
* \endcode * \endcode
* \param[in] mS delay (1..65535 milliseconds) * \param[in] mS delay
* \return < 0 on errors * \return < 0 on errors
*/ */
int32_t PIOS_DELAY_WaitmS(uint32_t mS) int32_t PIOS_DELAY_WaitmS(uint32_t mS)
@ -133,11 +133,21 @@ int32_t PIOS_DELAY_WaitmS(uint32_t mS)
* @brief Query the Delay timer for the current uS * @brief Query the Delay timer for the current uS
* @return A microsecond value * @return A microsecond value
*/ */
uint32_t PIOS_DELAY_GetuS() uint32_t PIOS_DELAY_GetuS(void)
{ {
return DWT_CYCCNT / us_ticks; return DWT_CYCCNT / us_ticks;
} }
/**
* @brief Calculate time in microseconds since a previous time
* @param[in] t previous time
* @return time in us since previous time t.
*/
uint32_t PIOS_DELAY_GetuSSince(uint32_t t)
{
return (PIOS_DELAY_GetuS() - t);
}
#endif #endif
/** /**

View File

@ -37,6 +37,7 @@ extern int32_t PIOS_DELAY_Init(void);
extern int32_t PIOS_DELAY_WaituS(uint32_t uS); extern int32_t PIOS_DELAY_WaituS(uint32_t uS);
extern int32_t PIOS_DELAY_WaitmS(uint32_t mS); extern int32_t PIOS_DELAY_WaitmS(uint32_t mS);
extern uint32_t PIOS_DELAY_GetuS(); extern uint32_t PIOS_DELAY_GetuS();
extern uint32_t PIOS_DELAY_GetuSSince(uint32_t t);
#endif /* PIOS_DELAY_H */ #endif /* PIOS_DELAY_H */