Trident IoT SDK
 
Loading...
Searching...
No Matches
T32CZ20_trng.h
Go to the documentation of this file.
1
12
13#ifndef T32CZ20_TRNG_H_
14#define T32CZ20_TRNG_H_
15
16#include "tr_hal_platform.h"
17
18
24
25
35#define CHIP_MEMORY_MAP_SECURITY_CTRL_BASE 0x50003000
36
37typedef struct
38{
39 __IO uint32_t reserved[18]; // 0x00 - 0x44
40 __IO uint32_t sec_otp_write_key; // 0x48
41
43
44#define SECURITY_CTRL_CHIP_REGISTERS ((SECURITY_CTRL_REGISTERS_T *) CHIP_MEMORY_MAP_SECURITY_CTRL_BASE)
45
46#define OTP_WRITE_ENABLE_KEY (0x28514260)
47#define OTP_WRITE_DISABLE_KEY (0x00000000)
48
49
60// this is the address of the PUFrt register, PLUS the offset of 0xA00
61// which is where the TRNG registers start, see section 11.4
62#ifdef PUF_OTP_SECURE_EN
63 #define CHIP_MEMORY_MAP_TRNG_BASE (0x50044A00UL)
64#else
65 #define CHIP_MEMORY_MAP_TRNG_BASE (0x40044A00UL)
66#endif // PUF_OTP_SECURE_EN
67
68
74typedef struct
75{
76 // expect this to be 0x39304200
77 __IO uint32_t version; // 0x00
78 __IO uint32_t reserved1[3]; // 0x04, 0x08, 0x0C
79
80 // use this to determine if TRNG is working
81 __IO uint32_t status; // 0x10
82 __IO uint32_t reserved2[3]; // 0x14, 0x18, 0x1C
83
84 // use this to enable clock, enable TRNG
85 __IO uint32_t control; // 0x20
86 __IO uint32_t reserved3[19]; // 0x24 - 0x6C
87
88 // read this to get the random number
89 __IO uint32_t data; // 0x70
90
92
93
94// *****************************************************************
95// helper define for VERSION register (0x00)
96
97#define REG_TRNG_EXPECTED_VERSION 0x39304200
98
99
100// *****************************************************************
101// helper defines for STATUS register (0x04)
102
103#define REG_TRNG_STATUS_BUSY 0x01
104#define REG_TRNG_STATUS_FIFO_CLEARED 0x02
105#define REG_TRNG_STATUS_ENTROPY_SRC_AVAIL 0x04
106// bits 3 to 7 reserved (5 bits): 0x08, 0x10, 0x20, 0x40, 0x80
107#define REG_TRNG_STATUS_NOT_ENABLED 0x100
108#define REG_TRNG_STATUS_HEALTH_TEST_ACTIVE 0x200
109#define REG_TRNG_STATUS_DATA_READY 0x400
110#define REG_TRNG_STATUS_HALTED_ERROR 0x800
111
112
113// *****************************************************************
114// helper defines for CONTROL register (0x08)
115
116#define REG_CONTROL_ENABLE_TRNG_FUNCTION 0x01
117#define REG_CONTROL_ENABLE_TRNG_CLOCK 0x02
118
119
120// *****************************************************************
121// this orients the TRNG_REGISTER struct with the correct addresses
122// so referencing a field will now read/write the correct GPIO register
123// chip address
124#define TRNG_CHIP_REGISTERS ((TRNG_REGISTERS_T *) CHIP_MEMORY_MAP_TRNG_BASE)
125
126
127// this is for the timeout when waiting for TRNG to finish creating
128// a random number. This usually works in 4000 - 7000 iterations on
129// a system with no load
130#define TRNG_TIMEOUT_COUNT 20000
131
132
133// used for testing. This returns a 4 byte random number but also
134// returns the number of cycles it took to generate the number
136 uint32_t* busy_cycles);
137
138// used for testing
140 uint32_t* status,
141 uint32_t* data,
142 uint32_t* control);
143
144
148
149
150#endif // T32CZ20_GPIO_H_
This file contains the CHIP SPECIFIC types and defines for the T32CZ20.
tr_hal_status_t
Definition tr_hal_common.h:25
tr_hal_status_t tr_hal_trng_debug(uint32_t *version, uint32_t *status, uint32_t *data, uint32_t *control)
tr_hal_status_t tr_hal_trng_read_internal(uint32_t *result, uint32_t *busy_cycles)
Definition T32CZ20_trng.h:38
__IO uint32_t sec_otp_write_key
Definition T32CZ20_trng.h:40
Definition T32CZ20_trng.h:75
__IO uint32_t version
Definition T32CZ20_trng.h:77
__IO uint32_t status
Definition T32CZ20_trng.h:81
__IO uint32_t data
Definition T32CZ20_trng.h:89
__IO uint32_t control
Definition T32CZ20_trng.h:85