Contiki-NG
aux-ctrl.c
1/*
2 * Copyright (c) 2016, University of Bristol - http://www.bris.ac.uk/
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#include "contiki.h"
32#include "dev/aux-ctrl.h"
33#include "lib/list.h"
34
35#include "ti-lib.h"
36
37#include <stdint.h>
38#include <stdbool.h>
39#include <stddef.h>
40/*---------------------------------------------------------------------------*/
41LIST(consumers_list);
42/*---------------------------------------------------------------------------*/
43void
45{
46 bool interrupts_disabled = ti_lib_int_master_disable();
47
48 list_add(consumers_list, consumer);
49
51
52 ti_lib_aux_wuc_clock_enable(consumer->clocks);
53 while(ti_lib_aux_wuc_clock_status(consumer->clocks) != AUX_WUC_CLOCK_READY);
54
55 if(!interrupts_disabled) {
56 ti_lib_int_master_enable();
57 }
58}
59/*---------------------------------------------------------------------------*/
60void
62{
63 bool interrupts_disabled = ti_lib_int_master_disable();
64
65 list_remove(consumers_list, consumer);
66
68
69 if(!interrupts_disabled) {
70 ti_lib_int_master_enable();
71 }
72}
73/*---------------------------------------------------------------------------*/
74void
76{
77 /* Don't if we have no consumers */
78 if(list_head(consumers_list) == NULL) {
79 return;
80 }
81
82 ti_lib_aon_wuc_aux_wakeup_event(AONWUC_AUX_WAKEUP);
83 while(!(ti_lib_aon_wuc_power_status_get() & AONWUC_AUX_POWER_ON));
84}
85/*---------------------------------------------------------------------------*/
86void
88{
89 aux_consumer_module_t *consumer;
90 uint32_t clocks_in_use = 0;
91
92 if(!force) {
93 /* Visit all modules and release clocks */
94 for(consumer = list_head(consumers_list); consumer != NULL;
95 consumer = consumer->next) {
96 clocks_in_use |= consumer->clocks;
97 }
98
99 /* If any clocks are still in use, AUX needs to stay powered and clocked */
100 if(clocks_in_use) {
101 ti_lib_aon_wuc_aux_power_down_config(AONWUC_CLOCK_SRC_LF);
102 return;
103 }
104 }
105
106 /* No clock for AUX in power down */
107 ti_lib_aon_wuc_aux_power_down_config(AONWUC_NO_CLOCK);
108
109 /* Disable retention */
110 ti_lib_aon_wuc_aux_sram_config(false);
111
112 /* Turn off AUX */
113 ti_lib_aon_wuc_aux_wakeup_event(AONWUC_AUX_ALLOW_SLEEP);
114 ti_lib_aux_wuc_power_ctrl(AUX_WUC_POWER_OFF);
115 while(ti_lib_aon_wuc_power_status_get() & AONWUC_AUX_POWER_ON);
116}
117/*---------------------------------------------------------------------------*/
Header file for the management of the CC13xx/CC26xx AUX domain.
void aux_ctrl_unregister_consumer(aux_consumer_module_t *consumer)
Deregister a module that no longer requires access to the AUX power domain.
Definition: aux-ctrl.c:61
void aux_ctrl_power_up()
Power-up the AUX power domain.
Definition: aux-ctrl.c:75
void aux_ctrl_power_down(bool force)
Power down the AUX power domain.
Definition: aux-ctrl.c:87
void aux_ctrl_register_consumer(aux_consumer_module_t *consumer)
Register a module that no longer requires access to the AUX power domain.
Definition: aux-ctrl.c:44
#define LIST(name)
Declare a linked list.
Definition: list.h:89
void list_add(list_t list, void *item)
Add an item at the end of a list.
Definition: list.c:89
void list_remove(list_t list, const void *item)
Remove a specific element from a list.
Definition: list.c:152
void * list_head(const_list_t list)
Get a pointer to the first element of a list.
Definition: list.c:63
Linked list manipulation routines.
The data structure to be used for modules that require access to AUX.
Definition: aux-ctrl.h:62
Header file with macros which rename TI CC26xxware functions.