Skip to content

Commit

Permalink
use only 16 bits of timers
Browse files Browse the repository at this point in the history
even if the timer is 32 bits, use only bottom 16 bits for consistency
  • Loading branch information
tridge committed Oct 9, 2024
1 parent 4001544 commit c4a8b58
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Mcu/e230/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static inline void bl_timer_disable(void)
timer_disable(BL_TIMER);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return timer_counter_read(BL_TIMER);
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/f031/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static inline void bl_timer_disable(void)
LL_TIM_DeInit(BL_TIMER);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return LL_TIM_GetCounter(BL_TIMER);
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/f051/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static inline void bl_timer_disable(void)
LL_TIM_DeInit(BL_TIMER);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return LL_TIM_GetCounter(BL_TIMER);
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/f415/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static inline void bl_timer_disable(void)
BL_TIMER->ctrl1_bit.tmren = FALSE;
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return BL_TIMER->cval;
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/f421/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static inline void bl_timer_disable(void)
BL_TIMER->ctrl1_bit.tmren = FALSE;
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return BL_TIMER->cval;
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/g071/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static inline void bl_timer_disable(void)
LL_TIM_DeInit(BL_TIMER);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return LL_TIM_GetCounter(BL_TIMER);
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/g431/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static inline void bl_timer_disable(void)
LL_TIM_DeInit(BL_TIMER);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return LL_TIM_GetCounter(BL_TIMER);
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/l431/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static inline void bl_timer_disable(void)
LL_TIM_DeInit(BL_TIMER);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return LL_TIM_GetCounter(BL_TIMER);
}
Expand Down
2 changes: 1 addition & 1 deletion Mcu/v203/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static inline void bl_timer_disable(void)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, DISABLE);
}

static inline uint32_t bl_timer_us(void)
static inline uint16_t bl_timer_us(void)
{
return BL_TIMER->CNT;
}
Expand Down
6 changes: 3 additions & 3 deletions bl_update/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static uint32_t input_pin;
static void delayMicroseconds(uint32_t micros)
{
while (micros > 0) {
uint32_t us = micros>10000?10000:micros;
const uint32_t us_start = bl_timer_us();
while (bl_timer_us() - us_start < us) ;
uint16_t us = micros>10000?10000:micros;
const uint16_t us_start = bl_timer_us();
while ((uint16_t)(bl_timer_us() - us_start) < us) ;
micros -= us;
}
}
Expand Down
2 changes: 1 addition & 1 deletion bootloader/DroneCAN/sys_can_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
void usleep(uint32_t usec)
{
const uint16_t start_us = (uint16_t)bl_timer_us();
while (((uint16_t)bl_timer_us()) - start_us < (uint16_t)usec) ;
while ((uint16_t)(bl_timer_us() - start_us) < (uint16_t)usec) ;
}

/*
Expand Down
6 changes: 3 additions & 3 deletions bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ static void serialwriteChar(uint8_t data);
#define HALFBITTIME 26 // 500000/BAUDRATE

// used for timing bytes
static uint32_t us_start;
static uint16_t us_start;

static void bl_timer_reset(void)
{
us_start = bl_timer_us();
}

static uint32_t bl_timer_elapsed(void)
static uint16_t bl_timer_elapsed(void)
{
return bl_timer_us() - us_start;
}

static void delayMicroseconds(uint32_t micros)
static void delayMicroseconds(uint16_t micros)
{
bl_timer_reset();
while (bl_timer_elapsed() < micros) {
Expand Down

0 comments on commit c4a8b58

Please sign in to comment.