1 /****************************************************************************** 2 * 3 * Copyright (C) 2018 ST Microelectronics S.A. 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 #ifndef SPILAYERDRIVER_H_ 20 #define SPILAYERDRIVER_H_ 21 22 #include <fcntl.h> 23 #include <linux/spi/spidev.h> 24 #include <stdint.h> 25 #include <stdio.h> 26 #include <sys/ioctl.h> 27 #include <unistd.h> 28 #include "SpiLayerInterface.h" 29 30 #define ATP_FILE_PATH "/data/vendor/ese/atp.bin" 31 32 #define MODE_TX 0 33 #define MODE_RX 1 34 #define MIN_TIME_BETWEEN_MODE_SWITCH 1 35 #define ST54J_SE_MAGIC 0xE5 36 #define ST54J_SE_PULSE_RESET _IOR(ST54J_SE_MAGIC, 0x01, unsigned int) 37 38 /** 39 * Initialize internal variables. 40 * 41 * @return null 42 */ 43 44 void SpiLayerDriver_init(SpiDriver_config_t* tSpiDriver); 45 46 /** 47 * Open the spi device driver. 48 * 49 * @return -1 if an error occurred, file descriptor if success. 50 */ 51 int SpiLayerDriver_open(char *spiDevPath); 52 53 /** 54 * Close the spi device driver. 55 * 56 */ 57 void SpiLayerDriver_close(); 58 59 /** 60 * Reads bytesToRead bytes from the SPI interface. 61 * 62 * @param rxBuffer The buffer where the received bytes are stored. 63 * @param bytesToRead The expected number of bytes to be read. 64 * 65 * @return The amount of bytes read from the slave, -1 if something failed. 66 */ 67 int SpiLayerDriver_read(uint8_t *rxBuffer, unsigned int bytesToRead); 68 69 /** 70 * Write txBufferLength bytes to the SPI interface. 71 * 72 * @param txBuffer The buffer where the bytes to write are placed. 73 * @param txBufferLength The number of bytes to be written. 74 * 75 * @return The amount of bytes written to the slave, -1 if something failed. 76 */ 77 int SpiLayerDriver_write(uint8_t *writeBuffer, unsigned int bytesToWrite); 78 79 /** 80 * Send a Reset pulse to the eSE. 81 * 82 * @return 0 if success, -1 if something failed. 83 */ 84 int SpiLayerDriver_reset(); 85 86 #endif /* SPILAYERDRIVER_H_ */ 87