Contiki 3.x
llwu.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Eistec AB.
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 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND 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 COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the Mulle platform port of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Provide common UART routines for MK60DZ10.
36  *
37  * \author Henrik Makitaavola <henrik@makitaavola.se>
38  * \author Joakim Gebart <joakim.gebart@eistec.se>
39  */
40 
41 #ifndef LLWU_H_
42 #define LLWU_H_
43 
44 #include <stdint.h>
45 #include "K60.h"
46 #include "synchronization.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 extern volatile uint32_t llwu_inhibit_lls_sema;
53 extern volatile uint32_t llwu_inhibit_vlps_sema;
54 extern volatile uint32_t llwu_inhibit_stop_sema;
55 
56 /** Internal modules whose interrupts are mapped to LLWU wake up sources.
57  *
58  * Wake up source module number: Kinetis Module
59  * 0: LPTMR
60  * 1: CMP0
61  * 2: CMP1
62  * 3: CMP2
63  * 4: TSI
64  * 5: RTC Alarm
65  * 6: Reserved
66  * 7: RTC Seconds
67  *
68  * Other modules CAN NOT be used to wake the CPU from LLS or VLLSx power modes.
69  */
70 typedef enum llwu_wakeup_module {
71  LLWU_WAKEUP_MODULE_LPTMR = 0,
72  LLWU_WAKEUP_MODULE_CMP0 = 1,
73  LLWU_WAKEUP_MODULE_CMP1 = 2,
74  LLWU_WAKEUP_MODULE_CMP2 = 3,
75  LLWU_WAKEUP_MODULE_TSI = 4,
76  LLWU_WAKEUP_MODULE_RTC_ALARM = 5,
77  LLWU_WAKEUP_MODULE_RESERVED = 6,
78  LLWU_WAKEUP_MODULE_RTC_SECONDS = 7,
79  LLWU_WAKEUP_MODULE_END,
81 
82 /** enum that maps physical pins to wakeup pin numbers in LLWU module
83  *
84  * Other modules CAN NOT be used to wake the CPU from LLS or VLLSx power modes. */
85 typedef enum llwu_wakeup_pin {
86  LLWU_WAKEUP_PIN_PTE1 = 0,
87  LLWU_WAKEUP_PIN_PTE2 = 1,
88  LLWU_WAKEUP_PIN_PTE4 = 2,
89  LLWU_WAKEUP_PIN_PTA4 = 3,
90  LLWU_WAKEUP_PIN_PTA13 = 4,
91  LLWU_WAKEUP_PIN_PTB0 = 5,
92  LLWU_WAKEUP_PIN_PTC1 = 6,
93  LLWU_WAKEUP_PIN_PTC3 = 7,
94  LLWU_WAKEUP_PIN_PTC4 = 8,
95  LLWU_WAKEUP_PIN_PTC5 = 9,
96  LLWU_WAKEUP_PIN_PTC6 = 10,
97  LLWU_WAKEUP_PIN_PTC11 = 11,
98  LLWU_WAKEUP_PIN_PTD0 = 12,
99  LLWU_WAKEUP_PIN_PTD2 = 13,
100  LLWU_WAKEUP_PIN_PTD4 = 14,
101  LLWU_WAKEUP_PIN_PTD6 = 15,
102  LLWU_WAKEUP_PIN_END
104 
105 typedef enum llwu_wakeup_edge {
106  LLWU_WAKEUP_EDGE_DISABLE = 0b00,
107  LLWU_WAKEUP_EDGE_RISING = 0b01,
108  LLWU_WAKEUP_EDGE_FALLING = 0b10,
109  LLWU_WAKEUP_EDGE_ANY = 0b11,
110 } llwu_wakeup_edge_t;
111 
112 #define LLWU_WAKEUP_EDGE_MASK (0x03)
113 #define LLWU_WAKEUP_EDGE_WIDTH (2)
114 #define LLWU_WAKEUP_PIN_REG_SIZE (4)
115 
116 typedef struct llwu_control {
117  struct llwu_control *next;
118  char allow_llwu;
119 } llwu_control_t;
120 
121 /* Macro to create new llwu control struct for clients. */
122 #define LLWU_CONTROL(name) static llwu_control_t name[1] = { { NULL, 1 } } /* default allow deep sleep */
123 
124 void llwu_init();
125 
126 /**
127  * Sleep until some process is polled, ie interrupt occurs.
128  */
129 void llwu_sleep();
130 /**
131  * Register as a controller for llwu.
132  * @param c Controller struct.
133  */
134 void llwu_register(llwu_control_t *c);
135 
136 /**
137  * Method for a controller to allow or disallow deep sleep.
138  * @param c Control struct
139  * @param allow 0 to disable deep sleep, other than 0 to allow.
140  */
141 void llwu_set_allow(llwu_control_t *c, char allow);
142 
143 void llwu_enable_wakeup_module(const llwu_wakeup_module_t module);
144 void llwu_disable_wakeup_module(const llwu_wakeup_module_t module);
145 void llwu_set_wakeup_pin(const llwu_wakeup_pin_t pin, const llwu_wakeup_edge_t edge);
146 
147 /* We can not use a lock variable for the inhibit counters, because that can
148  * lead to deadlocks in ISRs, but we can use the exclusive load/store
149  * instructions (same as used for implementing thread safe locks) for the
150  * inhibit counters themselves to make sure we never lose an increment or
151  * decrement. */
152 #define LLWU_INHIBIT_STOP() (exclusive_increment(&llwu_inhibit_lls_sema))
153 #define LLWU_INHIBIT_VLPS() (exclusive_increment(&llwu_inhibit_vlps_sema))
154 #define LLWU_INHIBIT_LLS() (exclusive_increment(&llwu_inhibit_lls_sema))
155 #define LLWU_UNINHIBIT_STOP() (exclusive_decrement(&llwu_inhibit_stop_sema))
156 #define LLWU_UNINHIBIT_VLPS() (exclusive_decrement(&llwu_inhibit_vlps_sema))
157 #define LLWU_UNINHIBIT_LLS() (exclusive_decrement(&llwu_inhibit_lls_sema))
158 
159 #ifdef __cplusplus
160 } /* extern "C" */
161 #endif
162 
163 #endif /* LLWU_H_ */
enum llwu_wakeup_pin llwu_wakeup_pin_t
enum that maps physical pins to wakeup pin numbers in LLWU module
llwu_wakeup_pin
enum that maps physical pins to wakeup pin numbers in LLWU module
Definition: llwu.h:85
void llwu_sleep(void)
Sleep until some process is polled, ie interrupt occurs.
Definition: llwu.c:76
K60 hardware register header wrapper.
void llwu_set_allow(llwu_control_t *c, char allow)
Method for a controller to allow or disallow deep sleep.
Definition: llwu.c:54
Synchronization primitives for Cortex-M3/M4 processors.
enum llwu_wakeup_module llwu_wakeup_module_t
Internal modules whose interrupts are mapped to LLWU wake up sources.
void llwu_register(llwu_control_t *c)
Register as a controller for llwu.
Definition: llwu.c:47
llwu_wakeup_module
Internal modules whose interrupts are mapped to LLWU wake up sources.
Definition: llwu.h:70