TRNG HAL

The TRNG HAL definitions is in dev_trng.h, it provide interfaces for trng driver to implement. Here is a diagram for the trng interface.

TRNG HAL

Definitions

group DEVICE_HAL_TRNG_DEVSTRUCT

Contains definitions of trng device interface structure.

This structure will be used in user implemented code, which was called Device Driver Implement Layer for trng to use in implementation code. Application developer should use the TRNG API provided here to access to TRNG devices. BSP developer should follow the API definition to implement TRNG device drivers.

Defines

DEV_TRNG_INFO_SET_EXTRA_OBJECT(trng_info_ptr, extra_info)

Set extra information pointer of trng info.

DEV_TRNG_INFO_GET_EXTRA_OBJECT(trng_info_ptr)

Get extra information pointer of trng info.

Typedefs

typedef struct dev_trng_info DEV_TRNG_INFO

TRNG information struct definition.

informations about trng open count, working status, baudrate, trng registers and ctrl structure, trng dps format

typedef struct dev_trng_info *DEV_TRNG_INFO_PTR
typedef struct dev_trng DEV_TRNG
typedef struct dev_trng *DEV_TRNG_PTR

Variables

int32_t (*trng_open)(void)

Open trng device

open trng device

Return Value
  • E_OK: Open successfully without any issues

  • E_OPNED: If device was opened before with different parameters, then just increase the opn_cnt and return E_OPNED

  • E_OBJ: Device object is not valid

  • E_PAR: Parameter is not valid

  • E_NOSPT: Open settings are not supported

int32_t (*trng_close)(void)

Close trng device

close an trng device, just decrease the opn_cnt, if opn_cnt equals 0, then close the device

Return Value
  • E_OK: Close successfully without any issues(including scenario that device is already closed)

  • E_OPNED: Device is still opened, the device opn_cnt decreased by 1

  • E_OBJ: Device object is not valid

int32_t (*trng_control)(uint32_t ch, uint32_t cmd, void *param2)

Control trng device

control an trng device [channel number: ch] by ctrl_cmd, with passed param.

Parameters
  • [in] ch: channel number of trng to control, must >= 0

  • [in] ctrl_cmd: control command, to change or get some thing related to trng

  • [inout] param: parameters that maybe argument of the command, or return values of the command

Return Value
  • E_OK: Control device successfully

  • E_CLSED: Device is not opened

  • E_OBJ: Device object is not valid or not exists

  • E_PAR: Parameter is not valid for current control command

  • E_SYS: Control device failed, due to hardware issues, such as device is disabled

  • E_CTX: Control device failed, due to different reasons like in transfer state

  • E_NOSPT: Control command is not supported or not valid

int32_t (*trng_read)(uint32_t *data_buf)

Read data from trng device(blocked)

read the configuration of trng.

Parameters
  • [out] data_buf: pointer to data buffer read from trng, must not be NULL

Return Value
  • E_OK: Read device successfully

  • E_OBJ: Device object is not valid or not exists

  • E_PAR: Parameter is not valid

  • E_SYS: Can’t receive data from hardware due to hardware issues, such as device is disabled

struct dev_trng_info
#include <dev_trng.h>

TRNG information struct definition.

informations about trng open count, working status, baudrate, trng registers and ctrl structure, trng dps format