Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion drivers/gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
#

zephyr_library_amend()
zephyr_library_sources_ifdef(CONFIG_GPIO_NRFE gpio_nrfe.c)

if(CONFIG_GPIO_NRFE)
if(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG)
zephyr_library_sources(gpio_nrfe_icmsg.c)
elseif(CONFIG_GPIO_NRFE_EGPIO_BACKEND_MBOX)
zephyr_library_sources(gpio_nrfe_mbox.c)
endif()

zephyr_library_sources(gpio_nrfe.c)
endif()
20 changes: 20 additions & 0 deletions drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ config GPIO_NRFE_INIT_PRIORITY
eGPIO driver device initialization priority.
eGPIO initialization depends on IPC initialization which is done at the same init level and
has init priority equal to 46.

choice GPIO_NRFE_EGPIO_BACKEND
prompt "eGPIO driver backend type"
default GPIO_NRFE_EGPIO_BACKEND_ICMSG
help
Select the backend type for the eGPIO driver and application.

config GPIO_NRFE_EGPIO_BACKEND_MBOX
bool "MBOX"
help
Use MBOX backend driver for eGPIO.
The MBOX version is more resource-efficient than the ICMSG backend,
but needs to have a shared structure defined as a communication channel.

config GPIO_NRFE_EGPIO_BACKEND_ICMSG
bool "ICMSG"
help
Use ICMSG backend driver for eGPIO.

endchoice
50 changes: 1 addition & 49 deletions drivers/gpio/gpio_nrfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,10 @@

#define DT_DRV_COMPAT nordic_nrf_egpio

#include <drivers/gpio/nrfe_gpio.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_utils.h>

#include <zephyr/device.h>

#include <zephyr/ipc/ipc_service.h>

K_SEM_DEFINE(bound_sem, 0, 1);

static void ep_bound(void *priv)
{
k_sem_give(&bound_sem);
}

static struct ipc_ept_cfg ep_cfg = {
.cb = {
.bound = ep_bound,
.received = NULL,
},
};

static struct ipc_ept ep;
#include "gpio_nrfe.h"

struct gpio_nrfe_data {
/* gpio_driver_data needs to be first */
Expand All @@ -46,16 +27,6 @@ static inline const struct gpio_nrfe_cfg *get_port_cfg(const struct device *port
return port->config;
}

static int gpio_send(nrfe_gpio_data_packet_t *msg)
{
if (ipc_service_send(&ep, (void *)(&msg), sizeof(nrfe_gpio_data_packet_t))
== sizeof(nrfe_gpio_data_packet_t)) {
return 0;
} else {
return -EIO;
}
}

static int gpio_nrfe_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
{
nrfe_gpio_data_packet_t msg = {.opcode = NRFE_GPIO_PIN_CONFIGURE,
Expand Down Expand Up @@ -112,25 +83,6 @@ static int gpio_nrfe_port_toggle_bits(const struct device *port, gpio_port_pins_
return gpio_send(&msg);
}

static int gpio_nrfe_init(const struct device *port)
{
const struct device *ipc0_instance = DEVICE_DT_GET(DT_NODELABEL(ipc0));
int ret = ipc_service_open_instance(ipc0_instance);

if ((ret < 0) && (ret != -EALREADY)) {
return ret;
}

ret = ipc_service_register_endpoint(ipc0_instance, &ep, &ep_cfg);
if (ret < 0) {
return ret;
}

k_sem_take(&bound_sem, K_FOREVER);

return 0;
}

static const struct gpio_driver_api gpio_nrfe_drv_api_funcs = {
.pin_configure = gpio_nrfe_pin_configure,
.port_set_masked_raw = gpio_nrfe_port_set_masked_raw,
Expand Down
20 changes: 20 additions & 0 deletions drivers/gpio/gpio_nrfe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef GPIO_NRFE_H__
#define GPIO_NRFE_H__

#include <drivers/gpio/nrfe_gpio.h>
#include <zephyr/device.h>

#if !defined(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG) && !defined(CONFIG_GPIO_NRFE_EGPIO_BACKEND_MBOX)
#error "Configure communication backend type"
#endif

int gpio_send(nrfe_gpio_data_packet_t *msg);
int gpio_nrfe_init(const struct device *port);

#endif /* GPIO_NRFE_H__ */
69 changes: 69 additions & 0 deletions drivers/gpio/gpio_nrfe_icmsg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2024, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_utils.h>
#include <zephyr/ipc/ipc_service.h>

#include "gpio_nrfe.h"

#if defined(CONFIG_MULTITHREADING)
K_SEM_DEFINE(bound_sem, 0, 1);
#else
static volatile uint32_t bound_sem = 1;
#endif

static void ep_bound(void *priv)
{
#if defined(CONFIG_MULTITHREADING)
k_sem_give(&bound_sem);
#else
bound_sem = 0;
#endif
}

static struct ipc_ept_cfg ep_cfg = {
.cb = {
.bound = ep_bound,
.received = NULL,
},
};

static struct ipc_ept ep;

int gpio_send(nrfe_gpio_data_packet_t *msg)
{
if (ipc_service_send(&ep, (void *)msg, sizeof(nrfe_gpio_data_packet_t)) ==
sizeof(nrfe_gpio_data_packet_t)) {
return 0;
} else {
return -EIO;
}
}

int gpio_nrfe_init(const struct device *port)
{
const struct device *ipc0_instance = DEVICE_DT_GET(DT_NODELABEL(ipc0));
int ret = ipc_service_open_instance(ipc0_instance);

if ((ret < 0) && (ret != -EALREADY)) {
return ret;
}

ret = ipc_service_register_endpoint(ipc0_instance, &ep, &ep_cfg);
if (ret < 0) {
return ret;
}

#if defined(CONFIG_MULTITHREADING)
k_sem_take(&bound_sem, K_FOREVER);
#else
while (bound_sem != 0) {
}
#endif

return 0;
}
41 changes: 41 additions & 0 deletions drivers/gpio/gpio_nrfe_mbox.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_utils.h>
#include <zephyr/drivers/mbox.h>
#include <zephyr/sys/printk.h>

#include "gpio_nrfe.h"

static const struct mbox_dt_spec tx_channel = MBOX_DT_SPEC_GET(DT_PATH(mbox_consumer), tx);
static nrfe_gpio_mbox_data_t *tx_data =
(nrfe_gpio_mbox_data_t *)((uint8_t *)(DT_REG_ADDR(DT_NODELABEL(sram_tx))));
#define MAX_MSG_SIZE (DT_REG_SIZE(DT_NODELABEL(sram_tx)))

int gpio_send(nrfe_gpio_data_packet_t *msg)
{
printk("Sending opcode: %d, pin %d, port %d, flag: %d\n", msg->opcode, msg->pin, msg->port,
msg->flags);
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be using logger.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use logging subsystem

/* Try and get lock */
if (atomic_flag_test_and_set(&tx_data->lock.locked)) {
/* Return -1 in case lock is not acquired (used by other core)*/
return -1;
}

memcpy((void *)&tx_data->data, (void *)msg, sizeof(nrfe_gpio_data_packet_t));
tx_data->lock.data_size = sizeof(nrfe_gpio_data_packet_t);

/* Release lock */
atomic_flag_clear(&tx_data->lock.locked);

return mbox_send_dt(&tx_channel, NULL);
}

int gpio_nrfe_init(const struct device *port)
{
return 0;
}
6 changes: 6 additions & 0 deletions include/drivers/gpio/nrfe_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define NRFE_GPIO_H

#include <drivers/nrfx_common.h>
#include <sdp/nrfe_common.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -32,6 +33,11 @@ typedef struct __packed {
*/
} nrfe_gpio_data_packet_t;

typedef struct __packed {
nrfe_shared_data_lock_t lock;
nrfe_gpio_data_packet_t data;
} nrfe_gpio_mbox_data_t;
Comment on lines +36 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs.


#ifdef __cplusplus
}
#endif
Expand Down
25 changes: 25 additions & 0 deletions include/sdp/nrfe_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef NRFE_COMMON_H__
#define NRFE_COMMON_H__

#include <stdatomic.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct __packed {
atomic_bool locked;
uint32_t data_size;
} nrfe_shared_data_lock_t;
Comment on lines +16 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs.


#ifdef __cplusplus
}
#endif

#endif /* NRFE_COMMON_H__ */