Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions applications/sdp/gpio/src/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include <drivers/gpio/nrfe_gpio.h>

#if !defined(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG) && \
!defined(CONFIG_GPIO_NRFE_EGPIO_BACKEND_MBOX) && \
!defined(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICBMSG)
#if !IS_ENABLED(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG) && \
!IS_ENABLED(CONFIG_GPIO_NRFE_EGPIO_BACKEND_MBOX) && \
!IS_ENABLED(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICBMSG)
#error "Define communication backend type"
#endif

Expand Down
9 changes: 5 additions & 4 deletions applications/sdp/gpio/src/backend/backend_mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ static void mbox_callback(const struct device *instance, uint32_t channel, void
nrfe_gpio_mbox_data_t *rx_data = (nrfe_gpio_mbox_data_t *)user_data;

/* Try and get lock for the shared data structure */
if (atomic_flag_test_and_set(&rx_data->lock.locked)) {
/* Return in case lock is not acquired (used by other core)*/
if (!atomic_cas(&rx_data->lock.locked, DATA_LOCK_STATE_WITH_DATA, DATA_LOCK_STATE_BUSY)) {
/* Return in case buffer is without data */
atomic_set(&rx_data->lock.locked, DATA_LOCK_STATE_READY);
return;
}

Expand All @@ -49,7 +50,7 @@ static void mbox_callback(const struct device *instance, uint32_t channel, void
rx_data->lock.data_size = 0;

/* We are finished with the shared data structure, so we can release the lock */
atomic_flag_clear(&rx_data->lock.locked);
atomic_set(&rx_data->lock.locked, DATA_LOCK_STATE_READY);
}

/**
Expand Down Expand Up @@ -88,8 +89,8 @@ int backend_init(backend_callback_t callback)
}

/* clear the buffer locks and their size holders */
atomic_flag_clear(&rx_data->lock.locked);
rx_data->lock.data_size = 0;
atomic_set(&rx_data->lock.locked, DATA_LOCK_STATE_READY);

return 0;
}
2 changes: 1 addition & 1 deletion drivers/gpio/gpio_nrfe_icmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "gpio_nrfe.h"

#if defined(CONFIG_MULTITHREADING)
K_SEM_DEFINE(bound_sem, 0, 1);
static K_SEM_DEFINE(bound_sem, 0, 1);
#else
static volatile uint32_t bound_sem = 1;
#endif
Expand Down
13 changes: 4 additions & 9 deletions drivers/gpio/gpio_nrfe_mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#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"

Expand All @@ -18,19 +17,15 @@ static nrfe_gpio_mbox_data_t *tx_data =

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;
/* Wait for the access to the shared data structure */
while (!atomic_cas(&tx_data->lock.locked, DATA_LOCK_STATE_READY, DATA_LOCK_STATE_BUSY)) {
}

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);
/* Inform the consumer that new data is available */
atomic_set(&tx_data->lock.locked, DATA_LOCK_STATE_WITH_DATA);

return mbox_send_dt(&tx_channel, NULL);
}
Expand Down
4 changes: 2 additions & 2 deletions include/drivers/gpio/nrfe_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ typedef struct __packed {
*/
} nrfe_gpio_data_packet_t;

typedef struct __packed {
nrfe_shared_data_lock_t lock;
typedef struct {
struct nrfe_shared_data_lock lock;
nrfe_gpio_data_packet_t data;
} nrfe_gpio_mbox_data_t;

Expand Down
21 changes: 14 additions & 7 deletions include/sdp/nrfe_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef NRFE_COMMON_H__
#define NRFE_COMMON_H__
#ifndef SDP_NRFE_COMMON_H__
#define SDP_NRFE_COMMON_H__

#include <stdatomic.h>
#include <zephyr/sys/atomic.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct __packed {
atomic_bool locked;
enum data_lock_state {
DATA_LOCK_STATE_OFF = 0,
DATA_LOCK_STATE_BUSY,
DATA_LOCK_STATE_WITH_DATA,
DATA_LOCK_STATE_READY,
};

struct nrfe_shared_data_lock {
uint32_t data_size;
} nrfe_shared_data_lock_t;
atomic_t locked;
};

#ifdef __cplusplus
}
#endif

#endif /* NRFE_COMMON_H__ */
#endif /* SDP_NRFE_COMMON_H__ */
Loading