From 565305d6c3012d046686588491f41bd4ebf14faf Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 3 Dec 2017 21:56:13 +0000 Subject: [PATCH 01/12] Introduce new GPIO Hardware Abstraction Layer --- os/dev/gpio-hal.c | 97 +++++++++ os/dev/gpio-hal.h | 495 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 592 insertions(+) create mode 100644 os/dev/gpio-hal.c create mode 100644 os/dev/gpio-hal.h diff --git a/os/dev/gpio-hal.c b/os/dev/gpio-hal.c new file mode 100644 index 000000000..70b50b688 --- /dev/null +++ b/os/dev/gpio-hal.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup gpio-hal + * @{ + * + * \file + * Implementation of the platform-independent aspects of the GPIO HAL + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +#include "lib/list.h" + +#include +#include +/*---------------------------------------------------------------------------*/ +LIST(handlers); +/*---------------------------------------------------------------------------*/ +void +gpio_hal_register_handler(gpio_hal_event_handler_t *handler) +{ + list_add(handlers, handler); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_event_handler(gpio_hal_pin_mask_t pins) +{ + gpio_hal_event_handler_t *this; + + for(this = list_head(handlers); this != NULL; this = this->next) { + if(pins & this->pin_mask) { + if(this->handler != NULL) { + this->handler(pins & this->pin_mask); + } + } + } +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_init() +{ + list_init(handlers); +} +/*---------------------------------------------------------------------------*/ +#if GPIO_HAL_ARCH_SW_TOGGLE +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_toggle_pin(gpio_hal_pin_t pin) +{ + if(pin >= GPIO_HAL_PIN_COUNT) { + return; + } + + gpio_hal_arch_write_pin(pin, gpio_hal_arch_read_pin(pin) ^ 1); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_toggle_pins(gpio_hal_pin_mask_t pins) +{ + gpio_hal_arch_write_pins(pins, ~gpio_hal_arch_read_pins(pins)); +} +/*---------------------------------------------------------------------------*/ +#endif /* GPIO_HAL_ARCH_SW_TOGGLE */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/os/dev/gpio-hal.h b/os/dev/gpio-hal.h new file mode 100644 index 000000000..aacbfb1f1 --- /dev/null +++ b/os/dev/gpio-hal.h @@ -0,0 +1,495 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup dev + * @{ + * + * \defgroup gpio-hal GPIO Hardware Abstraction Layer + * + * The GPIO HAL provides a set of common functions that can be used in a + * platform-independent fashion. + * + * Internally, the GPIO HAL handles edge detection handling and also provides + * fallback functions for GPIO pin toggling if the hardware does not have + * a direct method of toggling pins through direct register access. + * + * @{ + * + * \file + * Header file for the GPIO HAL + */ +/*---------------------------------------------------------------------------*/ +#ifndef GPIO_HAL_H_ +#define GPIO_HAL_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" + +#include +/*---------------------------------------------------------------------------*/ +/** + * \brief Specifies whether software-based pin toggle is required + * + * Some MCUs allow GPIO pin toggling via direct register access. For these + * MCUs, define GPIO_HAL_CONF_ARCH_SW_TOGGLE to 0 and then implement + * gpio_hal_arch_toggle_pin() and gpio_hal_arch_toggle_pins() + * + * \sa gpio_hal_arch_toggle_pin() + * \sa gpio_hal_arch_toggle_pins() + */ +#ifdef GPIO_HAL_CONF_ARCH_SW_TOGGLE +#define GPIO_HAL_ARCH_SW_TOGGLE GPIO_HAL_CONF_ARCH_SW_TOGGLE +#else +#define GPIO_HAL_ARCH_SW_TOGGLE 1 +#endif +/*---------------------------------------------------------------------------*/ +/** + * \brief GPIO pin number representation + */ +typedef uint8_t gpio_hal_pin_t; + +/** + * \brief GPIO pin configuration + * + * A logical representation of a pin's configuration. It is an OR combination + * of GPIO_HAL_PIN_CFG_xyz macros. + */ +typedef uint8_t gpio_hal_pin_cfg_t; + +#ifdef GPIO_HAL_CONF_PIN_COUNT +#define GPIO_HAL_PIN_COUNT GPIO_HAL_CONF_PIN_COUNT +#else +#define GPIO_HAL_PIN_COUNT 32 +#endif + +#if GPIO_HAL_PIN_COUNT > 32 +typedef uint64_t gpio_hal_pin_mask_t; +#else +/** + * \brief GPIO pin mask representation + */ +typedef uint32_t gpio_hal_pin_mask_t; +#endif + +typedef void (*gpio_hal_callback_t)(gpio_hal_pin_mask_t pin_mask); +/*---------------------------------------------------------------------------*/ +#define GPIO_HAL_PIN_CFG_PULL_NONE 0x00 +#define GPIO_HAL_PIN_CFG_PULL_UP 0x01 +#define GPIO_HAL_PIN_CFG_PULL_DOWN 0x02 +#define GPIO_HAL_PIN_CFG_PULL_MASK (GPIO_HAL_PIN_CFG_PULL_UP | \ + GPIO_HAL_PIN_CFG_PULL_DOWN) + +#define GPIO_HAL_PIN_CFG_EDGE_NONE 0x00 +#define GPIO_HAL_PIN_CFG_EDGE_RISING 0x04 +#define GPIO_HAL_PIN_CFG_EDGE_FALLING 0x08 +#define GPIO_HAL_PIN_CFG_EDGE_BOTH (GPIO_HAL_PIN_CFG_EDGE_RISING | \ + GPIO_HAL_PIN_CFG_EDGE_FALLING) + +#define GPIO_HAL_PIN_CFG_INT_DISABLE 0x00 +#define GPIO_HAL_PIN_CFG_INT_ENABLE 0x80 +#define GPIO_HAL_PIN_CFG_INT_MASK 0x80 +/*---------------------------------------------------------------------------*/ +/** + * \brief Datatype for GPIO event handlers + * + * A GPIO event handler is a function that gets called whenever a pin triggers + * an event. The same handler can be registered to handle events for more than + * one pin by setting the respective pin's position but in \e pin_mask. + */ +typedef struct gpio_hal_event_handler_s { + struct gpio_hal_event_handler_s *next; + gpio_hal_callback_t handler; + gpio_hal_pin_mask_t pin_mask; +} gpio_hal_event_handler_t; +/*---------------------------------------------------------------------------*/ +/** + * \name Core GPIO functions + * + * Functions implemented by the HAL itself + * @{ + */ +/** + * \brief Initialise the GPIO HAL + */ +void gpio_hal_init(void); + +/** + * \brief Register a function to be called whenever a pin triggers an event + * \param handler The handler representation + * + * The handler must be pre-allocated statically by the caller. + * + * This function can be used to register a function to be called by the HAL + * whenever a GPIO interrupt occurs. + * + * \sa gpio_hal_event_handler + */ +void gpio_hal_register_handler(gpio_hal_event_handler_t *handler); + +/** + * \brief The platform-independent GPIO event handler + * \param pins OR mask of pins that generated an event + * + * Whenever a GPIO input interrupt occurs (edge or level detection) and an ISR + * is triggered, the ISR must call this function, passing as argument an ORd + * mask of the pins that triggered the interrupt. This function will then + * call the registered event handlers (if any) for the pins that triggered the + * event. The platform code should make no assumptions as to the order that + * the handlers will be called. + * + * If a pin set in the mask has an event handler registered, this function + * will call the registered handler. + * + * This function will not clear any CPU interrupt flags, this should be done + * by the calling ISR. + * + * \sa gpio_hal_register_handler + */ +void gpio_hal_event_handler(gpio_hal_pin_mask_t pins); + +/** + * \brief Convert a pin to a pin mask + * \param pin The pin + * \return The corresponding mask + */ +#define gpio_hal_pin_to_mask(pin) (1 << (pin)) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Functions to be provided by the platform + * + * All the functions below must be provided by the platform's developer. The + * HAL offers the developer a number of options of how to provide the required + * functionality. + * + * - The developer can provide a symbol. For example, the developer can create + * a .c file and implement a function called gpio_hal_arch_set_pin() + * - The developer can provide a function-like macro that has the same name as + * the function declared here. In this scenario, the declaration here will + * be removed by the pre-processor. For example, the developer can do + * something like: + * + * \code + * #define gpio_hal_arch_write_pin(p, v) platform_sdk_function(p, v) + * \endcode + * + * - The developer can provide a static inline implementation. For this to + * work, the developer can do something like: + * + * \code + * #define gpio_hal_arch_set_pin(p) set_pin(p) + * static inline void set_pin(gpio_hal_pin_t pin) { ... } + * \endcode + * + * In the latter two cases, the developer will likely provide implementations + * in a header file. In this scenario, one of the platform's configuration + * files must define GPIO_HAL_CONF_ARCH_HDR_PATH to the name of this header + * file. For example: + * + * \code + * #define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h" + * \endcode + * + * @{ + */ +/*---------------------------------------------------------------------------*/ +/* Include Arch-Specific conf */ +#ifdef GPIO_HAL_CONF_ARCH_HDR_PATH +#include GPIO_HAL_CONF_ARCH_HDR_PATH +#endif /* GPIO_HAL_CONF_ARCH_HDR_PATH */ +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_interrupt_enable +/** + * \brief Enable interrupts for a gpio pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_interrupt_disable +/** + * \brief Disable interrupts for a gpio pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_pin_cfg_set +/** + * \brief Configure a gpio pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * \param cfg The configuration + * + * \e cfg is an OR mask of GPIO_HAL_PIN_CFG_xyz + * + * The implementation of this function also has to make sure that \e pin is + * configured as software-controlled GPIO. + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_pin_cfg_get +/** + * \brief Read the configuration of a GPIO pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * \return An OR mask of GPIO_HAL_PIN_CFG_xyz + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +gpio_hal_pin_cfg_t gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_pin_set_input +/** + * \brief Configure a pin as GPIO input + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * The implementation of this function also has to make sure that \e pin is + * configured as software-controlled GPIO. + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_pin_set_input(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_pin_set_output +/** + * \brief Configure a pin as GPIO output + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * The implementation of this function also has to make sure that \e pin is + * configured as software-controlled GPIO. + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_pin_set_output(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_set_pin +/** + * \brief Set a GPIO pin to logical high + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_set_pin(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_clear_pin +/** + * \brief Clear a GPIO pin (logical low) + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_clear_pin(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_toggle_pin +/** + * \brief Toggle a GPIO pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * + * Some MCUs allow GPIO pin toggling directly via register access. In this + * case, it is a good idea to provide an implementation of this function. + * However, a default, software-based implementation is also provided by the + * HAL and can be used if the MCU does not have a pin toggle register. To use + * the HAL function, define GPIO_HAL_ARCH_SW_TOGGLE as 1. To provide your own + * implementation, define GPIO_HAL_ARCH_SW_TOGGLE as 0. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_toggle_pin(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_read_pin +/** + * \brief Read a GPIO pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * \retval 0 The pin is logical low + * \retval 1 The pin is logical high + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +uint8_t gpio_hal_arch_read_pin(gpio_hal_pin_t pin); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_write_pin +/** + * \brief Write a GPIO pin + * \param pin The GPIO pin number (0...GPIO_HAL_PIN_COUNT - 1) + * \param value 0: Logical low; 1: Logical high + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_set_pins +/** + * \brief Set multiple pins to logical high + * \param pins An ORd pin mask of the pins to set + * + * A pin will be set to logical high if its position in \e pins is set. For + * example you can set pins 0 and 3 by passing 0x09. + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_clear_pins +/** + * \brief Clear multiple pins to logical low + * \param pins An ORd pin mask of the pins to clear + * + * A pin will be set to logical low if its position in \e pins is set. For + * example you can clear pins 0 and 3 by passing 0x09. + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_toggle_pins +/** + * \brief Toggle multiple pins + * \param pins An ORd pin mask of the pins to toggle + * + * A pin will be toggled if its position in \e pins is set. For example you + * can toggle pins 0 and 3 by passing 0x09. + * + * Some MCUs allow GPIO pin toggling directly via register access. In this + * case, it is a good idea to provide an implementation of this function. + * However, a default, software-based implementation is also provided by the + * HAL and can be used if the MCU does not have a pin toggle register. To use + * the HAL function, define GPIO_HAL_ARCH_SW_TOGGLE as 1. To provide your own + * implementation, define GPIO_HAL_ARCH_SW_TOGGLE as 0. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_toggle_pins(gpio_hal_pin_mask_t pins); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_read_pins +/** + * \brief Read multiple pins + * \param pins An ORd pin mask of the pins to read + * \retval An ORd mask of the pins that are high + * + * If the position of the pin in \e pins is set and the pin is logical high + * then the position of the pin in the return value will be set. For example, + * if you pass 0x09 as the value of \e pins and the return value is 0x08 then + * pin 3 is logical high and pin 0 is logical low. + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +gpio_hal_pin_mask_t gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins); +#endif +/*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_write_pins +/** + * \brief Write multiple pins + * \param pins An ORd pin mask of the pins to write + * \param value An ORd mask of the value to write + * + * The function will modify GPIO pins that have their position in the mask set. + * pins, the function will write the value specified in the corresponding + * position in \e value. + + * For example, you can set pin 3 and clear pin 0 by a single call to this + * function. To achieve this, \e pins must be 0x09 and \e value 0x08. + * + * It is the platform developer's responsibility to provide an implementation. + * + * There is no guarantee that this function will result in an atomic operation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_write_pins(gpio_hal_pin_mask_t pins, + gpio_hal_pin_mask_t value); +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* GPIO_HAL_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From d88c3d0c01e5eec83a3cff4ff967be96cf4e25aa Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Dec 2017 22:18:07 +0000 Subject: [PATCH 02/12] Implement the GPIO HAL for CC13xx/CC26xx --- arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h | 4 + arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c | 156 +++++++++++++++++++++ arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h | 84 +++++++++++ 3 files changed, 244 insertions(+) create mode 100644 arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c create mode 100644 arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h index e8720b5f4..7b914ac1e 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h +++ b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h @@ -99,6 +99,10 @@ /* Path to headers with implementation of mutexes and memory barriers */ #define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h" #define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h" + +#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h" +/*---------------------------------------------------------------------------*/ +#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0 /*---------------------------------------------------------------------------*/ #endif /* CC13XX_CC26XX_DEF_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c new file mode 100644 index 000000000..a7b025800 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc26xx-gpio-hal + * @{ + * + * \file + * Implementation file for the CC13xx/CC26xx GPIO HAL functions + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "ti-lib.h" +#include "ti-lib-rom.h" +#include "dev/gpio-hal.h" + +#include +/*---------------------------------------------------------------------------*/ +#define CONFIG_MASK (IOC_IOPULL_M | IOC_INT_M | IOC_IOMODE_OPEN_SRC_INV) +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) +{ + uint32_t config; + gpio_hal_pin_cfg_t tmp; + + /* Clear settings that we are about to change, keep everything else */ + config = ti_lib_rom_ioc_port_configure_get(pin); + config &= ~CONFIG_MASK; + + tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH; + if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) { + config |= IOC_NO_EDGE; + } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) { + config |= IOC_RISING_EDGE; + } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) { + config |= IOC_FALLING_EDGE; + } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) { + config |= IOC_BOTH_EDGES; + } + + tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK; + if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) { + config |= IOC_NO_IOPULL; + } else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) { + config |= IOC_IOPULL_DOWN; + } else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) { + config |= IOC_IOPULL_UP; + } + + tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK; + if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) { + config |= IOC_INT_DISABLE; + } else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) { + config |= IOC_INT_ENABLE; + } + + ti_lib_rom_ioc_port_configure_set(pin, IOC_PORT_GPIO, config); +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_cfg_t +gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) +{ + gpio_hal_pin_cfg_t cfg; + uint32_t tmp; + uint32_t config; + + cfg = 0; + config = ti_lib_rom_ioc_port_configure_get(pin); + + /* Pull */ + tmp = config & IOC_IOPULL_M; + if(tmp == IOC_IOPULL_UP) { + cfg |= GPIO_HAL_PIN_CFG_PULL_UP; + } else if(tmp == IOC_IOPULL_DOWN) { + cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN; + } else if(tmp == IOC_NO_IOPULL) { + cfg |= GPIO_HAL_PIN_CFG_PULL_NONE; + } + + /* Interrupt enable/disable */ + tmp = config & IOC_INT_ENABLE; + if(tmp == IOC_INT_DISABLE) { + cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE; + } else if(tmp == IOC_INT_ENABLE) { + cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE; + } + + /* Edge detection */ + tmp = config & IOC_BOTH_EDGES; + if(tmp == IOC_NO_EDGE) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE; + } else if(tmp == IOC_FALLING_EDGE) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING; + } else if(tmp == IOC_RISING_EDGE) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING; + } else if(tmp == IOC_BOTH_EDGES) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH; + } + + return cfg; +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_mask_t +gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) +{ + gpio_hal_pin_mask_t oe_pins; + + /* For pins configured as output we need to read DOUT31_0 */ + oe_pins = ti_lib_gpio_get_output_enable_multi_dio(pins); + + pins &= ~oe_pins; + + return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) & oe_pins) | + ti_lib_gpio_read_multi_dio(pins); +} +/*---------------------------------------------------------------------------*/ +uint8_t +gpio_hal_arch_read_pin(gpio_hal_pin_t pin) +{ + if(ti_lib_gpio_get_output_enable_dio(pin)) { + return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) >> pin) & 1; + } + + return ti_lib_gpio_read_dio(pin); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h new file mode 100644 index 000000000..7d87670c5 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc26xx + * @{ + * + * \defgroup cc26xx-gpio-hal CC13xx/CC26xx GPIO HAL implementation + * + * @{ + * + * \file + * Header file for the CC13xx/CC26xx GPIO HAL functions + * + * \note + * Do not include this header directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef GPIO_HAL_ARCH_H_ +#define GPIO_HAL_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "ti-lib.h" +#include "ti-lib-rom.h" + +#include +/*---------------------------------------------------------------------------*/ +#define gpio_hal_arch_interrupt_enable(p) interrupt_enable(p) +#define gpio_hal_arch_interrupt_disable(p) ti_lib_rom_ioc_int_disable(p) + +#define gpio_hal_arch_pin_set_input(p) ti_lib_rom_ioc_pin_type_gpio_input(p) +#define gpio_hal_arch_pin_set_output(p) ti_lib_rom_ioc_pin_type_gpio_output(p) + +#define gpio_hal_arch_set_pin(p) ti_lib_gpio_set_dio(p) +#define gpio_hal_arch_clear_pin(p) ti_lib_gpio_clear_dio(p) +#define gpio_hal_arch_toggle_pin(p) ti_lib_gpio_toggle_dio(p) +#define gpio_hal_arch_write_pin(p, v) ti_lib_gpio_write_dio(p, v) + +#define gpio_hal_arch_set_pins(p) ti_lib_gpio_set_multi_dio(p) +#define gpio_hal_arch_clear_pins(p) ti_lib_gpio_clear_multi_dio(p) +#define gpio_hal_arch_toggle_pins(p) ti_lib_gpio_toggle_multi_dio(p) +#define gpio_hal_arch_write_pins(p, v) ti_lib_gpio_write_multi_dio(p, v) +/*---------------------------------------------------------------------------*/ +static inline void +interrupt_enable(gpio_hal_pin_t pin) +{ + ti_lib_gpio_clear_event_dio(pin); + ti_lib_rom_ioc_int_enable(pin); +} +/*---------------------------------------------------------------------------*/ +#endif /* GPIO_HAL_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From 421d95bc008c4161604742a20476cdf0ebfd7e8f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Dec 2017 22:43:20 +0000 Subject: [PATCH 03/12] Build the GPIO HAL for CC13xx/CC26xx --- arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index 9a2899ea7..22f1c4dd0 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -32,7 +32,7 @@ CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c soc-rtc.c uart.c CONTIKI_CPU_SOURCEFILES += contiki-watchdog.c aux-ctrl.c CONTIKI_CPU_SOURCEFILES += putchar.c ieee-addr.c batmon-sensor.c adc-sensor.c CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c cc26xx-uart.c lpm.c -CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c oscillators.c +CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c gpio-hal-arch.c oscillators.c CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c From f1d1932c5cde4a8a06bbe1ebbec5c258e6c1b7b9 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Dec 2017 22:47:44 +0000 Subject: [PATCH 04/12] Adjust CC13xx/CC26xx drivers to use the GPIO HAL --- arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c | 1 - arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c | 53 ++------------ arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.h | 71 ------------------- .../srf06-cc26xx/launchpad/button-sensor.c | 17 +++-- arch/platform/srf06-cc26xx/platform.c | 5 +- .../srf06-cc26xx/sensortag/button-sensor.c | 17 +++-- .../srf06-cc26xx/sensortag/reed-relay.c | 13 ++-- .../srf06-cc26xx/srf06/button-sensor.c | 23 +++--- 8 files changed, 58 insertions(+), 142 deletions(-) delete mode 100644 arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c b/arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c index 1f736bb53..c88b2e5fe 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c +++ b/arch/cpu/cc26xx-cc13xx/dev/adc-sensor.c @@ -39,7 +39,6 @@ #include "contiki.h" #include "lib/sensors.h" #include "dev/adc-sensor.h" -#include "gpio-interrupt.h" #include "sys/timer.h" #include "lpm.h" diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c b/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c index 348d0646a..c90e9239d 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c @@ -29,72 +29,33 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx-gpio-interrupts + * \addtogroup cc26xx * @{ * * \file - * Implementation of CC13xx/CC26xx GPIO interrupt handling. + * CC13xx/CC26xx GPIO interrupt ISR. */ /*---------------------------------------------------------------------------*/ -#include "ioc.h" -#include "gpio-interrupt.h" -#include "lpm.h" +#include "contiki.h" +#include "dev/gpio-hal.h" #include "ti-lib.h" #include /*---------------------------------------------------------------------------*/ #define gpio_interrupt_isr GPIOIntHandler /*---------------------------------------------------------------------------*/ -/* Handler array */ -static gpio_interrupt_handler_t handlers[NUM_IO_MAX]; -/*---------------------------------------------------------------------------*/ -void -gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f) -{ - uint8_t interrupts_disabled = ti_lib_int_master_disable(); - - /* Clear interrupts on specified pins */ - ti_lib_gpio_clear_event_dio(ioid); - - handlers[ioid] = f; - - /* Re-enable interrupts */ - if(!interrupts_disabled) { - ti_lib_int_master_enable(); - } -} -/*---------------------------------------------------------------------------*/ -void -gpio_interrupt_init() -{ - int i; - - for(i = 0; i < NUM_IO_MAX; i++) { - handlers[i] = NULL; - } - - ti_lib_int_enable(INT_AON_GPIO_EDGE); -} -/*---------------------------------------------------------------------------*/ void gpio_interrupt_isr(void) { - uint32_t pin_mask; - uint8_t i; + gpio_hal_pin_mask_t pin_mask; /* Read interrupt flags */ pin_mask = (HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) & GPIO_DIO_ALL_MASK); + gpio_hal_event_handler(pin_mask); + /* Clear the interrupt flags */ HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) = pin_mask; - - /* Run custom ISRs */ - for(i = 0; i < NUM_IO_MAX; i++) { - /* Call the handler if there is one registered for this event */ - if((pin_mask & (1 << i)) && handlers[i] != NULL) { - handlers[i](i); - } - } } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.h b/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.h deleted file mode 100644 index 1a993d3be..000000000 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc26xx - * @{ - * - * \defgroup cc26xx-gpio-interrupts CC13xx/CC26xx GPIO interrupt handling - * - * The CC13xx/CC26xx GPIO interrupt handler and an API which can be used by - * other parts of the code when they wish to be notified of a GPIO interrupt - * - * @{ - * - * \file - * Header file for the CC13xx/CC26xx GPIO interrupt management - */ -/*---------------------------------------------------------------------------*/ -#ifndef GPIO_INTERRUPT_H_ -#define GPIO_INTERRUPT_H_ -/*---------------------------------------------------------------------------*/ -#include -/*---------------------------------------------------------------------------*/ -typedef void (*gpio_interrupt_handler_t)(uint8_t ioid); -/*---------------------------------------------------------------------------*/ -/** \brief Initialise the GPIO interrupt handling module */ -void gpio_interrupt_init(void); - -/** - * \brief Register a GPIO interrupt handler - * \param f Pointer to a handler to be called when an interrupt is raised on - * ioid - * \param ioid Associate \a f with this ioid. \e ioid must be specified with - * its numeric representation (0, 1, .. 31). Defines for these - * numeric representations are IOID_x - */ -void gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f); - -#endif /* GPIO_INTERRUPT_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ diff --git a/arch/platform/srf06-cc26xx/launchpad/button-sensor.c b/arch/platform/srf06-cc26xx/launchpad/button-sensor.c index eb8bd3033..43d07ad9c 100644 --- a/arch/platform/srf06-cc26xx/launchpad/button-sensor.c +++ b/arch/platform/srf06-cc26xx/launchpad/button-sensor.c @@ -39,7 +39,7 @@ #include "contiki.h" #include "lib/sensors.h" #include "launchpad/button-sensor.h" -#include "gpio-interrupt.h" +#include "gpio-hal.h" #include "sys/timer.h" #include "lpm.h" @@ -70,9 +70,9 @@ struct btn_timer { static struct btn_timer left_timer, right_timer; /*---------------------------------------------------------------------------*/ static void -button_press_handler(uint8_t ioid) +button_press_handler(gpio_hal_pin_mask_t pin_mask) { - if(ioid == BOARD_IOID_KEY_LEFT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) { if(!timer_expired(&left_timer.debounce)) { return; } @@ -92,7 +92,7 @@ button_press_handler(uint8_t ioid) } } - if(ioid == BOARD_IOID_KEY_RIGHT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) { if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) { if(!timer_expired(&right_timer.debounce)) { return; @@ -117,6 +117,12 @@ button_press_handler(uint8_t ioid) } } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t press_handler = { + .next = NULL, + .handler = button_press_handler, + .pin_mask = 0, +}; +/*---------------------------------------------------------------------------*/ static void config_buttons(int type, int c, uint32_t key) { @@ -125,7 +131,8 @@ config_buttons(int type, int c, uint32_t key) ti_lib_gpio_clear_event_dio(key); ti_lib_rom_ioc_pin_type_gpio_input(key); ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); - gpio_interrupt_register_handler(key, button_press_handler); + press_handler.pin_mask |= gpio_hal_pin_to_mask(key); + gpio_hal_register_handler(&press_handler); break; case SENSORS_ACTIVE: if(c) { diff --git a/arch/platform/srf06-cc26xx/platform.c b/arch/platform/srf06-cc26xx/platform.c index c9ef7b928..ac44b5b0f 100644 --- a/arch/platform/srf06-cc26xx/platform.c +++ b/arch/platform/srf06-cc26xx/platform.c @@ -49,7 +49,7 @@ #include "contiki-net.h" #include "leds.h" #include "lpm.h" -#include "gpio-interrupt.h" +#include "dev/gpio-hal.h" #include "dev/oscillators.h" #include "ieee-addr.h" #include "vims.h" @@ -138,7 +138,7 @@ platform_init_stage_one() board_init(); - gpio_interrupt_init(); + gpio_hal_init(); leds_init(); fade(LEDS_RED); @@ -151,6 +151,7 @@ platform_init_stage_one() */ ti_lib_pwr_ctrl_io_freeze_disable(); + ti_lib_rom_int_enable(INT_AON_GPIO_EDGE); ti_lib_int_master_enable(); soc_rtc_init(); diff --git a/arch/platform/srf06-cc26xx/sensortag/button-sensor.c b/arch/platform/srf06-cc26xx/sensortag/button-sensor.c index 7ec0a5a18..f19704f81 100644 --- a/arch/platform/srf06-cc26xx/sensortag/button-sensor.c +++ b/arch/platform/srf06-cc26xx/sensortag/button-sensor.c @@ -39,7 +39,7 @@ #include "contiki.h" #include "lib/sensors.h" #include "sensortag/button-sensor.h" -#include "gpio-interrupt.h" +#include "gpio-hal.h" #include "sys/timer.h" #include "lpm.h" @@ -73,9 +73,9 @@ static struct btn_timer left_timer, right_timer; * \brief Handler for Sensortag-CC26XX button presses */ static void -button_press_handler(uint8_t ioid) +button_press_handler(gpio_hal_pin_mask_t pin_mask) { - if(ioid == BOARD_IOID_KEY_LEFT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) { if(!timer_expired(&left_timer.debounce)) { return; } @@ -95,7 +95,7 @@ button_press_handler(uint8_t ioid) } } - if(ioid == BOARD_IOID_KEY_RIGHT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) { if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) { if(!timer_expired(&right_timer.debounce)) { return; @@ -120,6 +120,12 @@ button_press_handler(uint8_t ioid) } } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t press_handler = { + .next = NULL, + .handler = button_press_handler, + .pin_mask = 0, +}; +/*---------------------------------------------------------------------------*/ /** * \brief Configuration function for the button sensor for all buttons. * @@ -135,7 +141,8 @@ config_buttons(int type, int c, uint32_t key) ti_lib_gpio_clear_event_dio(key); ti_lib_rom_ioc_pin_type_gpio_input(key); ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); - gpio_interrupt_register_handler(key, button_press_handler); + press_handler.pin_mask |= gpio_hal_pin_to_mask(key); + gpio_hal_register_handler(&press_handler); break; case SENSORS_ACTIVE: if(c) { diff --git a/arch/platform/srf06-cc26xx/sensortag/reed-relay.c b/arch/platform/srf06-cc26xx/sensortag/reed-relay.c index 736b2170a..6cfb186ab 100644 --- a/arch/platform/srf06-cc26xx/sensortag/reed-relay.c +++ b/arch/platform/srf06-cc26xx/sensortag/reed-relay.c @@ -39,9 +39,9 @@ #include "contiki.h" #include "sys/clock.h" #include "sys/timer.h" +#include "dev/gpio-hal.h" #include "lib/sensors.h" #include "sensortag/reed-relay.h" -#include "gpio-interrupt.h" #include "sys/timer.h" #include "ti-lib.h" @@ -60,7 +60,7 @@ static struct timer debouncetimer; * \brief Handler for Sensortag-CC26XX reed interrupts */ static void -reed_interrupt_handler(uint8_t ioid) +reed_interrupt_handler(gpio_hal_pin_mask_t pin_mask) { if(!timer_expired(&debouncetimer)) { return; @@ -76,6 +76,12 @@ value(int type) return (int)ti_lib_gpio_read_dio(BOARD_IOID_REED_RELAY); } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t event_handler = { + .next = NULL, + .handler = reed_interrupt_handler, + .pin_mask = gpio_hal_pin_to_mask(BOARD_IOID_REED_RELAY), +}; +/*---------------------------------------------------------------------------*/ /** * \brief Configuration function for the button sensor for all buttons. * @@ -99,8 +105,7 @@ configure(int type, int value) ti_lib_ioc_port_configure_set(BOARD_IOID_REED_RELAY, IOC_PORT_GPIO, REED_IO_CFG); - gpio_interrupt_register_handler(BOARD_IOID_REED_RELAY, - reed_interrupt_handler); + gpio_hal_register_handler(&event_handler); break; case SENSORS_ACTIVE: if(value) { diff --git a/arch/platform/srf06-cc26xx/srf06/button-sensor.c b/arch/platform/srf06-cc26xx/srf06/button-sensor.c index 23f668355..1f4a2db3b 100644 --- a/arch/platform/srf06-cc26xx/srf06/button-sensor.c +++ b/arch/platform/srf06-cc26xx/srf06/button-sensor.c @@ -39,7 +39,7 @@ #include "contiki.h" #include "lib/sensors.h" #include "srf06/button-sensor.h" -#include "gpio-interrupt.h" +#include "gpio-hal.h" #include "sys/timer.h" #include "lpm.h" @@ -74,9 +74,9 @@ static struct btn_timer sel_timer, left_timer, right_timer, up_timer, * \brief Handler for SmartRF button presses */ static void -button_press_handler(uint8_t ioid) +button_press_handler(gpio_hal_pin_mask_t pin_mask) { - if(ioid == BOARD_IOID_KEY_SELECT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_SELECT)) { if(!timer_expired(&sel_timer.debounce)) { return; } @@ -96,7 +96,7 @@ button_press_handler(uint8_t ioid) } } - if(ioid == BOARD_IOID_KEY_LEFT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) { if(!timer_expired(&left_timer.debounce)) { return; } @@ -116,7 +116,7 @@ button_press_handler(uint8_t ioid) } } - if(ioid == BOARD_IOID_KEY_RIGHT) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) { if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) { if(!timer_expired(&right_timer.debounce)) { return; @@ -140,7 +140,7 @@ button_press_handler(uint8_t ioid) } } - if(ioid == BOARD_IOID_KEY_UP) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_UP)) { if(!timer_expired(&up_timer.debounce)) { return; } @@ -160,7 +160,7 @@ button_press_handler(uint8_t ioid) } } - if(ioid == BOARD_IOID_KEY_DOWN) { + if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_DOWN)) { if(!timer_expired(&down_timer.debounce)) { return; } @@ -181,6 +181,12 @@ button_press_handler(uint8_t ioid) } } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t press_handler = { + .next = NULL, + .handler = button_press_handler, + .pin_mask = 0, +}; +/*---------------------------------------------------------------------------*/ /** * \brief Configuration function for the button sensor for all buttons. * @@ -196,7 +202,8 @@ config_buttons(int type, int c, uint32_t key) ti_lib_gpio_clear_event_dio(key); ti_lib_rom_ioc_pin_type_gpio_input(key); ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); - gpio_interrupt_register_handler(key, button_press_handler); + press_handler.pin_mask |= gpio_hal_pin_to_mask(key); + gpio_hal_register_handler(&press_handler); break; case SENSORS_ACTIVE: if(c) { From ab7d7cd9f420d65dae74172dbd5e715bad46c6c3 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 03:20:53 +0000 Subject: [PATCH 05/12] Implement the GPIO HAL for the CC2538 --- arch/cpu/cc2538/cc2538-def.h | 2 + arch/cpu/cc2538/dev/gpio-hal-arch.c | 196 ++++++++++++++++++++++++++++ arch/cpu/cc2538/dev/gpio-hal-arch.h | 88 +++++++++++++ arch/cpu/cc2538/dev/ioc.c | 6 + arch/cpu/cc2538/dev/ioc.h | 16 +++ 5 files changed, 308 insertions(+) create mode 100644 arch/cpu/cc2538/dev/gpio-hal-arch.c create mode 100644 arch/cpu/cc2538/dev/gpio-hal-arch.h diff --git a/arch/cpu/cc2538/cc2538-def.h b/arch/cpu/cc2538/cc2538-def.h index 39dd18c13..32aed6111 100644 --- a/arch/cpu/cc2538/cc2538-def.h +++ b/arch/cpu/cc2538/cc2538-def.h @@ -64,6 +64,8 @@ /* Path to headers with implementation of mutexes and memory barriers */ #define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h" #define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h" + +#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h" /*---------------------------------------------------------------------------*/ #endif /* CC2538_DEF_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc2538/dev/gpio-hal-arch.c b/arch/cpu/cc2538/dev/gpio-hal-arch.c new file mode 100644 index 000000000..dd8e5c513 --- /dev/null +++ b/arch/cpu/cc2538/dev/gpio-hal-arch.c @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538-gpio-hal + * @{ + * + * \file + * Implementation file for the CC2538 GPIO HAL functions + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +#include "dev/gpio.h" +#include "dev/ioc.h" + +#include +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) +{ + uint8_t port, pin_num, pin_mask; + uint32_t port_base; + + port = PIN_TO_PORT(pin); + port_base = PIN_TO_PORT_BASE(pin); + pin_num = pin % 8; + pin_mask = GPIO_PIN_MASK(pin_num); + + gpio_hal_pin_cfg_t tmp; + + tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH; + if(tmp == GPIO_HAL_PIN_CFG_EDGE_NONE) { + GPIO_DISABLE_INTERRUPT(port_base, pin_mask); + } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_RISING) { + GPIO_DETECT_EDGE(port_base, pin_mask); + GPIO_TRIGGER_SINGLE_EDGE(port_base, pin_mask); + GPIO_DETECT_RISING(port_base, pin_mask); + } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_FALLING) { + GPIO_DETECT_EDGE(port_base, pin_mask); + GPIO_TRIGGER_SINGLE_EDGE(port_base, pin_mask); + GPIO_DETECT_FALLING(port_base, pin_mask); + } else if(tmp == GPIO_HAL_PIN_CFG_EDGE_BOTH) { + GPIO_DETECT_EDGE(port_base, pin_mask); + GPIO_TRIGGER_BOTH_EDGES(port_base, pin_mask); + } + + tmp = cfg & GPIO_HAL_PIN_CFG_PULL_MASK; + if(tmp == GPIO_HAL_PIN_CFG_PULL_NONE) { + ioc_set_over(port, pin_num, IOC_OVERRIDE_DIS); + } else if(tmp == GPIO_HAL_PIN_CFG_PULL_DOWN) { + ioc_set_over(port, pin_num, IOC_OVERRIDE_PDE); + } else if(tmp == GPIO_HAL_PIN_CFG_PULL_UP) { + ioc_set_over(port, pin_num, IOC_OVERRIDE_PUE); + } + + tmp = cfg & GPIO_HAL_PIN_CFG_INT_MASK; + if(tmp == GPIO_HAL_PIN_CFG_INT_DISABLE) { + GPIO_DISABLE_INTERRUPT(port_base, pin_mask); + } else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) { + GPIO_ENABLE_INTERRUPT(port_base, pin_mask); + } + + GPIO_SOFTWARE_CONTROL(port_base, pin_mask); +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_cfg_t +gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) +{ + uint8_t port, pin_num, pin_mask; + uint32_t port_base; + gpio_hal_pin_cfg_t cfg; + uint32_t tmp; + + port = PIN_TO_PORT(pin); + port_base = PIN_TO_PORT_BASE(pin); + pin_num = pin % 8; + pin_mask = GPIO_PIN_MASK(pin_num); + + cfg = 0; + + /* Pull */ + tmp = ioc_get_over(port, pin_num); + if(tmp == IOC_OVERRIDE_PUE) { + cfg |= GPIO_HAL_PIN_CFG_PULL_UP; + } else if(tmp == IOC_OVERRIDE_PDE) { + cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN; + } else { + cfg |= GPIO_HAL_PIN_CFG_PULL_NONE; + } + + /* Interrupt enable/disable */ + tmp = REG((port_base) + GPIO_IE) & pin_mask; + if(tmp == 0) { + cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE; + } else { + cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE; + } + + /* Edge detection */ + if(REG((port_base) + GPIO_IS) & pin_mask) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE; + } else { + if(REG((port_base) + GPIO_IBE) & pin_mask) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH; + } else { + if(REG((port_base) + GPIO_IEV) & pin_mask) { + cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING; + } else { + cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING; + } + } + } + + return cfg; +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_write_pin(gpio_hal_pin_t pin, uint8_t value) +{ + if(value == 1) { + gpio_hal_arch_set_pin(pin); + return; + } + gpio_hal_arch_clear_pin(pin); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_set_pins(gpio_hal_pin_mask_t pins) +{ + GPIO_SET_PIN(GPIO_A_BASE, pins & 0xFF); + GPIO_SET_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF); + GPIO_SET_PIN(GPIO_C_BASE, (pins >> 16) & 0xFF); + GPIO_SET_PIN(GPIO_D_BASE, (pins >> 24) & 0xFF); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_clear_pins(gpio_hal_pin_mask_t pins) +{ + GPIO_CLR_PIN(GPIO_A_BASE, pins & 0xFF); + GPIO_CLR_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF); + GPIO_CLR_PIN(GPIO_C_BASE, (pins >> 16) & 0xFF); + GPIO_CLR_PIN(GPIO_D_BASE, (pins >> 24) & 0xFF); +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_mask_t +gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) +{ + gpio_hal_pin_mask_t rv = 0; + + rv |= GPIO_READ_PIN(GPIO_A_BASE, pins & 0xFF); + rv |= GPIO_READ_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF) << 8; + rv |= GPIO_READ_PIN(GPIO_C_BASE, (pins >> 16) & 0xFF) << 16; + rv |= GPIO_READ_PIN(GPIO_D_BASE, (pins >> 24) & 0xFF) << 24; + + return rv; +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_write_pins(gpio_hal_pin_mask_t pins, gpio_hal_pin_mask_t value) +{ + GPIO_WRITE_PIN(GPIO_A_BASE, pins & 0xFF, value & 0xFF); + GPIO_WRITE_PIN(GPIO_B_BASE, (pins >> 8) & 0xFF, (value >> 8) & 0xFF); + GPIO_WRITE_PIN(GPIO_C_BASE, (pins >> 16) & 0xFF, (value >> 16) & 0xFF); + GPIO_WRITE_PIN(GPIO_D_BASE, (pins >> 24) & 0xFF, (value >> 24) & 0xFF); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/cc2538/dev/gpio-hal-arch.h b/arch/cpu/cc2538/dev/gpio-hal-arch.h new file mode 100644 index 000000000..78842634a --- /dev/null +++ b/arch/cpu/cc2538/dev/gpio-hal-arch.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538 + * @{ + * + * \defgroup cc2538-gpio-hal CC2538 GPIO HAL implementation + * + * @{ + * + * \file + * Header file for the CC2538 GPIO HAL functions + * + * \note + * Do not include this header directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef GPIO_HAL_ARCH_H_ +#define GPIO_HAL_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio.h" + +#include +/*---------------------------------------------------------------------------*/ +#define PIN_TO_PORT(pin) (pin >> 3) +#define PIN_TO_PORT_BASE(pin) GPIO_PORT_TO_BASE(PIN_TO_PORT(pin)) +/*---------------------------------------------------------------------------*/ +#define gpio_hal_arch_interrupt_enable(p) \ + GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) + +#define gpio_hal_arch_interrupt_disable(p) \ + GPIO_DISABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) + +#define gpio_hal_arch_pin_set_input(p) do { \ + GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ + GPIO_SET_INPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ +} while(0); + +#define gpio_hal_arch_pin_set_output(p) do { \ + GPIO_SOFTWARE_CONTROL(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ + GPIO_SET_OUTPUT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ +} while(0); + +#define gpio_hal_arch_set_pin(p) \ + GPIO_SET_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) + +#define gpio_hal_arch_clear_pin(p) \ + GPIO_CLR_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) + +#define gpio_hal_arch_read_pin(p) \ + (GPIO_READ_PIN(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)) == 0 ? 0 : 1) +/*---------------------------------------------------------------------------*/ +#endif /* GPIO_HAL_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/cc2538/dev/ioc.c b/arch/cpu/cc2538/dev/ioc.c index 53a9218a9..5bb631c46 100644 --- a/arch/cpu/cc2538/dev/ioc.c +++ b/arch/cpu/cc2538/dev/ioc.c @@ -56,6 +56,12 @@ ioc_set_over(uint8_t port, uint8_t pin, uint8_t over) ioc_over[(port << 3) + pin] = over; } /*---------------------------------------------------------------------------*/ +uint32_t +ioc_get_over(uint8_t port, uint8_t pin) +{ + return ioc_over[(port << 3) + pin] & 0x0F; +} +/*---------------------------------------------------------------------------*/ void ioc_set_sel(uint8_t port, uint8_t pin, uint8_t sel) { diff --git a/arch/cpu/cc2538/dev/ioc.h b/arch/cpu/cc2538/dev/ioc.h index 7fad9d275..ae14a616f 100644 --- a/arch/cpu/cc2538/dev/ioc.h +++ b/arch/cpu/cc2538/dev/ioc.h @@ -249,6 +249,22 @@ void ioc_init(); */ void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over); +/** + * \brief Get Port:Pin override function + * \param port The port as a number (PA: 0, PB: 1 etc) + * \param pin The pin as a number + * \return The override function + * + * The return value can be one of + * + * - IOC_OVERRIDE_OE: Output + * - IOC_OVERRIDE_PUE: Pull-Up + * - IOC_OVERRIDE_PDE: Pull-Down + * - IOC_OVERRIDE_ANA: Analog + * - IOC_OVERRIDE_DIS: Disabled + */ +uint32_t ioc_get_over(uint8_t port, uint8_t pin); + /** * \brief Function select for Port:Pin * \param port The port as a number (PA: 0, PB: 1 etc) From 10c2bcde15ec6de93273ea34350f8108d06f00dc Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 03:21:13 +0000 Subject: [PATCH 06/12] Build the GPIO HAL for the CC2538 --- arch/cpu/cc2538/Makefile.cc2538 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index c0a2bb2f0..f6e76f571 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -17,7 +17,7 @@ CONTIKI_CPU_DIRS = . dev usb usb/common usb/common/cdc-acm CONTIKI_CPU_SOURCEFILES += soc.c clock.c rtimer-arch.c uart.c watchdog.c CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi.c adc.c CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c -CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c +CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c gpio-hal-arch.c CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c int-master.c CONTIKI_CPU_SOURCEFILES += pka.c bignum-driver.c ecc-driver.c ecc-algorithm.c From 095a89d937484892cad4e2cb69a14b73f7da0189 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 03:21:36 +0000 Subject: [PATCH 07/12] Adjust CC2538 CPU drivers to use the GPIO HAL --- arch/cpu/cc2538/dev/gpio.c | 42 ++------------------------------------ arch/cpu/cc2538/dev/gpio.h | 36 +++----------------------------- arch/cpu/cc2538/soc.c | 3 ++- 3 files changed, 7 insertions(+), 74 deletions(-) diff --git a/arch/cpu/cc2538/dev/gpio.c b/arch/cpu/cc2538/dev/gpio.c index a09ca6dc3..c5c72594b 100644 --- a/arch/cpu/cc2538/dev/gpio.c +++ b/arch/cpu/cc2538/dev/gpio.c @@ -37,46 +37,13 @@ */ #include "contiki.h" #include "dev/leds.h" +#include "dev/gpio-hal.h" #include "dev/gpio.h" #include "dev/nvic.h" #include "reg.h" #include "lpm.h" #include - -/** - * \brief Pointer to a function to be called when a GPIO interrupt is detected. - * Callbacks for Port A, Pins[0:7] are stored in positions [0:7] of this - * buffer, Port B callbacks in [8:15] and so on - */ -static gpio_callback_t gpio_callbacks[32]; -/*---------------------------------------------------------------------------*/ -void -gpio_register_callback(gpio_callback_t f, uint8_t port, uint8_t pin) -{ - gpio_callbacks[(port << 3) + pin] = f; -} -/*---------------------------------------------------------------------------*/ -/** \brief Run through all registered GPIO callbacks and invoke those - * associated with the \a port and the pins specified by \a mask - * \param mask Search callbacks associated with pins specified by this mask - * \param port Search callbacks associated with this port. Here, port is - * specified as a number between 0 and 3. Port A: 0, Port B: 1 etc */ -void -notify(uint8_t mask, uint8_t port) -{ - uint8_t i; - gpio_callback_t *f = &gpio_callbacks[port << 3]; - - for(i = 0; i < 8; i++) { - if(mask & (1 << i)) { - if((*f) != NULL) { - (*f)(port, i); - } - } - f++; - } -} /*---------------------------------------------------------------------------*/ /** \brief Interrupt service routine for Port \a port * \param port Number between 0 and 3. Port A: 0, Port B: 1, etc. @@ -93,7 +60,7 @@ gpio_port_isr(uint8_t port) int_status = GPIO_GET_MASKED_INT_STATUS(base); power_up_int_status = GPIO_GET_POWER_UP_INT_STATUS(port); - notify(int_status | power_up_int_status, port); + gpio_hal_event_handler((int_status | power_up_int_status) << (port << 3)); GPIO_CLEAR_INTERRUPT(base, int_status); GPIO_CLEAR_POWER_UP_INTERRUPT(port, power_up_int_status); @@ -110,9 +77,4 @@ GPIO_PORT_ISR(b, B) GPIO_PORT_ISR(c, C) GPIO_PORT_ISR(d, D) /*---------------------------------------------------------------------------*/ -void -gpio_init() -{ - memset(gpio_callbacks, 0, sizeof(gpio_callbacks)); -} /** @} */ diff --git a/arch/cpu/cc2538/dev/gpio.h b/arch/cpu/cc2538/dev/gpio.h index 00ee1b1dc..a09ed8cfe 100644 --- a/arch/cpu/cc2538/dev/gpio.h +++ b/arch/cpu/cc2538/dev/gpio.h @@ -42,27 +42,12 @@ */ #ifndef GPIO_H_ #define GPIO_H_ - +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" #include "reg.h" #include - -/** - * \brief Type definition for callbacks invoked by the GPIO ISRs - * \param port The port that triggered the GPIO interrupt. \e port is passed - * by its numeric representation (Port A:0, B:1 etc). Defines for - * these numeric representations are GPIO_x_NUM - * \param pin The pin that triggered the interrupt, specified by number - * (0, 1, ..., 7) - * - * This is the prototype of a function pointer passed to - * gpio_register_callback(). These callbacks are registered on a port/pin - * basis. When a GPIO port generates an interrupt, if a callback has been - * registered for the port/pin combination, the ISR will invoke it. The ISR - * will pass the port/pin as arguments in that call, so that a developer can - * re-use the same callback for multiple port/pin combinations - */ -typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin); /*---------------------------------------------------------------------------*/ /** \name Base addresses for the GPIO register instances * @{ @@ -612,21 +597,6 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin); #define GPIO_IRQ_DETECT_UNMASK_PAIACK0 0x00000001 /**< Port A bit 0 */ /** @} */ /*---------------------------------------------------------------------------*/ -/** \brief Initialise the GPIO module */ -void gpio_init(); - -/** - * \brief Register GPIO callback - * \param f Pointer to a function to be called when \a pin of \a port - * generates an interrupt - * \param port Associate \a f with this port. \e port must be specified with - * its numeric representation (Port A:0, B:1 etc). Defines for these - * numeric representations are GPIO_x_NUM - * \param pin Associate \a f with this pin, which is specified by number - * (0, 1, ..., 7) - */ -void gpio_register_callback(gpio_callback_t f, uint8_t port, uint8_t pin); - #endif /* GPIO_H_ */ /** diff --git a/arch/cpu/cc2538/soc.c b/arch/cpu/cc2538/soc.c index e0ab1a918..1aa910095 100644 --- a/arch/cpu/cc2538/soc.c +++ b/arch/cpu/cc2538/soc.c @@ -41,6 +41,7 @@ #include "dev/ioc.h" #include "dev/nvic.h" #include "dev/sys-ctrl.h" +#include "dev/gpio-hal.h" #include "lpm.h" #include "reg.h" #include "soc.h" @@ -123,7 +124,7 @@ soc_init() clock_init(); lpm_init(); rtimer_init(); - gpio_init(); + gpio_hal_init(); } /*----------------------------------------------------------------------------*/ /** @} */ From 749c4e5cd80da63343357ae34913a39e6a7eedbf Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 03:21:52 +0000 Subject: [PATCH 08/12] Use the GPIO HAL (Zoul) --- arch/platform/zoul/dev/button-sensor.c | 18 +++++++++--------- arch/platform/zoul/dev/cc1200-zoul-arch.c | 17 ++++++++++++----- arch/platform/zoul/dev/rtcc.c | 10 ++++++++-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/arch/platform/zoul/dev/button-sensor.c b/arch/platform/zoul/dev/button-sensor.c index 80c7b75cb..9b410cdbf 100644 --- a/arch/platform/zoul/dev/button-sensor.c +++ b/arch/platform/zoul/dev/button-sensor.c @@ -43,6 +43,7 @@ #include "dev/nvic.h" #include "dev/ioc.h" #include "dev/gpio.h" +#include "dev/gpio-hal.h" #include "dev/button-sensor.h" #include "sys/timer.h" #include "sys/ctimer.h" @@ -94,15 +95,8 @@ value(int type) return 0; } /*---------------------------------------------------------------------------*/ -/** - * \brief Callback registered with the GPIO module. Gets fired with a button - * port/pin generates an interrupt - * \param port The port number that generated the interrupt - * \param pin The pin number that generated the interrupt. This is the pin - * absolute number (i.e. 0, 1, ..., 7), not a mask - */ static void -btn_callback(uint8_t port, uint8_t pin) +button_press_handler(gpio_hal_pin_mask_t pin_mask) { if(!timer_expired(&debouncetimer)) { return; @@ -123,6 +117,12 @@ btn_callback(uint8_t port, uint8_t pin) sensors_changed(&button_sensor); } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t press_handler = { + .next = NULL, + .handler = button_press_handler, + .pin_mask = gpio_hal_pin_to_mask(BUTTON_USER_PIN) << (BUTTON_USER_PORT << 3), +}; +/*---------------------------------------------------------------------------*/ /** * \brief Init function for the User button. * \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1 @@ -152,7 +152,7 @@ config_user(int type, int value) ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE); - gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN); + gpio_hal_register_handler(&press_handler); break; case SENSORS_ACTIVE: if(value) { diff --git a/arch/platform/zoul/dev/cc1200-zoul-arch.c b/arch/platform/zoul/dev/cc1200-zoul-arch.c index 92e686a4e..1aff2ef40 100644 --- a/arch/platform/zoul/dev/cc1200-zoul-arch.c +++ b/arch/platform/zoul/dev/cc1200-zoul-arch.c @@ -52,6 +52,7 @@ #include "dev/spi.h" #include "dev/ssi.h" #include "dev/gpio.h" +#include "dev/gpio-hal.h" #include /*---------------------------------------------------------------------------*/ #define CC1200_SPI_CLK_PORT_BASE GPIO_PORT_TO_BASE(SPI0_CLK_PORT) @@ -92,7 +93,7 @@ extern int cc1200_rx_interrupt(void); /*---------------------------------------------------------------------------*/ void -cc1200_int_handler(uint8_t port, uint8_t pin) +cc1200_int_handler(gpio_hal_pin_mask_t pin_mask) { /* To keep the gpio_register_callback happy */ cc1200_rx_interrupt(); @@ -166,6 +167,14 @@ cc1200_arch_spi_rw(uint8_t *inbuf, const uint8_t *write_buf, uint16_t len) return 0; } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t interrupt_handler = { + .next = NULL, + .handler = cc1200_int_handler, + .pin_mask = + (gpio_hal_pin_to_mask(CC1200_GDO0_PIN) << (CC1200_GDO0_PORT << 3)) | + (gpio_hal_pin_to_mask(CC1200_GDO2_PIN) << (CC1200_GDO2_PORT << 3)) +}; +/*---------------------------------------------------------------------------*/ void cc1200_arch_gpio0_setup_irq(int rising) { @@ -184,8 +193,7 @@ cc1200_arch_gpio0_setup_irq(int rising) GPIO_ENABLE_INTERRUPT(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK); ioc_set_over(CC1200_GDO0_PORT, CC1200_GDO0_PIN, IOC_OVERRIDE_PUE); NVIC_EnableIRQ(CC1200_GPIOx_VECTOR); - gpio_register_callback(cc1200_int_handler, CC1200_GDO0_PORT, - CC1200_GDO0_PIN); + gpio_hal_register_handler(&interrupt_handler); } /*---------------------------------------------------------------------------*/ void @@ -206,8 +214,7 @@ cc1200_arch_gpio2_setup_irq(int rising) GPIO_ENABLE_INTERRUPT(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK); ioc_set_over(CC1200_GDO2_PORT, CC1200_GDO2_PIN, IOC_OVERRIDE_PUE); NVIC_EnableIRQ(CC1200_GPIOx_VECTOR); - gpio_register_callback(cc1200_int_handler, CC1200_GDO2_PORT, - CC1200_GDO2_PIN); + gpio_hal_register_handler(&interrupt_handler); } /*---------------------------------------------------------------------------*/ void diff --git a/arch/platform/zoul/dev/rtcc.c b/arch/platform/zoul/dev/rtcc.c index b5cb116c3..d03413d5b 100644 --- a/arch/platform/zoul/dev/rtcc.c +++ b/arch/platform/zoul/dev/rtcc.c @@ -735,7 +735,7 @@ rtcc_print(uint8_t value) } /*---------------------------------------------------------------------------*/ static void -rtcc_interrupt_handler(uint8_t port, uint8_t pin) +rtcc_interrupt_handler(gpio_hal_pin_mask_t pin_mask) { process_poll(&rtcc_int_process); } @@ -912,6 +912,12 @@ rtcc_set_calibration(uint8_t mode, int32_t adjust) return AB08_SUCCESS; } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t rtcc_handler = { + .next = NULL, + .handler = rtcc_interrupt_handler, + .pin_mask = gpio_hal_pin_to_mask(RTC_INT1_PIN) << (RTC_INT1_PORT << 3), +}; +/*---------------------------------------------------------------------------*/ int8_t rtcc_init(void) { @@ -937,7 +943,7 @@ rtcc_init(void) GPIO_DETECT_EDGE(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK); GPIO_TRIGGER_SINGLE_EDGE(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK); GPIO_DETECT_FALLING(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK); - gpio_register_callback(rtcc_interrupt_handler, RTC_INT1_PORT, RTC_INT1_PIN); + gpio_hal_register_handler(&rtcc_handler); /* Spin process until an interrupt is received */ process_start(&rtcc_int_process, NULL); From 488a9060184a0f02d14aa7060a1fbee288b36857 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 03:32:49 +0000 Subject: [PATCH 09/12] Use the GPIO HAL (OpenMote CC2538) --- .../openmote-cc2538/dev/button-sensor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/platform/openmote-cc2538/dev/button-sensor.c b/arch/platform/openmote-cc2538/dev/button-sensor.c index 9c6a7d6c8..a6c5fe2d8 100644 --- a/arch/platform/openmote-cc2538/dev/button-sensor.c +++ b/arch/platform/openmote-cc2538/dev/button-sensor.c @@ -95,15 +95,8 @@ value(int type) return 0; } /*---------------------------------------------------------------------------*/ -/** - * \brief Callback registered with the GPIO module. Gets fired with a button - * port/pin generates an interrupt - * \param port The port number that generated the interrupt - * \param pin The pin number that generated the interrupt. This is the pin - * absolute number (i.e. 0, 1, ..., 7), not a mask - */ static void -btn_callback(uint8_t port, uint8_t pin) +button_press_handler(gpio_hal_pin_mask_t pin_mask) { if(!timer_expired(&debouncetimer)) { return; @@ -124,6 +117,12 @@ btn_callback(uint8_t port, uint8_t pin) sensors_changed(&button_sensor); } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t press_handler = { + .next = NULL, + .handler = button_press_handler, + .pin_mask = gpio_hal_pin_to_mask(BUTTON_USER_PIN) << (BUTTON_USER_PORT << 3), +}; +/*---------------------------------------------------------------------------*/ /** * \brief Init function for the User button. * \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1 @@ -153,7 +152,7 @@ config_user(int type, int value) ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE); - gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN); + gpio_hal_register_handler(&press_handler); break; case SENSORS_ACTIVE: if(value) { From df0659cd1a66c2c29923b6d46b03cdc850666f97 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 03:33:05 +0000 Subject: [PATCH 10/12] Use the GPIO HAL (CC2538DK) --- arch/platform/cc2538dk/dev/button-sensor.c | 49 ++++++++++++++-------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/arch/platform/cc2538dk/dev/button-sensor.c b/arch/platform/cc2538dk/dev/button-sensor.c index 14d4e7d15..6c34bb847 100644 --- a/arch/platform/cc2538dk/dev/button-sensor.c +++ b/arch/platform/cc2538dk/dev/button-sensor.c @@ -88,15 +88,8 @@ config(uint32_t port_base, uint32_t pin_mask) GPIO_ENABLE_INTERRUPT(port_base, pin_mask); } /*---------------------------------------------------------------------------*/ -/** - * \brief Callback registered with the GPIO module. Gets fired with a button - * port/pin generates an interrupt - * \param port The port number that generated the interrupt - * \param pin The pin number that generated the interrupt. This is the pin - * absolute number (i.e. 0, 1, ..., 7), not a mask - */ static void -btn_callback(uint8_t port, uint8_t pin) +button_press_handler(gpio_hal_pin_mask_t pin_mask) { if(!timer_expired(&debouncetimer)) { return; @@ -104,19 +97,39 @@ btn_callback(uint8_t port, uint8_t pin) timer_set(&debouncetimer, CLOCK_SECOND / 8); - if((port == BUTTON_SELECT_PORT) && (pin == BUTTON_SELECT_PIN)) { + if(pin_mask & + (gpio_hal_pin_to_mask(BUTTON_SELECT_PIN) << (BUTTON_SELECT_PORT << 3))) { sensors_changed(&button_select_sensor); - } else if((port == BUTTON_LEFT_PORT) && (pin == BUTTON_LEFT_PIN)) { + } else if(pin_mask & + (gpio_hal_pin_to_mask(BUTTON_LEFT_PIN) << (BUTTON_LEFT_PORT << 3))) { sensors_changed(&button_left_sensor); - } else if((port == BUTTON_RIGHT_PORT) && (pin == BUTTON_RIGHT_PIN)) { + } else if(pin_mask & + (gpio_hal_pin_to_mask(BUTTON_RIGHT_PIN) << (BUTTON_RIGHT_PORT << 3))) { sensors_changed(&button_right_sensor); - } else if((port == BUTTON_UP_PORT) && (pin == BUTTON_UP_PIN)) { + } else if(pin_mask & + (gpio_hal_pin_to_mask(BUTTON_UP_PIN) << (BUTTON_UP_PORT << 3))) { sensors_changed(&button_up_sensor); - } else if((port == BUTTON_DOWN_PORT) && (pin == BUTTON_DOWN_PIN)) { + } else if(pin_mask & + (gpio_hal_pin_to_mask(BUTTON_DOWN_PIN) << (BUTTON_DOWN_PORT << 3))) { sensors_changed(&button_down_sensor); } } /*---------------------------------------------------------------------------*/ +static gpio_hal_event_handler_t press_handler = { + .next = NULL, + .handler = button_press_handler, + .pin_mask = 0, +}; +/*---------------------------------------------------------------------------*/ +static void +register_btn_callback(uint8_t port_num, uint8_t pin) +{ + press_handler.pin_mask |= + gpio_hal_pin_to_mask(pin) << (port_num << 3); + + gpio_hal_register_handler(&press_handler); +} +/*---------------------------------------------------------------------------*/ /** * \brief Init function for the select button. * @@ -137,7 +150,7 @@ config_select(int type, int value) NVIC_EnableIRQ(BUTTON_SELECT_VECTOR); - gpio_register_callback(btn_callback, BUTTON_SELECT_PORT, BUTTON_SELECT_PIN); + register_btn_callback(BUTTON_SELECT_PORT, BUTTON_SELECT_PIN); return 1; } /*---------------------------------------------------------------------------*/ @@ -161,7 +174,7 @@ config_left(int type, int value) NVIC_EnableIRQ(BUTTON_LEFT_VECTOR); - gpio_register_callback(btn_callback, BUTTON_LEFT_PORT, BUTTON_LEFT_PIN); + register_btn_callback(BUTTON_LEFT_PORT, BUTTON_LEFT_PIN); return 1; } /*---------------------------------------------------------------------------*/ @@ -185,7 +198,7 @@ config_right(int type, int value) NVIC_EnableIRQ(BUTTON_RIGHT_VECTOR); - gpio_register_callback(btn_callback, BUTTON_RIGHT_PORT, BUTTON_RIGHT_PIN); + register_btn_callback(BUTTON_RIGHT_PORT, BUTTON_RIGHT_PIN); return 1; } /*---------------------------------------------------------------------------*/ @@ -209,7 +222,7 @@ config_up(int type, int value) NVIC_EnableIRQ(BUTTON_UP_VECTOR); - gpio_register_callback(btn_callback, BUTTON_UP_PORT, BUTTON_UP_PIN); + register_btn_callback(BUTTON_UP_PORT, BUTTON_UP_PIN); return 1; } /*---------------------------------------------------------------------------*/ @@ -233,7 +246,7 @@ config_down(int type, int value) NVIC_EnableIRQ(BUTTON_DOWN_VECTOR); - gpio_register_callback(btn_callback, BUTTON_DOWN_PORT, BUTTON_DOWN_PIN); + register_btn_callback(BUTTON_DOWN_PORT, BUTTON_DOWN_PIN); return 1; } /*---------------------------------------------------------------------------*/ From b9a321d6021c277ad01f1e625df350a8b436c7d0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 22:12:36 +0000 Subject: [PATCH 11/12] Add GPIO HAL example --- arch/platform/zoul/firefly-reva/board.h | 15 +- arch/platform/zoul/firefly/board.h | 15 +- arch/platform/zoul/orion/board.h | 15 +- arch/platform/zoul/remote-reva/board.h | 15 +- arch/platform/zoul/remote-revb/board.h | 9 +- examples/dev/gpio-hal/Makefile | 10 ++ examples/dev/gpio-hal/README.md | 36 +++++ examples/dev/gpio-hal/cc2538dk/pins.c | 51 +++++++ examples/dev/gpio-hal/gpio-hal-example.c | 139 +++++++++++++++++++ examples/dev/gpio-hal/openmote-cc2538/pins.c | 48 +++++++ examples/dev/gpio-hal/srf06-cc26xx/pins.c | 45 ++++++ examples/dev/gpio-hal/zoul/pins.c | 42 ++++++ 12 files changed, 425 insertions(+), 15 deletions(-) create mode 100644 examples/dev/gpio-hal/Makefile create mode 100644 examples/dev/gpio-hal/README.md create mode 100644 examples/dev/gpio-hal/cc2538dk/pins.c create mode 100644 examples/dev/gpio-hal/gpio-hal-example.c create mode 100644 examples/dev/gpio-hal/openmote-cc2538/pins.c create mode 100644 examples/dev/gpio-hal/srf06-cc26xx/pins.c create mode 100644 examples/dev/gpio-hal/zoul/pins.c diff --git a/arch/platform/zoul/firefly-reva/board.h b/arch/platform/zoul/firefly-reva/board.h index bea1fc746..4eaacac3a 100644 --- a/arch/platform/zoul/firefly-reva/board.h +++ b/arch/platform/zoul/firefly-reva/board.h @@ -99,9 +99,18 @@ */ /*---------------------------------------------------------------------------*/ /* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN (1 << 4) /**< LED1 (Green) -> PD4 */ -#define LEDS_BLUE (1 << 3) /**< LED2 (Blue) -> PD3 */ -#define LEDS_RED (1 << 5) /**< LED3 (Red) -> PD5 */ +#define LEDS_GREEN_PIN 4 +#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ + +#define LEDS_BLUE_PIN 3 +#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ + +#define LEDS_RED_PIN 5 +#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ + +#define LEDS_GREEN_PORT_BASE GPIO_D_BASE +#define LEDS_BLUE_PORT_BASE GPIO_D_BASE +#define LEDS_RED_PORT_BASE GPIO_D_BASE #define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) diff --git a/arch/platform/zoul/firefly/board.h b/arch/platform/zoul/firefly/board.h index 4a58fc0cc..e78dc22af 100644 --- a/arch/platform/zoul/firefly/board.h +++ b/arch/platform/zoul/firefly/board.h @@ -99,9 +99,18 @@ */ /*---------------------------------------------------------------------------*/ /* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN (1 << 4) /**< LED1 (Green) -> PD4 */ -#define LEDS_BLUE (1 << 3) /**< LED2 (Blue) -> PD3 */ -#define LEDS_RED (1 << 5) /**< LED3 (Red) -> PD5 */ +#define LEDS_GREEN_PIN 4 +#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ + +#define LEDS_BLUE_PIN 3 +#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ + +#define LEDS_RED_PIN 5 +#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ + +#define LEDS_GREEN_PORT_BASE GPIO_D_BASE +#define LEDS_BLUE_PORT_BASE GPIO_D_BASE +#define LEDS_RED_PORT_BASE GPIO_D_BASE #define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) diff --git a/arch/platform/zoul/orion/board.h b/arch/platform/zoul/orion/board.h index 494d79372..f1c22ad9e 100644 --- a/arch/platform/zoul/orion/board.h +++ b/arch/platform/zoul/orion/board.h @@ -68,9 +68,18 @@ */ /*---------------------------------------------------------------------------*/ /* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN (1 << 4) /**< LED1 (Green) -> PD4 */ -#define LEDS_BLUE (1 << 3) /**< LED2 (Blue) -> PD3 */ -#define LEDS_RED (1 << 5) /**< LED3 (Red) -> PD5 */ +#define LEDS_GREEN_PIN 4 +#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ + +#define LEDS_BLUE_PIN 3 +#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ + +#define LEDS_RED_PIN 5 +#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ + +#define LEDS_GREEN_PORT_BASE GPIO_D_BASE +#define LEDS_BLUE_PORT_BASE GPIO_D_BASE +#define LEDS_RED_PORT_BASE GPIO_D_BASE #define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) diff --git a/arch/platform/zoul/remote-reva/board.h b/arch/platform/zoul/remote-reva/board.h index 70a8ffdab..dfd79b914 100644 --- a/arch/platform/zoul/remote-reva/board.h +++ b/arch/platform/zoul/remote-reva/board.h @@ -103,9 +103,18 @@ */ /*---------------------------------------------------------------------------*/ /* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN (1 << 4) /**< LED1 (Green) -> PD4 */ -#define LEDS_BLUE (1 << 3) /**< LED2 (Blue) -> PD3 */ -#define LEDS_RED (1 << 5) /**< LED3 (Red) -> PD5 */ +#define LEDS_GREEN_PIN 4 +#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ + +#define LEDS_BLUE_PIN 3 +#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ + +#define LEDS_RED_PIN 5 +#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ + +#define LEDS_GREEN_PORT_BASE GPIO_D_BASE +#define LEDS_BLUE_PORT_BASE GPIO_D_BASE +#define LEDS_RED_PORT_BASE GPIO_D_BASE #define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) diff --git a/arch/platform/zoul/remote-revb/board.h b/arch/platform/zoul/remote-revb/board.h index 432b4b062..601eced0c 100644 --- a/arch/platform/zoul/remote-revb/board.h +++ b/arch/platform/zoul/remote-revb/board.h @@ -106,15 +106,18 @@ */ /*---------------------------------------------------------------------------*/ #define LEDS_RED 1 /**< LED1 (Red) -> PD4 */ -#define LEDS_RED_PIN_MASK (1 << 4) +#define LEDS_RED_PIN 4 +#define LEDS_RED_PIN_MASK (1 << LEDS_RED_PIN) #define LEDS_RED_PORT_BASE GPIO_D_BASE #define LEDS_GREEN 2 /**< LED2 (Green) -> PB7 */ -#define LEDS_GREEN_PIN_MASK (1 << 7) +#define LEDS_GREEN_PIN 7 +#define LEDS_GREEN_PIN_MASK (1 << LEDS_GREEN_PIN) #define LEDS_GREEN_PORT_BASE GPIO_B_BASE #define LEDS_BLUE 4 /**< LED3 (Blue) -> PB6 */ -#define LEDS_BLUE_PIN_MASK (1 << 6) +#define LEDS_BLUE_PIN 6 +#define LEDS_BLUE_PIN_MASK (1 << LEDS_BLUE_PIN) #define LEDS_BLUE_PORT_BASE GPIO_B_BASE #define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) /* 7 */ diff --git a/examples/dev/gpio-hal/Makefile b/examples/dev/gpio-hal/Makefile new file mode 100644 index 000000000..d20495a60 --- /dev/null +++ b/examples/dev/gpio-hal/Makefile @@ -0,0 +1,10 @@ +CONTIKI_PROJECT = gpio-hal-example +CONTIKI = ../../.. + +include $(CONTIKI)/Makefile.identify-target + +MODULES_REL += $(TARGET) + +all: $(CONTIKI_PROJECT) + +include $(CONTIKI)/Makefile.include diff --git a/examples/dev/gpio-hal/README.md b/examples/dev/gpio-hal/README.md new file mode 100644 index 000000000..84ab68f88 --- /dev/null +++ b/examples/dev/gpio-hal/README.md @@ -0,0 +1,36 @@ +# GPIO HAL Example +This example demonstrates and tests the functionality of the GPIO HAL. You can +use it to: + +* Understand the logic of the GPIO HAL. +* Test your implementation of arch-specific GPIO HAL components if you are +developing a new port. + +This example assumes a device with: + +* 3 output pins (e.g. LEDs). +* 1 button. + +# Supported devices +This example is expected to work off-the-shelf on the following boards: + +* All CC13xx/CC26xx devices +* All CC2538 devices + +# Extending for other platforms +Create a sub-directory with the same name as your platform. For example, for +platform `my-new-platform` create a subdirectory called `my-new-platform`. +Source files in this directory will be compiled automatically. In the most +simple case, all you will need is a source file called e.g. `pins.c` (it's OK +to use a different filename). In this file, you will need to provide +definitions of the variables used by the example to manipulate pins. These +variables are: + +* `out_pin1`, `out_pin2` and `out_pin3` for output pins. +* `btn_pin` for the button pin. + +Assign to those variables a value that corresponds to the output pin in your +board that you wish to test with the example. For example, if you have a LED +connected to pin 20, then you will need to + + gpio_hal_pin_t out_pin1 = 20; diff --git a/examples/dev/gpio-hal/cc2538dk/pins.c b/examples/dev/gpio-hal/cc2538dk/pins.c new file mode 100644 index 000000000..4cb3e9742 --- /dev/null +++ b/examples/dev/gpio-hal/cc2538dk/pins.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +/* + * LEDs on the SmartRF06 (EB and BB) are connected as follows: + * - LED1 (Red) -> PC0 + * - LED2 (Yellow) -> PC1 (gpio_hal_pin_t 17) + * - LED3 (Green) -> PC2 (gpio_hal_pin_t 18) + * - LED4 (Orange) -> PC3 (gpio_hal_pin_t 19) + * + * LED1 shares the same pin with the USB pullup, so here we'll use PC1, PC2 + * and PC3. + */ +gpio_hal_pin_t out_pin1 = 17; +gpio_hal_pin_t out_pin2 = 18; +gpio_hal_pin_t out_pin3 = 19; +/*---------------------------------------------------------------------------*/ +/* Button pin: Button select, PA3 */ +gpio_hal_pin_t btn_pin = 3; +/*---------------------------------------------------------------------------*/ diff --git a/examples/dev/gpio-hal/gpio-hal-example.c b/examples/dev/gpio-hal/gpio-hal-example.c new file mode 100644 index 000000000..83f3b6a2f --- /dev/null +++ b/examples/dev/gpio-hal/gpio-hal-example.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +#include "sys/etimer.h" +#include "lib/sensors.h" +#include "dev/button-sensor.h" + +#include +/*---------------------------------------------------------------------------*/ +extern gpio_hal_pin_t out_pin1, out_pin2, out_pin3; +extern gpio_hal_pin_t btn_pin; +/*---------------------------------------------------------------------------*/ +static struct etimer et; +static uint8_t counter; +/*---------------------------------------------------------------------------*/ +PROCESS(gpio_hal_example, "GPIO HAL Example"); +AUTOSTART_PROCESSES(&gpio_hal_example); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(gpio_hal_example, ev, data) +{ + PROCESS_BEGIN(); + + counter = 0; + + etimer_set(&et, CLOCK_SECOND); + + while(1) { + + PROCESS_YIELD(); + + if(ev == PROCESS_EVENT_TIMER && data == &et) { + if((counter & 7) == 0) { + /* Set output and test write, high */ + gpio_hal_arch_pin_set_output(out_pin1); + gpio_hal_arch_pin_set_output(out_pin2); + gpio_hal_arch_pin_set_output(out_pin3); + + gpio_hal_arch_write_pin(out_pin1, 1); + gpio_hal_arch_write_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3), + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); + } else if((counter & 7) == 1) { + /* Test write, low */ + gpio_hal_arch_write_pin(out_pin1, 0); + gpio_hal_arch_write_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3), 0); + } else if((counter & 7) == 2) { + /* Test set */ + gpio_hal_arch_set_pin(out_pin1); + gpio_hal_arch_set_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); + } else if((counter & 7) == 3) { + /* Test clear */ + gpio_hal_arch_clear_pin(out_pin1); + gpio_hal_arch_clear_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); + } else if((counter & 7) == 4) { + /* Test toggle (should go high) */ + gpio_hal_arch_toggle_pin(out_pin1); + gpio_hal_arch_toggle_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); + } else if((counter & 7) == 5) { + /* Test toggle (should go low) */ + gpio_hal_arch_toggle_pin(out_pin1); + gpio_hal_arch_toggle_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); + } else if((counter & 7) == 6) { + /* Set to input and then set. Should stay off */ + gpio_hal_arch_pin_set_input(out_pin1); + gpio_hal_arch_pin_set_input(out_pin2); + gpio_hal_arch_pin_set_input(out_pin3); + gpio_hal_arch_set_pin(out_pin1); + gpio_hal_arch_set_pins( + gpio_hal_pin_to_mask(out_pin2) | gpio_hal_pin_to_mask(out_pin3)); + } else if((counter & 7) == 7) { + /* Toggle button interrupt */ + gpio_hal_pin_cfg_t interrupt; + + interrupt = gpio_hal_arch_pin_cfg_get(btn_pin) & + GPIO_HAL_PIN_CFG_INT_ENABLE; + + if(interrupt == 0) { + printf("Enabling button interrupt\n"); + gpio_hal_arch_interrupt_enable(btn_pin); + } else { + printf("Disabling button interrupt\n"); + gpio_hal_arch_interrupt_disable(btn_pin); + } + } + + /* Test read */ + printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08lx\n", counter & 7, + gpio_hal_arch_read_pin(out_pin1), + gpio_hal_arch_read_pin(out_pin2), + gpio_hal_arch_read_pin(out_pin3), + gpio_hal_arch_read_pins(gpio_hal_pin_to_mask(out_pin1) | + gpio_hal_pin_to_mask(out_pin2) | + gpio_hal_pin_to_mask(out_pin3))); + + counter++; + etimer_set(&et, CLOCK_SECOND); + } else if(ev == sensors_event && data == &button_sensor) { + printf("Button event\n"); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/dev/gpio-hal/openmote-cc2538/pins.c b/examples/dev/gpio-hal/openmote-cc2538/pins.c new file mode 100644 index 000000000..340aff15c --- /dev/null +++ b/examples/dev/gpio-hal/openmote-cc2538/pins.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +/* + * LEDs on the OpenMote-CC2538 are connected as follows: + * - LED1 (Red) -> PC4 (gpio_hal_pin_t 20) + * - LED2 (Yellow) -> PC6 (gpio_hal_pin_t 22) + * - LED3 (Green) -> PC7 (gpio_hal_pin_t 23) + * - LED4 (Orange) -> PC5 + */ +gpio_hal_pin_t out_pin1 = 20; +gpio_hal_pin_t out_pin2 = 22; +gpio_hal_pin_t out_pin3 = 23; +/*---------------------------------------------------------------------------*/ +/* Button pin: PC3 */ +gpio_hal_pin_t btn_pin = 19; +/*---------------------------------------------------------------------------*/ diff --git a/examples/dev/gpio-hal/srf06-cc26xx/pins.c b/examples/dev/gpio-hal/srf06-cc26xx/pins.c new file mode 100644 index 000000000..700f8961b --- /dev/null +++ b/examples/dev/gpio-hal/srf06-cc26xx/pins.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +#if CONTIKI_BOARD_SENSORTAG_CC1350 +#define PINS2_AND_3 BOARD_IOID_LED_1 +#else +#define PINS2_AND_3 BOARD_IOID_LED_2 +#endif +gpio_hal_pin_t out_pin1 = BOARD_IOID_LED_1; +gpio_hal_pin_t out_pin2 = PINS2_AND_3; +gpio_hal_pin_t out_pin3 = PINS2_AND_3; +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_t btn_pin = BOARD_IOID_KEY_LEFT; +/*---------------------------------------------------------------------------*/ diff --git a/examples/dev/gpio-hal/zoul/pins.c b/examples/dev/gpio-hal/zoul/pins.c new file mode 100644 index 000000000..950254088 --- /dev/null +++ b/examples/dev/gpio-hal/zoul/pins.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +#define BASE_TO_PORT_NUM(base) (((base) - GPIO_A_BASE) >> 12) + +gpio_hal_pin_t out_pin1 = (BASE_TO_PORT_NUM(LEDS_GREEN_PORT_BASE) << 3) + LEDS_GREEN_PIN; +gpio_hal_pin_t out_pin2 = (BASE_TO_PORT_NUM(LEDS_BLUE_PORT_BASE) << 3) + LEDS_BLUE_PIN; +gpio_hal_pin_t out_pin3 = (BASE_TO_PORT_NUM(LEDS_RED_PORT_BASE) << 3) + LEDS_RED_PIN; +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_t btn_pin = (BUTTON_USER_PORT << 3) + BUTTON_USER_PIN; +/*---------------------------------------------------------------------------*/ From 48ffc8f6f18ba239862db01a4adc01dd7b07dd57 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 17 Dec 2017 23:20:43 +0000 Subject: [PATCH 12/12] Compile-test the GPIO HAL example --- tests/02-compile-arm-ports-01/Makefile | 8 ++++++++ tests/03-compile-arm-ports-02/Makefile | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index 4d20fe5d8..83ab79b13 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -14,6 +14,13 @@ platform-specific/cc26xx/very-sleepy-demo/srf06-cc26xx \ rpl-border-router/srf06-cc26xx:BOARD=launchpad/cc2650 \ sensniff/srf06-cc26xx \ sensniff/srf06-cc26xx:BOARD=launchpad/cc1310 \ +dev/gpio-hal/srf06-cc26xx:BOARD=srf06/cc13xx \ +dev/gpio-hal/srf06-cc26xx:BOARD=srf06/cc26xx \ +dev/gpio-hal/srf06-cc26xx:BOARD=sensortag/cc1350 \ +dev/gpio-hal/srf06-cc26xx:BOARD=sensortag/cc2650 \ +dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1310 \ +dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1350 \ +dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc2650 \ 6tisch/etsi-plugtest-2017/srf06-cc26xx:BOARD=launchpad/cc2650 \ storage/cfs-coffee/cc2538dk \ sensniff/cc2538dk \ @@ -22,6 +29,7 @@ coap/cc2538dk \ slip-radio/cc2538dk \ ipso-objects/cc2538dk \ multicast/cc2538dk \ +dev/gpio-hal/cc2538dk \ platform-specific/cc2538-common/cc2538dk \ platform-specific/cc2538-common/mqtt-demo/cc2538dk \ platform-specific/cc2538-common/crypto/cc2538dk \ diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index 4c6cb6d01..454c5d161 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -30,10 +30,16 @@ libs/trickle-library/zoul \ libs/data-structures/zoul \ nullnet/zoul \ slip-radio/zoul \ +dev/gpio-hal/zoul:BOARD=remote-reva \ +dev/gpio-hal/zoul:BOARD=remote-revb \ +dev/gpio-hal/zoul:BOARD=firefly-reva \ +dev/gpio-hal/zoul:BOARD=firefly \ +dev/gpio-hal/zoul:BOARD=orion \ storage/cfs-coffee/openmote-cc2538 \ sensniff/openmote-cc2538 \ hello-world/openmote-cc2538 \ rpl-udp/openmote-cc2538 \ +dev/gpio-hal/openmote-cc2538 \ rpl-border-router/openmote-cc2538 TOOLS=