1 /****************************************************************************** 2 * 3 * Copyright 2010-2018, 2021 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 95 static const uint8_t PN557_SET_CONFIG_CMD_PLL_13MHZ[] = { 96 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x08, 97 0x52, 0xA2, 0x02, 0x30, 0x01, 0xE1, 0x02}; 98 99 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_13MHZ[] = { 100 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x40, 101 0x42, 0xA3, 0x02, 0x88, 0x01, 0xE2, 0x02}; 102 103 static const uint8_t PN557_SET_CONFIG_CMD_PLL_19_2MHZ[] = { 104 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x88, 105 0x51, 0xE3, 0x02, 0xB8, 0x21, 0xE1, 0x02}; 106 107 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_19_2MHZ[] = { 108 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x88, 109 0x01, 0xE2, 0x02, 0xF0, 0x00, 0xA2, 0x01}; 110 111 static const uint8_t PN557_SET_CONFIG_CMD_PLL_24MHZ[] = { 112 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x28, 113 0xC2, 0xA2, 0x83, 0x88, 0x11, 0xE1, 0x02}; 114 115 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_24MHZ[] = { 116 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x38, 117 0x41, 0xD3, 0x02, 0x88, 0x01, 0xE2, 0x02}; 118 119 static const uint8_t PN557_SET_CONFIG_CMD_PLL_26MHZ[] = { 120 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x08, 121 0x52, 0xA2, 0x82, 0x30, 0x01, 0xE1, 0x02}; 122 123 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_26MHZ[] = { 124 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x20, 125 0x41, 0xA3, 0x01, 0x88, 0x01, 0xE2, 0x02}; 126 127 static const uint8_t PN557_SET_CONFIG_CMD_PLL_32MHZ[] = { 128 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0xB8, 129 0x51, 0xA3, 0x82, 0x88, 0xF1, 0xF0, 0x02}; 130 131 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_32MHZ[] = { 132 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0xB0, 133 0x01, 0xA3, 0x82, 0x88, 0x01, 0xE2, 0x02}; 134 135 static const uint8_t PN557_SET_CONFIG_CMD_PLL_38_4MHZ[] = { 136 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x20, 0x08, 0x88, 137 0x51, 0xE3, 0x82, 0xB8, 0x21, 0xE1, 0x02}; 138 139 static const uint8_t PN557_SET_CONFIG_CMD_DPLL_38_4MHZ[] = { 140 0x20, 0x02, 0x0C, 0x01, 0xA0, 0x26, 0x08, 0x88, 141 0x01, 0xE2, 0x82, 0xF0, 0x00, 0xA2, 0x01}; 142 /* Set to one of CLK_FREQ_<value> */ 143 #define NXP_SYS_CLK_FREQ_SEL CLK_FREQ_19_2MHZ 144 145 #define CLK_TO_CFG_DEF 1 146 #define CLK_TO_CFG_MAX 6 147 148 #define CLK_REQ_DELAY_MIN 1 149 #define CLK_REQ_DELAY_MAX 31 150 #define CLK_REQ_DELAY_DEF 22 151 #define CLK_REQ_DELAY_MASK 0x1F 152 #define CLK_REQ_DELAY_PLL_OFFSET 13 153 #define CLK_REQ_DELAY_XTAL_OFFSET 14 154 /* 155 * information to configure OSAL 156 */ 157 typedef struct phOsalNfc_Config { 158 uint8_t* pLogFile; /* Log File Name*/ 159 uintptr_t dwCallbackThreadId; /* Client ID to which message is posted */ 160 } phOsalNfc_Config_t, *pphOsalNfc_Config_t /* Pointer to #phOsalNfc_Config_t */; 161 162 /* 163 * Deferred call declaration. 164 * This type of API is called from ClientApplication (main thread) to notify 165 * specific callback. 166 */ 167 typedef void (*pphOsalNfc_DeferFuncPointer_t)(void*); 168 169 /* 170 * Deferred message specific info declaration. 171 */ 172 typedef struct phOsalNfc_DeferedCallInfo { 173 pphOsalNfc_DeferFuncPointer_t pDeferedCall; /* pointer to Deferred callback */ 174 void* pParam; /* contains timer message specific details*/ 175 } phOsalNfc_DeferedCallInfo_t; 176 177 /* 178 * States in which a OSAL timer exist. 179 */ 180 typedef enum { 181 eTimerIdle = 0, /* Indicates Initial state of timer */ 182 eTimerRunning = 1, /* Indicate timer state when started */ 183 eTimerStopped = 2 /* Indicates timer state when stopped */ 184 } phOsalNfc_TimerStates_t; /* Variable representing State of timer */ 185 186 /* 187 **Timer Handle structure containing details of a timer. 188 */ 189 typedef struct phOsalNfc_TimerHandle { 190 uint32_t TimerId; /* ID of the timer */ 191 timer_t hTimerHandle; /* Handle of the timer */ 192 /* Timer callback function to be invoked */ 193 pphOsalNfc_TimerCallbck_t Application_callback; 194 void* pContext; /* Parameter to be passed to the callback function */ 195 phOsalNfc_TimerStates_t eState; /* Timer states */ 196 /* Osal Timer message posted on User Thread */ 197 phLibNfc_Message_t tOsalMessage; 198 /* Deferred Call structure to Invoke Callback function */ 199 phOsalNfc_DeferedCallInfo_t tDeferedCallInfo; 200 /* Variables for Structure Instance and Structure Ptr */ 201 } phOsalNfc_TimerHandle_t, *pphOsalNfc_TimerHandle_t; 202 203 #endif /* PHOSALNFC_H */ 204