mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 04:52:02 +08:00
Add the set counter function for stm32 timers
This commit is contained in:
committed by
Gregory Nutt
parent
795650a2fb
commit
8c35b2ddca
@@ -339,6 +339,7 @@ static int stm32_tim_setclock(FAR struct stm32_tim_dev_s *dev, uint32_t freq);
|
||||
static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev,
|
||||
uint32_t period);
|
||||
static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev);
|
||||
static void stm32_tim_setcounter(FAR struct stm32_tim_dev_s *dev, uint32_t count);
|
||||
static int stm32_tim_getwidth(FAR struct stm32_tim_dev_s *dev);
|
||||
static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, uint8_t channel,
|
||||
stm32_tim_channel_t mode);
|
||||
@@ -362,6 +363,7 @@ static const struct stm32_tim_ops_s stm32_tim_ops =
|
||||
.setclock = stm32_tim_setclock,
|
||||
.setperiod = stm32_tim_setperiod,
|
||||
.getcounter = stm32_tim_getcounter,
|
||||
.setcounter = stm32_tim_setcounter,
|
||||
.getwidth = stm32_tim_getwidth,
|
||||
.setchannel = stm32_tim_setchannel,
|
||||
.setcompare = stm32_tim_setcompare,
|
||||
@@ -908,6 +910,24 @@ static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev)
|
||||
(uint32_t)stm32_getreg16(dev, STM32_BTIM_CNT_OFFSET);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_tim_setcounter
|
||||
************************************************************************************/
|
||||
|
||||
static void stm32_tim_setcounter(FAR struct stm32_tim_dev_s *dev, uint32_t count)
|
||||
{
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
if (stm32_tim_getwidth(dev) > 16)
|
||||
{
|
||||
stm32_putreg32(dev, STM32_BTIM_CNT_OFFSET, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
stm32_putreg16(dev, STM32_BTIM_CNT_OFFSET, (uint16_t)count);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_tim_getwidth
|
||||
************************************************************************************/
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
|
||||
#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period))
|
||||
#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
|
||||
#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c))
|
||||
#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
|
||||
#define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode))
|
||||
#define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp))
|
||||
@@ -164,6 +165,7 @@ struct stm32_tim_ops_s
|
||||
int (*setclock)(FAR struct stm32_tim_dev_s *dev, uint32_t freq);
|
||||
void (*setperiod)(FAR struct stm32_tim_dev_s *dev, uint32_t period);
|
||||
uint32_t (*getcounter)(FAR struct stm32_tim_dev_s *dev);
|
||||
void (*setcounter)(FAR struct stm32_tim_dev_s *dev, uint32_t count);
|
||||
|
||||
/* General and Advanced Timers Adds */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user