InPlay API
hal_hwacc.h
1 
13 #ifndef HAL_HWACC_H
14 #define HAL_HWACC_H
15 
25 #include <stdint.h>
26 #include <math.h>
27 #include "in_mmap.h"
28 #include "in_config.h"
29 
30 /*
31  ****************************************************************************************
32  * INLINE FUNCTIONS
33  ****************************************************************************************
34  */
35 
36 static __inline uint8_t hwacc_get_intr_status()
37 {
38  return RD_WORD(HWACC_REG_INTR_STATUS);
39 }
40 
41 static __inline uint8_t hwacc_get_mask_status()
42 {
43  return RD_WORD(HWACC_REG_INTR_MASK_STATUS);
44 }
45 
46 static __inline void hwacc_intr_clear()
47 {
48  WR_WORD(HWACC_REG_INTR_CLEAR, (HWACC_REG_INTR_CLEAR_HWACC_DONE | HWACC_REG_INTR_CLEAR_FAULT_DETECTED));
49 }
50 
51 static __inline void hwacc_intr_set()
52 {
53  WR_WORD(HWACC_REG_INTR_SET, (HWACC_REG_INTR_SET_HWACC_DONE | HWACC_REG_INTR_SET_FAULT_DETECTED));
54 }
55 
56 static __inline void hwacc_mask_clear()
57 {
58  WR_WORD(HWACC_REG_INTR_MASK_CLEAR, (HWACC_REG_INTR_MASK_CLEAR_HWACC_DONE | HWACC_REG_INTR_MASK_CLEAR_FAULT_DETECTED));
59 }
60 
61 static __inline void hwacc_mask_set()
62 {
63  WR_WORD(HWACC_REG_INTR_MASK_SET, (HWACC_REG_INTR_MASK_SET_HWACC_DONE | HWACC_REG_INTR_MASK_SET_FAULT_DETECTED));
64 }
65 
66 static __inline void hwacc_enable()
67 {
68  uint32_t reg = RD_WORD(HWACC_REG_MISC_CTRL);
69  reg |= HWACC_REG_MISC_CTRL_CTL_ENABLE;
70  WR_WORD(HWACC_REG_MISC_CTRL, reg);
71 }
72 
73 static __inline void hwacc_disable()
74 {
75  uint32_t reg = RD_WORD(HWACC_REG_MISC_CTRL);
76  reg &= ~HWACC_REG_MISC_CTRL_CTL_ENABLE;
77  WR_WORD(HWACC_REG_MISC_CTRL, reg);
78 }
79 
80 static __inline void hwacc_start()
81 {
82  uint32_t reg = RD_WORD(HWACC_REG_MISC_CTRL);
83  reg |= HWACC_REG_MISC_CTRL_CTL_START;
84  WR_WORD(HWACC_REG_MISC_CTRL, reg);
85 
86  reg &= ~HWACC_REG_MISC_CTRL_CTL_START;
87  WR_WORD(HWACC_REG_MISC_CTRL, reg);
88 }
89 
90 static __inline void hwacc_set_num_inst(uint16_t num_inst)
91 {
92  uint32_t reg = RD_WORD(HWACC_REG_MISC_CTRL);
93  reg &= ~HWACC_REG_MISC_CTRL_CTL_NUM_INSTRUCTION;
94  reg |= ((num_inst & HWACC_REG_MISC_CTRL_CTL_NUM_INSTRUCTION_MASK) << HWACC_REG_MISC_CTRL_CTL_NUM_INSTRUCTION_SHIFT);
95  WR_WORD(HWACC_REG_MISC_CTRL, reg);
96 }
97 
98 static __inline void hwacc_set_inst_addr(uint16_t inst_addr)
99 {
100  uint32_t reg = RD_WORD(HWACC_REG_MISC_CTRL);
101  reg &= ~HWACC_REG_MISC_CTRL_CTL_INSTRUCTION_ADDRESS;
102  reg |= ((inst_addr & HWACC_REG_MISC_CTRL_CTL_INSTRUCTION_ADDRESS_MASK) << HWACC_REG_MISC_CTRL_CTL_INSTRUCTION_ADDRESS_SHIFT);
103  WR_WORD(HWACC_REG_MISC_CTRL, reg);
104 }
105 
106 static __inline void hwacc_mem_acc_ahb()
107 {
108  WR_WORD(HWACC_REG_MEM_ACC_CTRL, HWACC_REG_MEM_ACC_CTRL_DEFAULT);
109 }
110 
111 static __inline void hwacc_mem_acc_comp_core()
112 {
113  WR_WORD(HWACC_REG_MEM_ACC_CTRL, HWACC_REG_MEM_ACC_CTRL_CTL_MEM_A_ACC_SEL | HWACC_REG_MEM_ACC_CTRL_CTL_MEM_B_ACC_SEL | HWACC_REG_MEM_ACC_CTRL_CTL_MEM_C_ACC_SEL | HWACC_REG_MEM_ACC_CTRL_CTL_MEM_D_ACC_SEL);
114 }
115 
116 static __inline void hwacc_pv_search_enable()
117 {
118  uint32_t reg = RD_WORD(HWACC_REG_INVERSE_CTRL);
119  reg |= HWACC_REG_INVERSE_CTRL_CTL_PV_SEARCH_ON;
120  WR_WORD(HWACC_REG_INVERSE_CTRL, reg);
121 }
122 
123 static __inline void hwacc_pv_search_disable()
124 {
125  uint32_t reg = RD_WORD(HWACC_REG_INVERSE_CTRL);
126  reg &= ~HWACC_REG_INVERSE_CTRL_CTL_PV_SEARCH_ON;
127  WR_WORD(HWACC_REG_INVERSE_CTRL, reg);
128 }
129 
130 static __inline void hwacc_check_min_pv_enable()
131 {
132  uint32_t reg = RD_WORD(HWACC_REG_INVERSE_CTRL);
133  reg |= HWACC_REG_INVERSE_CTRL_CTL_CHECK_MIN_PV_ON;
134  WR_WORD(HWACC_REG_INVERSE_CTRL, reg);
135 }
136 
137 static __inline void hwacc_check_min_pv_disable()
138 {
139  uint32_t reg = RD_WORD(HWACC_REG_INVERSE_CTRL);
140  reg &= ~HWACC_REG_INVERSE_CTRL_CTL_CHECK_MIN_PV_ON;
141  WR_WORD(HWACC_REG_INVERSE_CTRL, reg);
142 }
143 
144 static __inline void hwacc_check_zero_pv_enable()
145 {
146  uint32_t reg = RD_WORD(HWACC_REG_INVERSE_CTRL);
147  reg |= HWACC_REG_INVERSE_CTRL_CTL_CHECK_ZERO_PV_ON;
148  WR_WORD(HWACC_REG_INVERSE_CTRL, reg);
149 }
150 
151 static __inline void hwacc_check_zero_pv_disable()
152 {
153  uint32_t reg = RD_WORD(HWACC_REG_INVERSE_CTRL);
154  reg &= ~HWACC_REG_INVERSE_CTRL_CTL_CHECK_ZERO_PV_ON;
155  WR_WORD(HWACC_REG_INVERSE_CTRL, reg);
156 }
157 
158 static __inline void hwacc_set_min_pv(uint32_t min_pv)
159 {
160  WR_WORD(HWACC_REG_INVERSE_MIN_PV, min_pv);
161 }
162 
163 static __inline uint32_t hwacc_get_curr_inst_word_0()
164 {
165  return RD_WORD(HWACC_REG_CURR_INST_WORD0);
166 }
167 
168 static __inline uint32_t hwacc_get_curr_inst_word_1()
169 {
170  return RD_WORD(HWACC_REG_CURR_INST_WORD1);
171 }
172 
173 static __inline uint32_t hwacc_get_curr_inst_word_2()
174 {
175  return RD_WORD(HWACC_REG_CURR_INST_WORD2);
176 }
177 
178 static __inline uint32_t hwacc_get_curr_inst_cycle_cnt()
179 {
180  return RD_WORD(HWACC_REG_CURR_INST_CYCLE_CNT);
181 }
182 
183 /*
184  ****************************************************************************************
185  * IMPLEMENTATION
186  ****************************************************************************************
187  */
188 
189 #define HWACC_MEM_0_BASE_ADDR 0x44007000
190 #define HWACC_MEM_1_BASE_ADDR 0x44007800
191 #define HWACC_MEM_2_BASE_ADDR 0x44008000
192 #define HWACC_MEM_3_BASE_ADDR 0x44008400
193 
195 typedef enum {
213 } hwacc_op_t;
214 
215 typedef struct {
217  uint8_t mem_block;
219  uint16_t offset;
221  uint8_t nrows;
223  uint8_t ncols;
224 } hwacc_matrix_desc_t;
225 
227 typedef enum {
246 
247 // DEFAULT INITIALIZATION
256 int hal_hwacc_open(void);
257 
265 int hal_hwacc_close(void);
266 
277 int hal_hwacc_write_matrix(hwacc_matrix_desc_t *matrix, const float *head);
278 
289 int hal_hwacc_read_matrix(hwacc_matrix_desc_t *matrix, float *head);
290 
306 int hal_hwacc_insert_inst(hwacc_matrix_desc_t *matrix_C, int C_symm, hwacc_matrix_desc_t *matrix_A, int A_trans, hwacc_matrix_desc_t *matrix_B, int B_trans, hwacc_op_t op);
307 
315 int hal_hwacc_execute(void);
317 
318 #endif
319 
320 
Matrix addition: (C = A + B) Addition of A/B (each from a different memory), result saved to another ...
Definition: hal_hwacc.h:199
int hal_hwacc_write_matrix(hwacc_matrix_desc_t *matrix, const float *head)
Write matrix into hardware accelerator memory blocks.
Matrix scale: (C = A * B) Scale A by B (b is a scalar 1x1 matrix).
Definition: hal_hwacc.h:212
Matrix clear: (C = A * 0) C is zero matrix matching size of A. (Clear memory bank and offset of C wit...
Definition: hal_hwacc.h:210
Matrix copy: (C = B) Copy B from one memory location to another memory location (same or different me...
Definition: hal_hwacc.h:197
int hal_hwacc_open(void)
Initialize hardware accelerator driver.
HWACC unable to initialize.
Definition: hal_hwacc.h:239
Matrix dimension mismatch within instruction operation.
Definition: hal_hwacc.h:241
HWACC driver already initialized with hwacc_open().
Definition: hal_hwacc.h:235
HWACC driver not yet initialized with hwacc_open().
Definition: hal_hwacc.h:237
Hardware configuration error detected.
Definition: hal_hwacc.h:231
hwacc_op_t
hwacc operator
Definition: hal_hwacc.h:195
HWACC input issue.
Definition: hal_hwacc.h:243
int hal_hwacc_insert_inst(hwacc_matrix_desc_t *matrix_C, int C_symm, hwacc_matrix_desc_t *matrix_A, int A_trans, hwacc_matrix_desc_t *matrix_B, int B_trans, hwacc_op_t op)
Insert instruction into queue.
No error. Good status.
Definition: hal_hwacc.h:229
int hal_hwacc_close(void)
Clean-up hardware accelerator driver.
Matrix subtraction: (C = A - B) Subtraction of B from A (each from a different memory), result saved to another memory. A/B/C must have same size.
Definition: hal_hwacc.h:201
int hal_hwacc_execute(void)
Execute HW Accelerator instructions in queue.
Definition: hal_hwacc.h:208
Matrix multiplication: (C = AB) Multiplication of A/B (each from a different memory), result saved to another memory. Dimensions must match.
Definition: hal_hwacc.h:203
hwacc_status_t
HWACC function status return.
Definition: hal_hwacc.h:227
Matrix inversion: (C = A^-1) Inversion of A, result saved to another memory, at return: C = A^-1...
Definition: hal_hwacc.h:205
Instruction overflow detected. Too many instructions inserted.
Definition: hal_hwacc.h:233
int hal_hwacc_read_matrix(hwacc_matrix_desc_t *matrix, float *head)
Read matrix data from hardware accelerator memory blocks.