le_spi_interface.h File Reference

#include "legato.h"

Go to the source code of this file.

Macros

#define LE_SPI_MAX_WRITE_SIZE   1024
 
#define LE_SPI_MAX_READ_SIZE   1024
 

Typedefs

typedef void(* le_spi_DisconnectHandler_t) (void *)
 
typedef struct le_spi_DeviceHandle * le_spi_DeviceHandleRef_t
 

Functions

void le_spi_ConnectService (void)
 
le_result_t le_spi_TryConnectService (void)
 
void le_spi_SetServerDisconnectHandler (le_spi_DisconnectHandler_t disconnectHandler, void *contextPtr)
 
void le_spi_DisconnectService (void)
 
le_result_t le_spi_Open (const char *LE_NONNULL deviceName, le_spi_DeviceHandleRef_t *handlePtr)
 
void le_spi_Close (le_spi_DeviceHandleRef_t handle)
 
void le_spi_Configure (le_spi_DeviceHandleRef_t handle, int32_t mode, uint8_t bits, uint32_t speed, int32_t msb)
 
le_result_t le_spi_WriteReadHD (le_spi_DeviceHandleRef_t handle, const uint8_t *writeDataPtr, size_t writeDataSize, uint8_t *readDataPtr, size_t *readDataSizePtr)
 
le_result_t le_spi_WriteHD (le_spi_DeviceHandleRef_t handle, const uint8_t *writeDataPtr, size_t writeDataSize)
 
le_result_t le_spi_ReadHD (le_spi_DeviceHandleRef_t handle, uint8_t *readDataPtr, size_t *readDataSizePtr)
 
le_result_t le_spi_WriteReadFD (le_spi_DeviceHandleRef_t handle, const uint8_t *writeDataPtr, size_t writeDataSize, uint8_t *readDataPtr, size_t *readDataSizePtr)
 

Detailed Description

Legato c_le_spi include file.

Macro Definition Documentation

#define LE_SPI_MAX_READ_SIZE   1024

Max byte storage size for read buffer

#define LE_SPI_MAX_WRITE_SIZE   1024

Max byte storage size for write buffer

Typedef Documentation

typedef struct le_spi_DeviceHandle* le_spi_DeviceHandleRef_t

Handle for passing to related functions to access the SPI device

typedef void(* le_spi_DisconnectHandler_t) (void *)

Type for handler called when a server disconnects.

Function Documentation

void le_spi_Close ( le_spi_DeviceHandleRef_t  handle)

Closes the device associated with the given handle and frees the associated resources.

Note
Once a handle is closed, it's not permitted to use it for future SPI access without first calling Open.
Parameters
[in]handleHandle for the SPI master to close
void le_spi_Configure ( le_spi_DeviceHandleRef_t  handle,
int32_t  mode,
uint8_t  bits,
uint32_t  speed,
int32_t  msb 
)

Configures an SPI device's data sample settings. The required values should be included in your target's datasheet. Most common Mode values are 0 and 3.

These are the SPI Mode options:

Mode Clock Polarity Clock Phase Clock Edge
0 0 0 1
1 0 1 0
2 1 0 1
3 1 1 0
Note
This function should be called before any of the Read/Write functions to ensure the SPI bus configuration is in a known state.
Parameters
[in]handleHandle for the SPI master to configure
[in]modeChoose mode options for the bus per above table
[in]bitsbits per word, typically 8 bits per word
[in]speedmax speed (Hz), this is slave dependant
[in]msbset as 0 for MSB as first bit or 1 for LSB as first bit
void le_spi_ConnectService ( void  )

Connect the current client thread to the service providing this API. Block until the service is available.

For each thread that wants to use this API, either ConnectService or TryConnectService must be called before any other functions in this API. Normally, ConnectService is automatically called for the main thread, but not for any other thread. For details, see Client-specific Functions.

This function is created automatically.

void le_spi_DisconnectService ( void  )

Disconnect the current client thread from the service providing this API.

Normally, this function doesn't need to be called. After this function is called, there's no longer a connection to the service, and the functions in this API can't be used. For details, see Client-specific Functions.

This function is created automatically.

le_result_t le_spi_Open ( const char *LE_NONNULL  deviceName,
le_spi_DeviceHandleRef_t handlePtr 
)

Opens an SPI device so that the attached device may be accessed.

Returns
  • LE_OK on success
  • LE_BAD_PARAMETER if the device name string is bad
  • LE_NOT_FOUND if the SPI device file could not be found
  • LE_NOT_PERMITTED if the SPI device file can't be opened for read/write
  • LE_DUPLICATE if the given device file is already opened by another spiService client
  • LE_FAULT for non-specific failures
Parameters
[in]deviceNameHandle for the SPI master to open
[out]handlePtrHandle for passing to related functions in order to access the SPI device
le_result_t le_spi_ReadHD ( le_spi_DeviceHandleRef_t  handle,
uint8_t *  readDataPtr,
size_t *  readDataSizePtr 
)

SPI Read for Half Duplex Communication

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform the read from
[out]readDataPtrRX response from slave with number of bytes reserved on master
[in,out]readDataSizePtr
void le_spi_SetServerDisconnectHandler ( le_spi_DisconnectHandler_t  disconnectHandler,
void *  contextPtr 
)

Set handler called when server disconnection is detected.

When a server connection is lost, call this handler then exit with LE_FATAL. If a program wants to continue without exiting, it should call longjmp() from inside the handler.

le_result_t le_spi_TryConnectService ( void  )

Try to connect the current client thread to the service providing this API. Return with an error if the service is not available.

For each thread that wants to use this API, either ConnectService or TryConnectService must be called before any other functions in this API. Normally, ConnectService is automatically called for the main thread, but not for any other thread. For details, see Client-specific Functions.

This function is created automatically.

Returns
  • LE_OK if the client connected successfully to the service.
  • LE_UNAVAILABLE if the server is not currently offering the service to which the client is bound.
  • LE_NOT_PERMITTED if the client interface is not bound to any service (doesn't have a binding).
  • LE_COMM_ERROR if the Service Directory cannot be reached.
le_result_t le_spi_WriteHD ( le_spi_DeviceHandleRef_t  handle,
const uint8_t *  writeDataPtr,
size_t  writeDataSize 
)

SPI Write for Half Duplex Communication

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform the write on
[in]writeDataPtrTX command/address being sent to slave with size
[in]writeDataSize
le_result_t le_spi_WriteReadFD ( le_spi_DeviceHandleRef_t  handle,
const uint8_t *  writeDataPtr,
size_t  writeDataSize,
uint8_t *  readDataPtr,
size_t *  readDataSizePtr 
)

Simultaneous SPI Write and Read for full duplex communication

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform full duplex write-read on
[in]writeDataPtrTX command/address being sent to slave with size
[in]writeDataSize
[out]readDataPtrRX response from slave with same buffer size as TX
[in,out]readDataSizePtr
le_result_t le_spi_WriteReadHD ( le_spi_DeviceHandleRef_t  handle,
const uint8_t *  writeDataPtr,
size_t  writeDataSize,
uint8_t *  readDataPtr,
size_t *  readDataSizePtr 
)

Performs SPI WriteRead Half Duplex. You can send send Read command/ address of data to read.

Returns
LE_OK on success or LE_FAULT on failure.
Parameters
[in]handleHandle for the SPI master to perform the write-read on
[in]writeDataPtrTX command/address being sent to slave with size
[in]writeDataSize
[out]readDataPtrRX response from slave with number of bytes reserved on master
[in,out]readDataSizePtr