Contiki-NG
power-mgmt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, Zolertia - http://www.zolertia.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup remote-revb
33 * @{
34 *
35 * \defgroup remote-power-mgmt-revb RE-Mote power management driver
36 *
37 * Driver control the power management of the RE-Mote rev B platform. This
38 * driver is an I2C communication with external power manager chip
39 * that controls few functions of the board. Note the driver will work if
40 * powered both over USB and external battery, but the shutdown mode will only
41 * be actually working with external battery
42 *
43 * @{
44 *
45 * \file
46 * Header file for the RE-Mote Power Management driver
47 *
48 * \ingroup remote-power-mgmt-revb
49 * @{
50 */
51/* -------------------------------------------------------------------------- */
52#ifndef POWER_MGMT_H_
53#define POWER_MGMT_H_
54#include "dev/gpio.h"
55/* -------------------------------------------------------------------------- */
56/**
57 * \name Power management controller
58 * @{
59 */
60/* -------------------------------------------------------------------------- */
61#define PWR_MNGMT_ADDR 0x7F /**< Power Management slave address */
62/** @} */
63/* -------------------------------------------------------------------------- */
64#define PM_ENABLE_PORT_BASE GPIO_PORT_TO_BASE(PM_ENABLE_PORT)
65#define PM_ENABLE_PIN_MASK GPIO_PIN_MASK(PM_ENABLE_PIN)
66/* -------------------------------------------------------------------------- */
67/** \name Power Management return values
68 * @{
69 */
70#define PM_SUCCESS 0
71#define PM_ERROR (-1)
72/** @} */
73/* -------------------------------------------------------------------------- */
74/** \name Power Management Registers
75 * @{
76 */
77typedef enum {
78 PM_VBAT = 34, /* Connect/Disconnect battery, it can be "1" (ON) or "0" (OFF) */
79 PM_CURRENT_CHARGE, /* register with pm_charge_current_states options */
80 PM_CHARGE_ENABLE, /* Enable the current charge mode on the battery */
81 PM_SYSOFF, /* Control SYSOFF pin on the battery charger */
82 PM_EXTERNAL_REFERENCE, /* Use reference fot vdd. 0: internal 1:External */
83 PM_HARD_SLEEP_CONFIG, /* Disconnect Battery until event ext2 on RTCC. */
84 PM_SOFT_SLEEP_CONFIG, /* Disconnect Batt without RTCC until PM_SOFT_TIME val */
85 PM_SOFT_TIME, /* Time Out used by system time on hard/soft config */
86 PM_GET_VDD, /* Command to get the current VDD on the system */
87 PM_FW_VERSION, /* Get the Firmware version */
88 PM_GET_NUM_CYCLES, /* Obtain the current sleep cycles at moment */
89 PM_CMD_RST_HARD, /* Disconnect and reconnect the battery */
90 PM_MAX_COMMANDS /* Maximum register commands. Register not valid */
91} pm_registers_t;
92/** @} */
93/* -------------------------------------------------------------------------- */
94/** \name Power Management status and masks
95 * @{
96 */
97#define PM_ENABLE 1 /* Pin status on */
98#define PM_DISABLE 0 /* Pin status off */
99
100#define BATT_CHARGED_VAL 0
101#define BATT_UNCHARGED_VAL 1
102
103#define PM_REFERENCE_INTERNAL 0
104#define PM_REFERENCE_EXTERNAL 1
105
106/* The PIC interval time is 57.20ms given in PM_SOFT_SHTDN_INTERVAL, to set a
107 * timeout period (using the soft shutdown mode) then calculate the time using
108 * this value as base, i.e 10 minutes would be roughly 600000/57.20 ~10490.
109 * The maximum value is 28 days!
110 */
111#define PM_SOFT_SHTDN_INTERVAL 5720
112
113#define PM_SOFT_SHTDN_0_5_SEC 8
114#define PM_SOFT_SHTDN_1_SEC 17
115#define PM_SOFT_SHTDN_1_4_SEC 25
116#define PM_SOFT_SHTDN_5_7_SEC 100
117#define PM_SOFT_SHTDN_30_SEC 524
118#define PM_SOFT_SHTDN_1_MIN 1049
119#define PM_SOFT_SHTDN_5_MIN 5245
120#define PM_SOFT_SHTDN_10_MIN 10490
121#define PM_SOFT_SHTDN_1_H 62937
122#define PM_SOFT_SHTDN_24_H 1510490
123#define PM_SOFT_SHTDN_7_DAYS 10573427
124#define PM_SOFT_SHTDN_14_DAYS 21146853
125#define PM_SOFT_SHTDN_28_DAYS 42383709
126#define PM_SOFT_SHTDN_TEST 0xCC00FFEE
127
128typedef enum {
129 PM_USB100 = 0, /* 100mA chage */
130 PM_USB500, /* 500mA chage */
131 PM_USBEXT, /* USB set by external resistor to ILIM (1K) */
132 PM_USBSUSPEND /* USB in suspend mode */
133} pm_charge_current_states;
134
135/*
136 * VBAT Curve compensation
137 */
138#define PM_VBAT_MULT (float)-181.9
139#define PM_VBAT_OFF (float)1294.72
140
141/** @} */
142/* -------------------------------------------------------------------------- */
143/** \name Power Management functions
144 * @{
145 */
146/** \brief Initializes the Power Management driver
147 * \return PM_SUCCESS if initialized, else PM_ERROR
148 */
149int8_t pm_enable(void);
150
151/** \brief Gets the current firmware version of power management module
152 * \param fwver pointer to get the value of firmware
153 * \return PM_SUCCESS if success, else PM_ERROR
154 */
155int8_t pm_get_fw_ver(uint8_t *fwver);
156
157/** \brief Disconnects the board battery and enter shutdown mode
158 * PM_SOFT/HARD_SLEEP_CONFIG
159 * \param type Hard shutdown (RTCC based) or soft (PIC-governed)
160 * \return Value byte of the register requested.
161 */
162int8_t pm_shutdown_now(uint8_t type);
163
164/** \brief Configure Internal Timeout for Hard and Soft shutdown modes.
165 * In Hard mode, any positive value counts as internal security timeout.
166 * In Soft mode, this value is needed.
167 * \param time value as timeout maximum
168 * \return PM_SUCCESS if success, else PM_ERROR
169 */
170int8_t pm_set_timeout(uint32_t time);
171
172/** \brief Gets the current timeout value configured in power management module
173 * \return value with timeout.
174 */
175uint32_t pm_get_timeout(void);
176
177/** \brief Gets current cycles. incremented each shutdown cycle
178 * \return Number of shutdown cycles
179 */
180uint32_t pm_get_num_cycles(void);
181
182/** \brief Reads the voltage of the external battery if connected to VIN pin
183 * \param state pointer to get the voltage value
184 * \return PM_SUCCESS if success, else PM_ERROR
185 */
186int8_t pm_get_voltage(uint16_t *state);
187
188/** \brief Restarts the on-board low-power PIC, provoking a board reset
189 * \return PM_SUCCESS if success, else PM_ERROR
190 */
191int8_t pm_reset_system(void);
192/* -------------------------------------------------------------------------- */
193/** @} */
194#endif /* POWER_MGMT_H_ */
195/*---------------------------------------------------------------------------*/
196/**
197 * @}
198 * @}
199 * @}
200 */
Header file with register and macro declarations for the cc2538 GPIO module.
uint32_t pm_get_timeout(void)
Gets the current timeout value configured in power management module.
Definition: power-mgmt.c:180
int8_t pm_get_voltage(uint16_t *state)
Reads the voltage of the external battery if connected to VIN pin.
Definition: power-mgmt.c:250
int8_t pm_reset_system(void)
Restarts the on-board low-power PIC, provoking a board reset.
Definition: power-mgmt.c:128
int8_t pm_enable(void)
Initializes the Power Management driver.
Definition: power-mgmt.c:74
int8_t pm_get_fw_ver(uint8_t *fwver)
Gets the current firmware version of power management module.
Definition: power-mgmt.c:280
uint32_t pm_get_num_cycles(void)
Gets current cycles.
Definition: power-mgmt.c:203
int8_t pm_shutdown_now(uint8_t type)
Disconnects the board battery and enter shutdown mode PM_SOFT/HARD_SLEEP_CONFIG.
Definition: power-mgmt.c:223
int8_t pm_set_timeout(uint32_t time)
Configure Internal Timeout for Hard and Soft shutdown modes.
Definition: power-mgmt.c:149