Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.
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
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# CMake file to compile this BabbleSim component as a west module in Zephyr

if(CONFIG_BOARD_NRF52_BSIM)
if(CONFIG_SOC_COMPATIBLE_BSIM)

if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH})
message(FATAL_ERROR "This Zephyr module requires the BabbleSim simulator.\
Expand Down Expand Up @@ -34,6 +34,15 @@ if(CONFIG_BOARD_NRF52_BSIM)
zephyr_library_compile_definitions(NO_POSIX_CHEATS)

file(GLOB_RECURSE HW_MODEL_SRCS . src/*.c)
if (CONFIG_BOARD_NRF52_BSIM)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can replace CONFIG_BOARD_NRF52_BSIM with CONFIG_HAS_HW_NRF_DPPIC

list(REMOVE_ITEM HW_MODEL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/HW_models/NRF_DPPI.c)
list(REMOVE_ITEM HW_MODEL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/hal/nrf_dppi.c)
elseif(CONFIG_BOARD_NRF53_CPUNET_BSIM)
list(REMOVE_ITEM HW_MODEL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/HW_models/NRF_PPI.c)
list(REMOVE_ITEM HW_MODEL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/hal/nrf_ppi.c)
else()
message(FATAL_ERROR "Unknown board")
endif()
zephyr_library_sources(${HW_MODEL_SRCS})

zephyr_library_include_directories(
Expand Down
31 changes: 31 additions & 0 deletions src/HW_models/NRF_AAR.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <stdbool.h>
#include "time_machine_if.h"
#include "NRF_HW_model_top.h"
#if defined(PPI_PRESENT)
#include "NRF_PPI.h"
#elif defined(DPPI_PRESENT)
#include "NRF_DPPI.h"
#endif
#include "irq_ctrl.h"
#include "irq_sources.h"
#include "bs_tracing.h"
Expand Down Expand Up @@ -40,7 +44,16 @@ static int nrf_aar_resolve(int *good_irk);

static void signal_EVENTS_END(){
NRF_AAR_regs.EVENTS_END = 1;

#if !defined(DPPI_PRESENT)
nrf_ppi_event(AAR_EVENTS_END);
#else
if (NRF_AAR_regs.PUBLISH_END & AAR_PUBLISH_END_EN_Msk)
{
uint8_t channel = NRF_AAR_regs.PUBLISH_END & AAR_PUBLISH_END_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (AAR_INTEN & AAR_INTENSET_END_Msk){
hw_irq_ctrl_set_irq(NRF5_IRQ_CCM_AAR_IRQn);
Expand All @@ -49,7 +62,16 @@ static void signal_EVENTS_END(){

static void signal_EVENTS_RESOLVED(){
NRF_AAR_regs.EVENTS_RESOLVED = 1;

#if !defined(DPPI_PRESENT)
nrf_ppi_event(AAR_EVENTS_RESOLVED);
#else
if (NRF_AAR_regs.PUBLISH_RESOLVED & AAR_PUBLISH_RESOLVED_EN_Msk)
{
uint8_t channel = NRF_AAR_regs.PUBLISH_RESOLVED & AAR_PUBLISH_RESOLVED_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (AAR_INTEN & AAR_INTENCLR_RESOLVED_Msk){
hw_irq_ctrl_set_irq(NRF5_IRQ_CCM_AAR_IRQn);
Expand All @@ -58,7 +80,16 @@ static void signal_EVENTS_RESOLVED(){

static void signal_EVENTS_NOTRESOLVED(){
NRF_AAR_regs.EVENTS_NOTRESOLVED = 1;

#if !defined(DPPI_PRESENT)
nrf_ppi_event(AAR_EVENTS_NOTRESOLVED);
#else
if (NRF_AAR_regs.PUBLISH_NOTRESOLVED & AAR_PUBLISH_NOTRESOLVED_EN_Msk)
{
uint8_t channel = NRF_AAR_regs.PUBLISH_NOTRESOLVED & AAR_PUBLISH_NOTRESOLVED_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (AAR_INTEN & AAR_INTENCLR_NOTRESOLVED_Msk){
hw_irq_ctrl_set_irq(NRF5_IRQ_CCM_AAR_IRQn);
Expand Down
33 changes: 32 additions & 1 deletion src/HW_models/NRF_AES_CCM.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include <stdbool.h>
#include "time_machine_if.h"
#include "NRF_HW_model_top.h"
#if defined(PPI_PRESENT)
#include "NRF_PPI.h"
#elif defined(DPPI_PRESENT)
#include "NRF_DPPI.h"
#endif
#include "irq_ctrl.h"
#include "irq_sources.h"
#include "bs_tracing.h"
Expand Down Expand Up @@ -180,7 +184,16 @@ static void nrf_ccm_decrypt_rx(bool crc_error) {

static void signal_EVENTS_ENDKSGEN() {
NRF_CCM_regs.EVENTS_ENDKSGEN = 1;

#if !defined(DPPI_PRESENT)
nrf_ppi_event(CCM_EVENTS_ENDKSGEN);
#else
if (NRF_CCM_regs.PUBLISH_ENDKSGEN & CCM_PUBLISH_ENDKSGEN_EN_Msk)
{
uint8_t channel = NRF_CCM_regs.PUBLISH_ENDKSGEN & CCM_PUBLISH_ENDKSGEN_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (CCM_INTEN & CCM_INTENSET_ENDKSGEN_Msk) {
hw_irq_ctrl_set_irq(NRF5_IRQ_CCM_AAR_IRQn);
Expand All @@ -193,7 +206,16 @@ static void signal_EVENTS_ENDKSGEN() {

static void signal_EVENTS_ENDCRYPT(){
NRF_CCM_regs.EVENTS_ENDCRYPT = 1;

#if !defined(DPPI_PRESENT)
nrf_ppi_event(CCM_EVENTS_ENDCRYPT);
#else
if (NRF_CCM_regs.PUBLISH_ENDCRYPT & CCM_PUBLISH_ENDCRYPT_EN_Msk)
{
uint8_t channel = NRF_CCM_regs.PUBLISH_ENDCRYPT & CCM_PUBLISH_ENDCRYPT_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (CCM_INTEN & CCM_INTENSET_ENDCRYPT_Msk) {
hw_irq_ctrl_set_irq(NRF5_IRQ_CCM_AAR_IRQn);
Expand All @@ -202,7 +224,16 @@ static void signal_EVENTS_ENDCRYPT(){

/* static void signal_EVENTS_ERROR(){
NRF_CCM_regs.EVENTS_ERROR = 1;
NRF_PPI_Event(CCM_EVENTS_ERROR);

#if !defined(DPPI_PRESENT)
nrf_ppi_event(CCM_EVENTS_ERROR);
#else
if (NRF_CCM_regs.PUBLISH_ERROR & CCM_PUBLISH_ERROR_EN_Msk)
{
uint8_t channel = NRF_CCM_regs.PUBLISH_ERROR & CCM_PUBLISH_ERROR_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (CCM_INTEN & CCM_INTENSET_ERROR_Msk) {
hw_irq_ctrl_set_irq(NRF5_IRQ_CCM_AAR_IRQn);
Expand Down
20 changes: 20 additions & 0 deletions src/HW_models/NRF_AES_ECB.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "NRF_AES_ECB.h"
#if defined(PPI_PRESENT)
#include "NRF_PPI.h"
#elif defined(DPPI_PRESENT)
#include "NRF_DPPI.h"
#endif
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -46,7 +50,15 @@ void nrf_aes_ecb_clean_up(){

static void signal_ENDECB(){
NRF_ECB_regs.EVENTS_ENDECB = 1;
#if defined(PPI_PRESENT)
nrf_ppi_event(ECB_EVENTS_ENDECB);
#elif defined(DPPI_PRESENT)
if (NRF_ECB_regs.PUBLISH_ENDECB & ECB_PUBLISH_ENDECB_EN_Msk)
{
uint8_t channel = NRF_ECB_regs.PUBLISH_ENDECB & ECB_PUBLISH_ENDECB_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (ECB_INTEN & ECB_INTENSET_ENDECB_Msk){
hw_irq_ctrl_set_irq(NRF5_IRQ_ECB_IRQn);
Expand All @@ -55,7 +67,15 @@ static void signal_ENDECB(){

static void signal_ERRORECB(){
NRF_ECB_regs.EVENTS_ERRORECB = 1;
#if defined(PPI_PRESENT)
nrf_ppi_event(ECB_EVENTS_ERRORECB);
#elif defined(DPPI_PRESENT)
if (NRF_ECB_regs.PUBLISH_ERRORECB & ECB_PUBLISH_ERRORECB_EN_Msk)
{
uint8_t channel = NRF_ECB_regs.PUBLISH_ERRORECB & ECB_PUBLISH_ERRORECB_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if (ECB_INTEN & ECB_INTENSET_ERRORECB_Msk){
hw_irq_ctrl_set_irq(NRF5_IRQ_ECB_IRQn);
Expand Down
2 changes: 2 additions & 0 deletions src/HW_models/NRF_AES_ECB.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ extern "C"{

void nrf_aes_ecb_init();
void nrf_aes_ecb_clean_up();
void nrf_ecb_TASK_STOPECB();
void nrf_ecb_TASK_STARTECB();
void nrf_ecb_timer_triggered();
void nrf_ecb_regw_sideeffects_INTENSET();
void nrf_ecb_regw_sideeffects_INTENCLEAR();
Expand Down
29 changes: 29 additions & 0 deletions src/HW_models/NRF_CLOCK.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include <stdint.h>
#include "time_machine_if.h"
#include "NRF_HW_model_top.h"
#if defined(PPI_PRESENT)
#include "NRF_PPI.h"
#elif defined(DPPI_PRESENT)
#include "NRF_DPPI.h"
#endif
#include "NRF_RTC.h"
#include "irq_ctrl.h"
#include "irq_sources.h"
Expand Down Expand Up @@ -141,7 +145,17 @@ void nrf_clock_LFTimer_triggered(){
| (NRF_CLOCK_regs.LFCLKSRCCOPY << CLOCK_LFCLKSTAT_SRC_Pos);

NRF_CLOCK_regs.EVENTS_LFCLKSTARTED = 1;

#if defined(PPI_PRESENT)
nrf_ppi_event(CLOCK_EVENTS_LFCLKSTARTED);
#elif defined(DPPI_PRESENT)
if (NRF_CLOCK_regs.PUBLISH_LFCLKSTARTED & CLOCK_PUBLISH_LFCLKSTARTED_EN_Msk)
{
uint8_t channel = NRF_CLOCK_regs.PUBLISH_LFCLKSTARTED & CLOCK_PUBLISH_LFCLKSTARTED_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if ( CLOCK_INTEN & CLOCK_INTENSET_LFCLKSTARTED_Msk ){
hw_irq_ctrl_set_irq(NRF5_IRQ_POWER_CLOCK_IRQn);
}
Expand All @@ -157,11 +171,26 @@ void nrf_clock_HFTimer_triggered(){
if ( HF_Clock_state == Starting ){
HF_Clock_state = Started;

#if !defined(NRF53_SERIES)
NRF_CLOCK_regs.HFCLKSTAT = CLOCK_HFCLKSTAT_STATE_Msk
| ( CLOCK_HFCLKSTAT_SRC_Xtal << CLOCK_HFCLKSTAT_SRC_Pos);
#else
NRF_CLOCK_regs.HFCLKSTAT = CLOCK_HFCLKSTAT_STATE_Msk
| ( CLOCK_HFCLKSTAT_SRC_HFXO << CLOCK_HFCLKSTAT_SRC_Pos);
#endif

NRF_CLOCK_regs.EVENTS_HFCLKSTARTED = 1;

#if defined(PPI_PRESENT)
nrf_ppi_event(CLOCK_EVENTS_HFCLKSTARTED);
#elif defined(DPPI_PRESENT)
if (NRF_CLOCK_regs.PUBLISH_HFCLKSTARTED & CLOCK_PUBLISH_HFCLKSTARTED_EN_Msk)
{
uint8_t channel = NRF_CLOCK_regs.PUBLISH_HFCLKSTARTED & CLOCK_PUBLISH_HFCLKSTARTED_CHIDX_Msk;
nrf_dppi_publish(channel);
}
#endif

if ( CLOCK_INTEN & CLOCK_INTENSET_HFCLKSTARTED_Msk ){
hw_irq_ctrl_set_irq(NRF5_IRQ_POWER_CLOCK_IRQn);
}
Expand Down
1 change: 1 addition & 0 deletions src/HW_models/NRF_CLOCK.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void nrf_clock_LFTimer_triggered();
void nrf_clock_HFTimer_triggered();
void nrf_clock_TASKS_LFCLKSTART();
void nrf_clock_TASKS_HFCLKSTART();
void nrf_clock_TASKS_HFCLKSTOP();
void nrf_clock_reqw_sideeffects_INTENSET();
void nrf_clock_reqw_sideeffects_INTENCLR();
void nrf_clock_reqw_sideeffects_TASKS_LFCLKSTART();
Expand Down
Loading