From 277cac15ddbda2b1d64577b299079645091abe15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20St=C4=99pnicki?= Date: Wed, 26 Feb 2025 16:07:37 +0100 Subject: [PATCH] zephyr vevif missing testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Łukasz Stępnicki --- drivers/mbox/mbox_nrf_bellboard_rx.c | 19 +++++ drivers/mbox/mbox_nrf_bellboard_tx.c | 30 ++++++++ drivers/mbox/mbox_nrf_vevif_event_rx.c | 1 + drivers/mbox/mbox_nrf_vevif_task_rx.c | 37 ++++++++++ drivers/mbox/mbox_nrf_vevif_task_tx.c | 46 ++++++++++++ .../nrfs/backends/nrfs_backend_ipc_service.c | 35 +++++++++ samples/bluetooth/hci_ipc/src/main.c | 11 +++ .../mgmt/mcumgr/smp_svr/src/bluetooth.c | 6 ++ soc/nordic/nrf54h/gpd/gpd.c | 17 ++++- subsys/ipc/ipc_service/lib/icmsg.c | 74 +++++++++++++++++++ 10 files changed, 275 insertions(+), 1 deletion(-) diff --git a/drivers/mbox/mbox_nrf_bellboard_rx.c b/drivers/mbox/mbox_nrf_bellboard_rx.c index 54dd21b9624..53c843f39f2 100644 --- a/drivers/mbox/mbox_nrf_bellboard_rx.c +++ b/drivers/mbox/mbox_nrf_bellboard_rx.c @@ -12,6 +12,11 @@ #include +#if CONFIG_SOC_NRF54H20_CPURAD +#include +extern const struct gpio_dt_spec led1; +#endif + #define BELLBOARD_NUM_IRQS 4U BUILD_ASSERT(DT_NUM_IRQS(DT_DRV_INST(0)) <= BELLBOARD_NUM_IRQS, "# interrupt exceeds maximum"); @@ -43,12 +48,26 @@ static void bellboard_rx_isr(const void *parameter) uint8_t irq_idx = (uint8_t)(uintptr_t)parameter; uint32_t int_pend; + #if CONFIG_SOC_NRF54H20_CPURAD + //if(i==0) gpio_pin_toggle_dt(&led1); + //gpio_pin_toggle_dt(&led1); + #endif + + int_pend = nrf_bellboard_int_pending_get(bellboard, irq_idx); for (uint8_t i = 0U; i < NRF_BELLBOARD_EVENTS_TRIGGERED_COUNT; i++) { nrf_bellboard_event_t event = nrf_bellboard_triggered_event_get(i); + + if ((int_pend & BIT(i)) != 0U) { + + #if CONFIG_SOC_NRF54H20_CPURAD + //if(i==0) gpio_pin_toggle_dt(&led1); + if(i == 6) gpio_pin_toggle_dt(&led1); + #endif + /* Only clear those events that have their corresponding bit set * in INTPEND at the time we read it. Otherwise, if two (or more) * events are generated in quick succession, INTPEND may be set for diff --git a/drivers/mbox/mbox_nrf_bellboard_tx.c b/drivers/mbox/mbox_nrf_bellboard_tx.c index 9f98f57ff5d..6df491754bc 100644 --- a/drivers/mbox/mbox_nrf_bellboard_tx.c +++ b/drivers/mbox/mbox_nrf_bellboard_tx.c @@ -9,11 +9,26 @@ #include #include +#include struct mbox_bellboard_tx_conf { NRF_BELLBOARD_Type *bellboard; }; +#if CONFIG_SOC_NRF54H20_CPUSYS +//volatile uint32_t app_bellboard_tx_count = 0; +//volatile uint32_t rad_bellboard_tx_count = 0; +//volatile uint32_t sec_bellboard_tx_count = 0; +//volatile uint32_t all_bellboard_tx_count = 0; +#endif + +#if CONFIG_SOC_NRF54H20_CPUSYS +#include +extern const struct gpio_dt_spec led0; +extern const struct gpio_dt_spec led1; + +#endif + static int bellboard_tx_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg) { const struct mbox_bellboard_tx_conf *config = dev->config; @@ -26,7 +41,22 @@ static int bellboard_tx_send(const struct device *dev, uint32_t id, const struct return -EMSGSIZE; } + + + #if CONFIG_SOC_NRF54H20_CPUSYS + + //gpio_pin_toggle_dt(&led0); + + //printk("bellboard id 0x%x\n", (uint32_t)config->bellboard); + //if(config->bellboard == 0x5f09a000) app_bellboard_tx_count++; + //if(config->bellboard == 0x5f09b000) rad_bellboard_tx_count++; + //if(config->bellboard == 0x5f099000) sec_bellboard_tx_count++; + //all_bellboard_tx_count++; + //printk("bellboard_tx_count %d\n", bellboard_tx_count); + #endif + nrfy_bellboard_task_trigger(config->bellboard, nrf_bellboard_trigger_task_get(id)); + //nrfy_bellboard_task_trigger(config->bellboard, nrf_bellboard_trigger_task_get(id)); return 0; } diff --git a/drivers/mbox/mbox_nrf_vevif_event_rx.c b/drivers/mbox/mbox_nrf_vevif_event_rx.c index b5be6a97b79..40938c23433 100644 --- a/drivers/mbox/mbox_nrf_vevif_event_rx.c +++ b/drivers/mbox/mbox_nrf_vevif_event_rx.c @@ -41,6 +41,7 @@ static void vevif_event_rx_isr(const void *device) uint8_t idx = id - EVENTS_IDX_MIN; if ((cbs->enabled_mask & BIT(id)) && (cbs->cb[idx] != NULL)) { + cbs->cb[idx](dev, id, cbs->user_data[idx], NULL); } } diff --git a/drivers/mbox/mbox_nrf_vevif_task_rx.c b/drivers/mbox/mbox_nrf_vevif_task_rx.c index 8783424ae98..c7dfef4975e 100644 --- a/drivers/mbox/mbox_nrf_vevif_task_rx.c +++ b/drivers/mbox/mbox_nrf_vevif_task_rx.c @@ -37,11 +37,48 @@ static const uint8_t vevif_irqs[VEVIF_TASKS_NUM] = { LISTIFY(DT_NUM_IRQS(DT_DRV_INST(0)), VEVIF_IRQN, (,)) }; +#if 0//CONFIG_SOC_NRF54H20_CPUSYS +#define LED0_NODE DT_ALIAS(led0) +#define LED1_NODE DT_ALIAS(led1) +#include +static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); +static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); +#endif + +//volatile uint32_t rad_count = 0; +//volatile uint32_t app_count = 0; +//volatile uint32_t sec_count = 0; + +#if CONFIG_SOC_NRF54H20_CPUSYS +#include +extern const struct gpio_dt_spec led0; +extern const struct gpio_dt_spec led1; + +#endif + + static void vevif_task_rx_isr(const void *parameter) { + #if CONFIG_SOC_NRF54H20_CPUSYS + //gpio_pin_toggle_dt(&led0); + #endif + uint8_t channel = *(uint8_t *)parameter; uint8_t idx = channel - TASKS_IDX_MIN; + + #if CONFIG_SOC_NRF54H20_CPUSYS + //if(idx == 18) gpio_pin_toggle_dt(&led1); + //gpio_pin_toggle_dt(&led1); + //if(idx == 18) rad_count++; + #endif + + #if CONFIG_SOC_NRF54H20_CPUSYS + //if(idx == 12) gpio_pin_toggle_dt(&led1); + //if(idx == 12) app_count++; + //if(idx == 0) sec_count++; + #endif + nrf_vpr_csr_vevif_tasks_clear(BIT(channel)); if (cbs.cb[idx] != NULL) { diff --git a/drivers/mbox/mbox_nrf_vevif_task_tx.c b/drivers/mbox/mbox_nrf_vevif_task_tx.c index a409ef214b7..fcd403996ff 100644 --- a/drivers/mbox/mbox_nrf_vevif_task_tx.c +++ b/drivers/mbox/mbox_nrf_vevif_task_tx.c @@ -7,6 +7,7 @@ #include #include +#include #include @@ -25,6 +26,39 @@ static inline bool vevif_task_tx_is_valid(const struct device *dev, uint32_t id) return ((id <= TASKS_IDX_MAX) && ((config->tasks_mask & BIT(id)) != 0U)); } +#if CONFIG_SOC_NRF54H20_CPURAD +#define LED0_NODE DT_ALIAS(led0) +#define LED1_NODE DT_ALIAS(led1) +#define LED2_NODE DT_ALIAS(led2) +#define LED3_NODE DT_ALIAS(led3) +#define LED4_NODE DT_ALIAS(led4) +#define LED5_NODE DT_ALIAS(led5) +#include +const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); +const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); +const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); +const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios); +const struct gpio_dt_spec led4 = GPIO_DT_SPEC_GET(LED4_NODE, gpios); +const struct gpio_dt_spec led5 = GPIO_DT_SPEC_GET(LED5_NODE, gpios); + +int mbox_led_init(void) +{ + gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led4, GPIO_OUTPUT_ACTIVE); + gpio_pin_configure_dt(&led5, GPIO_OUTPUT_ACTIVE); + + return 0; +} + +SYS_INIT(mbox_led_init, PRE_KERNEL_2, 53); + +#endif + +#define VEVIF_RETRIGGER_DELAY 12 + static int vevif_task_tx_send(const struct device *dev, uint32_t id, const struct mbox_msg *msg) { const struct mbox_vevif_task_tx_conf *config = dev->config; @@ -37,6 +71,18 @@ static int vevif_task_tx_send(const struct device *dev, uint32_t id, const struc return -EMSGSIZE; } + #if CONFIG_SOC_NRF54H20_CPURAD + gpio_pin_toggle_dt(&led0); + #endif + + nrfy_vpr_task_trigger(config->vpr, nrfy_vpr_trigger_task_get(id)); + + k_busy_wait(VEVIF_RETRIGGER_DELAY); + + #if CONFIG_SOC_NRF54H20_CPURAD + gpio_pin_toggle_dt(&led0); + #endif + nrfy_vpr_task_trigger(config->vpr, nrfy_vpr_trigger_task_get(id)); return 0; diff --git a/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c b/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c index bf5dec9fe16..6ed3ff78cb0 100644 --- a/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c +++ b/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c @@ -15,6 +15,16 @@ #include #include +#if CONFIG_SOC_NRF54H20_CPURAD +#include +extern const struct gpio_dt_spec led2; +#endif + +#if CONFIG_SOC_NRF54H20_CPURAD +#include +extern const struct gpio_dt_spec led1; +#endif + LOG_MODULE_REGISTER(NRFS_BACKEND, CONFIG_NRFS_BACKEND_LOG_LEVEL); #define MAX_PACKET_DATA_SIZE (CONFIG_NRFS_MAX_BACKEND_PACKET_SIZE) @@ -54,6 +64,13 @@ static struct ipc_channel_config ipc_cpusys_channel_config = { .enabled = true }; +#if CONFIG_SOC_NRF54H20_CPURAD +#include +extern const struct gpio_dt_spec led3; +extern const struct gpio_dt_spec led4; +extern const struct gpio_dt_spec led5; +#endif + /** * @brief nrfs backend error handler * @@ -93,6 +110,9 @@ __weak void nrfs_backend_error_handler(enum nrfs_backend_error error_id, int err static void ipc_sysctrl_ept_bound(void *priv) { LOG_DBG("Bound to sysctrl."); + #if CONFIG_SOC_NRF54H20_CPURAD + gpio_pin_toggle_dt(&led2); + #endif k_event_post(&ipc_connected_event, IPC_INIT_DONE_EVENT); atomic_set(&ipc_cpusys_channel_config.status, CONNECTED); @@ -101,10 +121,17 @@ static void ipc_sysctrl_ept_bound(void *priv) } } +//static struct ipc_data_packet rx_data; + static void ipc_sysctrl_ept_recv(const void *data, size_t size, void *priv) { + struct ipc_data_packet rx_data; + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led3); + #endif + __ASSERT(size <= MAX_PACKET_DATA_SIZE, "Received data is too long. Config error."); if (size <= MAX_PACKET_DATA_SIZE) { rx_data.channel_id = IPC_CPUSYS_CHANNEL_ID; @@ -169,14 +196,22 @@ static int ipc_channel_init(void) return ret; } + + nrfs_err_t nrfs_backend_send(void *message, size_t size) { + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led2); + #endif return nrfs_backend_send_ex(message, size, K_NO_WAIT, false); } nrfs_err_t nrfs_backend_send_ex(void *message, size_t size, k_timeout_t timeout, bool high_prio) { if (!k_is_in_isr() && nrfs_backend_connected()) { + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led2); + #endif return ipc_service_send(&ipc_cpusys_channel_config.ipc_ept, message, size) ? NRFS_SUCCESS : NRFS_ERR_IPC; } else if (size <= MAX_PACKET_DATA_SIZE) { diff --git a/samples/bluetooth/hci_ipc/src/main.c b/samples/bluetooth/hci_ipc/src/main.c index f0f71ca384f..94a4af73d3e 100644 --- a/samples/bluetooth/hci_ipc/src/main.c +++ b/samples/bluetooth/hci_ipc/src/main.c @@ -374,6 +374,11 @@ static struct ipc_ept_cfg hci_ept_cfg = { }, }; +#include +#include + +#include + int main(void) { int err; @@ -407,6 +412,10 @@ int main(void) LOG_ERR("Registering endpoint failed with %d", err); } + //NRF_VPR_Type * p_vpr = (NRF_VPR_Type *)NRF_VPR120; + + //nrfy_vpr_task_trigger(p_vpr, nrfy_vpr_trigger_task_get(18)); + k_sem_take(&ipc_bound_sem, K_FOREVER); while (1) { @@ -414,6 +423,8 @@ int main(void) buf = k_fifo_get(&rx_queue, K_FOREVER); hci_ipc_send(buf, HCI_REGULAR_MSG); + + //nrfy_vpr_task_trigger(p_vpr, nrfy_vpr_trigger_task_get(18)); } return 0; } diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c b/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c index 2eedfc66911..201716fa662 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c +++ b/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c @@ -28,6 +28,8 @@ static const struct bt_data sd[] = { BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), }; +#include + static void advertise(struct k_work *work) { int rc; @@ -38,6 +40,10 @@ static void advertise(struct k_work *work) return; } + k_msleep(190); + //k_msleep(1000); + sys_reboot(SYS_REBOOT_WARM); + LOG_INF("Advertising successfully started"); } diff --git a/soc/nordic/nrf54h/gpd/gpd.c b/soc/nordic/nrf54h/gpd/gpd.c index 3cee31b700e..b5e4c1d027b 100644 --- a/soc/nordic/nrf54h/gpd/gpd.c +++ b/soc/nordic/nrf54h/gpd/gpd.c @@ -38,7 +38,13 @@ struct gpd_onoff_manager { static void start(struct onoff_manager *mgr, onoff_notify_fn notify); static void stop(struct onoff_manager *mgr, onoff_notify_fn notify); -#define GPD_READY_TIMEOUT_MS 1000 +#if CONFIG_SOC_NRF54H20_CPURAD +#include +extern const struct gpio_dt_spec led4; +extern const struct gpio_dt_spec led5; +#endif + +#define GPD_READY_TIMEOUT_MS 100 #define GPD_SERVICE_READY BIT(0) #define GPD_SERVICE_ERROR BIT(1) @@ -139,15 +145,24 @@ static int nrf_gpd_sync(struct gpd_onoff_manager *gpd_mgr) if (atomic_test_bit(&gpd_service_status, GPD_SERVICE_REQ_OK)) { return 0; } + //k_yield(); } LOG_ERR("nRFs GDPWR request timed out"); + while(1); return -ETIMEDOUT; } static void evt_handler(nrfs_gdpwr_evt_t const *p_evt, void *context) { + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led4); + //k_busy_wait(10); + //_work_schedule_for_queue(workq, &dev_data->notify_work, K_NO_WAIT); + //ret = mbox_send_dt(&conf->mbox_tx, NULL); + #endif + if (atomic_test_bit(&gpd_service_status, GPD_SERVICE_READY)) { struct gpd_onoff_manager *gpd_mgr = context; diff --git a/subsys/ipc/ipc_service/lib/icmsg.c b/subsys/ipc/ipc_service/lib/icmsg.c index 9de8a99ad58..dc2e046c55d 100644 --- a/subsys/ipc/ipc_service/lib/icmsg.c +++ b/subsys/ipc/ipc_service/lib/icmsg.c @@ -12,6 +12,12 @@ #include #include +#if CONFIG_SOC_NRF54H20_CPURAD +#include +extern const struct gpio_dt_spec led3; +extern const struct gpio_dt_spec led2; +#endif + #define BOND_NOTIFY_REPEAT_TO K_MSEC(CONFIG_IPC_SERVICE_ICMSG_BOND_NOTIFY_REPEAT_TO_MS) #define SHMEM_ACCESS_TO K_MSEC(CONFIG_IPC_SERVICE_ICMSG_SHMEM_ACCESS_TO_MS) @@ -62,6 +68,10 @@ static bool is_endpoint_ready(struct icmsg_data_t *dev_data) #ifdef CONFIG_MULTITHREADING static void notify_process(struct k_work *item) { + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led3); + #endif + struct k_work_delayable *dwork = k_work_delayable_from_work(item); struct icmsg_data_t *dev_data = CONTAINER_OF(dwork, struct icmsg_data_t, notify_work); @@ -74,6 +84,9 @@ static void notify_process(struct k_work *item) int ret; ret = k_work_reschedule_for_queue(workq, dwork, BOND_NOTIFY_REPEAT_TO); + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led3); + #endif __ASSERT_NO_MSG(ret >= 0); (void)ret; } @@ -147,6 +160,10 @@ static void submit_work_if_buffer_free_and_data_available( return; } + #if CONFIG_SOC_NRF54H20_CPURAD + //gpio_pin_toggle_dt(&led2); + #endif + submit_mbox_work(dev_data); } #else @@ -197,6 +214,9 @@ static void mbox_callback_process(struct icmsg_data_t *dev_data) if (state == ICMSG_STATE_READY) { if (dev_data->cb->received) { + #if CONFIG_SOC_NRF54H20_CPURAD + gpio_pin_toggle_dt(&led2); + #endif dev_data->cb->received(rx_buffer, len, dev_data->ctx); } } else { @@ -211,8 +231,13 @@ static void mbox_callback_process(struct icmsg_data_t *dev_data) return; } + //k_work_cancel_delayable() + + //(void)k_work_cancel_delayable(&dev_data->notify_work); + if (dev_data->cb->bound) { dev_data->cb->bound(dev_data->ctx); + } atomic_set(&dev_data->state, ICMSG_STATE_READY); @@ -296,6 +321,11 @@ int icmsg_open(const struct icmsg_config_t *conf, return ret; } #ifdef CONFIG_MULTITHREADING + +#if CONFIG_SOC_NRF54H20_CPURAD +//gpio_pin_toggle_dt(&led3); +#endif + ret = k_work_schedule_for_queue(workq, &dev_data->notify_work, K_NO_WAIT); if (ret < 0) { return ret; @@ -321,6 +351,15 @@ int icmsg_close(const struct icmsg_config_t *conf, return 0; } +#if CONFIG_SOC_NRF54H20_CPUSYS +//volatile uint32_t icmsg_send_count = 0; +//volatile uint32_t icmsg_send_count_2 = 0; +#endif + +#if CONFIG_SOC_NRF54H20_CPURAD +static uint8_t send_cnt = 0; +#endif + int icmsg_send(const struct icmsg_config_t *conf, struct icmsg_data_t *dev_data, const void *msg, size_t len) @@ -332,6 +371,17 @@ int icmsg_send(const struct icmsg_config_t *conf, #endif int sent_bytes; + #if CONFIG_SOC_NRF54H20_CPUSYS + //icmsg_send_count++; + #endif + + #if CONFIG_SOC_NRF54H20_CPURAD + gpio_pin_toggle_dt(&led3); + //k_busy_wait(10); + //_work_schedule_for_queue(workq, &dev_data->notify_work, K_NO_WAIT); + //ret = mbox_send_dt(&conf->mbox_tx, NULL); + #endif + if (!is_endpoint_ready(dev_data)) { return -EBUSY; } @@ -346,6 +396,17 @@ int icmsg_send(const struct icmsg_config_t *conf, if (ret < 0) { return -ENOBUFS; } +#endif + +#if CONFIG_SOC_NRF54H20_CPURAD + +if(++send_cnt == 4) { + //k_work_schedule_for_queue(workq, &dev_data->notify_work, K_NO_WAIT); + //k_usleep(1); + //mbox_send_dt(&conf->mbox_tx, NULL); + //k_busy_wait(5); +} + #endif write_ret = pbuf_write(dev_data->tx_pb, msg, len); @@ -364,11 +425,24 @@ int icmsg_send(const struct icmsg_config_t *conf, __ASSERT_NO_MSG(conf->mbox_tx.dev != NULL); + + ret = mbox_send_dt(&conf->mbox_tx, NULL); if (ret) { + #if CONFIG_SOC_NRF54H20_CPUSYS + //icmsg_send_count++; + //while(1); + #endif return ret; } + #if CONFIG_SOC_NRF54H20_CPURAD +//gpio_pin_toggle_dt(&led3); +//k_busy_wait(10); +//_work_schedule_for_queue(workq, &dev_data->notify_work, K_NO_WAIT); +//ret = mbox_send_dt(&conf->mbox_tx, NULL); +#endif + return sent_bytes; }