Home | History | Annotate | Download | only in pal
      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
     21  * \brief PAL implementation
     22  * @{ */
     23 
     24 #ifndef _PHNXPESE_PAL_H
     25 #define _PHNXPESE_PAL_H
     26 
     27 #define LOG_TAG "NxpEseHal"
     28 
     29 /* Basic type definitions */
     30 #include <errno.h>
     31 #include <phEseStatus.h>
     32 #include <phNxpEseFeatures.h>
     33 /*!
     34  * \brief Value indicates to reset device
     35  */
     36 #define PH_PALESE_RESETDEVICE (0x00008001)
     37 
     38 /*!
     39  * \ingroup eSe_PAL
     40  *
     41  * \brief Enum definition contains supported ioctl control codes.
     42  *
     43  * phPalEse_IoCtl
     44  */
     45 typedef enum {
     46   phPalEse_e_Invalid = 0,                         /*!< Invalid control code */
     47   phPalEse_e_ResetDevice = PH_PALESE_RESETDEVICE, /*!< Reset the device */
     48   phPalEse_e_EnableLog,      /*!< Enable the spi driver logs */
     49   phPalEse_e_EnablePollMode, /*!< Enable the polling for SPI */
     50   phPalEse_e_GetEseAccess,   /*!< get the bus access in specified timeout */
     51   phPalEse_e_ChipRst,        /*!< eSE Chip reset using ISO RST pin*/
     52   phPalEse_e_EnableThroughputMeasurement, /*!< Enable throughput measurement */
     53   phPalEse_e_SetPowerScheme,              /*!< Set power scheme */
     54   phPalEse_e_GetSPMStatus,                /*!< Get SPM(power mgt) status */
     55   phPalEse_e_DisablePwrCntrl
     56 #ifdef NXP_ESE_JCOP_DWNLD_PROTECTION
     57   ,
     58   phPalEse_e_SetJcopDwnldState, /*!< Set Jcop Download state */
     59 #endif
     60 } phPalEse_ControlCode_t; /*!< Control code for IOCTL call */
     61 
     62 /*!
     63  * \ingroup eSe_PAL
     64  *
     65  * \brief PAL Configuration exposed to upper layer.
     66  */
     67 typedef struct phPalEse_Config {
     68   int8_t* pDevName;
     69   /*!< Port name connected to ESE
     70    *
     71    * Platform specific canonical device name to which ESE is connected.
     72    *
     73    * e.g. On Linux based systems this would be /dev/p73
     74    */
     75 
     76   uint32_t dwBaudRate;
     77   /*!< Communication speed between DH and ESE
     78    *
     79    * This is the baudrate of the bus for communication between DH and ESE
     80    */
     81 
     82   void* pDevHandle;
     83   /*!< Device handle output */
     84 } phPalEse_Config_t, *pphPalEse_Config_t; /* pointer to phPalEse_Config_t */
     85 
     86 /* Function declarations */
     87 /**
     88  * \ingroup eSe_PAL
     89  * \brief This function is used to close the ESE device
     90  *
     91  * \retval None
     92  *
     93  */
     94 void phPalEse_close(void* pDevHandle);
     95 
     96 /**
     97  * \ingroup eSe_PAL
     98  * \brief Open and configure ESE device
     99  *
    100  * \param[in]       pphPalEse_Config_t: Config to open the device
    101  *
    102  * \retval  ESESTATUS On Success ESESTATUS_SUCCESS else proper error code
    103  *
    104  */
    105 ESESTATUS phPalEse_open_and_configure(pphPalEse_Config_t pConfig);
    106 
    107 /**
    108  * \ingroup eSe_PAL
    109  * \brief Reads requested number of bytes from ESE into given buffer
    110  *
    111  * \param[in]    pDevHandle       - valid device handle
    112  **\param[in]    pBuffer           - buffer for read data
    113  **\param[in]    nNbBytesToRead    - number of bytes requested to be read
    114  *
    115  * \retval   numRead      - number of successfully read bytes.
    116  * \retval      -1             - read operation failure
    117  *
    118  */
    119 int phPalEse_read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead);
    120 
    121 /**
    122  * \ingroup eSe_PAL
    123  * \brief Writes requested number of bytes from given buffer into pn547 device
    124  *
    125  * \param[in]    pDevHandle                 - valid device handle
    126  * \param[in]    pBuffer                    - buffer to write
    127  * \param[in]    nNbBytesToWrite            - number of bytes to write
    128  *
    129  * \retval  numWrote   - number of successfully written bytes
    130  * \retval      -1         - write operation failure
    131  *
    132  */
    133 int phPalEse_write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite);
    134 
    135 /**
    136  * \ingroup eSe_PAL
    137  * \brief Exposed ioctl by ESE driver
    138  *
    139  * \param[in]    eControlCode       - phPalEse_ControlCode_t for the respective
    140  *configs
    141  * \param[in]    pDevHandle         - valid device handle
    142  * \param[in]    pBuffer            - buffer for read data
    143  * \param[in]    level              - reset level
    144  *
    145  * \retval    0   - ioctl operation success
    146  * \retval   -1  - ioctl operation failure
    147  *
    148  */
    149 ESESTATUS phPalEse_ioctl(phPalEse_ControlCode_t eControlCode, void* pDevHandle,
    150                          long level);
    151 
    152 /**
    153  * \ingroup eSe_PAL
    154  * \brief Print packet data
    155  *
    156  * \param[in]    pString            - String to be printed
    157  * \param[in]    p_data             - data to be printed
    158  * \param[in]    len                - Length of data to be printed
    159  *
    160  * \retval   void
    161  *
    162  */
    163 void phPalEse_print_packet(const char* pString, const uint8_t* p_data,
    164                            uint16_t len);
    165 
    166 /**
    167  * \ingroup eSe_PAL
    168  * \brief This function  suspends execution of the calling thread for
    169  *                  (at least) usec microseconds
    170  *
    171  * \param[in]    usec                - number of micro seconds to sleep
    172  *
    173  * \retval   void
    174  *
    175  */
    176 void phPalEse_sleep(long usec);
    177 
    178 /**
    179  * \ingroup eSe_PAL
    180  * \brief This function updates destination buffer with val
    181  *                 data in len size
    182  *
    183  * \param[in]    buff                - Array to be udpated
    184  * \param[in]    val                 - value to be updated
    185  * \param[in]    len                 - length of array to be updated
    186  *
    187  * \retval   void
    188  *
    189  */
    190 void* phPalEse_memset(void* buff, int val, size_t len);
    191 
    192 /**
    193  * \ingroup eSe_PAL
    194  * \brief This function copies source buffer to  destination buffer
    195  *                 data in len size
    196  *
    197  * \param[in]    dest                - Destination array to be updated
    198  * \param[in]    src                 - Source array to be updated
    199  * \param[in]    len                 - length of array to be updated
    200  *
    201  * \retval   void
    202  *
    203  */
    204 void* phPalEse_memcpy(void* dest, const void* src, size_t len);
    205 
    206 /**
    207  * \ingroup eSe_PAL
    208  * \brief This is utility function for runtime heap memory allocation
    209  *
    210  * \param[in]    size                 - number of bytes to be allocated
    211  *
    212  * \retval   void
    213  *
    214  */
    215 void* phPalEse_memalloc(uint32_t size);
    216 
    217 /**
    218  * \ingroup eSe_PAL
    219  * \brief This is utility function for runtime heap memory allocation
    220  *
    221  * \param[in]    len                 - number of bytes to be allocated
    222  *
    223  * \retval   void
    224  *
    225  */
    226 void* phPalEse_calloc(size_t dataType, size_t size);
    227 
    228 /**
    229  * \ingroup eSe_PAL
    230  * \brief This is utility function for freeeing heap memory allocated
    231  *
    232  * \param[in]    ptr                 - Address pointer to previous allocation
    233  *
    234  * \retval   void
    235  *
    236  */
    237 void phPalEse_free(void* ptr);
    238 
    239 /** @} */
    240 #endif /*  _PHNXPESE_PAL_H    */
    241