/******************************************************************************/
/* Component Name   ICU-M COMM(PE) Driver                                     */
/******************************************************************************/
/* Product      : ICU-M Firmware                                              */
/******************************************************************************/
/*******************************************************************************
* Copyright(C) 2021-2023 Renesas Electronics Corporation.                       
*                                                                               
*          RENESAS ELECTRONICS CONFIDENTIAL AND PROPRIETARY                     
*                                                                               
* These instructions, statements, and programs are the confidential information 
* of Renesas Electronics Corporation. They must be used and modified solely for 
* the purpose for which it was furnished by Renesas Electronics Corporation.    
* All part of them must not be reproduced nor disclosed to others in any form,  
* without the prior written permission of Renesas Electronics Corporation.      
*******************************************************************************/

#if !defined(ICUM_D_COMM_PE_PUB_H)
#define ICUM_D_COMM_PE_PUB_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**************************************************************************************/
/* Return Value Definition                                                            */
/**************************************************************************************/
#define ER_OK                           (0x00000000U)
#define ER_PARAM                        (0x00000001U)

#define ER_D_COMM_BASE                  (0x00000400U)

#define ER_D_COMM_QUE_FULL              (ER_D_COMM_BASE+1U)     /* Service request queue FULL        */
#define ER_D_COMM_NO_ISD                (ER_D_COMM_BASE+2U)     /* No ISD in service response queue  */
#define ER_D_COMM_QUE_ALREADY_INIT      (ER_D_COMM_BASE+3U)     /* Service queue already initialized */
#define ER_D_COMM_QUE_NOT_INIT          (ER_D_COMM_BASE+4U)     /* Service queue not initialized     */
#define ER_D_COMM_PARAM_NOT_G_RAM       (ER_D_COMM_BASE+5U)     /* Param not within global RAM area  */
#define ER_D_COMM_QUE_NOT_ACCESS        (ER_D_COMM_BASE+6U)
#define ER_D_COMM_EXIST_ISD             (ER_D_COMM_BASE+7U)     /* ISD is exist in service response queue */
#define ER_D_COMM_MEMCHK_NG             (ER_D_COMM_BASE+8U)     /* address not within RAM area */
#define ER_D_COMM_ALIGN_NG              (ER_D_COMM_BASE+9U)     /* address not alignment NG */

/**************************************************************************************/
/* Definition                                                                         */
/**************************************************************************************/

/* Bit pattern indicate channel No. of interrupt to send ( ICUM_COMM_INT_TO_CHANNEL ) */
#define ICUM_COMM_ICH_TO_SERV_REQUEST       (0x00000002U)
#define ICUM_COMM_ICH_TO_CF_PRG_NOTIFY      (0x00000004U)
#define ICUM_COMM_ICH_TO_DF_PRG_NOTIFY      (0x00000008U)
#define ICUM_COMM_ICH_TO_CF_PRG_ERROR       (0x00000010U)
#define ICUM_COMM_ICH_TO_DF_PRG_ERROR       (0x00000020U)
#define ICUM_COMM_ICH_TO_OPERATION_END      (0x00000040U)

/* Service execution request single interrupt */
#define ICUM_COMM_ICH_TO_SINGLE_INTERRUPT   (0x00000001U)

/* Channel No. of interrupt to receive ( ICUM_COMM_INT_FROM_CHANNEL ) */
#define ICUM_COMM_ICH_FM_SYS_INTERRUPT      (0U)
#define ICUM_COMM_ICH_FM_SERV_RESPONSE      (1U)

/* PE status information ( ICUM_COMM_INFO_PE_STATUS ) */
#define ICUM_COMM_INF_PE_ST_FLS_DF_PRG      (0U)
#define ICUM_COMM_INF_PE_ST_FLS_CF_PRG      (1U)
#define ICUM_COMM_INF_PE_ST_FLS_OPRN        (2U)
#define ICUM_COMM_INF_PE_ST_FACIACCDIS      (3U)
#define ICUM_COMM_INF_PE_ST_PEID            (8U)

#define ICUM_COMM_MEMCHECK_OK                (0x00U)
#define ICUM_COMM_MEMCHECK_ERROR             (0x01U)

/* Total number of PE */
#define TOTAL_PE_NUM                        (7U)

/* Length of service queue ( SERVICE_QUEUE_LENGTH ) */
#define REQUEST_QUEUE_LENGTH                (16U)
#define RESPONSE_QUEUE_LENGTH               (16U)

#define RESPONSE_QUEUE_OFST                 (16U)
#define PE_QUEUE_DUMMY                      (0U)

#define TOTAL_QUEUE_LENGTH                  (REQUEST_QUEUE_LENGTH + PE_QUEUE_DUMMY + RESPONSE_QUEUE_LENGTH + PE_QUEUE_DUMMY)

#define VM_QUEUE_LENGTH                     (4U)

/* Defines item of memory information */
extern const uint32_t memory_information[];
#define MEM_INFO_SERVICEQUE_1_ADDR          (memory_information[0])
#define MEM_INFO_SERVICEQUE_1_SIZE          (memory_information[1])
#define MEM_INFO_SHAREDMEM_1_ADDR           (memory_information[2])
#define MEM_INFO_SHAREDMEM_1_SIZE           (memory_information[3])
#define MEM_INFO_SHAREDMEM_2_ADDR           (memory_information[4])
#define MEM_INFO_SHAREDMEM_2_SIZE           (memory_information[5])
#define MEM_INFO_SHAREDMEM_3_ADDR           (memory_information[6])
#define MEM_INFO_SHAREDMEM_3_SIZE           (memory_information[7])
#define MEM_INFO_ICUM_SECUREMOD             (memory_information[30])

/**************************************************************************************/
/* Macros                                                                             */
/**************************************************************************************/

/***************************************************************************************
* Function ID  : [ICUMFW_CD_S4_D_COMM_PE_0027]:[ICUMFW_UD_S4_D_COMM_PE_0027]
* Function name: GET_MY_PEID
* Description  : Retrieve PEID from thread configurator register
* Arguments    : None
*                
* Return Value : PEID Value
***************************************************************************************/
extern uint32_t USER_ICUMIF_GetMyPEID(void);
#define GET_MY_PEID     (USER_ICUMIF_GetMyPEID())

/**************************************************************************************/
/* Type definition                                                                    */
/**************************************************************************************/

/*====================================================================================*/
/* Type definition: Channel number of interrupt to send                               */
/*====================================================================================*/
typedef uint32_t    icum_comm_int_to_channel_t;

/*====================================================================================*/
/* Type definition: PE status information                                             */
/*====================================================================================*/
typedef uint32_t    icum_com_info_pe_status_t;

/**************************************************************************************/
/* Enumeration                                                                        */
/**************************************************************************************/
/* None */

/**************************************************************************************/
/* Structure Definition                                                               */
/**************************************************************************************/
/* None */

/**************************************************************************************/
/* Prototypes                                                                         */
/**************************************************************************************/

uint32_t D_COMM_PE_Init(uint32_t *p_request_queue);
uint32_t D_COMM_TriggerInterruptToICUP(icum_comm_int_to_channel_t channel,
                                       r_icumif_isd_t *p_isd);
uint32_t D_COMM_GetResponseISD(r_icumif_isd_t **p_isd);
r_icumif_sts_t *D_COMM_GetICUStatusAddr(void);
uint32_t D_COMM_SetPEStatusInfo(icum_com_info_pe_status_t info, uint8_t set_value);
void D_COMM_SetInterruptEnable(void);
uint32_t D_COMM_SetSystemCallBackFunc(R_ICUMIF_CB_REGIST_t *p_regist_info);
uint32_t D_COMM_GetICUMemCheckErrInfo(uint8_t *p_error);
void D_COMM_IRQ_Handler(void);
uint32_t D_COMM_PE_CheckMemorySharedRAM(uint32_t start_addr, uint32_t size);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* ICUM_D_COMM_PE_PUB_H */

