Skip to content

Commit e2af395

Browse files
khoa-nguyen-18KhiemNguyenT
authored andcommitted
hal: renesas: ra: Add support r_ipc HWIP
Add support Renesas RA r_ipc HWIP Signed-off-by: Khoa Nguyen <[email protected]>
1 parent 6ff5c06 commit e2af395

File tree

5 files changed

+683
-2
lines changed

5 files changed

+683
-2
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_IOPORT
9292
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_CTSU
9393
fsp/src/r_ctsu/r_ctsu.c)
9494
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_TOUCH
95-
fsp/src/rm_touch/rm_touch.c
96-
)
95+
fsp/src/rm_touch/rm_touch.c)
96+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_IPC
97+
fsp/src/r_ipc/r_ipc.c)
9798

9899
if(CONFIG_USE_RA_FSP_SCE)
99100
zephyr_include_directories(

drivers/ra/fsp/inc/api/r_ipc_api.h

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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_H
8+
#define R_IPC_H
9+
10+
/***********************************************************************************************************************
11+
* Includes
12+
**********************************************************************************************************************/
13+
#include "r_ipc_cfg.h"
14+
#include "r_ipc_api.h"
15+
16+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
17+
FSP_HEADER
18+
19+
/*******************************************************************************************************************//**
20+
* @addtogroup IPC
21+
* @{
22+
**********************************************************************************************************************/
23+
24+
/**********************************************************************************************************************
25+
* Typedef definitions
26+
**********************************************************************************************************************/
27+
28+
/* IPC Instance Control Block. DO NOT INITIALIZE. */
29+
typedef struct st_ipc_instance_ctrl
30+
{
31+
uint32_t open; // Used to determine if the channel is configured
32+
ipc_cfg_t const * p_cfg; // Pointer to the configuration block
33+
R_IPC_IPC_CH_Type * p_send_reg; // Base register for sending
34+
R_IPC_IPC_CH_Type * p_recv_reg; // Base register for receiving
35+
void (* p_callback)(ipc_callback_args_t *); // Pointer to callback
36+
ipc_callback_args_t * p_callback_memory; // Pointer to optional working memory
37+
void * p_context; // Pointer to context to be passed into callback function
38+
} ipc_instance_ctrl_t;
39+
40+
/**********************************************************************************************************************
41+
* Exported global variables
42+
**********************************************************************************************************************/
43+
44+
/** @cond INC_HEADER_DEFS_SEC */
45+
/** Interface Structure for user access */
46+
extern const ipc_api_t g_ipc_on_ipc;
47+
48+
/** @endcond */
49+
50+
/***********************************************************************************************************************
51+
* Public APIs
52+
**********************************************************************************************************************/
53+
fsp_err_t R_IPC_Open(ipc_ctrl_t * const p_api_ctrl, ipc_cfg_t const * const p_cfg);
54+
fsp_err_t R_IPC_MessageSend(ipc_ctrl_t * const p_api_ctrl, uint32_t message);
55+
fsp_err_t R_IPC_EventGenerate(ipc_ctrl_t * const p_api_ctrl, ipc_generate_event_t event);
56+
fsp_err_t R_IPC_CallbackSet(ipc_ctrl_t * const p_api_ctrl,
57+
void ( * p_callback)(ipc_callback_args_t *),
58+
void * const p_context,
59+
ipc_callback_args_t * const p_callback_memory);
60+
fsp_err_t R_IPC_Close(ipc_ctrl_t * const p_api_ctrl);
61+
62+
/*******************************************************************************************************************//**
63+
* @} (end addtogroup IPC)
64+
**********************************************************************************************************************/
65+
66+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
67+
FSP_FOOTER
68+
69+
#endif

0 commit comments

Comments
 (0)