arm/nrf52,nrf53,nrf91: fix TIMER driver bugs

- setcc/getcc accepted channel index equal to the channel count
- init never marked the instance as in use
- TIM_PRESCALER_MASK used the maximum value as the mask

Assisted-by: Claude Code
Signed-off-by: raiden00pl <raiden00@railab.me>
This commit is contained in:
raiden00pl 2026-09-24 15:32:29 +02:00 • committed by Xiang Xiao
parent a315d19fac
commit d490c80df2
6 changed files with 21 additions and 9 deletions

View file

@ -103,6 +103,6 @@
#define TIM_PRESCALER_SHIFT (0) /* Bits 0-3: Prescaler value */
#define TIM_PRESCALER_MAX (9)
#define TIM_PRESCALER_MASK (TIM_PRESCALER_MAX << TIM_PRESCALER_SHIFT)
#define TIM_PRESCALER_MASK (0xf << TIM_PRESCALER_SHIFT)
#endif /* __ARCH_ARM_SRC_NRF52_HARDWARE_NRF52_TIM_H */

View file

@ -488,7 +488,7 @@ static int nrf52_tim_setcc(struct nrf52_tim_dev_s *dev, uint8_t i,
/* Is the channel supported? */
if (i > tim->chan)
if (i >= tim->chan)
{
tmrerr("ERROR: unsupported TIMER channel %d\n", i);
ret = -EINVAL;
@ -518,7 +518,7 @@ static int nrf52_tim_getcc(struct nrf52_tim_dev_s *dev, uint8_t i,
/* Is the channel supported? */
if (i > tim->chan)
if (i >= tim->chan)
{
tmrerr("ERROR: unsupported TIMER channel %d\n", i);
ret = -EINVAL;
@ -832,6 +832,10 @@ struct nrf52_tim_dev_s *nrf52_tim_init(int timer)
tim = NULL;
}
else
{
tim->inuse = true;
}
errout:
return (struct nrf52_tim_dev_s *)tim;

View file

@ -106,7 +106,7 @@
#define TIM_PRESCALER_SHIFT (0) /* Bits 0-3: Prescaler value */
#define TIM_PRESCALER_MAX (9)
#define TIM_PRESCALER_MASK (TIM_PRESCALER_MAX << TIM_PRESCALER_SHIFT)
#define TIM_PRESCALER_MASK (0xf << TIM_PRESCALER_SHIFT)
/* ONESHOT Register */

View file

@ -488,7 +488,7 @@ static int nrf53_tim_setcc(struct nrf53_tim_dev_s *dev, uint8_t i,
/* Is the channel supported? */
if (i > tim->chan)
if (i >= tim->chan)
{
tmrerr("ERROR: unsupported TIMER channel %d\n", i);
ret = -EINVAL;
@ -518,7 +518,7 @@ static int nrf53_tim_getcc(struct nrf53_tim_dev_s *dev, uint8_t i,
/* Is the channel supported? */
if (i > tim->chan)
if (i >= tim->chan)
{
tmrerr("ERROR: unsupported TIMER channel %d\n", i);
ret = -EINVAL;
@ -832,6 +832,10 @@ struct nrf53_tim_dev_s *nrf53_tim_init(int timer)
tim = NULL;
}
else
{
tim->inuse = true;
}
errout:
return (struct nrf53_tim_dev_s *)tim;

View file

@ -106,7 +106,7 @@
#define TIM_PRESCALER_SHIFT (0) /* Bits 0-3: Prescaler value */
#define TIM_PRESCALER_MAX (9)
#define TIM_PRESCALER_MASK (TIM_PRESCALER_MAX << TIM_PRESCALER_SHIFT)
#define TIM_PRESCALER_MASK (0xf << TIM_PRESCALER_SHIFT)
/* ONESHOT Register */

View file

@ -488,7 +488,7 @@ static int nrf91_tim_setcc(struct nrf91_tim_dev_s *dev, uint8_t i,
/* Is the channel supported? */
if (i > tim->chan)
if (i >= tim->chan)
{
tmrerr("ERROR: unsupported TIMER channel %d\n", i);
ret = -EINVAL;
@ -518,7 +518,7 @@ static int nrf91_tim_getcc(struct nrf91_tim_dev_s *dev, uint8_t i,
/* Is the channel supported? */
if (i > tim->chan)
if (i >= tim->chan)
{
tmrerr("ERROR: unsupported TIMER channel %d\n", i);
ret = -EINVAL;
@ -832,6 +832,10 @@ struct nrf91_tim_dev_s *nrf91_tim_init(int timer)
tim = NULL;
}
else
{
tim->inuse = true;
}
errout:
return (struct nrf91_tim_dev_s *)tim;