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