Skip to content

Commit 5624679

Browse files
committed
Servo register config improvements and inline func
1 parent e847a73 commit 5624679

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

libraries/Servo/Servo.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static volatile int8_t currentServoIndex[_Nbr_16timers];
4848
extern "C" {
4949
#endif
5050

51-
inline void Servo_Handler(timer16_Sequence_t timer, NRF_TIMER_Type *nrfTimer, uint32_t ccReg)
51+
static __inline__ void Servo_Handler(timer16_Sequence_t timer, NRF_TIMER_Type *nrfTimer, uint32_t ccReg) __attribute__((always_inline));
52+
static __inline__ void Servo_Handler(timer16_Sequence_t timer, NRF_TIMER_Type *nrfTimer, uint32_t ccReg)
5253
{
5354
// Clear the interrupt event flag
5455
nrfTimer->EVENTS_COMPARE[ccReg] = 0;
@@ -125,10 +126,10 @@ static void _initISR(NRF_TIMER_Type *nrfTimer, uint32_t ccReg, IRQn_Type timerIR
125126
__disable_irq();
126127
nrfTimer->TASKS_STOP = 1;
127128

128-
nrfTimer->MODE = TIMER_MODE_MODE_Timer;
129-
nrfTimer->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
130-
nrfTimer->PRESCALER = (TMR_FREQ_REG_PRESCALER << TIMER_PRESCALER_PRESCALER_Pos);
131-
nrfTimer->SHORTS = 0; // No CC event and CLEAR task shortcuts
129+
nrfTimer->MODE = TIMER_MODE_MODE_Timer << TIMER_MODE_MODE_Pos;
130+
nrfTimer->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
131+
nrfTimer->PRESCALER = TMR_FREQ_REG_PRESCALER << TIMER_PRESCALER_PRESCALER_Pos;
132+
nrfTimer->SHORTS = TIMER_SHORTS_DISABLE_ALL;
132133
nrfTimer->TASKS_CLEAR = 1; // Clear task
133134
nrfTimer->EVENTS_COMPARE[ccReg] = 0; // Clear interrupt event flag
134135
nrfTimer->CC[ccReg] = (uint32_t)usToTicks(REFRESH_INTERVAL);
@@ -142,6 +143,7 @@ static void _initISR(NRF_TIMER_Type *nrfTimer, uint32_t ccReg, IRQn_Type timerIR
142143
} else if (ccReg == TMR_CC_REG3) {
143144
nrfTimer->INTENSET = (TIMER_INTENSET_COMPARE3_Set << TIMER_INTENSET_COMPARE3_Pos);
144145
}
146+
NVIC_ClearPendingIRQ(timerIRQn);
145147
NVIC_SetPriority(timerIRQn, TMR_PRIORITY);
146148
NVIC_EnableIRQ(timerIRQn);
147149

libraries/Servo/ServoTimers.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@
5151
#define TMR_FREQ 2000000
5252
#define TMR_FREQ_REG_PRESCALER 3
5353

54+
#define TIMER_SHORTS_DISABLE_ALL ( \
55+
(TIMER_SHORTS_COMPARE0_CLEAR_Disabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos) | \
56+
(TIMER_SHORTS_COMPARE1_CLEAR_Disabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos) | \
57+
(TIMER_SHORTS_COMPARE2_CLEAR_Disabled << TIMER_SHORTS_COMPARE2_CLEAR_Pos) | \
58+
(TIMER_SHORTS_COMPARE3_CLEAR_Disabled << TIMER_SHORTS_COMPARE3_CLEAR_Pos) | \
59+
(TIMER_SHORTS_COMPARE0_STOP_Disabled << TIMER_SHORTS_COMPARE0_STOP_Pos) | \
60+
(TIMER_SHORTS_COMPARE1_STOP_Disabled << TIMER_SHORTS_COMPARE1_STOP_Pos) | \
61+
(TIMER_SHORTS_COMPARE2_STOP_Disabled << TIMER_SHORTS_COMPARE2_STOP_Pos) | \
62+
(TIMER_SHORTS_COMPARE3_STOP_Disabled << TIMER_SHORTS_COMPARE3_STOP_Pos))
63+
5464
// Each timer has 4 Capture/Compare set of registers
5565
#define TMR_CC_REG0 0
5666
#define TMR_CC_REG1 1
@@ -98,7 +108,6 @@
98108
#endif
99109
#endif
100110

101-
102111
// The timers here are organised in allocation sequence
103112
typedef enum {
104113
#if defined (_useTimer4)
@@ -119,4 +128,4 @@ typedef enum {
119128
_Nbr_16timers
120129
} timer16_Sequence_t;
121130

122-
#endif // __SERVO_TIMERS_H__
131+
#endif // __SERVO_TIMERS_H__

0 commit comments

Comments
 (0)