|
| 1 | +/* |
| 2 | + * Copyright 2021-2024 NXP |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: BSD-3-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef HSE_IP_H |
| 8 | +#define HSE_IP_H |
| 9 | + |
| 10 | +/** |
| 11 | +* @file |
| 12 | +* |
| 13 | +* @addtogroup HSE_IP |
| 14 | +* @{ |
| 15 | +*/ |
| 16 | + |
| 17 | +#ifdef __cplusplus |
| 18 | +extern "C"{ |
| 19 | +#endif |
| 20 | + |
| 21 | +/*================================================================================================== |
| 22 | +* INCLUDE FILES |
| 23 | +* 1) system and project includes |
| 24 | +* 2) needed interfaces from external units |
| 25 | +* 3) internal and external interfaces from this unit |
| 26 | +==================================================================================================*/ |
| 27 | +#include "Hse_Ip_Cfg.h" |
| 28 | +#include "StandardTypes.h" |
| 29 | +#include "hse_interface.h" |
| 30 | + |
| 31 | +/*================================================================================================== |
| 32 | +* SOURCE FILE VERSION INFORMATION |
| 33 | +==================================================================================================*/ |
| 34 | +#define HSE_IP_VENDOR_ID_H 43 |
| 35 | +#define HSE_IP_SW_MAJOR_VERSION_H 2 |
| 36 | +#define HSE_IP_SW_MINOR_VERSION_H 0 |
| 37 | +#define HSE_IP_SW_PATCH_VERSION_H 0 |
| 38 | +#define HSE_IP_AR_RELEASE_MAJOR_VERSION_H 4 |
| 39 | +#define HSE_IP_AR_RELEASE_MINOR_VERSION_H 7 |
| 40 | + |
| 41 | +/*================================================================================================== |
| 42 | +* FILE VERSION CHECKS |
| 43 | +==================================================================================================*/ |
| 44 | +/* Check if Hse_Ip header file and Hse_Ip_Cfg header file are of the same vendor */ |
| 45 | +#if (HSE_IP_VENDOR_ID_H != HSE_IP_CFG_VENDOR_ID_H) |
| 46 | + #error "Hse_Ip.h and Hse_Ip_Cfg.h have different vendor ids" |
| 47 | +#endif |
| 48 | + |
| 49 | +/* Check if Hse_Ip header file and Hse_Ip_Cfg header file are of the same Software version */ |
| 50 | +#if ((HSE_IP_SW_MAJOR_VERSION_H != HSE_IP_CFG_SW_MAJOR_VERSION_H) || \ |
| 51 | + (HSE_IP_SW_MINOR_VERSION_H != HSE_IP_CFG_SW_MINOR_VERSION_H) || \ |
| 52 | + (HSE_IP_SW_PATCH_VERSION_H != HSE_IP_CFG_SW_PATCH_VERSION_H) \ |
| 53 | + ) |
| 54 | + #error "Software Version Numbers of Hse_Ip.h and Hse_Ip_Cfg.h are different" |
| 55 | +#endif |
| 56 | + |
| 57 | +#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK |
| 58 | +/* Check if the files Hse_Ip.h and StandardTypes.h are of the same AutoSar version */ |
| 59 | +#if ((HSE_IP_AR_RELEASE_MAJOR_VERSION_H != STD_AR_RELEASE_MAJOR_VERSION) || \ |
| 60 | + (HSE_IP_AR_RELEASE_MINOR_VERSION_H != STD_AR_RELEASE_MINOR_VERSION) \ |
| 61 | + ) |
| 62 | + #error "AutoSar Version Numbers of Hse_Ip.h and StandardTypes.h are different" |
| 63 | +#endif |
| 64 | +#endif |
| 65 | + |
| 66 | +/*================================================================================================== |
| 67 | +* CONSTANTS |
| 68 | +==================================================================================================*/ |
| 69 | + |
| 70 | +/*================================================================================================== |
| 71 | +* DEFINES AND MACROS |
| 72 | +==================================================================================================*/ |
| 73 | + |
| 74 | +/*================================================================================================== |
| 75 | +* ENUMS |
| 76 | +==================================================================================================*/ |
| 77 | + |
| 78 | +/*================================================================================================== |
| 79 | +* STRUCTURES AND OTHER TYPEDEFS |
| 80 | +==================================================================================================*/ |
| 81 | +/** @brief Macro returned when no MU channel is available */ |
| 82 | +#define HSE_IP_INVALID_MU_CHANNEL_U8 ((uint8)0xFFU) |
| 83 | + |
| 84 | +/** @brief Extension to the list of responses returned by HSE */ |
| 85 | +#define HSE_IP_SRV_RSP_NO_RESPONSE ((hseSrvResponse_t)0xBB55BB55UL) |
| 86 | +#define HSE_IP_SRV_RSP_BUSY ((hseSrvResponse_t)0xBB66BB66UL) |
| 87 | + |
| 88 | +/** @brief Type defining HseSrv callback type for notifications that will be sent to the caller when |
| 89 | + * a response is received from HSE, as a result of an asynchronous request |
| 90 | + * @implements Hse_Ip_pfResponseCallbackType_typedef |
| 91 | + */ |
| 92 | +typedef void (*Hse_Ip_pfResponseCallbackType)(uint8 u8MuInstance, uint8 u8MuChannel, hseSrvResponse_t HseResponse, void* pCallbackParam); |
| 93 | + |
| 94 | +/** @brief Type defining HseSrv callback type for notifications that will be sent to the caller when |
| 95 | + * HSE triggers an interrupt signaling certain intern events |
| 96 | + * @implements Hse_Ip_pfGenericPurposeCallbackType_typedef |
| 97 | + */ |
| 98 | +typedef void (*Hse_Ip_pfGenericPurposeCallbackType)(uint8 u8MuInstance, uint32 u32HseNotifEvents); |
| 99 | + |
| 100 | +/** @brief Enum defining the possible return type values for the HSE IP API |
| 101 | + * @implements Hse_Ip_StatusType_enum |
| 102 | + */ |
| 103 | +typedef enum |
| 104 | +{ |
| 105 | + HSE_IP_STATUS_SUCCESS = 0x00U, /*!< Operation success status */ |
| 106 | + HSE_IP_STATUS_ERROR /*!< Operation error status */ |
| 107 | +}Hse_Ip_StatusType; |
| 108 | + |
| 109 | +/** |
| 110 | + * @brief Enum defining the possible types of service requests that can be sent to HSE |
| 111 | + * @implements Hse_Ip_ReqTypeType_enum |
| 112 | + */ |
| 113 | +typedef enum |
| 114 | +{ |
| 115 | + HSE_IP_REQTYPE_SYNC = 0UL, /*!< Synchronous - the service request function does not return until the HSE completes |
| 116 | + the request, or the timeout expires */ |
| 117 | + HSE_IP_REQTYPE_ASYNC_IRQ, /*!< Asynchronous using interrupts - the service request function returns right after |
| 118 | + sending the request to HSE; an interrupt is triggered when HSE completes the request |
| 119 | + (application can be notified through the channel callback) */ |
| 120 | + HSE_IP_REQTYPE_ASYNC_POLL /*!< Asynchronous polling - the service request function returns right after sending the |
| 121 | + request to HSE; application must poll the driver by calling Hse_Ip_MainFunction */ |
| 122 | +}Hse_Ip_ReqTypeType; |
| 123 | + |
| 124 | +/** |
| 125 | + * @brief Structure defining how a request sent from the upper layer to Hse_Ip should look like |
| 126 | + * @implements Hse_Ip_ReqType_struct |
| 127 | + */ |
| 128 | +typedef struct |
| 129 | +{ |
| 130 | + Hse_Ip_ReqTypeType eReqType; /*!< Selects the request type (SYNC/ASYNC) */ |
| 131 | + Hse_Ip_pfResponseCallbackType pfCallback; /*!< The callback for asynchronous request */ |
| 132 | + void* pCallbackParam; /*!< Parameter used to call the asynchronous callback(can be NULL) */ |
| 133 | + uint32 u32Timeout; /*!< Timeout for the synchronous requests (in us or ticks depending on selected counter) */ |
| 134 | +} Hse_Ip_ReqType; |
| 135 | + |
| 136 | +/** |
| 137 | + * @brief Structure defining the internal state machine of the Hse_Ip layer for a given MU instance |
| 138 | + * @implements Hse_Ip_MuStateType_struct |
| 139 | + */ |
| 140 | +typedef struct |
| 141 | +{ |
| 142 | + Hse_Ip_ReqType* apChannelRequest[HSE_IP_NUM_OF_CHANNELS_PER_MU]; /*!< Reference to channel request */ |
| 143 | + volatile boolean abChannelAllocated[HSE_IP_NUM_OF_CHANNELS_PER_MU]; /*!< Channel allocated flag */ |
| 144 | + Hse_Ip_pfGenericPurposeCallbackType pfGenericPurposeCallback; /*!< General purpose callback */ |
| 145 | +} Hse_Ip_MuStateType; |
| 146 | + |
| 147 | +/*================================================================================================== |
| 148 | +* GLOBAL VARIABLE DECLARATIONS |
| 149 | +==================================================================================================*/ |
| 150 | + |
| 151 | +/*================================================================================================== |
| 152 | +* FUNCTION PROTOTYPES |
| 153 | +==================================================================================================*/ |
| 154 | +#define CRYPTO_43_HSE_START_SEC_CODE |
| 155 | +#include "Crypto_43_HSE_MemMap.h" |
| 156 | + |
| 157 | +/*! |
| 158 | + * @brief Initializes the HSE Host driver. |
| 159 | + * @details This function initializes the HSE host driver over an MU instance. It initializes the state |
| 160 | + * structure with default values. |
| 161 | + * |
| 162 | + * @param[in] u8MuInstance MU Instance number |
| 163 | + * @param[in] pHseIpMuState Pointer to the state structure which will be used for holding |
| 164 | + * the internal state of the driver. |
| 165 | + * |
| 166 | + * @return An error code or HSE_IP_STATUS_SUCCESS |
| 167 | + */ |
| 168 | +Hse_Ip_StatusType Hse_Ip_Init |
| 169 | +( |
| 170 | + uint8 u8MuInstance, |
| 171 | + Hse_Ip_MuStateType* pHseIpMuState |
| 172 | +); |
| 173 | + |
| 174 | +/*! |
| 175 | + * @brief Deinitializes the HSE Host driver. |
| 176 | + * @details This function clears the reference to the previous state structure. |
| 177 | + * |
| 178 | + * @param[in] u8MuInstance: MU Instance number |
| 179 | + * |
| 180 | + * @return An error code or HSE_IP_STATUS_SUCCESS |
| 181 | + */ |
| 182 | +Hse_Ip_StatusType Hse_Ip_Deinit |
| 183 | +( |
| 184 | + uint8 u8MuInstance |
| 185 | +); |
| 186 | + |
| 187 | +/*! |
| 188 | + * @brief Retrieves the next free channel to be used by the application. |
| 189 | + * @details This function finds the next available channel and locks it for the use of the current task. |
| 190 | + * If all channels are allocated, the function returns HSE_IP_INVALID_MU_CHANNEL_U8. |
| 191 | + * |
| 192 | + * @param[in] u8MuInstance MU Instance number |
| 193 | + * |
| 194 | + * @return HSE channel number or HSE_IP_INVALID_MU_CHANNEL_U8 |
| 195 | + */ |
| 196 | +uint8 Hse_Ip_GetFreeChannel |
| 197 | +( |
| 198 | + uint8 u8MuInstance |
| 199 | +); |
| 200 | + |
| 201 | +/*! |
| 202 | + * @brief Releases a channel previously obtained. |
| 203 | + * @details This releases the lock on an MU channel, making it available for other tasks. |
| 204 | + * |
| 205 | + * @param[in] u8MuInstance MU Instance number |
| 206 | + * @param[in] u8MuChannel MU channel to be released |
| 207 | + * |
| 208 | + * @return void |
| 209 | + */ |
| 210 | +void Hse_Ip_ReleaseChannel |
| 211 | +( |
| 212 | + uint8 u8MuInstance, |
| 213 | + uint8 u8MuChannel |
| 214 | +); |
| 215 | + |
| 216 | +/** |
| 217 | +* @brief Function translates an address to HSE host address |
| 218 | +* @details Function translates an address to HSE host address; if Hse TCM support is enabled, address offset for specific processor is added |
| 219 | +* |
| 220 | +* @param[in] Address: Address to be converted |
| 221 | +* |
| 222 | +* @returns HOST_ADDR: Hse Host Address |
| 223 | +*/ |
| 224 | +HOST_ADDR Hse_Ip_ToAHBAddress |
| 225 | +( |
| 226 | + HOST_ADDR Address |
| 227 | +); |
| 228 | + |
| 229 | +/*! |
| 230 | + * @brief Sends a service request to HSE. |
| 231 | + * @details This function sends a service request to HSE on the specified channel. |
| 232 | + * If the request type is synchronous, this function will not return until either the request has been services, |
| 233 | + * or the timeout expires. |
| 234 | + * If the request type is asynchronous, the function returns right after launching the service request to HSE. |
| 235 | + * The application then either needs to poll the result of the request (calling Hse_Ip_MainFunction()) or wait |
| 236 | + * to be notified by the interrupt when the service is done. |
| 237 | + * |
| 238 | + * @param[in] u8MuInstance MU Instance number |
| 239 | + * @param[in] u8MuChannel MU channel number |
| 240 | + * @param[in] pRequest Structure that describes the request parameters: |
| 241 | + * type (sync/interrupts/polling), callback, timeout |
| 242 | + * @param[in] pHseSrvDesc Requested service descriptor |
| 243 | + * |
| 244 | + * @return HSE service response |
| 245 | + */ |
| 246 | +hseSrvResponse_t Hse_Ip_ServiceRequest |
| 247 | +( |
| 248 | + uint8 u8MuInstance, |
| 249 | + uint8 u8MuChannel, |
| 250 | + Hse_Ip_ReqType* pRequest, |
| 251 | + hseSrvDescriptor_t* pHseSrvDesc |
| 252 | +); |
| 253 | + |
| 254 | +/*! |
| 255 | + * @brief Function that should be called cyclically to process the requests sent using asynchronous poll method . |
| 256 | + * @details After an asynchronous poll request is sent using Hse_Ip_ServiceRequest() service, the layer on top of the Hse_Ip |
| 257 | + * should call periodically the Hse_Ip_MainFunction() in order to retrieve message processing status from HSE |
| 258 | + * and when a response is received, call the callback sent at request time. |
| 259 | + * |
| 260 | + * @param[in] u8MuInstance MU Instance number |
| 261 | + * |
| 262 | + * @return void |
| 263 | + */ |
| 264 | +void Hse_Ip_MainFunction |
| 265 | +( |
| 266 | + uint8 u8MuInstance |
| 267 | +); |
| 268 | + |
| 269 | +/*! |
| 270 | + * @brief Returns the HSE firmware status. |
| 271 | + * @details This function retrieves the global status of the HSE firmware, read from MU_FSR register. |
| 272 | + * As a note, this function can be called by the application on a MU instance even before initializing the |
| 273 | + * Hse_IP layer by calling Hse_Ip_Init() on that particular MU instance. |
| 274 | + * |
| 275 | + * @param[in] u8MuInstance MU Instance number |
| 276 | + * |
| 277 | + * @return void |
| 278 | + */ |
| 279 | +hseStatus_t Hse_Ip_GetHseStatus |
| 280 | +( |
| 281 | + uint8 u8MuInstance |
| 282 | +); |
| 283 | + |
| 284 | +/*! |
| 285 | + * @brief Registers a general purpose callback. |
| 286 | + * @details This function saves the reference to a generic callback to be called whenever an error is reported by HSE. |
| 287 | + * The signature of the callback should be: |
| 288 | + * void callback(uint8 u8MuInstance, uint32 u32HseNotifEvents) |
| 289 | + * |
| 290 | + * @param[in] u8MuInstance MU Instance number |
| 291 | + * @param[in] notifEventsMask HSE Errors to be enabled (see definition of hseError_t). |
| 292 | + * @param[in] callback Pointer to the callback function. |
| 293 | + * |
| 294 | + * @return void |
| 295 | + */ |
| 296 | +void Hse_Ip_RegisterGenericCallback |
| 297 | +( |
| 298 | + uint8 u8MuInstance, |
| 299 | + uint32 u32NotifEventsMask, |
| 300 | + Hse_Ip_pfGenericPurposeCallbackType pfCallback |
| 301 | +); |
| 302 | + |
| 303 | +/*! |
| 304 | + * @brief Sends one or more events to Hse Firmware. |
| 305 | + * @details This function helps the host application sending to the Hse Firmware one or more of the events defined in hse_status_and_errors.h header file. |
| 306 | + * |
| 307 | + * @param[in] HseHostEvent Bit map of events that can be sent to Hse (see definition of hseHostEvent_t in hse_status_and_errors.h header file). |
| 308 | + * |
| 309 | + * @return void |
| 310 | + */ |
| 311 | +void Hse_Ip_SendHseEvent |
| 312 | +( |
| 313 | + hseHostEvent_t HseHostEvent |
| 314 | +); |
| 315 | + |
| 316 | +/*! |
| 317 | + * @brief Rx interrupt handler. |
| 318 | + * @details This function processes the RX related interrupts from MU Ip layer |
| 319 | + * |
| 320 | + * @param[in] u8MuInstance MU Instance number |
| 321 | + * |
| 322 | + * @return void |
| 323 | + */ |
| 324 | +void Hse_Ip_RxIrqHandler |
| 325 | +( |
| 326 | + uint8 u8MuInstance |
| 327 | +); |
| 328 | + |
| 329 | +/*! |
| 330 | + * @brief General Purpose interrupt handler. |
| 331 | + * @details This function processes the General Purpose related interrupts from MU Ip layer |
| 332 | + * |
| 333 | + * @param[in] u8MuInstance MU Instance number |
| 334 | + * |
| 335 | + * @return void |
| 336 | + */ |
| 337 | +void Hse_Ip_GeneralPurposeIrqHandler |
| 338 | +( |
| 339 | + uint8 u8MuInstance |
| 340 | +); |
| 341 | + |
| 342 | + |
| 343 | +#define CRYPTO_43_HSE_STOP_SEC_CODE |
| 344 | +#include "Crypto_43_HSE_MemMap.h" |
| 345 | + |
| 346 | +#ifdef __cplusplus |
| 347 | +} |
| 348 | +#endif |
| 349 | + |
| 350 | +/** @} */ |
| 351 | + |
| 352 | +#endif /* HSE_IP_H */ |
| 353 | + |
0 commit comments