Skip to content
Closed
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
3 changes: 2 additions & 1 deletion subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ add_subdirectory_ifdef(CONFIG_SHELL_BT_NUS shell)
add_subdirectory(debug)
add_subdirectory(partition_manager)

add_subdirectory_ifdef(CONFIG_NRF_RPC nrf_rpc)
add_subdirectory_ifdef(CONFIG_NRF_802154_RADIO_DRIVER ieee802154)
add_subdirectory_ifdef(CONFIG_NRF_RPC nrf_rpc)
add_subdirectory_ifdef(CONFIG_SM_IPT sm_ipt)
4 changes: 3 additions & 1 deletion subsys/Kconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018 - 2020 Nordic Semiconductor
# Copyright (c) 2018 - 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
Expand Down Expand Up @@ -37,6 +37,8 @@ rsource "partition_manager/Kconfig"

rsource "nrf_rpc/Kconfig"

rsource "sm_ipt/Kconfig"

rsource "zigbee/Kconfig"

rsource "mgmt/fmfu/Kconfig"
Expand Down
10 changes: 10 additions & 0 deletions subsys/nrf_rpc/include/nrf_rpc_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
#define _NRF_RPC_LOG_REGISTER1(module) \
_NRF_RPC_LOG_REGISTER2(module)

#define _NRF_RPC_LOG_DECLARE2(module) \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why we need those two levels of macro ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I were to use only level 2, then "CONFIG_ ## module ## _LOG_LEVEL", would result in appending name of module macro, not its value. Level 1 makes sure to pass only value of level 1s define.

LOG_MODULE_DECLARE(module, CONFIG_ ## module ## _LOG_LEVEL)

#define _NRF_RPC_LOG_DECLARE1(module) \
_NRF_RPC_LOG_DECLARE2(module)

#ifdef NRF_RPC_LOG_MODULE
_NRF_RPC_LOG_REGISTER1(NRF_RPC_LOG_MODULE);
#elif defined(NRF_RPC_LOG_MODULE_DECLARE)
_NRF_RPC_LOG_DECLARE1(NRF_RPC_LOG_MODULE_DECLARE);
#endif

#define NRF_RPC_ERR(...) LOG_ERR(__VA_ARGS__)
#define NRF_RPC_WRN(...) LOG_WRN(__VA_ARGS__)
Expand Down
9 changes: 5 additions & 4 deletions subsys/nrf_rpc/nrf_rpc_os.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
* Copyright (c) 2020-2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#define NRF_RPC_LOG_MODULE NRF_RPC_OS
#include <nrf_rpc_log.h>

#include "nrf_rpc_errno.h"
#include "nrf_rpc_os.h"

#define NRF_RPC_LOG_MODULE NRF_RPC_OS
#include "nrf_rpc_log.h"

/* Maximum number of remote thread that this implementation allows. */
#define MAX_REMOTE_THREADS 255

Expand Down
11 changes: 11 additions & 0 deletions subsys/sm_ipt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

zephyr_include_directories(include)

zephyr_library()

zephyr_library_sources(sm_ipt_os.c)
18 changes: 18 additions & 0 deletions subsys/sm_ipt/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2021 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "SM IPT (Shared Memory Inter-Processor Transport) library"

if SM_IPT

module = SM_IPT_OS
module-str = SM IPT OS
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

endif # SM_IPT

endmenu

31 changes: 31 additions & 0 deletions subsys/sm_ipt/include/sm_ipt_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef SM_IPT_LOG_H_
#define SM_IPT_LOG_H_

#include <logging/log.h>

#ifndef SM_IPT_LOG_MODULE

#define SM_IPT_LOG_MODULE SM_IPT

#endif

#define _SM_IPT_LOG_REGISTER2(module) \
LOG_MODULE_REGISTER(module, CONFIG_ ## module ## _LOG_LEVEL)

#define _SM_IPT_LOG_REGISTER1(module) \
_SM_IPT_LOG_REGISTER2(module)

_SM_IPT_LOG_REGISTER1(SM_IPT_LOG_MODULE);

#define SM_IPT_ERR(...) LOG_ERR(__VA_ARGS__)
#define SM_IPT_WRN(...) LOG_WRN(__VA_ARGS__)
#define SM_IPT_INF(...) LOG_INF(__VA_ARGS__)
#define SM_IPT_DBG(...) LOG_DBG(__VA_ARGS__)

#endif /* SM_IPT_LOG_H_ */
82 changes: 82 additions & 0 deletions subsys/sm_ipt/include/sm_ipt_os.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef SM_IPT_OS_H_
#define SM_IPT_OS_H_

#include <zephyr.h>

/**
* @defgroup sm_ipt_os_zephyr SM IPT OS abstraction for Zephyr.
* @{
* @brief SM IPT OS abstraction for Zephyr.
*
* API is compatible with sm_ipt_os API. For API documentation
* @see sm_ipt_os_tmpl.h
*/

#ifdef __cplusplus
extern "C" {
#endif


struct sm_ipt_os_ctx{
void *out_shmem_ptr;
void *in_shmem_ptr;
uint32_t out_total_size;
uint32_t in_total_size;
void (*signal_handler)(struct sm_ipt_os_ctx *);
const struct device *ipm_tx_handle;
};

#define SM_IPT_ASSERT(_expr) __ASSERT(_expr, "SM IPT assertion failed")

#define SM_IPT_OS_MEMORY_BARRIER() __DSB()

#define SM_IPT_OS_GET_CONTAINTER(ptr, type, field) CONTAINER_OF(ptr, type, field)

void sm_ipt_os_signal(struct sm_ipt_os_ctx *os_ctx);
void sm_ipt_os_signal_handler(struct sm_ipt_os_ctx *os_ctx, void (*handler)(struct sm_ipt_os_ctx *));
int sm_ipt_os_init(struct sm_ipt_os_ctx *os_ctx);

typedef atomic_t sm_ipt_os_atomic_t;
#define sm_ipt_os_atomic_or atomic_or
#define sm_ipt_os_atomic_and atomic_and
#define sm_ipt_os_atomic_get atomic_get

typedef struct k_mutex sm_ipt_os_mutex_t;
#define sm_ipt_os_mutex_init k_mutex_init
#define sm_ipt_os_unlock k_mutex_unlock

static inline void sm_ipt_os_lock(sm_ipt_os_mutex_t *mutex) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add blank line above

k_mutex_lock(mutex, K_FOREVER);
}

typedef struct k_sem sm_ipt_os_sem_t;
#define sm_ipt_os_give k_sem_give

static inline void sm_ipt_os_sem_init(sm_ipt_os_sem_t *sem) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add blank line above

k_sem_init(sem, 0, 1);
}
static inline void sm_ipt_os_take(sm_ipt_os_sem_t *sem) {
k_sem_take(sem, K_FOREVER);
}

#define sm_ipt_os_yield k_yield
#define sm_ipt_os_fatal k_oops
#define sm_ipt_os_clz64 __builtin_clzll
#define sm_ipt_os_clz32 __builtin_clz


#ifdef __cplusplus
}
#endif

/**
*@}
*/

#endif /* SM_IPT_OS_H */
78 changes: 78 additions & 0 deletions subsys/sm_ipt/sm_ipt_os.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <sm_ipt_errno.h>
#include <sm_ipt_os.h>

#define SM_IPT_LOG_MODULE SM_IPT_OS
#include <sm_ipt_log.h>

#include <drivers/ipm.h>

#define SHM_NODE DT_CHOSEN(zephyr_ipc_shm)
#define SHM_START_ADDR DT_REG_ADDR(SHM_NODE)
#define SHM_SIZE DT_REG_SIZE(SHM_NODE)

void sm_ipt_os_signal(struct sm_ipt_os_ctx *os_ctx)
{
int err = ipm_send(os_ctx->ipm_tx_handle, 0, 0, NULL, 0);
if (err != 0) {
LOG_ERR("Failed to notify: %d", err);
}
}

void sm_ipt_os_signal_handler(struct sm_ipt_os_ctx *os_ctx, void (*handler)(struct sm_ipt_os_ctx *))
{
os_ctx->signal_handler = handler;
}

static void ipm_callback(const struct device *ipmdev, void *user_data, uint32_t id,
volatile void *data)
{
struct sm_ipt_os_ctx *os_ctx = (struct sm_ipt_os_ctx *)user_data;

if (os_ctx->signal_handler)
os_ctx->signal_handler(os_ctx);
}

int sm_ipt_os_init(struct sm_ipt_os_ctx *os_ctx)
{
const struct device *ipm_rx_handle;
uint32_t size = WB_DN(SHM_SIZE / 2);

os_ctx->out_total_size = size;
os_ctx->in_total_size = size;

uint32_t addr1 = SHM_START_ADDR;
uint32_t addr2 = SHM_START_ADDR + size;

if (IS_ENABLED(CONFIG_SM_IPT_PRIMARY)) {
os_ctx->out_shmem_ptr = (void*)addr1;
os_ctx->in_shmem_ptr = (void*)addr2;
} else {
os_ctx->out_shmem_ptr = (void*)addr2;
os_ctx->in_shmem_ptr = (void*)addr1;
}

/* IPM setup. */
os_ctx->ipm_tx_handle = device_get_binding(IS_ENABLED(CONFIG_SM_IPT_PRIMARY) ?
"IPM_1" : "IPM_0");
if (!os_ctx->ipm_tx_handle) {
LOG_ERR("Could not get TX IPM device handle");
return -NRF_ENODEV;
}

ipm_rx_handle = device_get_binding(IS_ENABLED(CONFIG_SM_IPT_PRIMARY) ?
"IPM_0" : "IPM_1");
if (!ipm_rx_handle) {
LOG_ERR("Could not get RX IPM device handle");
return -NRF_ENODEV;
}

ipm_register_callback(ipm_rx_handle, ipm_callback, os_ctx);

return 0;
}
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ manifest:
- name: nrfxlib
repo-path: sdk-nrfxlib
path: nrfxlib
revision: d048f584bb79997e1f60e3539b4520026ebb7745
revision: pull/525/head
- name: trusted-firmware-m
repo-path: sdk-trusted-firmware-m
path: modules/tee/tfm
Expand Down