1 /* 2 * Copyright (c) 2024 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef NRFS_BACKEND_IPC_SERVICE_H 8 #define NRFS_BACKEND_IPC_SERVICE_H 9 10 #include <stdint.h> 11 #include <nrfs_common.h> 12 #include <zephyr/ipc/ipc_service.h> 13 #include <zephyr/kernel.h> 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 struct __packed ipc_data_packet { 20 uint16_t channel_id; 21 uint16_t size; 22 uint8_t data[CONFIG_NRFS_MAX_BACKEND_PACKET_SIZE]; 23 }; 24 25 enum ipc_channel_status { 26 NOT_CONNECTED = 0, 27 CONNECTED = 1 28 }; 29 30 enum nrfs_backend_error { 31 NRFS_ERROR_EPT_RECEIVE_QUEUE_ERROR = 0, 32 NRFS_ERROR_EPT_RECEIVE_DATA_TOO_LONG, 33 NRFS_ERROR_IPC_CHANNEL_INIT, 34 NRFS_ERROR_SEND_DATA, 35 NRFS_ERROR_NO_DATA_RECEIVED, 36 NRFS_ERROR_IPC_OPEN_INSTANCE, 37 NRFS_ERROR_IPC_REGISTER_ENDPOINT, 38 NRFS_ERROR_BACKEND_NOT_CONNECTED, 39 NRFS_ERROR_COUNT 40 }; 41 42 #define IPC_CPUSYS_CHANNEL_ID 0x5C 43 44 /** 45 * @brief function to check if backend is connected to sysctrl 46 * 47 * @return true Backend connected. 48 * @return false Backend not connected. 49 */ 50 bool nrfs_backend_connected(void); 51 52 /** 53 * @brief this function will block until connection or timeout expires 54 * 55 * @param timeout 56 * 57 * @return 0 Connection done. 58 * @return -EAGAIN Waiting period timed out. 59 */ 60 int nrfs_backend_wait_for_connection(k_timeout_t timeout); 61 62 /** 63 * @brief Extended function for sending a message over the chosen transport backend. 64 * 65 * This function is used by services to send requests to the System Controller. 66 * 67 * @param[in] message Pointer to the message payload. 68 * @param[in] size Message payload size. 69 * @param[in] timeout Non-negative waiting period to add the message, 70 * or one of the special values K_NO_WAIT and K_FOREVER. 71 * @param[in] high_prio True if message should be sent with higher priority. 72 * 73 * @retval NRFS_SUCCESS Message sent successfully. 74 * @retval NRFS_ERR_IPC Backend returned error during message sending. 75 */ 76 nrfs_err_t nrfs_backend_send_ex(void *message, size_t size, k_timeout_t timeout, bool high_prio); 77 78 /** 79 * @brief Fatal error handler for unrecoverable errors 80 * 81 * This is weak function so it can be overridden if needed. 82 * Error is considered fatal when there is no option to send message to sysctrl 83 * even after retry. Communication with sysctrl is crucial for system to work properly. 84 * 85 * @param error_id parameter to identify error. 86 */ 87 void nrfs_backend_fatal_error_handler(enum nrfs_backend_error error_id); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif /* NRFS_BACKEND_IPC_SERVICE_H */ 94