Contiki 3.x
gpio-interrupt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*---------------------------------------------------------------------------*/
31 /**
32  * \addtogroup cc26xx-gpio-interrupts
33  * @{
34  *
35  * \file
36  * Implementation of CC13xx/CC26xx GPIO interrupt handling.
37  */
38 /*---------------------------------------------------------------------------*/
39 #include "ioc.h"
40 #include "gpio-interrupt.h"
41 #include "sys/energest.h"
42 #include "lpm.h"
43 #include "ti-lib.h"
44 
45 #include <string.h>
46 /*---------------------------------------------------------------------------*/
47 #define gpio_interrupt_isr GPIOIntHandler
48 /*---------------------------------------------------------------------------*/
49 /* Handler array */
50 static gpio_interrupt_handler_t handlers[NUM_IO_MAX];
51 /*---------------------------------------------------------------------------*/
52 void
53 gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f)
54 {
55  uint8_t interrupts_disabled = ti_lib_int_master_disable();
56 
57  /* Clear interrupts on specified pins */
58  ti_lib_gpio_event_clear(1 << ioid);
59 
60  handlers[ioid] = f;
61 
62  /* Re-enable interrupts */
63  if(!interrupts_disabled) {
64  ti_lib_int_master_enable();
65  }
66 }
67 /*---------------------------------------------------------------------------*/
68 void
70 {
71  int i;
72 
73  for(i = 0; i < NUM_IO_MAX; i++) {
74  handlers[i] = NULL;
75  }
76 
77  ti_lib_int_enable(INT_EDGE_DETECT);
78 }
79 /*---------------------------------------------------------------------------*/
80 void
81 gpio_interrupt_isr(void)
82 {
83  uint32_t pin_mask;
84  uint8_t i;
85 
86  ENERGEST_ON(ENERGEST_TYPE_IRQ);
87 
88  /* Read interrupt flags */
89  pin_mask = (HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) & GPIO_PIN_MASK);
90 
91  /* Clear the interrupt flags */
92  HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) = pin_mask;
93 
94  /* Run custom ISRs */
95  for(i = 0; i < NUM_GPIO_PINS; i++) {
96  /* Call the handler if there is one registered for this event */
97  if((pin_mask & (1 << i)) && handlers[i] != NULL) {
98  handlers[i](i);
99  }
100  }
101 
102  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
103 }
104 /*---------------------------------------------------------------------------*/
105 /** @} */
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
Definition: gpio.h:321
Header file with macros which rename TI CC26xxware functions.
Header file for the energy estimation mechanism
Header file for the CC13xx/CC26xx GPIO interrupt management.
#define NULL
The null pointer.
Header file with declarations for the I/O Control module.
void gpio_interrupt_register_handler(uint8_t ioid, gpio_interrupt_handler_t f)
Register a GPIO interrupt handler.
void gpio_interrupt_init()
Initialise the GPIO interrupt handling module.