Skip to content

Commit

Permalink
hal: renesas: rz: Initial support for IPM
Browse files Browse the repository at this point in the history
Initial HAL support for IPM

Signed-off-by: Phuc Pham <phuc.pham.xr@bp.renesas.com>
Signed-off-by: Nhut Nguyen <nhut.nguyen.kc@renesas.com>
  • Loading branch information
nhutnguyenkc authored and KhiemNguyenT committed Dec 24, 2024
1 parent 4dedba1 commit 3856689
Show file tree
Hide file tree
Showing 5 changed files with 782 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/rz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_SCIF_UART

zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_ADC
fsp/src/${SOC_SERIES_PREFIX}/r_adc_c/r_adc_c.c)

zephyr_library_sources_ifdef(CONFIG_USE_RZ_FSP_MHU
fsp/src/${SOC_SERIES_PREFIX}/r_mhu_ns/r_mhu_ns.c)
147 changes: 147 additions & 0 deletions drivers/rz/fsp/inc/api/r_mhu_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/*******************************************************************************************************************//**
* @ingroup RENESAS_INTERFACES
* @defgroup MHU_API MHU Interface (for secure and non secure channels)
* @brief Interface for Message Handling Unit
*
* @section MHU_API_SUMMARY Summary
* The Message Handling Unit interface provides a common API for MHU HAL drivers.
* The Message Handling Unit interface supports:
* - Message communication between Cortex-A55 and Cortex-M33.
* - 32-bit data can be communicated between CPUs via shared memory.
*
* Implemented by:
* - @ref MHU_S
* - @ref MHU_NS
*
* @{
**********************************************************************************************************************/

/***********************************************************************************************************************
* Includes
**********************************************************************************************************************/

/* Register definitions, common services and error codes. */
#include "bsp_api.h"

#ifndef R_MHU_API_H
#define R_MHU_API_H

/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
FSP_HEADER

/**********************************************************************************************************************
* Macro definitions
**********************************************************************************************************************/

/**********************************************************************************************************************
* Typedef definitions
**********************************************************************************************************************/

typedef enum e_mhu_send_type
{
MHU_SEND_TYPE_MSG = 0, ///< Channel for sending "message" and receiving "response".
MHU_SEND_TYPE_RSP, ///< Channel for sending "response" and receiving "message".
} mhu_send_type_t;

/** MHU callback parameter definition */
typedef struct st_mhu_callback_args
{
/** Placeholder for user data. Set in @ref mhu_api_t::open function in @ref mhu_cfg_t. */
void const * p_context;
uint32_t channel; ///< Channel where the receive interrupt occurred.
uint32_t msg; ///< 32-bit received data.
} mhu_callback_args_t;

/** MHU configuration block */
typedef struct st_mhu_cfg
{
/** Generic configuration */
uint32_t channel; ///< Identifier recognizable by implementation
uint8_t rx_ipl; ///< Receive interrupt priority
IRQn_Type rx_irq; ///< Receive interrupt ID

/** Parameters to control software behavior */
void (* p_callback)(mhu_callback_args_t * p_args); ///< Pointer to callback function

void const * p_shared_memory; ///< Pointer to 64-bit send/receive data buffer.

/** Placeholder for user data. Passed to the user callback in @ref mhu_callback_args_t. */
void const * p_context;
} mhu_cfg_t;

/** MHU control block. Allocate an instance specific control block to pass into the MHU API calls.
* @par Implemented as
* - mhu_instance_ctrl_t
*/
typedef void mhu_ctrl_t;

/** Interface definition for MHU */
typedef struct st_mhu_api
{
/** Opens the MHU driver and initializes the hardware.
* @par Implemented as
* - @ref R_MHU_S_Open()
* - @ref R_MHU_NS_Open()
*
* @param[in] p_ctrl Pointer to control block. Must be declared by user. Elements are set here.
* @param[in] p_cfg Pointer to configuration structure.
*/
fsp_err_t (* open)(mhu_ctrl_t * const p_ctrl, mhu_cfg_t const * const p_cfg);

/** Performs a send operation on an MHU device.
* @par Implemented as
* - @ref R_MHU_S_MsgSend()
* - @ref R_MHU_NS_MsgSend()
*
* @param[in] p_ctrl Pointer to control block set in mhu_api_t::open call.
* @param[in] msg 32bit send data.
*/
fsp_err_t (* msgSend)(mhu_ctrl_t * const p_ctrl, uint32_t const msg);

/**
* Specify callback function and optional context pointer and working memory pointer.
* @par Implemented as
* - @ref R_MHU_S_CallbackSet()
* - @ref R_MHU_NS_CallbackSet()
*
* @param[in] p_ctrl Control block set in @ref mhu_api_t::open call for this channel.
* @param[in] p_callback Callback function to register
* @param[in] p_context Pointer to send to callback function
* @param[in] p_callback_memory Pointer to volatile memory where callback structure can be allocated.
* Callback arguments allocated here are only valid during the callback.
*/
fsp_err_t (* callbackSet)(mhu_ctrl_t * const p_api_ctrl, void (* p_callback) (mhu_callback_args_t *),
void const * const p_context, mhu_callback_args_t * const p_callback_memory);

/** Closes the driver and releases the MHU device.
* @par Implemented as
* - @ref R_MHU_S_Close()
* - @ref R_MHU_NS_Close()
*
* @param[in] p_ctrl Pointer to control block set in mhu_api_t::open call.
*/
fsp_err_t (* close)(mhu_ctrl_t * const p_ctrl);
} mhu_api_t;

/** This structure encompasses everything that is needed to use an instance of this interface. */
typedef struct st_mhu_instance
{
mhu_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
mhu_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
mhu_api_t const * p_api; ///< Pointer to the API structure for this instance
} mhu_instance_t;

/******************************************************************************************************************//**
* @} (end addtogroup MHU_API)
*********************************************************************************************************************/

/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
FSP_FOOTER

#endif /* R_MHU_API_H */
91 changes: 91 additions & 0 deletions drivers/rz/fsp/inc/instances/rzg/r_mhu_ns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/*******************************************************************************************************************//**
* @addtogroup MHU_NS
* @{
**********************************************************************************************************************/

/***********************************************************************************************************************
* Includes
**********************************************************************************************************************/
#include "r_mhu_api.h"
#include "r_mhu_ns_cfg.h"

#ifndef R_MHU_NS_H
#define R_MHU_NS_H

/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
FSP_HEADER

/***********************************************************************************************************************
* Macro definitions
**********************************************************************************************************************/

/*************************************************************************************************
* Type defines
*************************************************************************************************/

/** Channel control block. DO NOT INITIALIZE. Initialization occurs when @ref mhu_api_t::open is called. */
typedef struct st_mhu_ns_instance_ctrl
{
uint32_t open; ///< Indicates whether the open() API has been successfully called.
mhu_cfg_t const * p_cfg; ///< Pointer to instance configuration
R_MHU0_Type * p_regs; ///< Base register for this channel

uint32_t channel; ///< channel
mhu_send_type_t send_type; ///< Send Type: Message or Response
uint32_t * p_shared_memory_tx; ///< Pointer to send data area
uint32_t * p_shared_memory_rx; ///< Pointer to recv data area

#if BSP_TZ_SECURE_BUILD
bool callback_is_secure; ///< p_callback is in secure memory
#endif

/* Pointer to callback and optional working memory */
void (* p_callback)(mhu_callback_args_t *);

/* Pointer to non-secure memory that can be used to pass arguments to a callback in non-secure memory. */
mhu_callback_args_t * p_callback_memory;

/* Pointer to context to be passed into callback function */
void const * p_context;
} mhu_ns_instance_ctrl_t;

/**********************************************************************************************************************
* Exported global variables
**********************************************************************************************************************/

/** @cond INC_HEADER_DEFS_SEC */
/** Filled in Interface API structure for this Instance. */
extern const mhu_api_t g_mhu_ns_on_mhu_ns;

/** @endcond */

/***********************************************************************************************************************
* Public APIs
**********************************************************************************************************************/
fsp_err_t R_MHU_NS_Open(mhu_ctrl_t * p_ctrl, mhu_cfg_t const * const p_cfg);

fsp_err_t R_MHU_NS_MsgSend(mhu_ctrl_t * const p_ctrl, uint32_t const msg);

fsp_err_t R_MHU_NS_Close(mhu_ctrl_t * const p_ctrl);

fsp_err_t R_MHU_NS_CallbackSet(mhu_ctrl_t * const p_api_ctrl,
void ( * p_callback ) (mhu_callback_args_t *),
void const * const p_context,
mhu_callback_args_t * const p_callback_memory);

void R_MHU_NS_IsrSub(uint32_t irq);

/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
FSP_FOOTER

#endif /* R_MHU_NS_H */

/*******************************************************************************************************************//**
* @} (end defgroup MHU_NS)
**********************************************************************************************************************/
Loading

0 comments on commit 3856689

Please sign in to comment.