1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
39
40
41
44
45
46
49
53
54
57
61
62
69
81
82
83
91
98
99
104
107
108
109
110
111
112
113
114
115
116
117
120
121
122
123
124
125
126
127
128
129
132
133
140
145
146
152
157
158
165
166
167
174
177
178
183
186
187
194
197
198
203
206
207
212
215
216
217
218
219
220
/* ... */
#ifndef _HARDWARE_SHA256_H
#define _HARDWARE_SHA256_H
#include "pico.h"
#include "hardware/structs/sha256.h"
/* ... */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef PARAM_ASSERTIONS_ENABLED_HARDWARE_SHA256
#ifdef PARAM_ASSERTIONS_ENABLED_SHA256
#define PARAM_ASSERTIONS_ENABLED_HARDWARE_SHA256 PARAM_ASSERTIONS_ENABLED_SHA256
#else
#define PARAM_ASSERTIONS_ENABLED_HARDWARE_SHA256 0
#endif/* ... */
#endif
/* ... */
#define SHA256_RESULT_BYTES 32
/* ... */
enum sha256_endianness {
SHA256_LITTLE_ENDIAN,
SHA256_BIG_ENDIAN,
...};
/* ... */
typedef union {
uint32_t words[SHA256_RESULT_BYTES/4];
uint8_t bytes[SHA256_RESULT_BYTES];
...} sha256_result_t;
/* ... */
static inline void sha256_set_dma_size(uint size_in_bytes) {
uint32_t val;
invalid_params_if(HARDWARE_SHA256, size_in_bytes != 1 && size_in_bytes != 2 && size_in_bytes != 4);
if (size_in_bytes == 1) {
val = SHA256_CSR_DMA_SIZE_VALUE_8BIT;
}if (size_in_bytes == 1) { ... } else if (size_in_bytes == 2) {
val = SHA256_CSR_DMA_SIZE_VALUE_16BIT;
}else if (size_in_bytes == 2) { ... } else {
val = SHA256_CSR_DMA_SIZE_VALUE_32BIT;
}else { ... }
hw_write_masked(&sha256_hw->csr, val << SHA256_CSR_DMA_SIZE_LSB, SHA256_CSR_DMA_SIZE_BITS);
}{ ... }
/* ... */
static inline void sha256_set_bswap(bool swap) {
if (swap) {
hw_set_bits(&sha256_hw->csr, SHA256_CSR_BSWAP_BITS);
}if (swap) { ... } else {
hw_clear_bits(&sha256_hw->csr, SHA256_CSR_BSWAP_BITS);
}else { ... }
}{ ... }
/* ... */
static inline void sha256_start(void) {
hw_set_bits(&sha256_hw->csr, SHA256_CSR_START_BITS);
}{ ... }
/* ... */
static inline bool sha256_is_sum_valid(void) {
return sha256_hw->csr & SHA256_CSR_SUM_VLD_BITS;
}{ ... }
/* ... */
static inline bool sha256_is_ready(void) {
return sha256_hw->csr & SHA256_CSR_WDATA_RDY_BITS;
}{ ... }
/* ... */
static inline void sha256_wait_valid_blocking(void) {
while (!sha256_is_sum_valid()) {
tight_loop_contents();
}while (!sha256_is_sum_valid()) { ... }
}{ ... }
/* ... */
static inline void sha256_wait_ready_blocking(void) {
while (!sha256_is_ready()) {
tight_loop_contents();
}while (!sha256_is_ready()) { ... }
}{ ... }
/* ... */
void sha256_get_result(sha256_result_t *out, enum sha256_endianness endianness);
/* ... */
static inline bool sha256_err_not_ready(void) {
return sha256_hw->csr & SHA256_CSR_ERR_WDATA_NOT_RDY_BITS;
}{ ... }
/* ... */
static inline void sha256_err_not_ready_clear(void) {
hw_clear_bits(&sha256_hw->csr, SHA256_CSR_ERR_WDATA_NOT_RDY_BITS);
}{ ... }
/* ... */
static inline volatile void *sha256_get_write_addr(void) {
return &sha256_hw->wdata;
}{ ... }
/* ... */
static inline void sha256_put_word(uint32_t word) {
sha256_hw->wdata = word;
}{ ... }
/* ... */
static inline void sha256_put_byte(uint8_t b) {
*((io_rw_8*)&sha256_hw->wdata) = b;
}{ ... }
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif