-
Notifications
You must be signed in to change notification settings - Fork 1.5k
sm_ipt: Provide zephyr porting layer #5191
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.