| Samsung Internal API reference 2.0

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

Data Structures | Typedefs | Functions
SPI API
Samsung Internal API

## Data Structures
struct | TEES_SPIConfig
| Configuration of SPI device. More...
struct | TEES_SPITransfer
| Descriptor to transfer data over SPI. More...

## Typedefs
typedef struct __TEES_SPIHandlerImpl * | TEES_SPIHandler

## Functions
TEE_Result | TEES_SPIDMAInit (uintptr_t address)
| Initialize DMA for working with SPI device. More...
TEE_Result | TEES_SPIInit (uint32_t port, const TEES_SPIConfig *cfg, TEES_SPIHandler *handler)
| Initialize handler fields. More...
TEE_Result | TEES_SPIExit (TEES_SPIHandler handler)
| Free handler resource. More...
TEE_Result | TEES_SPISetConfig (TEES_SPIHandler handler, const TEES_SPIConfig *cfg)
| Initialize handler with configuration values. More...
TEE_Result | TEES_SPISetClockSpeed (TEES_SPIHandler handler, uint32_t speedHz)
| Set clock frequency rate. More...
TEE_Result | TEES_SPISetBitsPerWord (TEES_SPIHandler handler, uint8_t bitsPerWord)
| Set the number of bits that will be transferred per SPI rate. More...
TEE_Result | TEES_SPISetDMAMode (TEES_SPIHandler handler, bool isEnabled)
| Enable or disable DMA mode. More...
TEE_Result | TEES_SPISetCPOL (TEES_SPIHandler handler, uint8_t cpol)
| Set SPI clock polarity bit. More...
TEE_Result | TEES_SPISetCPHA (TEES_SPIHandler handler, uint8_t cpha)
| Set SPI clock phase bit. More...
TEE_Result | TEES_SPIClockEnable (TEES_SPIHandler handler)
| Not implemented. More...
TEE_Result | TEES_SPIClockDisable (TEES_SPIHandler handler)
| Not implemented. More...
TEE_Result | TEES_SPIWrite (TEES_SPIHandler handler, TEES_SPITransfer *tx)
| Transfer data from buffer bus to SPI. More...
TEE_Result | TEES_SPIRead (TEES_SPIHandler handler, TEES_SPITransfer *rx)
| Transfer data from SPI bus to buffer. More...
TEE_Result | TEES_SPIWriteRead (TEES_SPIHandler handler, TEES_SPITransfer *tx, TEES_SPITransfer *rx)
| Transfer data from buffer to SPI bus. More...

## Detailed Description

Provides set of functions to manipulate device connected with SPI bus.

## Data Structure Documentation

struct TEES_SPIConfig

Configuration of SPI device.

Data Fields
uint8_t | bitsPerWord | Word size used to transfer data.
uint8_t | CPHA | Clock phase.
uint8_t | CPOL | Clock polarity.
bool | isDMAMode | Use DMA with SPI device for each transfer.
bool | manualClockControl | SPI clocks are controlled manually. SPI driver shouldn't enable/disable clocks for transfers.
uint32_t | speedHz | Clock rate to be used with SPI device for each transfer.

struct TEES_SPITransfer

Descriptor to transfer data over SPI.

Data Fields
void * | bufAddr | Buffer to be transmitted or received over SPI.
size_t | bufLen | Size of buffer in bytes.
size_t | transferredLen | Actual transfered size in bytes (for client information).

## Typedef Documentation

TEES_SPIHandler

`#include <tee_spi.h>`

SPI handler structure

## Function Documentation

TEE_Result TEES_SPIClockDisable | ( | TEES_SPIHandler | handler | ) |

`#include <tee_spi.h>`

Not implemented.

Parameters

  [in] | handler | SPI handler which contains device descriptor.

Returns
  TEE_SUCCESS - In case of success.

TEE_Result TEES_SPIClockEnable | ( | TEES_SPIHandler | handler | ) |

`#include <tee_spi.h>`

Not implemented.

Parameters

  [in] | handler | SPI handler which contains device descriptor.

Returns
  TEE_SUCCESS - In case of success.

TEE_Result TEES_SPIDMAInit | ( | uintptr_t | address | ) |

`#include <tee_spi.h>`

Initialize DMA for working with SPI device.

Parameters

  [in] | address | DMA address base.

Returns
  TEE_SUCCESS - In case of success.

TEE_Result TEES_SPIExit | ( | TEES_SPIHandler | handler | ) |

`#include <tee_spi.h>`

Free handler resource.

Parameters

  [in] | handler | SPI handler which contains device descriptor.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler handler;
TEES_SPIConfig cfg = {
.speedHz = 5000000,
.CPOL = 0,
.CPHA = 0,
.bitsPerWord = SPI_TYPE_WORD,
.isDMAMode = true,
};
TEES_SPIDMAInit(pa);
TEE_Result res = TEES_SPIInit(port, NULL, &handler);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to initalize SPI, tee_err: %#x\n", res);
return res;
}
res = TEES_SPISetConfig(handler, &cfg);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to configure SPI, tee_err: %#x\n", res);
TEES_SPIExit(handler);
return res;
}
…

TEE_Result TEES_SPIInit | ( | uint32_t | port,
|  | const TEES_SPIConfig * | cfg,
|  | TEES_SPIHandler * | handler
| ) |  |

`#include <tee_spi.h>`

Initialize handler fields.

Parameters

  [in] | port | Number of SPI controller.
  [in] | cfg | Pointer to SPI configuration for port initialisation.
  [out] | handler | Pointer to SPI handler which contains device descriptor.

Return values

  TEE_SUCCESS | on success.
  TEE_ERROR_OUT_OF_MEMORY | on failure.

Example:

TEES_SPIHandler handler;
TEES_SPIConfig cfg = {
.speedHz = 5000000,
.CPOL = 0,
.CPHA = 0,
.bitsPerWord = SPI_TYPE_WORD,
.isDMAMode = true,
};
unsigned long pa = 0;
unsigned int port = 0;
TEES_SPIDMAInit(pa);
TEE_Result res = TEES_SPIInit(port, NULL, &handler);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to initalize SPI, tee_err: %#x\n", res);
return res;
}

TEE_Result TEES_SPIRead | ( | TEES_SPIHandler | handler,
|  | TEES_SPITransfer * | rx
| ) |  |

`#include <tee_spi.h>`

Transfer data from SPI bus to buffer.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [out] | rx | Pointer to buffer to store data.

Return values

  TEE_SUCCESS | on success.
  TEE_ERROR_GENERIC | on failure.

Example:

TEES_SPIHandler handler;
TEES_SPIConfig cfg = {
.speedHz = 5000000,
.CPOL = 0,
.CPHA = 0,
.bitsPerWord = SPI_TYPE_WORD,
.isDMAMode = true
};
TEES_SPIDMAInit(pa);
TEE_Result res = TEES_SPIInit(port, &cfg, &handler);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to initalize SPI, tee_err: %#x\n", res);
return res;
}
TEES_SPITransfer rx = {
.bufAddr = (void *)(pa + DMA_RX_OFFSET),
.bufLen = buflen,
.transferredLen = 0
};
res = TEES_SPIRead(handler, &rx);
if (TEES_SPIExit(handler)) {
TEE_Panic(0);
}
if (rx.transferredLen == 0) {
printf("TEST: nothing was transferred over SPI, err: %#x\n", res);
return TEE_ERROR_GENERIC;
}

TEE_Result TEES_SPISetBitsPerWord | ( | TEES_SPIHandler | handler,
|  | uint8_t | bitsPerWord
| ) |  |

`#include <tee_spi.h>`

Set the number of bits that will be transferred per SPI rate.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | bitsPerWord | bits per word.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler spi;
TEES_SPISetBitsPerWord(spi, 0);
…

TEE_Result TEES_SPISetClockSpeed | ( | TEES_SPIHandler | handler,
|  | uint32_t | speedHz
| ) |  |

`#include <tee_spi.h>`

Set clock frequency rate.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | speedHz | Value of frequency rate.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler spi;
TEES_SPISetClockSpeed(spi, 0);
…

TEE_Result TEES_SPISetConfig | ( | TEES_SPIHandler | handler,
|  | const TEES_SPIConfig * | cfg
| ) |  |

`#include <tee_spi.h>`

Initialize handler with configuration values.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | cfg | Pointer to SPI configuration for handler initialisation.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler handler;
TEES_SPIConfig cfg = {
.speedHz = 5000000,
.CPOL = 0,
.CPHA = 0,
.bitsPerWord = SPI_TYPE_WORD,
.isDMAMode = true,
};
TEES_SPIDMAInit(pa);
TEE_Result res = TEES_SPIInit(port, NULL, &handler);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to initalize SPI, tee_err: %#x\n", res);
return res;
}
res = TEES_SPISetConfig(handler, &cfg);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to configure SPI, tee_err: %#x\n", res);
TEES_SPIExit(handler);
return res;
}
…

TEE_Result TEES_SPISetCPHA | ( | TEES_SPIHandler | handler,
|  | uint8_t | cpha
| ) |  |

`#include <tee_spi.h>`

Set SPI clock phase bit.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | cpha | Value of phase bit.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler spi;
TEES_SPISetCPHA(spi, 0);
…

TEE_Result TEES_SPISetCPOL | ( | TEES_SPIHandler | handler,
|  | uint8_t | cpol
| ) |  |

`#include <tee_spi.h>`

Set SPI clock polarity bit.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | cpol | Value of polarity bit.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler spi;
TEES_SPISetCPOL(spi, 0);
…

TEE_Result TEES_SPISetDMAMode | ( | TEES_SPIHandler | handler,
|  | bool | isEnabled
| ) |  |

`#include <tee_spi.h>`

Enable or disable DMA mode.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | isEnabled | true – enable, false - disable.

Returns
  TEE_SUCCESS - In case of success.

Example:

…
TEES_SPIHandler spi;
TEES_ SPISetDMAMode (spi, true);
…

TEE_Result TEES_SPIWrite | ( | TEES_SPIHandler | handler,
|  | TEES_SPITransfer * | tx
| ) |  |

`#include <tee_spi.h>`

Transfer data from buffer bus to SPI.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | tx | Pointer to buffer to read data from.

Return values

  TEE_SUCCESS | on success.
  TEE_ERROR_GENERIC | on failure.

TEE_Result TEES_SPIWriteRead | ( | TEES_SPIHandler | handler,
|  | TEES_SPITransfer * | tx,
|  | TEES_SPITransfer * | rx
| ) |  |

`#include <tee_spi.h>`

Transfer data from buffer to SPI bus.

Parameters

  [in] | handler | SPI handler which contains device descriptor.
  [in] | tx | Pointer to buffer to read data from.
  [out] | rx | Pointer to buffer to store data.

Return values

  TEE_SUCCESS | on success.
  TEE_ERROR_BAD_PARAMETERS | `rx` and `tx` buffers have different size.

Example:

TEES_SPIHandler handler;
TEES_SPIConfig cfg = {
.speedHz = 5000000,
.CPOL = 0,
.CPHA = 0,
.bitsPerWord = SPI_TYPE_WORD,
.isDMAMode = true
};
TEES_SPIDMAInit(pa);
TEE_Result res = TEES_SPIInit(port, &cfg, &handler);
if (res != TEE_SUCCESS) {
printf("TEST: Failed to initalize SPI, tee_err: %#x\n", res);
return res;
}
TEES_SPITransfer tx = {
.bufAddr = (void *)(pa + DMA_TX_OFFSET),
.bufLen = buflen,
.transferredLen = 0
};
TEES_SPITransfer rx = {
.bufAddr = (void *)(pa + DMA_RX_OFFSET),
.bufLen = buflen,
.transferredLen = 0
};
res = TEES_SPIWriteRead(handler, &tx, &rx);
if (TEES_SPIExit(handler)) {
TEE_Panic(0);
}
if (rx.transferredLen == 0 || tx.transferredLen == 0) {
printf("TEST: nothing was transferred over SPI, err: %#x\n", res);
return TEE_ERROR_GENERIC;
}