Skip to content

Commit fa4bbe8

Browse files
committed
pbio/drv/clock/clock_ev3: Switch to timer 12 instead of 34
The PRU1 code which will be added in the future expects the 34 part of Timer0 to count with a period which is a multiple of 256*256 in order to generate accurate PWM widths. We switch the system tick in order to not conflict with it.
1 parent 5ece1d3 commit fa4bbe8

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/pbio/drv/clock/clock_ev3.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ volatile uint32_t systick_ms = 0;
4141
*/
4242
void systick_isr_C(void) {
4343
/* Clear the interrupt status in AINTC and in timer */
44-
IntSystemStatusClear(SYS_INT_TINT34_0);
45-
TimerIntStatusClear(SOC_TMR_0_REGS, TMR_INTSTAT34_TIMER_NON_CAPT);
44+
IntSystemStatusClear(SYS_INT_TINT12_0);
45+
TimerIntStatusClear(SOC_TMR_0_REGS, TMR_INTSTAT12_TIMER_NON_CAPT);
4646

4747
++systick_ms;
4848

@@ -56,15 +56,15 @@ void systick_isr_C(void) {
5656
*/
5757
void systick_suspend(void) {
5858
/* Disable the timer interrupt */
59-
TimerDisable(SOC_TMR_0_REGS, TMR_TIMER34);
59+
TimerDisable(SOC_TMR_0_REGS, TMR_TIMER12);
6060
}
6161

6262
/**
6363
* Enable the timer and therefore the systick
6464
*/
6565
void systick_resume(void) {
6666
/* Enable the timer interrupt */
67-
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONT);
67+
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER12, TMR_ENABLE_CONT);
6868
}
6969

7070
/**
@@ -79,23 +79,22 @@ void pbdrv_clock_init(void) {
7979

8080
/* Set up the timer */
8181
TimerConfigure(SOC_TMR_0_REGS, TMR_CFG_32BIT_UNCH_CLK_BOTH_INT);
82-
TimerPreScalarCount34Set(SOC_TMR_0_REGS, 0);
83-
TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, timer_ms_period);
82+
TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER12, timer_ms_period);
8483

8584
/* Register the Timer ISR */
86-
IntRegister(SYS_INT_TINT34_0, systick_isr_C);
85+
IntRegister(SYS_INT_TINT12_0, systick_isr_C);
8786

8887
/* Set the channel number for Timer interrupt, it will map to IRQ */
89-
IntChannelSet(SYS_INT_TINT34_0, 3);
88+
IntChannelSet(SYS_INT_TINT12_0, 3);
9089

9190
/* Enable timer interrupts in AINTC */
92-
IntSystemEnable(SYS_INT_TINT34_0);
91+
IntSystemEnable(SYS_INT_TINT12_0);
9392

9493
/* Enable the timer interrupt */
95-
TimerIntEnable(SOC_TMR_0_REGS, TMR_INT_TMR34_NON_CAPT_MODE);
94+
TimerIntEnable(SOC_TMR_0_REGS, TMR_INT_TMR12_NON_CAPT_MODE);
9695

9796
/* Start the timer */
98-
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONT);
97+
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER12, TMR_ENABLE_CONT);
9998
}
10099

101100
uint32_t pbdrv_clock_get_us(void) {

0 commit comments

Comments
 (0)