1 /****************************************************************************** 2 * 3 * Copyright 2010-2018, 2021-2022, 2024 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 /* 19 * OSAL header files related to memory, debug, random, semaphore and mutex 20 * functions. 21 */ 22 23 #ifndef PHNFCCOMMON_H 24 #define PHNFCCOMMON_H 25 26 /* 27 ************************* Include Files **************************************** 28 */ 29 30 #include <phDal4Nfc_messageQueueLib.h> 31 #include <phNfcCompId.h> 32 #include <phNfcStatus.h> 33 #include <phOsalNfc_Timer.h> 34 #include <pthread.h> 35 #include <semaphore.h> 36 37 #define FW_DLL_ROOT_DIR "/system/vendor/" 38 #define FW_DLL_EXTENSION ".so" 39 40 /* Actual FW library name*/ 41 /* Restore Corrupted PLL Settings/etc */ 42 #define PLATFORM_LIB_PATH \ 43 FW_DLL_ROOT_DIR "libsn100u_fw_platform" FW_DLL_EXTENSION 44 /* Upgrade the public Key */ 45 #define PKU_LIB_PATH FW_DLL_ROOT_DIR "libsn100u_fw_pku" FW_DLL_EXTENSION 46 47 /* HAL Version number (Updated as per release) */ 48 #define NXP_MW_VERSION_MAJ (0x03) 49 #define NXP_MW_VERSION_MIN (0x02) 50 51 #define GET_EEPROM_DATA (1U) 52 #define SET_EEPROM_DATA (2U) 53 54 #define BITWISE (1U) 55 #define BYTEWISE (2U) 56 57 #define GET_FW_DWNLD_FLAG (1U) 58 #define RESET_FW_DWNLD_FLAG (2U) 59 60 #define FLASH_UPPER_VERSION (1) 61 #define FLASH_DIFFERENT_VERSION (2) 62 #define FLASH_ALWAYS (3) 63 /* 64 ***************************************************************** 65 *********** System clock source selection configuration ******** 66 ***************************************************************** 67 */ 68 69 #define CLK_SRC_UNDEF 0 70 #define CLK_SRC_XTAL 1 71 #define CLK_SRC_PLL 2 72 #define CLK_SRC_PADDIRECT 3 73 #define CLK_CFG_XTAL 8 74 75 /*Extern crystal clock source*/ 76 /* Use one of CLK_SRC_<value> */ 77 #define NXP_SYS_CLK_SRC_SEL CLK_SRC_PLL 78 /*Direct clock*/ 79 80 /* 81 ***************************************************************** 82 *********** System clock frequency selection configuration **************** 83 * If Clk_Src is set to PLL, make sure to set the Clk_Freq also* 84 ***************************************************************** 85 */ 86 #define CLK_FREQ_UNDEF 0 87 #define CLK_FREQ_13MHZ 1 88 #define CLK_FREQ_19_2MHZ 2 89 #define CLK_FREQ_24MHZ 3 90 #define CLK_FREQ_26MHZ 4 91 #define CLK_FREQ_38_4MHZ 5 92 #define CLK_FREQ_52MHZ 6 93 #define CLK_FREQ_32MHZ 7 94 #define CLK_FREQ_48MHZ 8 95 #define CLK_FREQ_76_8MHZ 9 96 97 static const uint8_t PN557_SET_CONFIG_CMD_PLL_13MHZ[] = { 98 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x08, 99 0x52, 0xA2, 0x02, 0x30, 0x01, 0xE1, 0x02}; 100 101 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_13MHZ[] = { 102 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x40, 103 0x42, 0xA3, 0x02, 0x88, 0x01, 0xE2, 0x02}; 104 105 static const uint8_t PN557_SET_CONFIG_CMD_PLL_19_2MHZ[] = { 106 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x88, 107 0x51, 0xE3, 0x02, 0xB8, 0x21, 0xE1, 0x02}; 108 109 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_19_2MHZ[] = { 110 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x88, 111 0x01, 0xE2, 0x02, 0xF0, 0x00, 0xA2, 0x01}; 112 113 static const uint8_t PN557_SET_CONFIG_CMD_PLL_24MHZ[] = { 114 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x28, 115 0xC2, 0xA2, 0x83, 0x88, 0x11, 0xE1, 0x02}; 116 117 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_24MHZ[] = { 118 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x38, 119 0x41, 0xD3, 0x02, 0x88, 0x01, 0xE2, 0x02}; 120 121 static const uint8_t PN557_SET_CONFIG_CMD_PLL_26MHZ[] = { 122 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x08, 123 0x52, 0xA2, 0x82, 0x30, 0x01, 0xE1, 0x02}; 124 125 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_26MHZ[] = { 126 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x20, 127 0x41, 0xA3, 0x01, 0x88, 0x01, 0xE2, 0x02}; 128 129 static const uint8_t PN557_SET_CONFIG_CMD_PLL_32MHZ[] = { 130 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0xB8, 131 0x51, 0xA3, 0x82, 0x88, 0xF1, 0xF0, 0x02}; 132 133 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_32MHZ[] = { 134 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0xB0, 135 0x01, 0xA3, 0x82, 0x88, 0x01, 0xE2, 0x02}; 136 137 static const uint8_t PN557_SET_CONFIG_CMD_PLL_38_4MHZ[] = { 138 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x88, 139 0x51, 0xE3, 0x82, 0xB8, 0x21, 0xE1, 0x02}; 140 141 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_38_4MHZ[] = { 142 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x88, 143 0x01, 0xE2, 0x82, 0xF0, 0x00, 0xA2, 0x01}; 144 145 static const uint8_t PN557_SET_CONFIG_CMD_PLL_48MHZ[] = { 146 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x38, 147 0x51, 0xD3, 0x82, 0x58, 0xE1, 0xE0, 0x02}; 148 149 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_48MHZ[] = { 150 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x38, 151 0x41, 0xD3, 0x82, 0x88, 0x01, 0xE2, 0x02}; 152 /* Set to one of CLK_FREQ_<value> */ 153 #define NXP_SYS_CLK_FREQ_SEL CLK_FREQ_19_2MHZ 154 155 #define CLK_TO_CFG_DEF 1 156 #define CLK_TO_CFG_MAX 6 157 158 #define CLK_REQ_DELAY_MIN 1 159 #define CLK_REQ_DELAY_MAX 31 160 #define CLK_REQ_DELAY_DEF 22 161 #define CLK_REQ_DELAY_MASK 0x1F 162 #define CLK_REQ_DELAY_PLL_OFFSET 13 163 #define CLK_REQ_DELAY_XTAL_OFFSET 14 164 /* 165 * information to configure OSAL 166 */ 167 typedef struct phOsalNfc_Config { 168 uint8_t* pLogFile; /* Log File Name*/ 169 uintptr_t dwCallbackThreadId; /* Client ID to which message is posted */ 170 } phOsalNfc_Config_t, *pphOsalNfc_Config_t /* Pointer to #phOsalNfc_Config_t */; 171 172 /* 173 * Deferred call declaration. 174 * This type of API is called from ClientApplication (main thread) to notify 175 * specific callback. 176 */ 177 typedef void (*pphOsalNfc_DeferFuncPointer_t)(void*); 178 179 /* 180 * Deferred message specific info declaration. 181 */ 182 typedef struct phOsalNfc_DeferedCallInfo { 183 pphOsalNfc_DeferFuncPointer_t pDeferedCall; /* pointer to Deferred callback */ 184 void* pParam; /* contains timer message specific details*/ 185 } phOsalNfc_DeferedCallInfo_t; 186 187 /* 188 * States in which a OSAL timer exist. 189 */ 190 typedef enum { 191 eTimerIdle = 0, /* Indicates Initial state of timer */ 192 eTimerRunning = 1, /* Indicate timer state when started */ 193 eTimerStopped = 2 /* Indicates timer state when stopped */ 194 } phOsalNfc_TimerStates_t; /* Variable representing State of timer */ 195 196 /* 197 **Timer Handle structure containing details of a timer. 198 */ 199 typedef struct phOsalNfc_TimerHandle { 200 uint32_t TimerId; /* ID of the timer */ 201 timer_t hTimerHandle; /* Handle of the timer */ 202 /* Timer callback function to be invoked */ 203 pphOsalNfc_TimerCallbck_t Application_callback; 204 void* pContext; /* Parameter to be passed to the callback function */ 205 phOsalNfc_TimerStates_t eState; /* Timer states */ 206 /* Osal Timer message posted on User Thread */ 207 phLibNfc_Message_t tOsalMessage; 208 /* Deferred Call structure to Invoke Callback function */ 209 phOsalNfc_DeferedCallInfo_t tDeferedCallInfo; 210 /* Variables for Structure Instance and Structure Ptr */ 211 } phOsalNfc_TimerHandle_t, *pphOsalNfc_TimerHandle_t; 212 213 #endif /* PHOSALNFC_H */ 214