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 #define LPM_MODE_MAX_SUPPORTED LPM_MODE_DEEP_SLEEP
58 /*---------------------------------------------------------------------------*/
59 #define LPM_DOMAIN_NONE 0
60 #define LPM_DOMAIN_SERIAL PRCM_DOMAIN_SERIAL
61 #define LPM_DOMAIN_PERIPH PRCM_DOMAIN_PERIPH
62 /*---------------------------------------------------------------------------*/
63 typedef struct lpm_registered_module {
64  struct lpm_registered_module *next;
65  uint8_t (*request_max_pm)(void);
66  void (*shutdown)(uint8_t mode);
67  void (*wakeup)(void);
68  uint32_t domain_lock;
69 } lpm_registered_module_t;
70 /*---------------------------------------------------------------------------*/
71 /**
72  * \brief Declare a variable to be used in order to get notifications from LPM
73  * \param n the variable name to be declared
74  * \param m A pointer to a function which will tell the LPM module the max
75  * PM this module is willing to handle. This function will return
76  * LPM_MODE_SLEEP, LPM_MODE_DEEP_SLEEP etc. The LPM module will ask all
77  * registered modules and will trigger the highest LPM permitted
78  * \param s A pointer to a function which will receive a notification just
79  * before entering the low power mode. The callee can prepare for the
80  * imminent LPM state. The argument to this function will be the
81  * upcoming low power mode. This function can e.g. turn off a
82  * peripheral before the LPM module shuts down the power domain.
83  * \param w A pointer to a function which will be called just after we have
84  * woken up. This can be used to e.g. turn a peripheral back on. This
85  * function is in charge of turning power domains back on. This
86  * function will normally be called within an interrupt context.
87  * \param l Power domain locks, if any are required. The module can request
88  * that the SERIAL or PERIPH PD be kept powered up at the transition
89  * to deep sleep. This field can be a bitwise OR of LPM_DOMAIN_x, so
90  * if required multiple domains can be kept powered.
91  */
92 #define LPM_MODULE(n, m, s, w, l) static lpm_registered_module_t n = \
93  { NULL, m, s, w, l }
94 /*---------------------------------------------------------------------------*/
95 /**
96  * \brief Drop the cortex to sleep / deep sleep and shut down peripherals
97  *
98  * Whether the cortex will drop to sleep or deep sleep is configurable. The
99  * exact peripherals which will be shut down is also configurable
100  */
101 void lpm_drop(void);
102 
103 /**
104  * \brief Enter sleep mode
105  */
106 void lpm_sleep(void);
107 
108 /**
109  * \brief Put the chip in shutdown power mode
110  * \param wakeup_pin The GPIO pin which will wake us up. Must be IOID_0 etc...
111  * \param io_pull Pull configuration for the shutdown pin: IOC_NO_IOPULL,
112  * IOC_IOPULL_UP or IOC_IOPULL_DOWN
113  * \param wake_on High or Low (IOC_WAKE_ON_LOW or IOC_WAKE_ON_HIGH)
114  */
115 void lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on);
116 
117 /**
118  * \brief Register a module for LPM notifications.
119  * \param module A pointer to the data structure with the module definition
120  *
121  * When the LPM module is about to drop to some low power mode, it will first
122  * notify all modules about this.
123  *
124  * This function must not be called before the module has been initialised
125  * with lpm_init(). The code does not perform checks: This is the caller's
126  * responsibility.
127  */
128 void lpm_register_module(lpm_registered_module_t *module);
129 
130 /**
131  * \brief Unregister a module from LPM notifications.
132  * \param module A pointer to the data structure with the module definition
133  *
134  * When a previously registered module is no longer interested in LPM
135  * notifications, this function can be used to unregister it.
136  */
137 void lpm_unregister_module(lpm_registered_module_t *module);
138 
139 /**
140  * \brief Initialise the low-power mode management module
141  */
142 void lpm_init(void);
143 
144 /**
145  * \brief Sets an IOID to a default state
146  * \param ioid IOID_0...
147  *
148  * This will set ioid to sw control, input, no pull. Input buffer and output
149  * driver will both be disabled
150  *
151  * The function will do nothing if ioid == IOID_UNUSED, so the caller does not
152  * have to check board configuration before calling this.
153  */
154 void lpm_pin_set_default_state(uint32_t ioid);
155 /*---------------------------------------------------------------------------*/
156 #endif /* LPM_H_ */
157 /*---------------------------------------------------------------------------*/
158 /**
159  * @}
160  * @}
161  */
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:80
void lpm_sleep(void)
Enter sleep mode.
Definition: lpm.c:376
void lpm_drop()
Drop the cortex to sleep / deep sleep and shut down peripherals.
Definition: lpm.c:519
void lpm_init()
Initialise the low-power mode management module.
Definition: lpm.c:551
void lpm_pin_set_default_state(uint32_t ioid)
Sets an IOID to a default state.
Definition: lpm.c:560
void lpm_unregister_module(lpm_registered_module_t *module)
Unregister a module from LPM notifications.
Definition: lpm.c:545
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.
Definition: lpm.c:539