Contiki-NG
gpio-hal-arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, George Oikonomou - http://www.spd.gr
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  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*---------------------------------------------------------------------------*/
32 /**
33  * \addtogroup cc2538
34  * @{
35  *
36  * \defgroup cc2538-gpio-hal CC2538 GPIO HAL implementation
37  *
38  * @{
39  *
40  * \file
41  * Header file for the CC2538 GPIO HAL functions
42  *
43  * \note
44  * Do not include this header directly
45  */
46 /*---------------------------------------------------------------------------*/
47 #ifndef GPIO_HAL_ARCH_H_
48 #define GPIO_HAL_ARCH_H_
49 /*---------------------------------------------------------------------------*/
50 #include "contiki.h"
51 #include "dev/gpio.h"
52 
53 #include <stdint.h>
54 /*---------------------------------------------------------------------------*/
55 #define PIN_TO_PORT(pin) (pin >> 3)
56 #define PIN_TO_NUM(pin) (pin % 8)
57 #define PIN_TO_PORT_BASE(pin) GPIO_PORT_TO_BASE(PIN_TO_PORT(pin))
58 /*---------------------------------------------------------------------------*/
59 #define gpio_hal_arch_interrupt_enable(p) do { \
60  GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
61  NVIC_EnableIRQ(PIN_TO_PORT(p)); \
62 } while(0);
63 
64 #define gpio_hal_arch_interrupt_disable(p) \
65  GPIO_DISABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
66 
67 #define gpio_hal_arch_pin_set_input(p) do { \
68  GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
69  GPIO_SET_INPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
70 } while(0);
71 
72 #define gpio_hal_arch_pin_set_output(p) do { \
73  GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
74  GPIO_SET_OUTPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
75 } while(0);
76 
77 #define gpio_hal_arch_set_pin(p) \
78  GPIO_SET_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
79 
80 #define gpio_hal_arch_clear_pin(p) \
81  GPIO_CLR_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
82 
83 #define gpio_hal_arch_read_pin(p) \
84  (GPIO_READ_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) == 0 ? 0 : 1)
85 /*---------------------------------------------------------------------------*/
86 #endif /* GPIO_HAL_ARCH_H_ */
87 /*---------------------------------------------------------------------------*/
88 /**
89  * @}
90  * @}
91  */
Header file with register and macro declarations for the cc2538 GPIO module.