Skip to content

Commit c9b4474

Browse files
committed
[M2351] Merge secure idle/powerdown sequences into one
Merge SYS_UnlockReg_S()/CLK_Idle_S() or CLK_PowerDown_S()/SYS_LockReg_S() into nu_idle_s() or nu_powerdown_s() when they are available.
1 parent a0a1c4d commit c9b4474

File tree

1 file changed

+24
-6
lines changed
  • targets/TARGET_NUVOTON/TARGET_M2351

1 file changed

+24
-6
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/sleep.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@
2222
#include "device.h"
2323
#include "objects.h"
2424
#include "PeripheralPins.h"
25+
#include "platform/mbed_toolchain.h"
2526
#include <stdbool.h>
2627

28+
/* Merge SYS_UnlockReg_S()/CLK_Idle_S() or CLK_PowerDown_S()/SYS_LockReg_S()
29+
* into nu_idle_s() or nu_powerdown_s()
30+
*
31+
* These APIs are secure calls. For performance, merge them into one when
32+
* nu_idle_s() and nu_powerdown_s() are available.
33+
*/
34+
MBED_WEAK void nu_idle_s(void);
35+
MBED_WEAK void nu_powerdown_s(void);
36+
2737
#if DEVICE_SERIAL
2838
bool serial_can_deep_sleep(void);
2939
#endif
@@ -38,9 +48,13 @@ void hal_sleep(void)
3848
CLK_Idle();
3949
SYS_LockReg();
4050
#else
41-
SYS_UnlockReg_S();
42-
CLK_Idle_S();
43-
SYS_LockReg_S();
51+
if (nu_idle_s) {
52+
nu_idle_s();
53+
} else {
54+
SYS_UnlockReg_S();
55+
CLK_Idle_S();
56+
SYS_LockReg_S();
57+
}
4458
#endif
4559
}
4660

@@ -60,9 +74,13 @@ void hal_deepsleep(void)
6074
CLK_PowerDown();
6175
SYS_LockReg();
6276
#else
63-
SYS_UnlockReg_S();
64-
CLK_PowerDown_S();
65-
SYS_LockReg_S();
77+
if (nu_powerdown_s) {
78+
nu_powerdown_s();
79+
} else {
80+
SYS_UnlockReg_S();
81+
CLK_PowerDown_S();
82+
SYS_LockReg_S();
83+
}
6684
#endif
6785
}
6886

0 commit comments

Comments
 (0)