1 /*
2  * Copyright (c) 2018 - 2023, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  *    contributors may be used to endorse or promote products derived from this
19  *    software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef NRF_FICR_H__
35 #define NRF_FICR_H__
36 
37 #include <nrfx.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * @defgroup nrf_ficr_hal FICR HAL
45  * @{
46  * @ingroup nrf_icr
47  * @brief   Hardware access layer (HAL) for getting data from
48  *          the Factory Information Configuration Registers (FICR).
49  */
50 
51 /**
52  * @brief Function for getting the size of the code memory page.
53  *
54  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
55  *
56  * @return Code memory page size in bytes.
57  */
58 NRF_STATIC_INLINE uint32_t nrf_ficr_codepagesize_get(NRF_FICR_Type const * p_reg);
59 
60 /**
61  * @brief Function for getting the size of the code memory rendered as number of pages.
62  *
63  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
64  *
65  * @return Code memory size rendered as number of pages.
66  */
67 NRF_STATIC_INLINE uint32_t nrf_ficr_codesize_get(NRF_FICR_Type const * p_reg);
68 
69 /**
70  * @brief Function for getting the unique device identifier.
71  *
72  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
73  * @param[in] reg_id Register index.
74  *
75  * @return Unique device identifier.
76  */
77 NRF_STATIC_INLINE uint32_t nrf_ficr_deviceid_get(NRF_FICR_Type const * p_reg, uint32_t reg_id);
78 
79 #if defined(FICR_NFC_TAGHEADER0_MFGID_Msk) || defined(__NRFX_DOXYGEN__)
80 /**
81  * @brief Function for getting the default header values for the NFC tag.
82  *
83  * @param[in] p_reg        Pointer to the structure of registers of the peripheral.
84  * @param[in] tagheader_id Tag header index.
85  *
86  * @return The default header value of the NFC tag for the specified header index.
87  */
88 NRF_STATIC_INLINE uint32_t nrf_ficr_nfc_tagheader_get(NRF_FICR_Type const * p_reg,
89                                                       uint32_t              tagheader_id);
90 #endif // defined(FICR_NFC_TAGHEADER0_MFGID_Msk) || defined(__NRFX_DOXYGEN__)
91 
92 #ifndef NRF_DECLARE_ONLY
93 
nrf_ficr_codepagesize_get(NRF_FICR_Type const * p_reg)94 NRF_STATIC_INLINE uint32_t nrf_ficr_codepagesize_get(NRF_FICR_Type const * p_reg)
95 {
96 #if defined(FICR_INFO_CODEPAGESIZE_CODEPAGESIZE_Msk)
97     return p_reg->INFO.CODEPAGESIZE;
98 #else
99     return p_reg->CODEPAGESIZE;
100 #endif
101 }
102 
nrf_ficr_codesize_get(NRF_FICR_Type const * p_reg)103 NRF_STATIC_INLINE uint32_t nrf_ficr_codesize_get(NRF_FICR_Type const * p_reg)
104 {
105 #if defined(FICR_INFO_CODESIZE_CODESIZE_Msk)
106     return p_reg->INFO.CODESIZE;
107 #else
108     return p_reg->CODESIZE;
109 #endif
110 }
111 
nrf_ficr_deviceid_get(NRF_FICR_Type const * p_reg,uint32_t reg_id)112 NRF_STATIC_INLINE uint32_t nrf_ficr_deviceid_get(NRF_FICR_Type const * p_reg, uint32_t reg_id)
113 {
114 #if defined(FICR_INFO_DEVICEID_DEVICEID_Msk)
115     return p_reg->INFO.DEVICEID[reg_id];
116 #else
117     return p_reg->DEVICEID[reg_id];
118 #endif
119 }
120 
121 #if defined(FICR_NFC_TAGHEADER0_MFGID_Msk)
nrf_ficr_nfc_tagheader_get(NRF_FICR_Type const * p_reg,uint32_t tagheader_id)122 NRF_STATIC_INLINE uint32_t nrf_ficr_nfc_tagheader_get(NRF_FICR_Type const * p_reg,
123                                                       uint32_t              tagheader_id)
124 {
125     switch(tagheader_id) {
126         case 0:
127             return p_reg->NFC.TAGHEADER0;
128         case 1:
129             return p_reg->NFC.TAGHEADER1;
130         case 2:
131             return p_reg->NFC.TAGHEADER2;
132         case 3:
133             return p_reg->NFC.TAGHEADER3;
134         default:
135             return 0;
136     }
137 }
138 #endif // defined(FICR_NFC_TAGHEADER0_MFGID_Msk)
139 
140 #endif // NRF_DECLARE_ONLY
141 
142 /** @} */
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif // NRF_FICR_H__
149