arch/nrf53: add GPIOTE support

This commit is contained in:
raiden00pl
2023-03-13 12:51:29 +01:00
committed by Alan Carvalho de Assis
parent 74b0e8c2c8
commit bcecf2023f
5 changed files with 860 additions and 1 deletions
+30
View File
@@ -23,6 +23,7 @@ config NRF53_APPCORE
select ARM_HAVE_DSP
select ARCH_HAVE_FPU
select NRF53_HAVE_PWM
select NRF52_HAVE_GPIOTE1
select NRF53_HAVE_SAADC
select NRF53_HAVE_UART1
@@ -75,6 +76,10 @@ config NRF53_HAVE_UART1
bool
default n
config NRF53_HAVE_GPIOTE1
bool
default n
config NRF53_HAVE_PWM
bool
default n
@@ -103,6 +108,10 @@ config NRF53_PWM
menu "NRF53 Peripheral Selection"
config NRF53_GPIOTE
bool "GPIOTE (GPIO interrupts)"
default n
config NRF53_UART0
bool "UART0"
default n
@@ -404,6 +413,27 @@ endif # NRF53_SAADC
endmenu # SAADC Configuration
menu "GPIO Interrupt Configuration"
config NRF53_PER_PIN_INTERRUPTS
bool "Per-pin interrupt callbacks"
default !DEFAULT_SMALL
depends on NRF53_GPIOTE
---help---
The GPIOTE peripheral supports a limited number of channels which can
be set to EVENT mode and thus generate interrupts on pin state changes.
Another mechanism offered by the GPIO/GPIOTE peripherals is the PORT
event. This event is generated from a signal shared by all pins in
the GPIO port.
This option enables the ability to set per-pin callbacks that will
be invoked from the main GPIOTE ISR when a PORT event is generated.
As this involves extra storage to store each callback, this option can
be disabled to save space. In such case, it is possible to set a callback
for the whole PORT event directly.
endmenu # GPIO Interrupt Configuration
menuconfig NRF53_SOFTDEVICE_CONTROLLER
bool "SoftDevice Controller"
depends on ALLOW_BSDNORDIC_COMPONENTS
+4
View File
@@ -35,6 +35,10 @@ ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y)
CHIP_CSRCS += nrf53_idle.c
endif
ifeq ($(CONFIG_NRF53_GPIOTE),y)
CHIP_CSRCS += nrf53_gpiote.c
endif
ifeq ($(CONFIG_NRF53_UART),y)
CHIP_CSRCS += nrf53_serial.c
endif
@@ -48,7 +48,7 @@
#define NRF53_CTRLAPPERI_BASE 0x41006000
#define NRF53_RADIO_BASE 0x41008000
#define NRF53_RNG_BASE 0x41009000
#define NRF53_GPIOTE_BASE 0x4100A000
#define NRF53_GPIOTE0_BASE 0x4100A000
#define NRF53_WDT_BASE 0x4100B000
#define NRF53_TIMER0_BASE 0x4100C000
#define NRF53_ECB_BASE 0x4100D000
File diff suppressed because it is too large Load Diff
+172
View File
@@ -0,0 +1,172 @@
/****************************************************************************
* arch/arm/src/nrf53/nrf53_gpiote.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_NRF53_NRF53_GPIOTE_H
#define __ARCH_ARM_SRC_NRF53_NRF53_GPIOTE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/irq.h>
#include "chip.h"
/****************************************************************************
* Public Types
****************************************************************************/
/* GPIOTE OUT task configuration */
enum nrf53_gpiote_outcfg_e
{
NRF53_GPIOTE_SET = 0,
NRF53_GPIOTE_CLEAR = 1,
NRF53_GPIOTE_TOGGLE = 2,
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: nrf53_gpiote_set_ch_event
*
* Description:
* Configures a GPIOTE channel in EVENT mode, assigns it to a given pin
* and sets a handler for the corresponding channel events.
*
* Input Parameters:
* - pinset: GPIO pin configuration
* - channel: GPIOTE channel used to capture events
* - risingedge: Enables interrupt on rising edges
* - fallingedge: Enables interrupt on falling edges
* - func: When non-NULL, generate interrupt
* - arg: Argument passed to the interrupt callback
*
****************************************************************************/
void nrf53_gpiote_set_ch_event(uint32_t pinset, int channel,
bool risingedge, bool fallingedge,
xcpt_t func, void *arg);
/****************************************************************************
* Name: nrf53_gpiote_set_event
*
* Description:
* Configures a GPIOTE channel in EVENT mode, assigns it to a given pin
* and sets a handler for the first availalbe GPIOTE channel
*
* Input Parameters:
* - pinset: GPIO pin configuration
* - risingedge: Enables interrupt on rising edges
* - fallingedge: Enables interrupt on falling edges
* - func: When non-NULL, generate interrupt
* - arg: Argument passed to the interrupt callback
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure indicating the
* nature of the failure.
*
****************************************************************************/
int nrf53_gpiote_set_event(uint32_t pinset,
bool risingedge, bool fallingedge,
xcpt_t func, void *arg);
#ifdef CONFIG_NRF53_PER_PIN_INTERRUPTS
/****************************************************************************
* Name: nrf53_gpiote_set_pin_event
*
* Description:
* Sets/clears a handler for a given pin for the GPIO PORT event. This
* will mean edge-sensitive or level-sensitive according to GPIO detect
* mode configuration for the port (see nrf53_gpio_detectmode()). Pin
* will be sensitive to high/low according to GPIO_SENSE_LOW/HIGH
* (set via nrf53_gpio_config()).
*
* The passed handler will be invoked from the main ISR for the PORT
* event and will take care of clearing the LATCH register.
*
* Input Parameters:
* - pinset: GPIO pin configuration
* - func: When non-NULL, generate interrupt
* - arg: Argument passed to the interrupt callback
*
****************************************************************************/
void nrf53_gpiote_set_pin_event(uint32_t pinset, xcpt_t func, void *arg);
#else
/****************************************************************************
* Name: nrf53_gpiote_set_port_event
*
* Description:
* Sets/clears the handler for the GPIO PORT event.
*
* The passed handler will be invoked from the main ISR for the PORT
* event and will take care of clearing the LATCH register.
*
* Input Parameters:
* - pinset: GPIO port will be extracted from this parameter
* - func: When non-NULL, generate interrupt
* - arg: Argument passed to the interrupt callback
*
****************************************************************************/
void nrf53_gpiote_set_port_event(uint32_t pinset, xcpt_t func, void *arg);
#endif
/****************************************************************************
* Name: nrf53_gpio_set_task
*
* Description:
* Configure GPIO in TASK mode (to be controlled via tasks).
* Note that a pin can only be either in TASK or EVENT mode (set by
* nrf53_gpiosetevent with event set to true). Also, once set to TASK mode,
* pin control is only possible via tasks on the via nrf53_gpio_write and
* will automatically set the output mode.
* Finally, a given pin should only be assigned to a given channel.
*
* Input Parameters:
* - pinset: gpio pin configuration (only port + pin is important here)
* - channel: the GPIOTE channel used to control the given pin
* - output_high: set pin initially to output HIGH or LOW.
* - outcfg: configure pin behavior one OUT task is triggered
*
****************************************************************************/
void nrf53_gpio_set_task(uint32_t pinset, int channel,
bool output_high, enum nrf53_gpiote_outcfg_e outcfg);
/****************************************************************************
* Name: nrf53_gpiote_init
*
* Description:
* Initialize GPIOTE
*
****************************************************************************/
int nrf53_gpiote_init(void);
#endif /* __ARCH_ARM_SRC_NRF53_NRF53_GPIOTE_H */