Skip to content

Commit f645ba5

Browse files
Ganesh Ramachandranadbridge
authored andcommitted
Low power consumption mode for deepsleep
1 parent cc29812 commit f645ba5

File tree

1 file changed

+38
-5
lines changed
  • targets/TARGET_TOSHIBA/TARGET_TMPM46B

1 file changed

+38
-5
lines changed

targets/TARGET_TOSHIBA/TARGET_TMPM46B/sleep.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,52 @@
1515
*/
1616
#include "sleep_api.h"
1717

18+
// Number of warm-up cycle = warm-up time to set / input frequency cycle (s)
19+
// Number of 3*10^-6 (s) / (1/12 (MHz)) = 60000 = 0xea60
20+
#define CG_WUODR_INT ((uint16_t)0xea60)
21+
22+
static void external_losc_enable(void);
23+
1824
void hal_sleep(void)
1925
{
2026
// Set low power consumption mode IDLE
2127
CG_SetSTBYMode(CG_STBY_MODE_IDLE);
22-
__DSB();
2328
// Enter idle mode
2429
__WFI();
2530
}
2631

2732
void hal_deepsleep(void)
2833
{
29-
// deepsleep = sleep because, TMPM46BF10FG does not support the low power
30-
// consumption mode configured with the SLEEPDEEP bit in the Cortex-M4 core.
31-
// Setting the bit of the system control register is prohibited.
32-
hal_sleep();
34+
// Set low power consumption mode STOP1
35+
CG_SetSTBYMode(CG_STBY_MODE_STOP1);
36+
// Setup warm up time
37+
CG_SetWarmUpTime(CG_WARM_UP_SRC_OSC_EXT_HIGH, CG_WUODR_INT);
38+
// Enter stop1 mode
39+
__WFI();
40+
// Switch over from IHOSC to EHOSC
41+
external_losc_enable();
42+
}
43+
44+
static void external_losc_enable(void)
45+
{
46+
// Enable high-speed oscillator
47+
CG_SetFosc(CG_FOSC_OSC_EXT, ENABLE);
48+
// Select internal(fIHOSC) as warm-up clock
49+
CG_SetWarmUpTime(CG_WARM_UP_SRC_OSC_INT_HIGH, CG_WUODR_INT);
50+
// Start warm-up
51+
CG_StartWarmUp();
52+
// Wait until EHOSC become stable
53+
while (CG_GetWarmUpState() != DONE) {
54+
// Do nothing
55+
}
56+
57+
// Set fosc source
58+
CG_SetFoscSrc(CG_FOSC_OSC_EXT);
59+
// Wait for <OSCSEL> to become "1"
60+
while (CG_GetFoscSrc() != CG_FOSC_OSC_EXT) {
61+
// Do nothing
62+
}
63+
64+
// Stop IHOSC
65+
CG_SetFosc(CG_FOSC_OSC_INT, DISABLE);
3366
}

0 commit comments

Comments
 (0)