Adjust CC13xx/CC26xx drivers to use the GPIO HAL

This commit is contained in:
George Oikonomou 2017-12-16 22:47:44 +00:00
parent 421d95bc00
commit f1d1932c5c
8 changed files with 58 additions and 142 deletions

View File

@ -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"

View File

@ -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 <string.h>
/*---------------------------------------------------------------------------*/
#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);
}
}
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -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 <stdint.h>
/*---------------------------------------------------------------------------*/
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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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) {

View File

@ -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();

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {