Skip to content

Commit

Permalink
modules: hal_nordic: move nRF 802.15.4 Radio Driver glue to Zephyr
Browse files Browse the repository at this point in the history
This commit moves all hal_nordic radio driver code that is
strictly dependent on Zephyr into the Zephyr repository.

Signed-off-by: Rafał Kuźnia <[email protected]>
  • Loading branch information
e-rk authored and carlescufi committed Mar 5, 2021
1 parent 19e5a9c commit dbd66c8
Show file tree
Hide file tree
Showing 18 changed files with 1,075 additions and 12 deletions.
15 changes: 6 additions & 9 deletions modules/hal_nordic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
if(CONFIG_HAS_NORDIC_DRIVERS OR CONFIG_HAS_NRFX)
zephyr_library()
endif()
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_HAS_NORDIC_DRIVERS)
add_subdirectory(${ZEPHYR_CURRENT_MODULE_DIR}/drivers drivers)
endif()
if(CONFIG_NRF_802154_RADIO_DRIVER OR CONFIG_NRF_802154_SERIALIZATION)
add_subdirectory(nrf_802154)
endif ()

if(CONFIG_HAS_NRFX)
add_subdirectory(nrfx)
endif()
add_subdirectory_ifdef(CONFIG_HAS_NRFX nrfx)
10 changes: 8 additions & 2 deletions modules/hal_nordic/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ config NRF_802154_RX_BUFFERS

endif # NRF_802154_RADIO_DRIVER

config NRF_802154_SERIALIZATION
bool
select RPMSG_SERVICE
help
This helper symbol indicates that the nRF 802.15.4 serialization is available.

config NRF_802154_SER_HOST
bool "nRF IEEE 802.15.4 Driver serialization host"
depends on !NRF_802154_RADIO_DRIVER
depends on !HAS_HW_NRF_RADIO_IEEE802154
select RPMSG_SERVICE
select IEEE802154_NRF5_EXT_IRQ_MGMT if IEEE802154_NRF5
select NRF_802154_SERIALIZATION
help
Enable serialization of nRF IEEE 802.15.4 Driver. This option is to be
used if radio is not available in the core, but radio services are
Expand All @@ -118,8 +124,8 @@ menuconfig NRF_802154_SER_RADIO
bool "nRF IEEE 802.15.4 Driver serialization radio"
depends on HAS_HW_NRF_RADIO_IEEE802154
depends on !IEEE802154_NRF5
select RPMSG_SERVICE
select NRF_802154_RADIO_DRIVER
select NRF_802154_SERIALIZATION
help
Enable serialization of nRF IEEE 802.15.4 Driver. This option is to be
used if radio is available in the core to provide radio services over
Expand Down
6 changes: 6 additions & 0 deletions modules/hal_nordic/nrf_802154/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

add_subdirectory_ifdef(CONFIG_NRF_802154_RADIO_DRIVER sl_opensource)
add_subdirectory_ifdef(CONFIG_NRF_802154_RADIO_DRIVER radio)
add_subdirectory_ifdef(CONFIG_NRF_802154_SERIALIZATION serialization)
118 changes: 118 additions & 0 deletions modules/hal_nordic/nrf_802154/radio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

set(NRF_802154_DRIVER_ROOT ${ZEPHYR_CURRENT_MODULE_DIR}/drivers/nrf_radio_802154)

include(${NRF_802154_DRIVER_ROOT}/nrf_802154_driver_sources.cmake)

zephyr_library()

zephyr_include_directories(${NRF_802154_DRIVER_INCLUDE_DIRS})

if (CONFIG_SOC_SERIES_NRF52X)
zephyr_library_sources(
${NRF_802154_DRIVER_SOURCES_NRF52}
)
elseif (CONFIG_SOC_SERIES_NRF53X)
zephyr_library_sources(
${NRF_802154_DRIVER_SOURCES_NRF53}
)
else()
message(FATAL_ERROR "SoC unsupported by this module")
endif()

if (CONFIG_NRF_802154_SL_OPENSOURCE)
zephyr_library_sources(
${NRF_802154_DRIVER_SOURCES_DIRECT}
)

else()
zephyr_library_sources(
${NRF_802154_DRIVER_SOURCES_SWI}
)

endif()

zephyr_library_sources(${CMAKE_CURRENT_SOURCE_DIR}/platform/nrf_802154_random_zephyr.c)

if( CONFIG_NRF_802154_CCA_MODE_ED)
set(radio_cca_mode NRF_RADIO_CCA_MODE_ED)

elseif( CONFIG_NRF_802154_CCA_MODE_CARRIER)
set(radio_cca_mode NRF_RADIO_CCA_MODE_CARRIER)

elseif( CONFIG_NRF_802154_CCA_MODE_CARRIER_AND_ED)
set(radio_cca_mode NRF_RADIO_CCA_MODE_CARRIER_AND_ED)

elseif( CONFIG_NRF_802154_CCA_MODE_CARRIER_OR_ED)
set(radio_cca_mode NRF_RADIO_CCA_MODE_CARRIER_OR_ED)

endif()

zephyr_compile_definitions(
# Radio driver shim layer uses raw api
NRF_802154_USE_RAW_API=1

# Number of slots containing short addresses of nodes for which
# pending data is stored.
NRF_802154_PENDING_SHORT_ADDRESSES=${CONFIG_NRF_802154_PENDING_SHORT_ADDRESSES}

# Number of slots containing extended addresses of nodes for which
# pending data is stored.
NRF_802154_PENDING_EXTENDED_ADDRESSES=${CONFIG_NRF_802154_PENDING_EXTENDED_ADDRESSES}

# Number of buffers in receive queue.
NRF_802154_RX_BUFFERS=${CONFIG_NRF_802154_RX_BUFFERS}

# CCA mode
NRF_802154_CCA_MODE_DEFAULT=${radio_cca_mode}

# CCA mode options
NRF_802154_CCA_CORR_LIMIT_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_LIMIT}
NRF_802154_CCA_CORR_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_CORR_THRESHOLD}
NRF_802154_CCA_ED_THRESHOLD_DEFAULT=${CONFIG_NRF_802154_CCA_ED_THRESHOLD}

# Enable CSMA/CA
NRF_802154_CSMA_CA_ENABLED=1
NRF_802154_TX_STARTED_NOTIFY_ENABLED=1

# ACK timeout
NRF_802154_ACK_TIMEOUT_ENABLED=1
)

if (CONFIG_IEEE802154_NRF5 OR NOT CONFIG_NRF_802154_SL_OPENSOURCE)
zephyr_compile_definitions(
NRF_802154_INTERNAL_RADIO_IRQ_HANDLING=0
)
else()
zephyr_compile_definitions(
NRF_802154_INTERNAL_RADIO_IRQ_HANDLING=1
)
endif()

if (CONFIG_NRF_802154_SL_OPENSOURCE OR CONFIG_SOC_SERIES_NRF53X)
zephyr_compile_definitions(
# Disable Frame Timestamps
NRF_802154_FRAME_TIMESTAMP_ENABLED=0
# Disable DTRX
NRF_802154_DELAYED_TRX_ENABLED=0
# Disable IFS
NRF_802154_IFS_ENABLED=0
)

else()
zephyr_compile_definitions(
# Enable Frame Timestamps
NRF_802154_FRAME_TIMESTAMP_ENABLED=1
# Enable DTRX
NRF_802154_DELAYED_TRX_ENABLED=1
# Enable IFS
NRF_802154_IFS_ENABLED=1
)
endif()

if (NOT CONFIG_NRF_802154_SL_OPENSOURCE)
zephyr_compile_definitions(
NRF_802154_VERIFY_PERIPHS_ALLOC_AGAINST_MPSL=1
)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2019 - 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/


#include <platform/temperature/nrf_802154_temperature.h>
#include <drivers/entropy.h>

static uint32_t state;

static uint32_t next(void)
{
uint32_t num = state;

state = 1664525 * num + 1013904223;
return num;
}

void nrf_802154_random_init(void)
{
const struct device *dev;
int err;

dev = device_get_binding(DT_CHOSEN_ZEPHYR_ENTROPY_LABEL);
__ASSERT_NO_MSG(dev != NULL);

do {
err = entropy_get_entropy(dev, (uint8_t *)&state, sizeof(state));
__ASSERT_NO_MSG(err == 0);
} while (state == 0);
}

void nrf_802154_random_deinit(void)
{
/* Intentionally empty */
}

uint32_t nrf_802154_random_get(void)
{
return next();
}
36 changes: 36 additions & 0 deletions modules/hal_nordic/nrf_802154/serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

set(NRF_802154_SER_SOURCE_DIR ${ZEPHYR_CURRENT_MODULE_DIR}/drivers/nrf_802154_serialization)

zephyr_library_named(nrf_802154_ser)

zephyr_library_sources(
${NRF_802154_SER_SOURCE_DIR}/spinel_base/spinel.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_buffer_allocator.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_buffer_mgr_dst.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_buffer_mgr_src.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_kvmap.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_spinel.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_spinel_dec.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/nrf_802154_serialization_crit_sect.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/nrf_802154_spinel_log.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/nrf_802154_spinel_backend_ipc.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/nrf_802154_spinel_response_notifier.c
)

zephyr_library_sources_ifdef(
CONFIG_NRF_802154_SER_HOST
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_spinel_app.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_spinel_dec_app.c
)

zephyr_library_sources_ifdef(
CONFIG_NRF_802154_SER_RADIO
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_spinel_net.c
${NRF_802154_SER_SOURCE_DIR}/src/nrf_802154_spinel_dec_net.c
${CMAKE_CURRENT_SOURCE_DIR}/platform/nrf_802154_init_net.c
)

zephyr_include_directories(${NRF_802154_SER_SOURCE_DIR}/include)
zephyr_library_include_directories(${NRF_802154_SER_SOURCE_DIR}/src/include)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 - 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <init.h>

#include "nrf_802154.h"
#include "nrf_802154_serialization.h"

static int serialization_init(const struct device *dev)
{
/* On NET core we don't use Zephyr's shim layer so we have to call inits manually */
nrf_802154_init();

nrf_802154_serialization_init();

return 0;
}

SYS_INIT(serialization_init, POST_KERNEL, CONFIG_NRF_802154_SER_RADIO_INIT_PRIO);
BUILD_ASSERT(CONFIG_NRF_802154_SER_RADIO_INIT_PRIO < CONFIG_RPMSG_SERVICE_INIT_PRIORITY,
"CONFIG_NRF_802154_SER_RADIO_INIT_PRIO must be lower than CONFIG_RPMSG_SERVICE_INIT_PRIORITY");
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "nrf_802154_serialization_crit_sect.h"

#ifndef TEST
#include <irq.h>
#endif

void nrf_802154_serialization_crit_sect_enter(uint32_t *p_critical_section)
{
#ifndef TEST
*p_critical_section = irq_lock();
#else
(void)p_critical_section;
#endif
}

void nrf_802154_serialization_crit_sect_exit(uint32_t critical_section)
{
#ifndef TEST
irq_unlock(critical_section);
#else
(void)critical_section;
#endif
}
Loading

0 comments on commit dbd66c8

Please sign in to comment.