|
| 1 | +/* |
| 2 | +* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates |
| 3 | +* |
| 4 | +* SPDX-License-Identifier: BSD-3-Clause |
| 5 | +*/ |
| 6 | + |
| 7 | +#ifndef R_IPC_API_H |
| 8 | +#define R_IPC_API_H |
| 9 | + |
| 10 | +/*******************************************************************************************************************//** |
| 11 | + * @ingroup RENESAS_SYSTEM_INTERFACES |
| 12 | + * @defgroup IPC_API IPC Interface |
| 13 | + * @brief Interface for inter-processor communications (IPC). |
| 14 | + * |
| 15 | + * @section IPC_INTERFACE_SUMMARY Summary |
| 16 | + * The IPC interface provides common APIs for IPC HAL drivers. The IPC interface supports the following features: |
| 17 | + * - Sending and receiving messages between cores via IPC one-way FIFOs |
| 18 | + * - Triggering maskable interrupts between cores |
| 19 | + * |
| 20 | + * |
| 21 | + * @{ |
| 22 | + **********************************************************************************************************************/ |
| 23 | + |
| 24 | +/*********************************************************************************************************************** |
| 25 | + * Includes |
| 26 | + **********************************************************************************************************************/ |
| 27 | + |
| 28 | +/* Includes board and MCU related header files. */ |
| 29 | +#include "bsp_api.h" |
| 30 | + |
| 31 | +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ |
| 32 | +FSP_HEADER |
| 33 | + |
| 34 | +/********************************************************************************************************************** |
| 35 | + * Typedef definitions |
| 36 | + **********************************************************************************************************************/ |
| 37 | + |
| 38 | +/** IPC Events */ |
| 39 | +typedef enum e_ipc_event |
| 40 | +{ |
| 41 | + IPC_EVENT_IRQ0 = (1UL << 0), ///< IRQ Event 0 set |
| 42 | + IPC_EVENT_IRQ1 = (1UL << 1), ///< IRQ Event 1 set |
| 43 | + IPC_EVENT_IRQ2 = (1UL << 2), ///< IRQ Event 2 set |
| 44 | + IPC_EVENT_IRQ3 = (1UL << 3), ///< IRQ Event 3 set |
| 45 | + IPC_EVENT_IRQ4 = (1UL << 4), ///< IRQ Event 4 set |
| 46 | + IPC_EVENT_IRQ5 = (1UL << 5), ///< IRQ Event 5 set |
| 47 | + IPC_EVENT_IRQ6 = (1UL << 6), ///< IRQ Event 6 set |
| 48 | + IPC_EVENT_IRQ7 = (1UL << 7), ///< IRQ Event 7 set |
| 49 | + IPC_EVENT_MESSAGE_RECEIVED = (1UL << 16), ///< Message received over FIFO |
| 50 | + IPC_EVENT_FIFO_ERROR_EMPTY = (1UL << 24), ///< A read was attempted on an empty FIFO |
| 51 | + IPC_EVENT_FIFO_ERROR_FULL = (1UL << 25), ///< Data couldn't be written to a full FIFO |
| 52 | +} ipc_event_t; |
| 53 | + |
| 54 | +/** IPC Generate Events */ |
| 55 | +typedef enum e_ipc_generate_event |
| 56 | +{ |
| 57 | + IPC_GENERATE_EVENT_IRQ0 = (1UL << 0), ///< Generate IRQ Event 0 |
| 58 | + IPC_GENERATE_EVENT_IRQ1 = (1UL << 1), ///< Generate IRQ Event 1 |
| 59 | + IPC_GENERATE_EVENT_IRQ2 = (1UL << 2), ///< Generate IRQ Event 2 |
| 60 | + IPC_GENERATE_EVENT_IRQ3 = (1UL << 3), ///< Generate IRQ Event 3 |
| 61 | + IPC_GENERATE_EVENT_IRQ4 = (1UL << 4), ///< Generate IRQ Event 4 |
| 62 | + IPC_GENERATE_EVENT_IRQ5 = (1UL << 5), ///< Generate IRQ Event 5 |
| 63 | + IPC_GENERATE_EVENT_IRQ6 = (1UL << 6), ///< Generate IRQ Event 6 |
| 64 | + IPC_GENERATE_EVENT_IRQ7 = (1UL << 7), ///< Generate IRQ Event 7 |
| 65 | +} ipc_generate_event_t; |
| 66 | + |
| 67 | +/** IPC Callback parameter definition */ |
| 68 | +typedef struct st_ipc_callback_args |
| 69 | +{ |
| 70 | + uint32_t channel; ///< IPC channel |
| 71 | + uint32_t message; ///< Received message data |
| 72 | + ipc_event_t event; ///< Event code |
| 73 | + void * p_context; ///< Context provided to user during callback |
| 74 | +} ipc_callback_args_t; |
| 75 | + |
| 76 | +/** IPC Configuration */ |
| 77 | +typedef struct st_ipc_cfg |
| 78 | +{ |
| 79 | + uint32_t channel; ///< IPC channel |
| 80 | + |
| 81 | + /** IPC IRQ number |
| 82 | + * @note Only required if the user wants to receive messages or interrupts over IPC. |
| 83 | + * IRQ should be set to FSP_INVALID_VECTOR when not used. |
| 84 | + */ |
| 85 | + IRQn_Type irq; |
| 86 | + |
| 87 | + /** IPC Interrupt priority |
| 88 | + * @note Only required if the user wants to receive messages or interrupts over IPC. |
| 89 | + */ |
| 90 | + uint8_t ipl; |
| 91 | + |
| 92 | + /** Pointer to callback function |
| 93 | + * @note Only required if the user wants to receive messages or interrupts over IPC. |
| 94 | + * p_callback should be set to NULL when not used. |
| 95 | + */ |
| 96 | + void (* p_callback)(ipc_callback_args_t * p_args); |
| 97 | + void * p_context; ///< User defined context passed into callback function |
| 98 | +} ipc_cfg_t; |
| 99 | + |
| 100 | +/** IPC control block. Allocate an instance specific control block to pass into the IPC API calls. |
| 101 | + */ |
| 102 | +typedef void ipc_ctrl_t; |
| 103 | + |
| 104 | +/** Interface definition for IPC */ |
| 105 | +typedef struct st_ipc_api |
| 106 | +{ |
| 107 | + /** Open IPC instance. |
| 108 | + * |
| 109 | + * @param[in,out] p_ctrl Pointer to the IPC control block. Must be declared by user. Value set here. |
| 110 | + * @param[in] p_cfg Pointer to IPC configuration structure. All elements of this structure must be set by |
| 111 | + * user. |
| 112 | + */ |
| 113 | + fsp_err_t (* open)(ipc_ctrl_t * const p_ctrl, ipc_cfg_t const * const p_cfg); |
| 114 | + |
| 115 | + /** Send message through the FIFO of the configured IPC channel. |
| 116 | + * @note Should only be called from the core on the transmit side of the IPC channel. |
| 117 | + * |
| 118 | + * @param[in] p_ctrl Pointer to the IPC control block. |
| 119 | + * @param[in] message Message to send. |
| 120 | + */ |
| 121 | + fsp_err_t (* messageSend)(ipc_ctrl_t * const p_ctrl, uint32_t message); |
| 122 | + |
| 123 | + /** Generate event through configured IPC channel interrupt. |
| 124 | + * @note Should only be called from the core on the transmit side of the IPC channel. |
| 125 | + * |
| 126 | + * @param[in] p_ctrl Pointer to the IPC control block. |
| 127 | + * @param[in] event Event to generate interrupt for. |
| 128 | + */ |
| 129 | + fsp_err_t (* eventGenerate)(ipc_ctrl_t * const p_ctrl, ipc_generate_event_t event); |
| 130 | + |
| 131 | + /** Specify callback function and optional context pointer and working memory pointer. |
| 132 | + * |
| 133 | + * @param[in] p_ctrl Pointer to the IPC control block. |
| 134 | + * @param[in] p_callback Callback function |
| 135 | + * @param[in] p_context Pointer to send to callback function |
| 136 | + * @param[in] p_callback_memory Pointer to volatile memory where callback structure can be allocated. |
| 137 | + * Callback arguments allocated here are only valid during the callback. |
| 138 | + */ |
| 139 | + fsp_err_t (* callbackSet)(ipc_ctrl_t * const p_ctrl, void (* p_callback)(ipc_callback_args_t *), |
| 140 | + void * const p_context, ipc_callback_args_t * const p_callback_memory); |
| 141 | + |
| 142 | + /** Close IPC instance. |
| 143 | + * |
| 144 | + * @param[in] p_ctrl Pointer to the IPC control block. |
| 145 | + */ |
| 146 | + fsp_err_t (* close)(ipc_ctrl_t * const p_ctrl); |
| 147 | +} ipc_api_t; |
| 148 | + |
| 149 | +/** This structure encompasses everything that is needed to use an instance of this interface. */ |
| 150 | +typedef struct st_ipc_instance |
| 151 | +{ |
| 152 | + ipc_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance |
| 153 | + ipc_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance |
| 154 | + ipc_api_t const * p_api; ///< Pointer to the API structure for this instance |
| 155 | +} ipc_instance_t; |
| 156 | + |
| 157 | +/******************************************************************************************************************//** |
| 158 | + * @} (end defgroup IPC_API) |
| 159 | + *********************************************************************************************************************/ |
| 160 | + |
| 161 | +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ |
| 162 | +FSP_FOOTER |
| 163 | + |
| 164 | +#endif |
0 commit comments