Contiki-NG
lpm.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.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 copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*---------------------------------------------------------------------------*/
31 /**
32  * \addtogroup cc26xx
33  * @{
34  *
35  * \defgroup cc26xx-lpm CC13xx/CC26xx Low-Power management
36  *
37  * CC13xx/CC26xx low-power operation
38  *
39  * @{
40  *
41  * \file
42  * Header file for the management of CC13xx/CC26xx low-power operation
43  */
44 /*---------------------------------------------------------------------------*/
45 #ifndef LPM_H_
46 #define LPM_H_
47 /*---------------------------------------------------------------------------*/
48 #include "pwr_ctrl.h"
49 
50 #include <stdint.h>
51 /*---------------------------------------------------------------------------*/
52 #define LPM_MODE_AWAKE 0
53 #define LPM_MODE_SLEEP 1
54 #define LPM_MODE_DEEP_SLEEP 2
55 #define LPM_MODE_SHUTDOWN 3
56 
57 #ifndef LPM_MODE_MAX_SUPPORTED_CONF
58 #define LPM_MODE_MAX_SUPPORTED LPM_MODE_DEEP_SLEEP
59 #else
60 #define LPM_MODE_MAX_SUPPORTED LPM_MODE_MAX_SUPPORTED_CONF
61 #endif
62 /*---------------------------------------------------------------------------*/
63 #define LPM_DOMAIN_NONE 0
64 #define LPM_DOMAIN_SERIAL PRCM_DOMAIN_SERIAL
65 #define LPM_DOMAIN_PERIPH PRCM_DOMAIN_PERIPH
66 /*---------------------------------------------------------------------------*/
67 typedef struct lpm_registered_module {
68  struct lpm_registered_module *next;
69  uint8_t (*request_max_pm)(void);
70  void (*shutdown)(uint8_t mode);
71  void (*wakeup)(void);
72  uint32_t domain_lock;
73 } lpm_registered_module_t;
74 /*---------------------------------------------------------------------------*/
75 /**
76  * \brief Declare a variable to be used in order to get notifications from LPM
77  * \param n the variable name to be declared
78  * \param m A pointer to a function which will tell the LPM module the max
79  * PM this module is willing to handle. This function will return
80  * LPM_MODE_SLEEP, LPM_MODE_DEEP_SLEEP etc. The LPM module will ask all
81  * registered modules and will trigger the highest LPM permitted
82  * \param s A pointer to a function which will receive a notification just
83  * before entering the low power mode. The callee can prepare for the
84  * imminent LPM state. The argument to this function will be the
85  * upcoming low power mode. This function can e.g. turn off a
86  * peripheral before the LPM module shuts down the power domain.
87  * \param w A pointer to a function which will be called just after we have
88  * woken up. This can be used to e.g. turn a peripheral back on. This
89  * function is in charge of turning power domains back on. This
90  * function will normally be called within an interrupt context.
91  * \param l Power domain locks, if any are required. The module can request
92  * that the SERIAL or PERIPH PD be kept powered up at the transition
93  * to deep sleep. This field can be a bitwise OR of LPM_DOMAIN_x, so
94  * if required multiple domains can be kept powered.
95  */
96 #define LPM_MODULE(n, m, s, w, l) static lpm_registered_module_t n = \
97  { NULL, m, s, w, l }
98 /*---------------------------------------------------------------------------*/
99 /**
100  * \brief Drop the cortex to sleep / deep sleep and shut down peripherals
101  *
102  * Whether the cortex will drop to sleep or deep sleep is configurable. The
103  * exact peripherals which will be shut down is also configurable
104  */
105 void lpm_drop(void);
106 
107 /**
108  * \brief Enter sleep mode
109  */
110 void lpm_sleep(void);
111 
112 /**
113  * \brief Put the chip in shutdown power mode
114  * \param wakeup_pin The GPIO pin which will wake us up. Must be IOID_0 etc...
115  * \param io_pull Pull configuration for the shutdown pin: IOC_NO_IOPULL,
116  * IOC_IOPULL_UP or IOC_IOPULL_DOWN
117  * \param wake_on High or Low (IOC_WAKE_ON_LOW or IOC_WAKE_ON_HIGH)
118  */
119 void lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on);
120 
121 /**
122  * \brief Register a module for LPM notifications.
123  * \param module A pointer to the data structure with the module definition
124  *
125  * When the LPM module is about to drop to some low power mode, it will first
126  * notify all modules about this.
127  *
128  * This function must not be called before the module has been initialised
129  * with lpm_init(). The code does not perform checks: This is the caller's
130  * responsibility.
131  */
132 void lpm_register_module(lpm_registered_module_t *module);
133 
134 /**
135  * \brief Unregister a module from LPM notifications.
136  * \param module A pointer to the data structure with the module definition
137  *
138  * When a previously registered module is no longer interested in LPM
139  * notifications, this function can be used to unregister it.
140  */
141 void lpm_unregister_module(lpm_registered_module_t *module);
142 
143 /**
144  * \brief Initialise the low-power mode management module
145  */
146 void lpm_init(void);
147 
148 /**
149  * \brief Sets an IOID to a default state
150  * \param ioid IOID_0...
151  *
152  * This will set ioid to sw control, input, no pull. Input buffer and output
153  * driver will both be disabled
154  *
155  * The function will do nothing if ioid == IOID_UNUSED, so the caller does not
156  * have to check board configuration before calling this.
157  */
158 void lpm_pin_set_default_state(uint32_t ioid);
159 /*---------------------------------------------------------------------------*/
160 #endif /* LPM_H_ */
161 /*---------------------------------------------------------------------------*/
162 /**
163  * @}
164  * @}
165  */
void lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on)
Put the chip in shutdown power mode.
Definition: lpm.c:83
void lpm_sleep(void)
Enter sleep mode.
Definition: lpm.c:379
void lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition: lpm.c:525
void lpm_init()
Initialise the low-power mode management module.
Definition: lpm.c:557
void lpm_pin_set_default_state(uint32_t ioid)
Sets an IOID to a default state.
Definition: lpm.c:566
void lpm_unregister_module(lpm_registered_module_t *module)
Unregister a module from LPM notifications.
Definition: lpm.c:551
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.
Definition: lpm.c:545