1 /*
2  * Copyright (c) 2017 Oticon A/S
3  * Copyright (c) 2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 /*
9  * Factory information configuration registers
10  * https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/ficr/doc/ficr.html?cp=4_0_0_4_3_1
11  * https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/ficr.network/doc/ficr.network.html?cp=4_0_0_5_3_0
12  */
13 
14 /*
15  * TOLOW: we start with most registers cleared, and a few evident ones set to some values.
16  * It could be interesting to let people load them from command line
17  * for example by specifying a file with their values. and/or by specifying particular ones
18  * with command line options; something like -deviceaddr=<bt_address>
19  */
20 
21 #include <string.h>
22 #include "bs_rand_main.h"
23 #include "nsi_tasks.h"
24 #include "NHW_common_types.h"
25 #include "NHW_config.h"
26 #include "NHW_peri_types.h"
27 #include "weak_stubs.h"
28 
29 static NRF_FICR_APP_Type NRF_FICR_APP_regs;
30 static NRF_FICR_NET_Type NRF_FICR_NET_regs;
31 
32 void *NRF_FICR_regs_p[] = {(void*)&NRF_FICR_APP_regs, (void*)&NRF_FICR_NET_regs};
33 
nhw_53_ficr_init(void)34 static void nhw_53_ficr_init(void) {
35   memset(&NRF_FICR_APP_regs, 0xFF, sizeof(NRF_FICR_APP_regs));
36   memset(&NRF_FICR_NET_regs, 0xFF, sizeof(NRF_FICR_NET_regs));
37 
38   NRF_FICR_APP_regs.INFO.DEVICEID[0] = (bs_random_uint32() & 0xFFFFFF00) + bsim_args_get_global_device_nbr();
39   NRF_FICR_APP_regs.INFO.DEVICEID[1] = bs_random_uint32();
40   NRF_FICR_APP_regs.INFO.PART = 0x5340;
41   NRF_FICR_APP_regs.INFO.FLASH = 0x400; /*1 MB*/
42   NRF_FICR_APP_regs.INFO.CODEPAGESIZE = 0x1000;
43   NRF_FICR_APP_regs.INFO.CODESIZE = 256;
44   NRF_FICR_APP_regs.INFO.DEVICETYPE = 0;
45 
46   NRF_FICR_NET_regs.INFO.DEVICEID[0] = NRF_FICR_APP_regs.INFO.DEVICEID[0];
47   NRF_FICR_NET_regs.INFO.DEVICEID[1] = NRF_FICR_APP_regs.INFO.DEVICEID[1];
48   NRF_FICR_NET_regs.INFO.PART = 0x5340;
49   NRF_FICR_NET_regs.INFO.FLASH = 0x100; /*256 KB*/
50   NRF_FICR_NET_regs.INFO.CODEPAGESIZE = 0x800;
51   NRF_FICR_NET_regs.INFO.CODESIZE = 128;
52   NRF_FICR_NET_regs.INFO.DEVICETYPE = 0;
53   for (int i = 0; i < 4; i++) {
54     NRF_FICR_NET_regs.ER[i] = bs_random_uint32();
55     NRF_FICR_NET_regs.IR[i] = bs_random_uint32();
56   }
57   NRF_FICR_NET_regs.DEVICEADDRTYPE = 0;
58   NRF_FICR_NET_regs.DEVICEADDR[0] = bs_random_uint32();
59   NRF_FICR_NET_regs.DEVICEADDR[1] = bs_random_uint32();
60 }
61 
62 NSI_TASK(nhw_53_ficr_init, HW_INIT, 100);
63