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_init() do { /* Do nothing */ } while(0)
60 
61 #define gpio_hal_arch_interrupt_enable(port, p) do { \
62  GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
63  NVIC_EnableIRQ(PIN_TO_PORT(p)); \
64 } while(0);
65 
66 #define gpio_hal_arch_interrupt_disable(port, p) \
67  GPIO_DISABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
68 
69 #define gpio_hal_arch_pin_set_input(port, p) do { \
70  GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
71  GPIO_SET_INPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
72 } while(0);
73 
74 #define gpio_hal_arch_pin_set_output(port, p) do { \
75  GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
76  GPIO_SET_OUTPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
77 } while(0);
78 
79 #define gpio_hal_arch_set_pin(port, p) \
80  GPIO_SET_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
81 
82 #define gpio_hal_arch_clear_pin(port, p) \
83  GPIO_CLR_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
84 
85 #define gpio_hal_arch_read_pin(port, p) \
86  (GPIO_READ_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) == 0 ? 0 : 1)
87 /*---------------------------------------------------------------------------*/
88 #endif /* GPIO_HAL_ARCH_H_ */
89 /*---------------------------------------------------------------------------*/
90 /**
91  * @}
92  * @}
93  */
Header file with register and macro declarations for the cc2538 GPIO module.