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