Developer World
Spresense Arduino Library v3.3.0-b2e6327
LowPower.h
Go to the documentation of this file.
1/*
2 * LowPower.h - Spresense Arduino Low Power library
3 * Copyright 2018 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef _LOW_POWER_H_
21#define _LOW_POWER_H_
22
23#ifdef SUBCORE
24#error "LowPower library is NOT supported by SubCore."
25#endif
26
41#include <Arduino.h>
42#include <arch/chip/pm.h>
43
44typedef enum {
76
77typedef enum {
82
89{
90public:
91
92 LowPowerClass() : isInitialized(false), isEnabledDVFS(false) {
93 hvlock.count = 0;
94 hvlock.info = PM_CPUFREQLOCK_TAG('L', 'P', 0);
95 hvlock.flag = PM_CPUFREQLOCK_FLAG_HV;
96
97 lvlock.count = 0;
98 lvlock.info = PM_CPUFREQLOCK_TAG('L', 'P', 1);
99 lvlock.flag = PM_CPUFREQLOCK_FLAG_LV;
100 }
101
106 void begin();
107
111 void end();
112
118 void sleep(uint32_t seconds);
119
123 void coldSleep();
124
129 void coldSleep(uint32_t seconds);
130
134 void deepSleep();
135
140 void deepSleep(uint32_t seconds);
141
145 void reboot();
146
152
159
165 bool isEnabledBootCause(uint8_t pin);
166
172
177 void enableBootCause(uint8_t pin);
178
184
189 void disableBootCause(uint8_t pin);
190
197
203
209
214 int getVoltage(void);
215
223 int getCurrent(void);
224
225private:
226 bootcause_e pin2bootcause(uint8_t pin);
227 bool isInitialized;
228 bool isEnabledDVFS;
229 struct pm_cpu_freqlock_s hvlock;
230 struct pm_cpu_freqlock_s lvlock;
231};
232
233extern LowPowerClass LowPower;
234
237#endif
This provides the features fo the power saving.
Definition: LowPower.h:89
void disableBootCause(uint8_t pin)
Disable the cause by the specified pin as the boot cause.
bool isEnabledBootCause(bootcause_e bc)
Check if the specified cause is permitted or not.
void reboot()
Reboot the system.
void end()
Finalize the Low Power library.
void clockMode(clockmode_e mode)
Set clock mode and change system clock dynamically.
void enableBootCause(uint8_t pin)
Enable the cause by the specified pin as the boot cause.
void deepSleep()
Enter the deep sleep state.
bool isEnabledBootCause(uint8_t pin)
Check if the cause by the specified pin is permitted or not.
void begin()
Initialize the Low Power library.
uint8_t getWakeupPin(bootcause_e bc)
Get a wakeup pin number from the boot cause.
void coldSleep(uint32_t seconds)
Enter the cold sleep state during the specified seconds.
int getCurrent(void)
Get the sensed battery current on CXD5247.
void disableBootCause(bootcause_e bc)
Disable the specified cause as the boot cause.
void sleep(uint32_t seconds)
Sleep (yield) this thread.
void coldSleep()
Enter the cold sleep state.
void enableBootCause(bootcause_e bc)
Enable the specified cause as the boot cause.
clockmode_e getClockMode()
Get clock mode.
void deepSleep(uint32_t seconds)
Enter the deep sleep state during the specified seconds.
bootcause_e bootCause()
Get the boot cause.
int getVoltage(void)
Get the sensed battery voltage on CXD5247.
bootcause_e
Definition: LowPower.h:44
clockmode_e
Definition: LowPower.h:77
@ COLD_GPIO_IRQ41
Definition: LowPower.h:63
@ WDT_REBOOT
Definition: LowPower.h:46
@ POR_NORMAL
Definition: LowPower.h:74
@ COLD_GPIO_IRQ43
Definition: LowPower.h:65
@ COLD_GPIO_IRQ39
Definition: LowPower.h:61
@ DEEP_WKUPS
Definition: LowPower.h:49
@ COLD_USB_ATTACH
Definition: LowPower.h:73
@ WDT_RESET
Definition: LowPower.h:47
@ COLD_RTC_ALM0
Definition: LowPower.h:54
@ DEEP_OTHERS
Definition: LowPower.h:52
@ COLD_SCU_INT
Definition: LowPower.h:53
@ COLD_RTC_ALMERR
Definition: LowPower.h:57
@ COLD_USB_DETACH
Definition: LowPower.h:72
@ COLD_GPIO_IRQ47
Definition: LowPower.h:69
@ COLD_PMIC_INT
Definition: LowPower.h:71
@ COLD_RTC_ALM2
Definition: LowPower.h:56
@ COLD_GPIO_IRQ36
Definition: LowPower.h:58
@ DEEP_WKUPL
Definition: LowPower.h:48
@ COLD_GPIO_IRQ46
Definition: LowPower.h:68
@ COLD_GPIO_IRQ40
Definition: LowPower.h:62
@ DEEP_RTC
Definition: LowPower.h:50
@ COLD_GPIO_IRQ44
Definition: LowPower.h:66
@ COLD_GPIO_IRQ37
Definition: LowPower.h:59
@ COLD_GPIO_IRQ42
Definition: LowPower.h:64
@ COLD_RTC_ALM1
Definition: LowPower.h:55
@ COLD_SEN_INT
Definition: LowPower.h:70
@ COLD_GPIO_IRQ45
Definition: LowPower.h:67
@ POR_SUPPLY
Definition: LowPower.h:45
@ COLD_GPIO_IRQ38
Definition: LowPower.h:60
@ DEEP_USB_ATTACH
Definition: LowPower.h:51
@ CLOCK_MODE_156MHz
Definition: LowPower.h:78
@ CLOCK_MODE_8MHz
Definition: LowPower.h:80
@ CLOCK_MODE_32MHz
Definition: LowPower.h:79