1 /****************************************************************************** 2 * 3 * Copyright 2018 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 /** 20 * \addtogroup eSe_PAL_Spi 21 * \brief PAL SPI port implementation for linux 22 * @{ */ 23 #ifndef _PHNXPESE_PAL_SPI_H 24 #define _PHNXPESE_PAL_SPI_H 25 26 /* Basic type definitions */ 27 #include <phNxpEsePal.h> 28 29 /*! 30 * \brief Start of frame marker 31 */ 32 #define SEND_PACKET_SOF 0x5A 33 /*! 34 * \brief ESE Poll timeout (max 2 seconds) 35 */ 36 #define ESE_POLL_TIMEOUT (2 * 1000) 37 /*! 38 * \brief ESE Poll timeout (max 2 seconds) 39 */ 40 #define ESE_NAD_POLLING_MAX (2 * 1000) 41 42 /*! 43 * \brief ESE wakeup delay in case of write error retry 44 */ 45 #define WRITE_WAKE_UP_DELAY 1000 46 47 /*! 48 * \brief ESE SOF polling delay 49 */ 50 #define READ_WAKE_UP_DELAY 100 51 52 /*! 53 * \brief ESE wakeup delay in case of write error retry 54 */ 55 #define NAD_POLLING_SCALER 10 56 57 /* Function declarations */ 58 /** 59 * \ingroup eSe_PAL_Spi 60 * \brief This function is used to close the ESE device 61 * 62 * \retval None 63 * 64 */ 65 66 void phPalEse_spi_close(void* pDevHandle); 67 68 /** 69 * \ingroup eSe_PAL_Spi 70 * \brief Open and configure ESE device 71 * 72 * \param[in] pphPalEse_Config_t: Config to open the device 73 * 74 * \retval ESESTATUS On Success ESESTATUS_SUCCESS else proper error code 75 * 76 */ 77 ESESTATUS phPalEse_spi_open_and_configure(pphPalEse_Config_t pConfig); 78 79 /** 80 * \ingroup eSe_PAL_Spi 81 * \brief Reads requested number of bytes from ESE into given buffer 82 * 83 * \param[in] pDevHandle - valid device handle 84 **\param[in] pBuffer - buffer for read data 85 **\param[in] nNbBytesToRead - number of bytes requested to be read 86 * 87 * \retval numRead - number of successfully read bytes. 88 * \retval -1 - read operation failure 89 * 90 */ 91 int phPalEse_spi_read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead); 92 93 /** 94 * \ingroup eSe_PAL_Spi 95 * \brief Writes requested number of bytes from given buffer into pn547 device 96 * 97 * \param[in] pDevHandle - valid device handle 98 * \param[in] pBuffer - buffer to write 99 * \param[in] nNbBytesToWrite - number of bytes to write 100 * 101 * \retval numWrote - number of successfully written bytes 102 * \retval -1 - write operation failure 103 * 104 */ 105 int phPalEse_spi_write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite); 106 107 /** 108 * \ingroup eSe_PAL_Spi 109 * \brief Exposed ioctl by ESE driver 110 * 111 * \param[in] eControlCode - phPalEse_ControlCode_t for the respective 112 *configs 113 * \param[in] pDevHandle - valid device handle 114 * \param[in] pBuffer - buffer for read data 115 * \param[in] level - reset level 116 * 117 * \retval 0 - ioctl operation success 118 * \retval -1 - ioctl operation failure 119 * 120 */ 121 ESESTATUS phPalEse_spi_ioctl(phPalEse_ControlCode_t eControlCode, 122 void* pDevHandle, long level); 123 124 /** 125 * \ingroup eSe_PAL_Spi 126 * \brief Print packet data 127 * 128 * \param[in] pString - String to be printed 129 * \param[in] p_data - data to be printed 130 * \param[in] len - Length of data to be printed 131 * 132 * \retval void 133 * 134 */ 135 void phPalEse_spi_print_packet(const char* pString, const uint8_t* p_data, 136 uint16_t len); 137 /** 138 * \ingroup eSe_PAL_Spi 139 * \brief This function suspends execution of the calling thread for 140 * (at least) usec microseconds 141 * 142 * \param[in] usec - number of micro seconds to sleep 143 * 144 * \retval void 145 * 146 */ 147 void phPalEse_spi_sleep(uint32_t usec); 148 /** @} */ 149 #endif /* _PHNXPESE_PAL_SPI_H */ 150