1 /* 2 * Copyright (c) 2024 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef NRFS_DIAG_H__ 8 #define NRFS_DIAG_H__ 9 10 #include <internal/services/nrfs_diag.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** @brief System Diagnostics Service response notification types. */ 17 typedef enum __NRFS_PACKED { 18 NRFS_DIAG_EVT_APPLIED = 0, /** Request applied succesfully */ 19 NRFS_DIAG_EVT_REJECT, /** Request rejected. */ 20 NRFS_DIAG_EVT_REG_RSP, /** Response for register request */ 21 } nrfs_diag_evt_type_t; 22 23 /** @brief System Diagnostics Service response data structure. */ 24 typedef struct __NRFS_PACKED { 25 nrfs_diag_evt_type_t type; /** Event type. */ 26 struct { 27 diag_reg_access_type_t access_type; /** Register access type. */ 28 uint32_t addr; /** Register address. */ 29 uint32_t val; /** Register value. */ 30 } reg; /** Register request. */ 31 } nrfs_diag_evt_t; 32 33 /** @brief System Diagnostics Service response handler type. */ 34 typedef void (*nrfs_diag_response_handler_t)(nrfs_diag_evt_t const * p_evt, void * p_context); 35 36 /** 37 * @brief Function for initializing the System Diagnostics service. 38 * 39 * @param[in] handler Function called as a response to the request 40 * 41 * @retval NRFS_SUCCESS Service initialized successfully. 42 * @retval NRFS_ERR_INVALID_STATE Service was already initialized. 43 */ 44 nrfs_err_t nrfs_diag_init(nrfs_diag_response_handler_t handler); 45 46 /** 47 * @brief Function for uninitializing the System Diagnostics service. 48 * 49 * @warning Notifications from previous requests are dropped after service uninitialization. 50 */ 51 void nrfs_diag_uninit(void); 52 53 /** 54 * @brief Function for reading a register 55 * 56 * Value of register read will be available for handler. 57 * 58 * @param[in] addr 32-bit register address 59 * @param[in] p_context Opaque user data that will be passed to registered callback. 60 * 61 * @retval NRFS_SUCCESS Request sent successfully. 62 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 63 * @retval NRFS_ERR_IPC Backend returned error during request sending. 64 */ 65 nrfs_err_t nrfs_diag_reg_read(uint32_t addr, void * p_context); 66 67 /** 68 * @brief Function for writing a register 69 * 70 * @param[in] addr 32-bit register address 71 * @param[in] val 32-bit value to be written to the register 72 * @param[in] p_context Opaque user data that will be passed to registered callback. 73 * 74 * @retval NRFS_SUCCESS Request sent successfully. 75 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 76 * @retval NRFS_ERR_IPC Backend returned error during request sending. 77 */ 78 nrfs_err_t nrfs_diag_reg_write(uint32_t addr, uint32_t val, void * p_context); 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif /* NRFS_DIAG_H__ */ 85