Skip to content

Commit 7e6e69e

Browse files
committed
[BH-1873] Update FreeRTOS ticks before re-enabling interrupts
Fix of the issue that when leaving WFI mode interrupts were being enabled before catching up FreeRTOS ticks, what resulted in IRQ handlers working on out-of-date system tick counter.
1 parent c3f73df commit 7e6e69e

19 files changed

Lines changed: 196 additions & 158 deletions

File tree

module-bsp/board/linux/lpm/LinuxLPM.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "LinuxLPM.h"
@@ -56,4 +56,11 @@ namespace bsp
5656
void LinuxLPM::EnableSysTick()
5757
{}
5858

59+
std::uint32_t LinuxLPM::DisableInterrupts()
60+
{
61+
return 0;
62+
}
63+
64+
void LinuxLPM::EnableInterrupts([[maybe_unused]] std::uint32_t primask)
65+
{}
5966
} // namespace bsp

module-bsp/board/linux/lpm/LinuxLPM.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -26,5 +26,8 @@ namespace bsp
2626

2727
void DisableSysTick() final;
2828
void EnableSysTick() final;
29+
30+
std::uint32_t DisableInterrupts() final;
31+
void EnableInterrupts(std::uint32_t primask) final;
2932
};
3033
} // namespace bsp
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
55

66
namespace bsp
77
{
8-
enum class NotificationSource : uint8_t
8+
enum class NotificationSource : std::uint8_t
99
{
10-
leftSideKeyPress = 1,
11-
leftSideKeyRelease,
12-
rightSideKeyPress,
13-
rightSideKeyRelease,
14-
lightCenterKeyPress,
15-
lightCenterKeyRelease,
16-
latchKeyPress,
17-
latchKeyRelease,
18-
rotaryEncoder,
10+
LeftSideKeyPress = 1,
11+
LeftSideKeyRelease,
12+
RightSideKeyPress,
13+
RightSideKeyRelease,
14+
LightCenterKeyPress,
15+
LightCenterKeyRelease,
16+
LatchKeyPress,
17+
LatchKeyRelease,
18+
RotaryEncoder,
1919
Invalid = 0xFF
2020
};
2121
} // namespace bsp

module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "RT1051LPM.hpp"
55
#include "WfiController.hpp"
6+
#include <fsl_common.h>
67

78
namespace bsp
89
{
@@ -31,4 +32,28 @@ namespace bsp
3132
{
3233
return getLastTimeSpentInWfi();
3334
}
35+
36+
void RT1051LPM::DisableSysTick()
37+
{
38+
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
39+
NVIC_ClearPendingIRQ(SysTick_IRQn);
40+
}
41+
42+
void RT1051LPM::EnableSysTick()
43+
{
44+
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
45+
}
46+
47+
std::uint32_t RT1051LPM::DisableInterrupts()
48+
{
49+
const auto primask = DisableGlobalIRQ();
50+
__DSB();
51+
__ISB();
52+
return primask;
53+
}
54+
55+
void RT1051LPM::EnableInterrupts(std::uint32_t primask)
56+
{
57+
EnableGlobalIRQ(primask);
58+
}
3459
} // namespace bsp

module-bsp/board/rt1051/bellpx/bsp/lpm/RT1051LPM.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#pragma once
@@ -15,7 +15,14 @@ namespace bsp
1515

1616
void AllowEnteringWfiMode() final;
1717
void BlockEnteringWfiMode() final;
18+
1819
std::uint32_t EnterWfiModeIfAllowed() final;
1920
std::uint32_t GetLastTimeSpentInWfi() final;
21+
22+
void DisableSysTick() final;
23+
void EnableSysTick() final;
24+
25+
std::uint32_t DisableInterrupts() final;
26+
void EnableInterrupts(std::uint32_t primask) final;
2027
};
2128
} // namespace bsp

module-bsp/board/rt1051/bellpx/bsp/lpm/WfiController.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ namespace bsp
9191
{
9292
return ((PMU->REG_2P5 & PMU_REG_2P5_BO_VDD2P5_MASK) != 0);
9393
}
94-
95-
void disableSystick()
96-
{
97-
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
98-
NVIC_ClearPendingIRQ(SysTick_IRQn);
99-
}
100-
101-
void enableSystick()
102-
{
103-
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
104-
}
10594
} // namespace
10695

10796
void allowEnteringWfiMode()
@@ -141,13 +130,8 @@ namespace bsp
141130
setWaitModeConfig();
142131
peripheralEnterDozeMode();
143132

144-
disableSystick();
145133
const auto enterWfiTicks = ulHighFrequencyTimerTicks();
146134

147-
const auto savedPrimask = DisableGlobalIRQ();
148-
__DSB();
149-
__ISB();
150-
151135
/* Clear the SLEEPDEEP bit to go into sleep mode (WAIT) */
152136
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
153137

@@ -160,16 +144,14 @@ namespace bsp
160144
__NOP();
161145

162146
const auto exitWfiTicks = ulHighFrequencyTimerTicks();
163-
enableSystick();
147+
timeSpentInWFI = ulHighFrequencyTimerTicksToMs(utils::computeIncrease(exitWfiTicks, enterWfiTicks));
164148

165149
peripheralExitDozeMode();
150+
setRunModeConfig();
166151
watchdog::refresh();
167-
EnableGlobalIRQ(savedPrimask);
168152

169153
blockEnteringWfiMode();
170-
setRunModeConfig();
171154

172-
timeSpentInWFI = ulHighFrequencyTimerTicksToMs(utils::computeIncrease(exitWfiTicks, enterWfiTicks));
173155
return timeSpentInWFI;
174156
}
175157
} // namespace bsp

module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "rotary_encoder.hpp"
@@ -91,7 +91,7 @@ namespace bsp::rotary_encoder
9191
{
9292
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
9393
if (gHandleIrq != nullptr) {
94-
std::uint8_t val = static_cast<std::uint8_t>(NotificationSource::rotaryEncoder);
94+
std::uint8_t val = static_cast<std::uint8_t>(NotificationSource::RotaryEncoder);
9595
xQueueSendFromISR(gHandleIrq, &val, &xHigherPriorityTaskWoken);
9696
}
9797
return xHigherPriorityTaskWoken;

0 commit comments

Comments
 (0)