Skip to content

Commit

Permalink
Merge pull request betaflight#4667 from jflyper/bfdev-TIMUP-pseudo-re…
Browse files Browse the repository at this point in the history
…source

Add TIMUP pseudo resource to use with DMAR
  • Loading branch information
mikeller authored Nov 28, 2017
2 parents d3c0a4a + 209be41 commit 6936ba6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/drivers/pwm_output_dshot_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
/* Link hdma_tim to hdma[x] (channelx) */
__HAL_LINKDMA(&motor->TimHandle, hdma[motor->timerDmaIndex], motor->hdma_tim);

dmaInit(timerHardware->dmaTimUPIrqHandler, OWNER_MOTOR, RESOURCE_INDEX(motorIndex));
dmaInit(timerHardware->dmaTimUPIrqHandler, OWNER_TIMUP, timerGetTIMNumber(timerHardware->tim));
dmaSetHandler(timerHardware->dmaTimUPIrqHandler, motor_DMA_IRQHandler, NVIC_BUILD_PRIORITY(1, 2), motorIndex);
#else
motor->timerDmaIndex = timerDmaIndex(timerHardware->channel);
Expand Down
1 change: 1 addition & 0 deletions src/main/drivers/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ const char * const ownerNames[OWNER_TOTAL_COUNT] = {
"RX_BIND_PLUG",
"ESCSERIAL",
"CAMERA_CONTROL",
"TIMUP",
};
1 change: 1 addition & 0 deletions src/main/drivers/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef enum {
OWNER_RX_BIND_PLUG,
OWNER_ESCSERIAL,
OWNER_CAMERA_CONTROL,
OWNER_TIMUP,
OWNER_TOTAL_COUNT
} resourceOwner_e;

Expand Down
2 changes: 2 additions & 0 deletions src/main/drivers/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,5 @@ uint16_t timerDmaSource(uint8_t channel);
uint16_t timerGetPrescalerByDesiredHertz(TIM_TypeDef *tim, uint32_t hz);
uint16_t timerGetPrescalerByDesiredMhz(TIM_TypeDef *tim, uint16_t mhz);
uint16_t timerGetPeriodByPrescaler(TIM_TypeDef *tim, uint16_t prescaler, uint32_t hz);

int8_t timerGetTIMNumber(const TIM_TypeDef *tim);
70 changes: 69 additions & 1 deletion src/main/drivers/timer_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,75 @@ TIM_TypeDef * const usedTimers[USED_TIMER_COUNT] = {
#undef _DEF
};

// Map timer index to timer number (Straight copy of usedTimers array)
const int8_t timerNumbers[USED_TIMER_COUNT] = {
#define _DEF(i) i

#if USED_TIMERS & TIM_N(1)
_DEF(1),
#endif
#if USED_TIMERS & TIM_N(2)
_DEF(2),
#endif
#if USED_TIMERS & TIM_N(3)
_DEF(3),
#endif
#if USED_TIMERS & TIM_N(4)
_DEF(4),
#endif
#if USED_TIMERS & TIM_N(5)
_DEF(5),
#endif
#if USED_TIMERS & TIM_N(6)
_DEF(6),
#endif
#if USED_TIMERS & TIM_N(7)
_DEF(7),
#endif
#if USED_TIMERS & TIM_N(8)
_DEF(8),
#endif
#if USED_TIMERS & TIM_N(9)
_DEF(9),
#endif
#if USED_TIMERS & TIM_N(10)
_DEF(10),
#endif
#if USED_TIMERS & TIM_N(11)
_DEF(11),
#endif
#if USED_TIMERS & TIM_N(12)
_DEF(12),
#endif
#if USED_TIMERS & TIM_N(13)
_DEF(13),
#endif
#if USED_TIMERS & TIM_N(14)
_DEF(14),
#endif
#if USED_TIMERS & TIM_N(15)
_DEF(15),
#endif
#if USED_TIMERS & TIM_N(16)
_DEF(16),
#endif
#if USED_TIMERS & TIM_N(17)
_DEF(17),
#endif
#undef _DEF
};

int8_t timerGetTIMNumber(const TIM_TypeDef *tim)
{
uint8_t index = lookupTimerIndex(tim);

if (index < USED_TIMER_COUNT) {
return timerNumbers[index];
} else {
return 0;
}
}

static inline uint8_t lookupChannelIndex(const uint16_t channel)
{
return channel >> 2;
Expand Down Expand Up @@ -1049,4 +1118,3 @@ HAL_StatusTypeDef DMA_SetCurrDataCounter(TIM_HandleTypeDef *htim, uint32_t Chann
/* Return function status */
return HAL_OK;
}

0 comments on commit 6936ba6

Please sign in to comment.