@@ -64,14 +64,246 @@ typedef enum
6464 /*lint -restore*/
6565} nrf_ccm_task_t ;
6666
67+ /** @brief CCM events. */
68+ typedef enum
69+ {
70+ NRF_CCM_EVENT_ENDKSGEN = offsetof(NRF_CCM_Type , EVENTS_ENDKSGEN ), ///< Keystream generation complete.
71+ NRF_CCM_EVENT_ENDCRYPT = offsetof(NRF_CCM_Type , EVENTS_ENDCRYPT ), ///< Encrypt/decrypt complete.
72+ NRF_CCM_EVENT_ERROR = offsetof(NRF_CCM_Type , EVENTS_ERROR ), ///< CCM error event.
73+ } nrf_ccm_event_t ;
74+
75+ /** @brief CCM interrupts. */
76+ typedef enum
77+ {
78+ NRF_CCM_INT_ENDKSGEN_MASK = CCM_INTENSET_ENDKSGEN_Msk , ///< Interrupt on ENDKSGEN event.
79+ NRF_CCM_INT_ENDCRYPT_MASK = CCM_INTENSET_ENDCRYPT_Msk , ///< Interrupt on ENDCRYPT event.
80+ NRF_CCM_INT_ERROR_MASK = CCM_INTENSET_ERROR_Msk , ///< Interrupt on ERROR event.
81+ } nrf_ccm_int_mask_t ;
82+
83+ /** @brief CCM modes of operation. */
84+ typedef enum
85+ {
86+ NRF_CCM_MODE_ENCRYPTION = CCM_MODE_MODE_Encryption , ///< Encryption mode.
87+ NRF_CCM_MODE_DECRYPTION = CCM_MODE_MODE_Decryption , ///< Decryption mode.
88+ } nrf_ccm_mode_t ;
89+
90+ #if defined(CCM_MODE_DATARATE_Pos ) || defined(__NRFX_DOXYGEN__ )
91+ /** @brief CCM data rates. */
92+ typedef enum
93+ {
94+ NRF_CCM_DATARATE_1M = CCM_MODE_DATARATE_1Mbit , ///< 1 Mbps.
95+ NRF_CCM_DATARATE_2M = CCM_MODE_DATARATE_2Mbit , ///< 2 Mbps.
96+ #if defined(CCM_MODE_DATARATE_125Kbps ) || defined(__NRFX_DOXYGEN__ )
97+ NRF_CCM_DATARATE_125K = CCM_MODE_DATARATE_125Kbps , ///< 125 Kbps.
98+ #endif
99+ #if defined(CCM_MODE_DATARATE_500Kbps ) || defined(__NRFX_DOXYGEN__ )
100+ NRF_CCM_DATARATE_500K = CCM_MODE_DATARATE_500Kbps , ///< 500 Kbps.
101+ #endif
102+ } nrf_ccm_datarate_t ;
103+ #endif // defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
104+
105+ #if defined(CCM_MODE_LENGTH_Pos ) || defined(__NRFX_DOXYGEN__ )
106+ /** @brief CCM packet length options. */
107+ typedef enum
108+ {
109+ NRF_CCM_LENGTH_DEFAULT = CCM_MODE_LENGTH_Default , ///< Default length.
110+ NRF_CCM_LENGTH_EXTENDED = CCM_MODE_LENGTH_Extended , ///< Extended length.
111+ } nrf_ccm_length_t ;
112+ #endif // defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
113+
114+ /** @brief CCM configuration. */
115+ typedef struct {
116+ nrf_ccm_mode_t mode ; ///< Operation mode.
117+ #if defined(CCM_MODE_DATARATE_Pos ) || defined(__NRFX_DOXYGEN__ )
118+ nrf_ccm_datarate_t datarate ; ///< Data rate.
119+ #endif
120+ #if defined(CCM_MODE_LENGTH_Pos ) || defined(__NRFX_DOXYGEN__ )
121+ nrf_ccm_length_t length ; ///< Lenght of the CCM packet.
122+ #endif
123+ } nrf_ccm_config_t ;
67124
68125void nrf_ccm_task_trigger (NRF_CCM_Type * p_reg ,
69126 nrf_ccm_task_t task );
70127
128+ /**
129+ * @brief Function for clearing a specific CCM event.
130+ *
131+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
132+ * @param[in] event Event to clear.
133+ */
134+ NRF_STATIC_INLINE void nrf_ccm_event_clear (NRF_CCM_Type * p_reg ,
135+ nrf_ccm_event_t event );
136+
137+ /**
138+ * @brief Function for retrieving the state of a specific CCM event.
139+ *
140+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
141+ * @param[in] event Event to be checked.
142+ *
143+ * @retval true The event has been generated.
144+ * @retval false The event has not been generated.
145+ */
146+ NRF_STATIC_INLINE bool nrf_ccm_event_check (NRF_CCM_Type const * p_reg ,
147+ nrf_ccm_event_t event );
148+
149+ /**
150+ * @brief Function for enabling specified interrupts.
151+ *
152+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
153+ * @param[in] mask Interrupts to be enabled.
154+ */
71155void nrf_ccm_int_enable (NRF_CCM_Type * p_reg , uint32_t mask );
72156
157+ /**
158+ * @brief Function for disabling specified interrupts.
159+ *
160+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
161+ * @param[in] mask Interrupts to be disabled.
162+ */
73163void nrf_ccm_int_disable (NRF_CCM_Type * p_reg , uint32_t mask );
74164
165+ /**
166+ * @brief Function for enabling the CCM peripheral.
167+ *
168+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
169+ */
170+ NRF_STATIC_INLINE void nrf_ccm_enable (NRF_CCM_Type * p_reg );
171+
172+ /**
173+ * @brief Function for disabling the CCM peripheral.
174+ *
175+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
176+ */
177+ NRF_STATIC_INLINE void nrf_ccm_disable (NRF_CCM_Type * p_reg );
178+
179+ /**
180+ * @brief Function for setting the CCM peripheral configuration.
181+ *
182+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
183+ * @param[in] p_config Pointer to the structure with configuration to be set.
184+ */
185+ NRF_STATIC_INLINE void nrf_ccm_configure (NRF_CCM_Type * p_reg ,
186+ nrf_ccm_config_t const * p_config );
187+
188+ /**
189+ * @brief Function for getting the MIC check result.
190+ *
191+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
192+ *
193+ * @retval true The MIC check passed.
194+ * @retval false The MIC check failed.
195+ */
196+ NRF_STATIC_INLINE bool nrf_ccm_micstatus_get (NRF_CCM_Type const * p_reg );
197+
198+ /**
199+ * @brief Function for setting the pointer to the data structure
200+ * holding the AES key and the CCM NONCE vector.
201+ *
202+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
203+ * @param[in] p_data Pointer to the data structure.
204+ */
205+ NRF_STATIC_INLINE void nrf_ccm_cnfptr_set (NRF_CCM_Type * p_reg ,
206+ uint32_t const * p_data );
207+
208+ /**
209+ * @brief Function for setting the input data pointer.
210+ *
211+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
212+ * @param[in] p_data Input data pointer.
213+ */
214+ NRF_STATIC_INLINE void nrf_ccm_inptr_set (NRF_CCM_Type * p_reg ,
215+ uint32_t const * p_data );
216+
217+ /**
218+ * @brief Function for setting the output data pointer.
219+ *
220+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
221+ * @param[in] p_data Output data pointer.
222+ */
223+ NRF_STATIC_INLINE void nrf_ccm_outptr_set (NRF_CCM_Type * p_reg ,
224+ uint32_t const * p_data );
225+
226+ /**
227+ * @brief Function for setting the pointer to the scratch area used for
228+ * temporary storage.
229+ *
230+ * @param[in] p_reg Pointer to the structure of registers of the peripheral.
231+ * @param[in] p_area Pointer to the scratch area.
232+ */
233+ NRF_STATIC_INLINE void nrf_ccm_scratchptr_set (NRF_CCM_Type * p_reg ,
234+ uint32_t const * p_area );
235+
236+ /*****************************/
237+ /* Inlined functions bodies: */
238+ /*****************************/
239+
240+ NRF_STATIC_INLINE void nrf_ccm_event_clear (NRF_CCM_Type * p_reg ,
241+ nrf_ccm_event_t event )
242+ {
243+ * ((volatile uint32_t * )((uint8_t * )p_reg + (uint32_t )event )) = 0x0UL ;
244+ #if __CORTEX_M == 0x04
245+ volatile uint32_t dummy = * ((volatile uint32_t * )((uint8_t * )p_reg + (uint32_t )event ));
246+ (void )dummy ;
247+ #endif
248+ }
249+
250+ NRF_STATIC_INLINE bool nrf_ccm_event_check (NRF_CCM_Type const * p_reg ,
251+ nrf_ccm_event_t event )
252+ {
253+ return (bool )* (volatile uint32_t * )((uint8_t * )p_reg + (uint32_t )event );
254+ }
255+
256+ NRF_STATIC_INLINE void nrf_ccm_enable (NRF_CCM_Type * p_reg )
257+ {
258+ p_reg -> ENABLE = (CCM_ENABLE_ENABLE_Enabled << CCM_ENABLE_ENABLE_Pos );
259+ }
260+
261+ NRF_STATIC_INLINE void nrf_ccm_disable (NRF_CCM_Type * p_reg )
262+ {
263+ p_reg -> ENABLE = (CCM_ENABLE_ENABLE_Disabled << CCM_ENABLE_ENABLE_Pos );
264+ }
265+
266+ NRF_STATIC_INLINE void nrf_ccm_configure (NRF_CCM_Type * p_reg ,
267+ nrf_ccm_config_t const * p_config )
268+ {
269+ p_reg -> MODE = (((uint32_t )p_config -> mode << CCM_MODE_MODE_Pos ) |
270+ #if defined(CCM_MODE_DATARATE_Pos )
271+ ((uint32_t )p_config -> datarate << CCM_MODE_DATARATE_Pos ) |
272+ #endif
273+ #if defined(CCM_MODE_LENGTH_Pos )
274+ ((uint32_t )p_config -> length << CCM_MODE_LENGTH_Pos ) |
275+ #endif
276+ 0 );
277+ }
278+
279+ NRF_STATIC_INLINE bool nrf_ccm_micstatus_get (NRF_CCM_Type const * p_reg )
280+ {
281+ return (bool )(p_reg -> MICSTATUS );
282+ }
283+
284+ NRF_STATIC_INLINE void nrf_ccm_cnfptr_set (NRF_CCM_Type * p_reg ,
285+ uint32_t const * p_data )
286+ {
287+ p_reg -> CNFPTR = (uint32_t )p_data ;
288+ }
289+
290+ NRF_STATIC_INLINE void nrf_ccm_inptr_set (NRF_CCM_Type * p_reg ,
291+ uint32_t const * p_data )
292+ {
293+ p_reg -> INPTR = (uint32_t )p_data ;
294+ }
295+
296+ NRF_STATIC_INLINE void nrf_ccm_outptr_set (NRF_CCM_Type * p_reg ,
297+ uint32_t const * p_data )
298+ {
299+ p_reg -> OUTPTR = (uint32_t )p_data ;
300+ }
301+
302+ NRF_STATIC_INLINE void nrf_ccm_scratchptr_set (NRF_CCM_Type * p_reg ,
303+ uint32_t const * p_area )
304+ {
305+ p_reg -> SCRATCHPTR = (uint32_t )p_area ;
306+ }
75307
76308#ifdef __cplusplus
77309}
0 commit comments