Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Conversation

@auroraslb
Copy link
Collaborator

@auroraslb auroraslb commented Dec 15, 2020

The goal of providing HW models for the nrf53 network core is to be able run tests in a simulator with the nrf53 HAL layer.
This will make it easier to find bugs and regressions in the hal layer of a Bluetooth Controller.

The models share the same source code as the models for the nrf52 series, as most HW peripherals are identical.
The same approach can also be used to create models for nrf51 series and similar.

@aescolar, I would like to get some input on how to adapt the makefiles to be able to build a 53-series model in a standalone build environment.
To build for the nrf53-series in zephyr is done here: zephyrproject-rtos/zephyr#30734

@carlescufi
Copy link
Collaborator

@cvinayak FYI

Copy link
Collaborator

@rugeGerritsen rugeGerritsen left a comment

Choose a reason for hiding this comment

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

The DPPI model can be simplified slightly. Added some other comments as well

CMakeLists.txt Outdated
# CMake file to compile this BabbleSim component as a west module in Zephyr

if(CONFIG_BOARD_NRF52_BSIM)
if(CONFIG_BOARD_NRF52_BSIM OR CONFIG_BOARD_NRF53_BSIM)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should add a configuration CONFIG_BOARD_BSIM_COMPATIBLE in upstream zephyr so that it becomes easier to support other boards in the future?

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

#endif

extern NRF_DPPIC_Type NRF_DPPI_regs;
#define NUMBER_DPPI_CHANNELS 32
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may use DPPI_CH_NUM instead. It is defined in nrf5340_network_peripherals.h

@@ -0,0 +1,49 @@
/*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should extract out a common file? We can make core_cmxx.h and let core_cm33.h and core_cm4.h include this file?

case NRF_CCM_TASK_STOP:
nrf_dppi_subscriber_add(channel, nrf_ccm_TASK_STOP);
break;
#if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to add || defined(__NRFX_DOXYGEN__) here. Similar in other places

/*
* Redefine the base addresses.
*/

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would consider splitting this file. @aescolar , what do you think?

static subscr_list_elem_t* dppi_subscriber_list[NUMBER_DPPI_CHANNELS];

//Function for checking if an element is in the subscriber linked list
static bool subscriber_list_check(dest_f_t task_function, subscr_list_elem_t ** pp_head)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to use pointer to pointer in this function. You may use
subscriber_in_list(dest_f_t task_function, subscr_list_elem_t * p_head)?

{
if (!subscriber_list_check(task_function, pp_head))
{
struct subscr_list_elem* p_elem = (struct subscr_list_elem*) malloc(sizeof(struct subscr_list_elem));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Strictly speaking, you should check the return code of the malloc

{
if(subscriber_list_check(task_function, pp_head))
{
struct subscr_list_elem* temp = (struct subscr_list_elem*) malloc(sizeof(struct subscr_list_elem));
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need this malloc and the free's below. The temp variable is assigned in the line below, so the new memory is never used. There are some similar cases in functions below.

/**
* Initialize the DPPI model
*/
void nrf_dppi_init()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The function signature should be explicit to indicate that the function takes no parameters

Suggested change
void nrf_dppi_init()
void nrf_dppi_init(void)

@aescolar
Copy link
Contributor

@wopu-ot FYI

Copy link
Contributor

@aescolar aescolar left a comment

Choose a reason for hiding this comment

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

A couple of general comments before anything else:

  • It is a risky choice to throw yourselves into a mayor change, without agreeing the direction first. (Meaning you risk spending a lot of time writing code which will be scrapped).
  • For mayor PRs, or mayor rework, it would be very nice if you gave a heads up, so we knew what is coming.

Before dwelling into details:

  • It would be good to talk and understand what you want to do overall, and agree the general direction.
  • That code does not account compiling without Zephyr (it does not compile without it)

(I just browsed very fast thru the code. The 4 things I pointed are in the only function I read carefully)

*/
void nrf_dppi_publish(uint8_t channel)
{
struct subscr_list_elem* temp = (struct subscr_list_elem*) malloc(sizeof(struct subscr_list_elem));
Copy link
Contributor

Choose a reason for hiding this comment

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

that's a memory leak :) (that malloc is not needed)

temp = temp->p_next;
}

free(temp);
Copy link
Contributor

Choose a reason for hiding this comment

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

this free is not needed (nor safe)

while (temp != NULL)
{
temp->task_function();
prev = temp;
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

{
struct subscr_list_elem* temp = (struct subscr_list_elem*) malloc(sizeof(struct subscr_list_elem));
temp = dppi_subscriber_list[channel];
subscr_list_elem_t *prev;
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

@auroraslb
Copy link
Collaborator Author

The goal of providing nrf53_bsim is to be able run tests in a simulator with the nrf53 HAL layer. This is currently not possible. We have had some bugs that would like have been uncovered if we had used nrf53_bsim

@aescolar
Copy link
Contributor

The goal of providing nrf53_bsim is to be able ..

Thanks :)

Add DPPI in order to be able to model the NRF53 HW.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Changes in CMakeLists, NRF_HW_model_top.c, nrfx_common.c
and nrf_bsim_redef.h in order for the model to support
both the NRF52 and the NRF53 series.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
NRF53 runs on cm33. Add this core in order for the model to
support NRF53.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add irq sources for NRF53.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to AAR if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to CCM if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to ECB if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to CLOCK if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to RADIO if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to RNG if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to TIMER if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add use of DPPI to RTC if DPPI is defined.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
Add a common core-file for easier maintenance.

Signed-off-by: Sletnes Bjørlo, Aurora <[email protected]>
@wopu-ot
Copy link

wopu-ot commented May 4, 2021

@auroraslb Do you still want to proceed with this PR or should I close it?

@rugeGerritsen
Copy link
Collaborator

@auroraslb Do you still want to proceed with this PR or should I close it?

@wopu-ot , we can close this PR for now and reopen later if needed.

@aescolar aescolar closed this May 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants