Contiki-NG
Loading...
Searching...
No Matches
power-mgmt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, 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-reva
33 * @{
34 *
35 * \defgroup remote-power-mgmt-reva RE-Mote power management driver
36 *
37 * The power management module is composed by a nano-watt (gating) timer and an
38 * ultra-low power MCU, driving the RE-Mote power supply when connected to an
39 * external battery, and allowing an application to enter a so-called "shutdown
40 * mode".
41 * While in shutdown mode, only the RTCC and the power management block is on,
42 * effectively reducing the RE-Mote power consumption down to <~200nA. The
43 * nano Timer allows the RE-Mote to be awaken off shutdown mode after a given
44 * period (from 100ms to 2 hours, default is 1 minute). To change the shutdown
45 * period, the R47 resistor (at the DELAY input pin, see the RE-Mote datasheet)
46 * has to be changed.
47 * See the TPL5110 datasheet ((Table 2 and 3) for more information about the R47
48 * resistor value, below is a table resuming most common periods:
49 *
50 * +------------+------------+
51 * | R47 (Ohm) | Time |
52 * +------------+------------+
53 * | 500 | 100ms |
54 * +------------+------------+
55 * | 2.5K | 500ms |
56 * +------------+------------+
57 * | 5.202K | 1s |
58 * +------------+------------+
59 * | 22.021K | 1min |
60 * +------------+------------+
61 * | 42.887K | 5min |
62 * +------------+------------+
63 * | 57.434K | 10min |
64 * +------------+------------+
65 * | 92.233K | 30min |
66 * +------------+------------+
67 * | 170K | 2h |
68 * +------------+------------+
69 *
70 * An application can enter the shutdown mode before the shutdown period expires
71 * by invoking the PM_SHUTDOWN_NOW macro.
72 * The on-board RTCC can also be used to drive the CC2538 off PM3 power mode, if
73 * the application requires to retain RAM. Note that while in shutdown mode the
74 * RE-Mote will be powered off.
75 *
76 * @{
77 *
78 * \file
79 * Header file for the RE-Mote Power Management driver
80 */
81/* -------------------------------------------------------------------------- */
82#ifndef POWER_MGMT_H_
83#define POWER_MGMT_H_
84#include "dev/gpio.h"
85/* -------------------------------------------------------------------------- */
86#define PM_CMD_PORT_BASE GPIO_PORT_TO_BASE(PM_CMD_PORT)
87#define PM_CMD_PIN_MASK GPIO_PIN_MASK(PM_CMD_PIN)
88#define PM_DONE_PORT_BASE GPIO_PORT_TO_BASE(PM_DONE_PORT)
89#define PM_DONE_PIN_MASK GPIO_PIN_MASK(PM_DONE_PIN)
90/* -------------------------------------------------------------------------- */
91/** \name Power Management return values
92 * @{
93 */
94#define PM_SUCCESS 0
95#define PM_ERROR (-1)
96#define PM_MAX_BITS 8
97/** @} */
98/* -------------------------------------------------------------------------- */
99/** \name Power Management "done" signal
100 * @{
101 */
102#define PM_SHUTDOWN_NOW GPIO_SET_PIN(PM_DONE_PORT_BASE, PM_DONE_PIN_MASK)
103/** @} */
104/* -------------------------------------------------------------------------- */
105/** \name Power Management timing values
106 * @{
107 */
108#define PM_1_MILISECOND 1000L
109#define PM_2_2_MILISECOND 2200L
110#define PM_3_MILISECOND 3000L
111#define PM_10_MILISECOND 10000L
112/** @} */
113/* -------------------------------------------------------------------------- */
114/** \name Power Management commands
115 * @{
116 */
117typedef enum {
118 PM_CMD_PWR_ON = 0x34,
119 PM_CMD_PWR_OFF = 0x35,
120 PM_CMD_RST_HARD = 0x36,
121 PM_CMD_RST_TIMED = 0x37, /* Not implemented */
122 PM_CMD_DTIMER_ON = 0x38,
123 PM_CMD_DTIMER_OFF = 0x39,
124 PM_CMD_DTIMER_TIMED = 0x3A, /* Not implemented */
125 PM_CMD_PARAM_SET_MAX_TIME = 0x3B, /* Not implemented */
126 PM_CMD_GET_STATE = 0x3C,
127 PM_CMD_GET_FW_VERSION = 0x3D,
128 PM_MAX_NUM_CMDS
129} pm_cmd_t;
130/** @} */
131/* -------------------------------------------------------------------------- */
132/** \name Power Management status and masks
133 * @{
134 */
135typedef enum {
136 PM_IDLE,
137 PM_SYSOFF_OFF,
138 PM_SYSOFF_ON,
139 PM_TIMER_DISABLED,
140 PM_TIMER_ENABLED,
141 PM_AWAITING_RTC_DIS, /* Not implemented */
142 PM_AWAITING_RTC_EVENT, /* Not implemented */
143} pm_state_t;
144
145#define PM_SYSOFF_ON_MASK 0x01
146#define PM_TIMER_ENABLED_MASK 0x02
147#define PM_AWAITING_RTC_EVENT_MASK 0x04
148
149/** @} */
150/* -------------------------------------------------------------------------- */
151/** \name Power Management functions
152 * @{
153 */
154/** \brief Initializes the Power Management driver
155 * \return PM_SUCCESS if initialized, else PM_ERROR
156 */
157int8_t pm_init(void);
158/* -------------------------------------------------------------------------- */
159/** \brief Enable the shutdown mode, periodically driven by the Nano Timer
160 * \return PM_SUCCESS if successful, else PM_ERROR
161 */
162int8_t pm_enable_timer(void);
163/* -------------------------------------------------------------------------- */
164/** \brief Disable the Nano Timer
165 * \return PM_SUCCESS if successful, else PM_ERROR
166 */
167int8_t pm_disable_timer(void);
168/* -------------------------------------------------------------------------- */
169/** \brief Get the current state of the power management module
170 * \param state Pointer to a variable to save the state
171 * \return PM_SUCCESS if successful, else PM_ERROR
172 */
173int8_t pm_get_state(uint8_t *state);
174/* -------------------------------------------------------------------------- */
175/** \brief Get the firmware version of the power management module
176 * \param state Pointer to a variable to save the state
177 * \return PM_SUCCESS if successful, else PM_ERROR
178 */
179int8_t pm_get_firmware_version(uint8_t *state);
180/* -------------------------------------------------------------------------- */
181/** @} */
182#endif /* POWER_MGMT_H_ */
183/*---------------------------------------------------------------------------*/
184/**
185 * @}
186 * @}
187 */
Header file with register and macro declarations for the cc2538 GPIO module.
int8_t pm_get_state(uint8_t *state)
Get the current state of the power management module.
Definition power-mgmt.c:187
int8_t pm_init(void)
Initializes the Power Management driver.
Definition power-mgmt.c:134
int8_t pm_disable_timer(void)
Disable the Nano Timer.
Definition power-mgmt.c:174
int8_t pm_get_firmware_version(uint8_t *state)
Get the firmware version of the power management module.
Definition power-mgmt.c:203
int8_t pm_enable_timer(void)
Enable the shutdown mode, periodically driven by the Nano Timer.
Definition power-mgmt.c:161