19 #include "./hal/hal_power.h" 20 #define CRC_OUT_MASK8 (0xFFU) 21 #define CRC_OUT_MASK16 (0xFFFFU) 22 #define CRC_OUT_MASK24 (0xFFFFFFU) 23 #define CRC_OUT_MASK32 (0xFFFFFFFFU) 26 CRC_ERR_INVALID_PARAM = -1,
38 typedef enum crc_input_bytes {
62 void (*callback)(
void* arg);
65 typedef struct crc_conf {
76 uint32_t init_xor_val;
77 uint32_t final_xor_val;
83 void (*callback)(
void* arg);
93 osSemaphoreId semaphore;
103 static __inline
void crc_clk_enble(
int en)
105 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
107 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_CLK_ENABLE;
109 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_CLK_ENABLE;
111 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
113 static __inline
void crc_enble(
int en)
115 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
117 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_ENABLE;
119 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_ENABLE;
121 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
123 static __inline
void crc_start(
int val)
125 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
127 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_START;
129 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_START;
131 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
133 static __inline
void crc_stop(
int val)
135 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
137 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_STOP;
139 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_STOP;
141 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
143 static __inline
void crc_shiftin_bit_order(
int lsb)
145 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
147 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_SHIFTIN_BIT_ORDER;
149 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_SHIFTIN_BIT_ORDER;
151 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
153 static __inline
void crc_shiftin_byte_order(
int lsb)
155 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
157 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_SHIFTIN_BYTE_ORDER;
159 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_SHIFTIN_BYTE_ORDER;
161 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
163 static __inline
void crc_final_bit_rev(
int val)
165 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
167 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_FINAL_BIT_REVERSE;
169 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_FINAL_BIT_REVERSE;
171 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
173 static __inline
void crc_final_byte_rev(
int val)
175 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
177 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_FINAL_BYTE_REVERSE;
179 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_FINAL_BYTE_REVERSE;
181 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
183 static __inline
void crc_append_zero(
int val)
185 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
187 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_FINAL_APPEND_ZERO;
189 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_FINAL_APPEND_ZERO;
191 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
193 static __inline
void crc_dma_enble(
int en)
195 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
197 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_DMA_ENABLE;
199 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_DMA_ENABLE;
201 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
203 static __inline
void crc_unknow_input_len(
int val)
205 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
207 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_UNKNOWN_INPUT_LENGTH;
209 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_UNKNOWN_INPUT_LENGTH;
211 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
213 static __inline
void crc_clr_total_byte_cnt(
int val)
215 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
217 reg |= PWM_REGS_CRC_MISC_CTRL_CTL_CRC_CLR_TOTAL_BYTE_CNT;
219 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_CLR_TOTAL_BYTE_CNT;
221 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
223 static __inline
void crc_poly_order(
int val)
225 uint32_t reg = RD_WORD(PWM_REGS_CRC_MISC_CTRL);
226 reg &= ~PWM_REGS_CRC_MISC_CTRL_CTL_CRC_POLY_ORDER;
227 reg |= (val&PWM_REGS_CRC_MISC_CTRL_CTL_CRC_POLY_ORDER_MASK)<<PWM_REGS_CRC_MISC_CTRL_CTL_CRC_POLY_ORDER_SHIFT;
228 WR_WORD(PWM_REGS_CRC_MISC_CTRL, reg);
230 static __inline
void crc_poly(uint32_t val)
232 WR_WORD(PWM_REGS_CRC_POLY, val);
234 static __inline
void crc_init_val(uint32_t val)
236 WR_WORD(PWM_REGS_CRC_INIT_VAL, val);
238 static __inline
void crc_init_xor_val(uint32_t val)
240 WR_WORD(PWM_REGS_CRC_INIT_XOR_VAL, val);
242 static __inline
void crc_final_xor_val(uint32_t val)
244 WR_WORD(PWM_REGS_CRC_FINAL_XOR_VAL, val);
246 static __inline
void crc_input_num_byte(
int num)
248 uint32_t reg = RD_WORD(PWM_REGS_CRC_INPUT_INFO);
249 reg &= ~PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_NUM_BYTE;
250 reg |= (num&PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_NUM_BYTE_MASK)<<PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_NUM_BYTE_SHIFT;
251 WR_WORD(PWM_REGS_CRC_INPUT_INFO, reg);
253 static __inline
void crc_input_last(
int val)
255 uint32_t reg = RD_WORD(PWM_REGS_CRC_INPUT_INFO);
257 reg |= PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_LAST;
259 reg &= ~PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_LAST;
260 WR_WORD(PWM_REGS_CRC_INPUT_INFO, reg);
262 static __inline uint32_t crc_wait_input(
void)
264 return (RD_WORD(PWM_REGS_CRC_INPUT_INFO)>>3)&0x1;
267 static __inline
void crc_input_total_byte(uint32_t num)
269 uint32_t reg = RD_WORD(PWM_REGS_CRC_INPUT_INFO);
270 reg &= ~PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_TOTAL_NUM_BYTE;
271 reg |= (num&PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_TOTAL_NUM_BYTE_MASK)<<PWM_REGS_CRC_INPUT_INFO_CTL_CRC_INPUT_TOTAL_NUM_BYTE_SHIFT;
272 WR_WORD(PWM_REGS_CRC_INPUT_INFO, reg);
274 static __inline
void crc_input(uint32_t val)
276 WR_WORD(PWM_REGS_CRC_INPUT, val);
278 static __inline uint32_t crc_curr_status(
void)
280 return RD_WORD(PWM_REGS_CRC_STATUS)&PWM_REGS_CRC_STATUS_STS_CRC_CURR_STATUS_MASK;
282 static __inline uint32_t crc_curr_done(
void)
284 return (RD_WORD(PWM_REGS_CRC_STATUS)&PWM_REGS_CRC_STATUS_STS_CRC_DONE)>>8;
286 static __inline uint32_t crc_curr_byte_cnt(
void)
288 return RD_WORD(PWM_REGS_CRC_STATUS)&PWM_REGS_CRC_BYTE_CNT_STS_CRC_CURR_BYTE_CNT_SHIFT;
290 static __inline uint32_t crc_value(
void)
292 return RD_WORD(PWM_REGS_CRC_VALUE);
302 int hal_crc_open(crc_init_t *init);
310 int hal_crc_close(
void);
321 int hal_crc_start(uint8_t *buf, uint32_t len, uint32_t *crc_val);
329 int hal_crc_stream_start(
void);
340 int hal_crc_stream_input(uint8_t *buf, uint32_t len,
int last);
349 int hal_crc_stream_end(uint32_t *crc_val);
351 int hal_crc_cfg(crc_conf_t *conf);
352 int hal_crc_open_status(
void);
353 int hal_crc_isr_status(
void);