MUTEX: Add nrf5340 MUTEX peripheral model

Including HAL replacements

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2023-10-09 12:22:50 +02:00
parent e84fca483b
commit 903f6439d6
9 changed files with 125 additions and 5 deletions

View File

@ -31,7 +31,7 @@ Notation:
| **IPC** | Interprocessor communication | N/A | &#x2714; | See [NHW_IPC.c](../src/HW_models/NHW_IPC.c) |
| **KMU** | Key management unit | &#x10102; | &#x10102; | |
| **LPCOMP** | Low-power comparator | &#x10102; | &#x10102; | |
| **MUTEX** | Mutual exclusive peripheral | N/A | &#x10102; | |
| **MUTEX** | Mutual exclusive peripheral | N/A | &#x2705; | |
| **MWU** | Memory watch unit | &#x10102; | N/A | |
| **NFCT** | Near field communication tag | &#x10102; | &#x10102; | |
| **NVMC** | Non-volatile memory controller | &#x2714; | &#x2714; | See [NHW_NVMC.c](../src/HW_models/NHW_NVMC.c) |

View File

@ -3,6 +3,7 @@ src/nrfx/hal/nrf_clock.c
src/nrfx/hal/nrf_dppi.c
src/nrfx/hal/nrf_egu.c
src/nrfx/hal/nrf_ipc.c
src/nrfx/hal/nrf_mutex.c
src/nrfx/hal/nrf_nvmc.c
src/nrfx/hal/nrf_rtc.c
src/nrfx/hal/nrf_timer.c

View File

@ -15,6 +15,7 @@ src/HW_models/NHW_CLOCK.c
src/HW_models/NHW_EGU.c
src/HW_models/NHW_IPC.c
src/HW_models/NHW_misc.c
src/HW_models/NHW_MUTEX.c
src/HW_models/NHW_NVMC.c
src/HW_models/NHW_NVM_backend.c
src/HW_models/NHW_RADIO.c

View File

@ -7,6 +7,7 @@ src/nrfx/hal/nrf_ecb.c
src/nrfx/hal/nrf_egu.c
src/nrfx/hal/nrf_hack.c
src/nrfx/hal/nrf_ipc.c
src/nrfx/hal/nrf_mutex.c
src/nrfx/hal/nrf_nvmc.c
src/nrfx/hal/nrf_radio.c
src/nrfx/hal/nrf_rng.c

53
src/HW_models/NHW_MUTEX.c Normal file
View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2023, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* MUTEX - Mutual exclusive peripheral
* https://infocenter.nordicsemi.com/topic/ps_nrf5340/mutex.html?cp=4_0_0_6_18
*
* This file provides the implementation of the nRF5340 MUTEX peripheral
*/
#include <string.h>
#include <stdbool.h>
#include "bs_types.h"
#include "nsi_tasks.h"
#include "NHW_config.h"
#include "NHW_peri_types.h"
NRF_MUTEX_Type NRF_MUTEX_regs;
static bool MUTEX_state[sizeof(NRF_MUTEX_regs.MUTEX)];
/**
* Initialize the MUTEX model
*/
static void nhw_mutex_init(void) {
memset(NRF_MUTEX_regs.MUTEX, 0, sizeof(NRF_MUTEX_regs.MUTEX));
memset(MUTEX_state, 0, sizeof(MUTEX_state));
}
NSI_TASK(nhw_mutex_init, HW_INIT, 100);
/*
* Handle the sideeffects of writing a 0 to the MUTEX register
*/
void nhw_MUTEX_regw_sideeffects_MUTEX(uint n) {
MUTEX_state[n] = 0;
NRF_MUTEX_regs.MUTEX[n] = 0;
}
/*
* Returns the value that would have been read from the MUTEX register
* and updates the MUTEX register itself
*/
int nhw_MUTEX_regr_sideeffects_MUTEX(uint n) {
if (MUTEX_state[n] == 0) {
MUTEX_state[n] = 1;
NRF_MUTEX_regs.MUTEX[n] = 1;
return 0;
}
return 1;
}

27
src/HW_models/NHW_MUTEX.h Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2023, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _NRF_HW_MODEL_MUTEX_H
#define _NRF_HW_MODEL_MUTEX_H
#include "bs_types.h"
#include "NHW_config.h"
#ifdef __cplusplus
extern "C"{
#endif
extern NRF_MUTEX_Type NRF_MUTEX_regs;
void nhw_MUTEX_regw_sideeffects_MUTEX(uint n);
int nhw_MUTEX_regr_sideeffects_MUTEX(uint n);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -2013,6 +2013,21 @@ typedef struct { /*!< (@ 0x41012000) IPC_NS Struc
} NRF_IPC_Type; /*!< Size = 1560 (0x618) */
/* =========================================================================================================================== */
/* ================ APPMUTEX_NS ================ */
/* =========================================================================================================================== */
/**
* @brief MUTEX 0 (APPMUTEX_NS)
*/
typedef struct { /*!< (@ 0x40030000) APPMUTEX_NS Structure */
__IM uint32_t RESERVED[256];
__IOM uint32_t MUTEX[16]; /*!< (@ 0x00000400) Description collection: Mutex register */
} NRF_MUTEX_Type; /*!< Size = 1088 (0x440) */
/* =========================================================================================================================== */
/* ================ NVMC ================ */

20
src/nrfx/hal/nrf_mutex.c Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*
* Note that the function prototypes are taken from the NRFx HAL
*/
#include "hal/nrf_mutex.h"
#include "bs_tracing.h"
#include "NHW_MUTEX.h"
bool nrf_mutex_lock(NRF_MUTEX_Type * p_reg, uint8_t mutex)
{
return (nhw_MUTEX_regr_sideeffects_MUTEX(mutex) == MUTEX_MUTEX_MUTEX_Unlocked);
}
void nrf_mutex_unlock(NRF_MUTEX_Type * p_reg, uint8_t mutex)
{
nhw_MUTEX_regw_sideeffects_MUTEX(mutex);
}

View File

@ -187,10 +187,11 @@ extern int NRF_SWI_regs[];
#define NRF_SWI2_NS_BASE (&NRF_SWI_regs[NHW_SWI_NET2])
#undef NRF_SWI3_NS_BASE
#define NRF_SWI3_NS_BASE (&NRF_SWI_regs[NHW_SWI_NET3])
extern NRF_MUTEX_Type NRF_MUTEX_regs;
#undef NRF_APPMUTEX_NS_BASE
#define NRF_APPMUTEX_NS_BASE NULL
#define NRF_APPMUTEX_NS_BASE (&NRF_MUTEX_regs)
#undef NRF_APPMUTEX_S_BASE
#define NRF_APPMUTEX_S_BASE NULL
#define NRF_APPMUTEX_S_BASE (&NRF_MUTEX_regs)
#undef NRF_ACL_NS_BASE
#define NRF_ACL_NS_BASE NULL
extern NRF_NVMC_Type *NRF_NVMC_regs_p[];
@ -458,10 +459,11 @@ extern NRF_IPC_Type NRF_IPC_regs[NHW_IPC_TOTAL_INST];
#define NRF_NFCT_S_BASE NULL
#undef NRF_GPIOTE1_NS_BASE
#define NRF_GPIOTE1_NS_BASE NULL
extern NRF_MUTEX_Type NRF_MUTEX_regs;
#undef NRF_MUTEX_NS_BASE
#define NRF_MUTEX_NS_BASE NULL
#define NRF_MUTEX_NS_BASE (&NRF_MUTEX_regs)
#undef NRF_MUTEX_S_BASE
#define NRF_MUTEX_S_BASE NULL
#define NRF_MUTEX_S_BASE (&NRF_MUTEX_regs)
#undef NRF_QDEC0_NS_BASE
#define NRF_QDEC0_NS_BASE NULL
#undef NRF_QDEC0_S_BASE