1 /* -------------------------------------------------------------------------- */ 2 /* Copyright 2020-2024 NXP */ 3 /* All rights reserved. */ 4 /* SPDX-License-Identifier: BSD-3-Clause */ 5 /* -------------------------------------------------------------------------- */ 6 7 #ifndef _FWK_PLATFORM_H_ 8 #define _FWK_PLATFORM_H_ 9 10 /*! 11 * @addtogroup FWK_Platform_module 12 * The FWK_Platform module 13 * 14 * FWK_Platform module provides APIs to set platform parameters. 15 * @{ 16 */ 17 /*! 18 * @addtogroup FWK_Platform 19 * The FWK_Platform main module 20 * 21 * FWK_Platform main module provides APIs to set main platform parameters. 22 * @{ 23 */ 24 25 /* -------------------------------------------------------------------------- */ 26 /* Includes */ 27 /* -------------------------------------------------------------------------- */ 28 29 #include "EmbeddedTypes.h" 30 #include <stdbool.h> 31 32 /* -------------------------------------------------------------------------- */ 33 /* Definitions */ 34 /* -------------------------------------------------------------------------- */ 35 36 /*! 37 * \brief type definition for the list of constraint frequency available on the nbu 38 * 39 */ 40 typedef enum 41 { 42 PLATFORM_NBU_MIN_FREQ_16MHZ, 43 PLATFORM_NBU_MIN_FREQ_24MHZ, 44 PLATFORM_NBU_MIN_FREQ_32MHZ, 45 PLATFORM_NBU_MIN_FREQ_48MHZ, 46 PLATFORM_NBU_MIN_FREQ_64MHZ, /* LDO core output voltage needs to be set to 1.1V to support 64MHz on nbu */ 47 } PLATFORM_NbuConstraintFrequency_t; 48 49 /*! 50 * \brief Error callback used to handle error at platform level that can be registered with 51 * PLATFORM_RegisterErrorCallback() 52 * 53 * \param[in] id of the caller of the callback. 54 * \param[in] error_status given by the caller of the callback. 55 * 56 */ 57 typedef void (*PLATFORM_ErrorCallback_t)(uint32_t id, int32_t error_status); 58 59 /*! 60 * \brief type definition for platform functions IDs used by the error callback system 61 * 62 */ 63 typedef enum 64 { 65 /* PLATFORM */ 66 PLATFORM_REMOTE_ACTIVE_REQ_ID, 67 /* PLATFORM_BLE */ 68 PLATFORM_INIT_BLE_ID, 69 PLATFORM_SEND_HCI_MESSAGE_ID, 70 } PLATFORM_Id_t; 71 72 /* -------------------------------------------------------------------------- */ 73 /* Public functions declaration */ 74 /* -------------------------------------------------------------------------- */ 75 #if defined(__cplusplus) 76 extern "C" { 77 #endif /* __cplusplus */ 78 79 /*! 80 * \brief Initialize NBU 81 * 82 * \return int 0 if success, 1 if already initialized, negative value if error. 83 */ 84 int PLATFORM_InitNbu(void); 85 86 /*! 87 * \brief Initialize of the multicore 88 * 89 * \return int 0 if success, negative if error. 90 */ 91 int PLATFORM_InitMulticore(void); 92 93 /*! 94 * \brief get 4 words of information that uniquely identifies the MCU 95 * 96 * \param[out] aOutUid16B pointer to UID bytes 97 * \param[out] pOutLen pointer to UID length 98 */ 99 void PLATFORM_GetMCUUid(uint8_t *aOutUid16B, uint8_t *pOutLen); 100 101 /*! 102 * \brief Request Radio domain to be active 103 * 104 * On return from this function, the Radio domain and all its HW ressources can be accessed safely 105 * until PLATFORM_RemoteActiveRel() is called 106 * 107 */ 108 void PLATFORM_RemoteActiveReq(void); 109 110 /*! 111 * \brief Release Radio domain from being active 112 * 113 * On return from this function, the Radio domain and all its HW ressources can not be accessed 114 * if the radio domain has turned into lowpower, 115 * Need to call PLATFORM_RemoteActiveReq() for accessing safely to the ressources it contains 116 * 117 */ 118 void PLATFORM_RemoteActiveRel(void); 119 120 /*! 121 * \brief Returns current timestamp in us 122 * 123 * \return uint64_t timestamp in us 124 */ 125 uint64_t PLATFORM_GetTimeStamp(void); 126 127 /*! 128 * \brief Returns the max timestamp value that can be returned by PLATFORM_GetTimeStamp 129 * Can be used by the user to handle timestamp wrapping 130 * 131 * \return uint64_t the max timestamp value 132 */ 133 uint64_t PLATFORM_GetMaxTimeStamp(void); 134 135 /*! 136 * \brief Tells if the timeout is expired 137 * 138 * \param[in] timestamp in us 139 * \param[in] delayUs time delay in us 140 * 141 * \return bool returns if timeout is expired 142 * 143 */ 144 bool PLATFORM_IsTimeoutExpired(uint64_t timestamp, uint64_t delayUs); 145 146 /*! 147 * \brief wait for the given delay in us 148 * 149 * \param[in] delayUs time delay in us 150 * 151 */ 152 void PLATFORM_Delay(uint64_t delayUs); 153 154 /*! 155 * \brief wait for the given delay in us starting from 156 * given Timestamp. Timestamp shall be get from PLATFORM_GetTimeStamp() 157 * 158 * \param[in] timestamp in us 159 * \param[in] delayUs time delay in us 160 * 161 */ 162 void PLATFORM_WaitTimeout(uint64_t timestamp, uint64_t delayUs); 163 164 /*! 165 * \brief Set the frequency constraint to the nbu for the host 166 * Nbu will choose the frequency to apply to its core depending this value and the value set in the controller 167 * directly. It will take the value the much higher between the two constraint. 168 * 169 * \note If a value higher than 32MHz is set, the LDO core output voltage needs to be set to 1.1V. 170 * 171 * \param[in] freq_constraint See PLATFORM_NbuConstraintFrequency_t 172 * 173 */ 174 void PLATFORM_SetNbuConstraintFrequency(PLATFORM_NbuConstraintFrequency_t freq_constraint); 175 176 /*! 177 * \brief Register error callback for platform functions 178 * 179 * \param[in] cb error callback for platform module 180 * 181 */ 182 void PLATFORM_RegisterErrorCallback(PLATFORM_ErrorCallback_t cb); 183 184 /*! 185 * \brief Query whether NBU is started so that messages could be sent to it without 186 * causing any problem. 187 * 188 * \note This function is used to avoid blocking of PLATFORM_FwkSrvSendPacket if NBU core 189 * is not expecting messages yet. 190 * 191 * \return 0 if NBU was not started yet, 1 otherwise. 192 * 193 */ 194 int PLATFORM_IsNbuStarted(void); 195 196 /*! 197 * \brief Detect if wake up from power down or Deep power down and clear IO isolation if true 198 * 199 * \return 1 if wakeup from power down or deep power down modes and IO isolation is cleared 200 * 0 Otherwise 201 * 202 */ 203 int PLATFORM_ClearIoIsolationFromLowPower(void); 204 205 #if defined(__cplusplus) 206 } 207 #endif /* __cplusplus */ 208 209 /*! 210 * @} end of FWK_Platform addtogroup 211 */ 212 /*! 213 * @} end of FWK_Platform_module addtogroup 214 */ 215 #endif /* _FWK_PLATFORM_H_ */ 216