-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add mbox backend for eGPIO #16592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add mbox backend for eGPIO #16592
Changes from 1 commit
e50e75d
1a9538b
4d7592d
9615800
dbc826b
722c094
cb2dc7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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__ */ |
| 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); | ||
jaz1-nordic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #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; | ||
| } | ||
| 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); | ||
|
||
| /* 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; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| #define NRFE_GPIO_H | ||
|
|
||
| #include <drivers/nrfx_common.h> | ||
| #include <sdp/nrfe_common.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
|
|
@@ -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; | ||
|
||
|
|
||
magp-nordic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| 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__ | ||
jaz1-nordic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define NRFE_COMMON_H__ | ||
|
|
||
| #include <stdatomic.h> | ||
jaz1-nordic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef struct __packed { | ||
| atomic_bool locked; | ||
jaz1-nordic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| uint32_t data_size; | ||
| } nrfe_shared_data_lock_t; | ||
|
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* NRFE_COMMON_H__ */ | ||
Uh oh!
There was an error while loading. Please reload this page.