Skip to content

Commit 7ed36e4

Browse files
committed
MCUXpresso_MCUS: Apply K64F us_ticker fix across all MCU's
Applied changes from commit b6a01de for other MCUXpresso MCUs Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent f0bda6c commit 7ed36e4

File tree

11 files changed

+65
-26
lines changed

11 files changed

+65
-26
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86-
uint32_t delta = timestamp - us_ticker_read();
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8791
PIT_StopTimer(PIT, kPIT_Chnl_3);
8892
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
93+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9094
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9195
PIT_StartTimer(PIT, kPIT_Chnl_3);
9296
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86-
uint32_t delta = timestamp - us_ticker_read();
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8791
PIT_StopTimer(PIT, kPIT_Chnl_3);
8892
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
93+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9094
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9195
PIT_StartTimer(PIT, kPIT_Chnl_3);
9296
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL27Z/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ void us_ticker_clear_interrupt(void)
9090

9191
void us_ticker_set_interrupt(timestamp_t timestamp)
9292
{
93-
uint32_t delta = timestamp - us_ticker_read();
93+
uint32_t now_us, delta_us;
94+
95+
now_us = us_ticker_read();
96+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
97+
9498
LPTMR_StopTimer(LPTMR0);
95-
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)delta);
99+
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)delta_us);
96100
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
97101
LPTMR_StartTimer(LPTMR0);
98102
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ void us_ticker_clear_interrupt(void)
9090

9191
void us_ticker_set_interrupt(timestamp_t timestamp)
9292
{
93-
uint32_t delta = timestamp - us_ticker_read();
93+
uint32_t now_us, delta_us;
94+
95+
now_us = us_ticker_read();
96+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
97+
9498
LPTMR_StopTimer(LPTMR0);
95-
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)delta);
99+
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)delta_us);
96100
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
97101
LPTMR_StartTimer(LPTMR0);
98102
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86-
uint32_t delta = timestamp - us_ticker_read();
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8791
PIT_StopTimer(PIT, kPIT_Chnl_3);
8892
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
93+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9094
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9195
PIT_StartTimer(PIT, kPIT_Chnl_3);
9296
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW24D/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86-
uint32_t delta = timestamp - us_ticker_read();
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8791
PIT_StopTimer(PIT, kPIT_Chnl_3);
8892
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
93+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9094
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9195
PIT_StartTimer(PIT, kPIT_Chnl_3);
9296
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KW41Z/us_ticker.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void lptmr_isr(void)
3030
us_ticker_irq_handler();
3131
}
3232

33-
void us_ticker_init(void)
33+
void us_ticker_init(void)
3434
{
3535
if (us_ticker_inited) {
3636
return;
@@ -69,7 +69,7 @@ void us_ticker_init(void)
6969
}
7070

7171

72-
uint32_t us_ticker_read()
72+
uint32_t us_ticker_read()
7373
{
7474
if (!us_ticker_inited) {
7575
us_ticker_init();
@@ -78,21 +78,25 @@ uint32_t us_ticker_read()
7878
return ~(PIT_GetCurrentTimerCount(PIT, kPIT_Chnl_1));
7979
}
8080

81-
void us_ticker_disable_interrupt(void)
81+
void us_ticker_disable_interrupt(void)
8282
{
8383
LPTMR_DisableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
8484
}
8585

86-
void us_ticker_clear_interrupt(void)
86+
void us_ticker_clear_interrupt(void)
8787
{
8888
LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
8989
}
9090

91-
void us_ticker_set_interrupt(timestamp_t timestamp)
91+
void us_ticker_set_interrupt(timestamp_t timestamp)
9292
{
93-
uint32_t delta = timestamp - us_ticker_read();
93+
uint32_t now_us, delta_us;
94+
95+
now_us = us_ticker_read();
96+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
97+
9498
LPTMR_StopTimer(LPTMR0);
95-
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)delta);
99+
LPTMR_SetTimerPeriod(LPTMR0, (uint32_t)delta_us);
96100
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
97101
LPTMR_StartTimer(LPTMR0);
98102
}

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K22F/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86-
uint32_t delta = timestamp - us_ticker_read();
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8791
PIT_StopTimer(PIT, kPIT_Chnl_3);
8892
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
93+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9094
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9195
PIT_StartTimer(PIT, kPIT_Chnl_3);
9296
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86-
uint32_t delta = timestamp - us_ticker_read();
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8791
PIT_StopTimer(PIT, kPIT_Chnl_3);
8892
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
93+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9094
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9195
PIT_StartTimer(PIT, kPIT_Chnl_3);
9296
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/us_ticker.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
8888
now_us = us_ticker_read();
8989
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
9090

91-
uint32_t delta = timestamp - us_ticker_read();
9291
PIT_StopTimer(PIT, kPIT_Chnl_3);
9392
PIT_StopTimer(PIT, kPIT_Chnl_2);
9493
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_IMX/us_ticker.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ void us_ticker_clear_interrupt(void)
8787

8888
void us_ticker_set_interrupt(timestamp_t timestamp)
8989
{
90-
uint32_t delta = timestamp - us_ticker_read();
90+
uint32_t now_us, delta_us;
91+
92+
now_us = us_ticker_read();
93+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
94+
9195
PIT_StopTimer(PIT, kPIT_Chnl_3);
9296
PIT_StopTimer(PIT, kPIT_Chnl_2);
93-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
97+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9498
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9599
PIT_StartTimer(PIT, kPIT_Chnl_3);
96100
PIT_StartTimer(PIT, kPIT_Chnl_2);

0 commit comments

Comments
 (0)