Lines Matching refs:hal
28 static esp_err_t init_send_queue(sdio_slave_context_t *hal);
152 void sdio_slave_hal_init(sdio_slave_context_t *hal) in sdio_slave_hal_init() argument
154 hal->host = sdio_slave_ll_get_host(0); in sdio_slave_hal_init()
155 hal->slc = sdio_slave_ll_get_slc(0); in sdio_slave_hal_init()
156 hal->hinf = sdio_slave_ll_get_hinf(0); in sdio_slave_hal_init()
157 hal->send_state = STATE_IDLE; in sdio_slave_hal_init()
158 … hal->recv_link_list = (sdio_slave_hal_recv_stailq_t)STAILQ_HEAD_INITIALIZER(hal->recv_link_list); in sdio_slave_hal_init()
160 init_send_queue(hal); in sdio_slave_hal_init()
163 void sdio_slave_hal_hw_init(sdio_slave_context_t *hal) in sdio_slave_hal_hw_init() argument
165 sdio_slave_ll_init(hal->slc); in sdio_slave_hal_hw_init()
166 sdio_slave_ll_enable_hs(hal->hinf, !hal->no_highspeed); in sdio_slave_hal_hw_init()
167 sdio_slave_ll_set_timing(hal->host, hal->timing); in sdio_slave_hal_hw_init()
169 sdio_slave_ll_slvint_set_ena(hal->slc, &intr_ena); in sdio_slave_hal_hw_init()
172 static esp_err_t init_send_queue(sdio_slave_context_t *hal) in init_send_queue() argument
176 sdio_ringbuf_t *buf = &(hal->send_desc_queue); in init_send_queue()
190 for (int i = 0; i < hal->send_queue_size + 1; i++) { in init_send_queue()
210 void sdio_slave_hal_set_ioready(sdio_slave_context_t *hal, bool ready) in sdio_slave_hal_set_ioready() argument
212 sdio_slave_ll_set_ioready(hal->hinf, ready); //set IO ready to 1 to allow host to use in sdio_slave_hal_set_ioready()
247 static inline void send_set_state(sdio_slave_context_t *hal, send_state_t state) in send_set_state() argument
249 hal->send_state = state; in send_set_state()
252 static inline send_state_t send_get_state(sdio_slave_context_t* hal) in send_get_state() argument
254 return hal->send_state; in send_get_state()
266 static void send_isr_invoker_enable(const sdio_slave_context_t *hal) in send_isr_invoker_enable() argument
268 sdio_slave_ll_send_reset(hal->slc); in send_isr_invoker_enable()
269 sdio_slave_ll_send_start(hal->slc, &start_desc); in send_isr_invoker_enable()
271 while(!sdio_slave_ll_send_invoker_ready(hal->slc)); in send_isr_invoker_enable()
272 sdio_slave_ll_send_stop(hal->slc); in send_isr_invoker_enable()
273 sdio_slave_ll_send_hostint_clr(hal->host); in send_isr_invoker_enable()
276 static void send_isr_invoker_disable(sdio_slave_context_t *hal) in send_isr_invoker_disable() argument
278 sdio_slave_ll_send_part_done_clear(hal->slc); in send_isr_invoker_disable()
281 void sdio_slave_hal_send_handle_isr_invoke(sdio_slave_context_t *hal) in sdio_slave_hal_send_handle_isr_invoke() argument
283 sdio_slave_ll_send_part_done_intr_ena(hal->slc, false); in sdio_slave_hal_send_handle_isr_invoke()
287 esp_err_t sdio_slave_hal_send_start(sdio_slave_context_t *hal) in sdio_slave_hal_send_start() argument
289 SDIO_SLAVE_CHECK(send_get_state(hal) == STATE_IDLE, in sdio_slave_hal_send_start()
291 send_set_state(hal, STATE_WAIT_FOR_START); in sdio_slave_hal_send_start()
292 send_isr_invoker_enable(hal); in sdio_slave_hal_send_start()
293 sdio_slave_ll_send_intr_clr(hal->slc); in sdio_slave_hal_send_start()
294 sdio_slave_ll_send_intr_ena(hal->slc, true); in sdio_slave_hal_send_start()
299 void sdio_slave_hal_send_stop(sdio_slave_context_t *hal) in sdio_slave_hal_send_stop() argument
301 sdio_slave_ll_send_stop(hal->slc); in sdio_slave_hal_send_stop()
302 send_isr_invoker_disable(hal); in sdio_slave_hal_send_stop()
303 sdio_slave_ll_send_intr_ena(hal->slc, false); in sdio_slave_hal_send_stop()
304 send_set_state(hal, STATE_IDLE); in sdio_slave_hal_send_stop()
307 static void send_new_packet(sdio_slave_context_t *hal) in send_new_packet() argument
311 sdio_slave_hal_send_desc_t *const start_desc = hal->in_flight_head; in send_new_packet()
312 sdio_slave_hal_send_desc_t *const end_desc = hal->in_flight_end; in send_new_packet()
315 sdio_slave_ll_send_stop(hal->slc); in send_new_packet()
316 sdio_slave_ll_send_reset(hal->slc); in send_new_packet()
317 sdio_slave_ll_send_start(hal->slc, (sdio_slave_ll_desc_t*)start_desc); in send_new_packet()
320 sdio_slave_ll_send_write_len(hal->slc, end_desc->pkt_len); in send_new_packet()
321 …send_length_write: %d, last_len: %08X", end_desc->pkt_len, sdio_slave_ll_send_read_len(hal->host)); in send_new_packet()
323 send_set_state(hal, STATE_SENDING); in send_new_packet()
328 static esp_err_t send_check_new_packet(sdio_slave_context_t *hal) in send_check_new_packet() argument
333 if (hal->sending_mode == SDIO_SLAVE_SEND_PACKET) { in send_check_new_packet()
334 ret = sdio_ringbuf_recv(&(hal->send_desc_queue), &start, &end, RINGBUF_GET_ONE); in send_check_new_packet()
336 ret = sdio_ringbuf_recv(&(hal->send_desc_queue), &start, &end, RINGBUF_GET_ALL); in send_check_new_packet()
339 hal->in_flight_head = start; in send_check_new_packet()
340 hal->in_flight_end = end; in send_check_new_packet()
343 hal->in_flight_next = SEND_DESC_NEXT(end); in send_check_new_packet()
349 bool sdio_slave_hal_send_eof_happened(sdio_slave_context_t* hal) in sdio_slave_hal_send_eof_happened() argument
353 if (sdio_slave_ll_send_done(hal->slc)) { in sdio_slave_hal_send_eof_happened()
355 HAL_ASSERT(send_get_state(hal) == STATE_SENDING); in sdio_slave_hal_send_eof_happened()
356 sdio_slave_ll_send_intr_clr(hal->slc); in sdio_slave_hal_send_eof_happened()
364 esp_err_t sdio_slave_hal_send_reset_counter(sdio_slave_context_t* hal) in sdio_slave_hal_send_reset_counter() argument
366 SDIO_SLAVE_CHECK(send_get_state(hal) == STATE_IDLE, in sdio_slave_hal_send_reset_counter()
369 sdio_slave_ll_send_write_len(hal->slc, 0); in sdio_slave_hal_send_reset_counter()
370 HAL_EARLY_LOGV(TAG, "last_len: %08X", sdio_slave_ll_send_read_len(hal->host)); in sdio_slave_hal_send_reset_counter()
372 hal->tail_pkt_len = 0; in sdio_slave_hal_send_reset_counter()
373 sdio_slave_hal_send_desc_t *desc = hal->in_flight_head; in sdio_slave_hal_send_reset_counter()
375 hal->tail_pkt_len += desc->dma_desc.length; in sdio_slave_hal_send_reset_counter()
376 desc->pkt_len = hal->tail_pkt_len; in sdio_slave_hal_send_reset_counter()
381 desc = (sdio_slave_hal_send_desc_t*)sdio_ringbuf_peek_front(&(hal->send_desc_queue)); in sdio_slave_hal_send_reset_counter()
383 hal->tail_pkt_len += desc->dma_desc.length; in sdio_slave_hal_send_reset_counter()
384 desc->pkt_len = hal->tail_pkt_len; in sdio_slave_hal_send_reset_counter()
391 static esp_err_t send_get_inflight_desc(sdio_slave_context_t *hal, void **out_arg, uint32_t *out_re… in send_get_inflight_desc() argument
396 HAL_ASSERT(hal->returned_desc == NULL); in send_get_inflight_desc()
397 hal->returned_desc = hal->in_flight_head; in send_get_inflight_desc()
398 send_set_state(hal, STATE_GETTING_RESULT); in send_get_inflight_desc()
401 if (hal->returned_desc != NULL) { in send_get_inflight_desc()
402 *out_arg = hal->returned_desc->arg; in send_get_inflight_desc()
403 hal->returned_desc = SEND_DESC_NEXT(hal->returned_desc); in send_get_inflight_desc()
406 if (hal->in_flight_head != NULL) { in send_get_inflight_desc()
408 HAL_ASSERT(hal->in_flight_end != NULL); in send_get_inflight_desc()
409 SEND_DESC_NEXT_SET(hal->in_flight_end, hal->in_flight_next); in send_get_inflight_desc()
411 … *out_returned_cnt = sdio_ringbuf_return(&(hal->send_desc_queue), (uint8_t*)hal->in_flight_head); in send_get_inflight_desc()
414 hal->in_flight_head = NULL; in send_get_inflight_desc()
415 hal->in_flight_end = NULL; in send_get_inflight_desc()
422 static esp_err_t send_get_unsent_desc(sdio_slave_context_t *hal, void **out_arg, uint32_t *out_retu… in send_get_unsent_desc() argument
427 ret = sdio_ringbuf_recv(&(hal->send_desc_queue), &head, &tail, RINGBUF_GET_ONE); in send_get_unsent_desc()
433 (*out_return_cnt) = sdio_ringbuf_return(&(hal->send_desc_queue), (uint8_t*) head); in send_get_unsent_desc()
438 send_set_state(hal, STATE_IDLE); in send_get_unsent_desc()
439 hal->tail_pkt_len = sdio_slave_ll_send_read_len(hal->host); in send_get_unsent_desc()
444 esp_err_t sdio_slave_hal_send_get_next_finished_arg(sdio_slave_context_t *hal, void **out_arg, uint… in sdio_slave_hal_send_get_next_finished_arg() argument
446 bool init = (send_get_state(hal) == STATE_SENDING); in sdio_slave_hal_send_get_next_finished_arg()
448 HAL_ASSERT(hal->in_flight_head != NULL); in sdio_slave_hal_send_get_next_finished_arg()
450 HAL_ASSERT(send_get_state(hal) == STATE_GETTING_RESULT); in sdio_slave_hal_send_get_next_finished_arg()
454 esp_err_t ret = send_get_inflight_desc(hal, out_arg, out_returned_cnt, init); in sdio_slave_hal_send_get_next_finished_arg()
458 send_set_state(hal, STATE_WAIT_FOR_START); in sdio_slave_hal_send_get_next_finished_arg()
464 esp_err_t sdio_slave_hal_send_flush_next_buffer(sdio_slave_context_t *hal, void **out_arg, uint32_t… in sdio_slave_hal_send_flush_next_buffer() argument
468 bool init = (send_get_state(hal) == STATE_IDLE); in sdio_slave_hal_send_flush_next_buffer()
470 …if (send_get_state(hal) != STATE_GETTING_RESULT && send_get_state(hal) != STATE_GETTING_UNSENT_DES… in sdio_slave_hal_send_flush_next_buffer()
475 if (init || send_get_state(hal) == STATE_GETTING_RESULT) { in sdio_slave_hal_send_flush_next_buffer()
476 ret = send_get_inflight_desc(hal, out_arg, out_return_cnt, init); in sdio_slave_hal_send_flush_next_buffer()
478 send_set_state(hal, STATE_GETTING_UNSENT_DESC); in sdio_slave_hal_send_flush_next_buffer()
481 if (send_get_state(hal) == STATE_GETTING_UNSENT_DESC) { in sdio_slave_hal_send_flush_next_buffer()
482 ret = send_get_unsent_desc(hal, out_arg, out_return_cnt); in sdio_slave_hal_send_flush_next_buffer()
484 send_set_state(hal, STATE_IDLE); in sdio_slave_hal_send_flush_next_buffer()
490 esp_err_t sdio_slave_hal_send_new_packet_if_exist(sdio_slave_context_t *hal) in sdio_slave_hal_send_new_packet_if_exist() argument
495 if (send_get_state(hal) == STATE_WAIT_FOR_START) { in sdio_slave_hal_send_new_packet_if_exist()
496 if (hal->in_flight_head == NULL) { in sdio_slave_hal_send_new_packet_if_exist()
497 send_check_new_packet(hal); in sdio_slave_hal_send_new_packet_if_exist()
500 if (hal->in_flight_head) { in sdio_slave_hal_send_new_packet_if_exist()
501 send_new_packet(hal); in sdio_slave_hal_send_new_packet_if_exist()
520 static void send_isr_invoke(sdio_slave_context_t *hal) in send_isr_invoke() argument
522 sdio_slave_ll_send_part_done_intr_ena(hal->slc, true); in send_isr_invoke()
525 esp_err_t sdio_slave_hal_send_queue(sdio_slave_context_t* hal, uint8_t *addr, size_t len, void *arg) in sdio_slave_hal_send_queue() argument
527 hal->tail_pkt_len += len; in sdio_slave_hal_send_queue()
535 .eof = (hal->sending_mode == SDIO_SLAVE_SEND_PACKET), in sdio_slave_hal_send_queue()
538 .pkt_len = hal->tail_pkt_len, in sdio_slave_hal_send_queue()
541 esp_err_t ret = sdio_ringbuf_send(&(hal->send_desc_queue), send_write_desc, &new_desc); in sdio_slave_hal_send_queue()
542 send_isr_invoke(hal); in sdio_slave_hal_send_queue()
550 static sdio_slave_ll_desc_t* recv_get_first_empty_buf(sdio_slave_context_t* hal) in recv_get_first_empty_buf() argument
552 sdio_slave_hal_recv_stailq_t *const queue = &(hal->recv_link_list); in recv_get_first_empty_buf()
560 void sdio_slave_hal_recv_stop(sdio_slave_context_t* hal) in sdio_slave_hal_recv_stop() argument
562 sdio_slave_ll_set_ioready(hal->hinf, false); //set IO ready to 0 to stop host from using in sdio_slave_hal_recv_stop()
563 sdio_slave_ll_send_stop(hal->slc); in sdio_slave_hal_recv_stop()
564 sdio_slave_ll_recv_stop(hal->slc); in sdio_slave_hal_recv_stop()
565 sdio_slave_ll_recv_intr_ena(hal->slc, false); in sdio_slave_hal_recv_stop()
569 bool sdio_slave_hal_recv_has_next_item(sdio_slave_context_t* hal) in sdio_slave_hal_recv_has_next_item() argument
572 if (hal->recv_cur_ret == NULL || hal->recv_cur_ret->owner != 0) return false; in sdio_slave_hal_recv_has_next_item()
578 hal->recv_cur_ret = STAILQ_NEXT(hal->recv_cur_ret, qe); in sdio_slave_hal_recv_has_next_item()
582 bool sdio_slave_hal_recv_done(sdio_slave_context_t *hal) in sdio_slave_hal_recv_done() argument
584 bool ret = sdio_slave_ll_recv_done(hal->slc); in sdio_slave_hal_recv_done()
586 sdio_slave_ll_recv_done_clear(hal->slc); in sdio_slave_hal_recv_done()
591 sdio_slave_ll_desc_t *sdio_slave_hal_recv_unload_desc(sdio_slave_context_t *hal) in sdio_slave_hal_recv_unload_desc() argument
593 sdio_slave_hal_recv_stailq_t *const queue = &hal->recv_link_list; in sdio_slave_hal_recv_unload_desc()
601 void sdio_slave_hal_recv_init_desc(sdio_slave_context_t* hal, sdio_slave_ll_desc_t *desc, uint8_t *… in sdio_slave_hal_recv_init_desc() argument
604 .size = hal->recv_buffer_size, in sdio_slave_hal_recv_init_desc()
609 void sdio_slave_hal_recv_start(sdio_slave_context_t *hal) in sdio_slave_hal_recv_start() argument
611 sdio_slave_ll_recv_reset(hal->slc); in sdio_slave_hal_recv_start()
612 sdio_slave_ll_desc_t *desc = recv_get_first_empty_buf(hal); in sdio_slave_hal_recv_start()
617 sdio_slave_ll_recv_start(hal->slc, desc); in sdio_slave_hal_recv_start()
618 sdio_slave_ll_recv_intr_ena(hal->slc, true); in sdio_slave_hal_recv_start()
622 void sdio_slave_hal_recv_reset_counter(sdio_slave_context_t *hal) in sdio_slave_hal_recv_reset_counter() argument
624 sdio_slave_ll_recv_size_reset(hal->slc); in sdio_slave_hal_recv_reset_counter()
625 sdio_slave_ll_desc_t *desc = recv_get_first_empty_buf(hal); in sdio_slave_hal_recv_reset_counter()
627 sdio_slave_ll_recv_size_inc(hal->slc); in sdio_slave_hal_recv_reset_counter()
632 void sdio_slave_hal_recv_flush_one_buffer(sdio_slave_context_t *hal) in sdio_slave_hal_recv_flush_one_buffer() argument
634 sdio_slave_hal_recv_stailq_t *const queue = &hal->recv_link_list; in sdio_slave_hal_recv_flush_one_buffer()
640 sdio_slave_ll_recv_size_inc(hal->slc); in sdio_slave_hal_recv_flush_one_buffer()
644 void sdio_slave_hal_load_buf(sdio_slave_context_t *hal, sdio_slave_ll_desc_t *desc) in sdio_slave_hal_load_buf() argument
646 sdio_slave_hal_recv_stailq_t *const queue = &(hal->recv_link_list); in sdio_slave_hal_load_buf()
652 if (hal->recv_cur_ret == NULL) { in sdio_slave_hal_load_buf()
653 hal->recv_cur_ret = desc; in sdio_slave_hal_load_buf()
658 sdio_slave_ll_recv_start(hal->slc, desc); in sdio_slave_hal_load_buf()
659 sdio_slave_ll_recv_intr_ena(hal->slc, true); in sdio_slave_hal_load_buf()
663 sdio_slave_ll_recv_restart(hal->slc); in sdio_slave_hal_load_buf()
666 sdio_slave_ll_recv_size_inc(hal->slc); in sdio_slave_hal_load_buf()
690 void sdio_slave_hal_hostint_get_ena(sdio_slave_context_t *hal, sdio_slave_hostint_t *out_int_mask) in sdio_slave_hal_hostint_get_ena() argument
692 *out_int_mask = sdio_slave_ll_host_get_intena(hal->host); in sdio_slave_hal_hostint_get_ena()
695 void sdio_slave_hal_hostint_clear(sdio_slave_context_t *hal, const sdio_slave_hostint_t *mask) in sdio_slave_hal_hostint_clear() argument
697 sdio_slave_ll_host_intr_clear(hal->host, mask);//clear all interrupts in sdio_slave_hal_hostint_clear()
700 void sdio_slave_hal_hostint_set_ena(sdio_slave_context_t *hal, const sdio_slave_hostint_t *mask) in sdio_slave_hal_hostint_set_ena() argument
702 sdio_slave_ll_host_set_intena(hal->host, mask); in sdio_slave_hal_hostint_set_ena()
705 void sdio_slave_hal_hostint_send(sdio_slave_context_t *hal, const sdio_slave_hostint_t *mask) in sdio_slave_hal_hostint_send() argument
707 sdio_slave_ll_host_send_int(hal->slc, mask); in sdio_slave_hal_hostint_send()
710 uint8_t sdio_slave_hal_host_get_reg(sdio_slave_context_t *hal, int pos) in sdio_slave_hal_host_get_reg() argument
712 return sdio_slave_ll_host_get_reg(hal->host, pos); in sdio_slave_hal_host_get_reg()
714 void sdio_slave_hal_host_set_reg(sdio_slave_context_t *hal, int pos, uint8_t reg) in sdio_slave_hal_host_set_reg() argument
716 sdio_slave_ll_host_set_reg(hal->host, pos, reg); in sdio_slave_hal_host_set_reg()
719 void sdio_slave_hal_slvint_fetch_clear(sdio_slave_context_t *hal, sdio_slave_ll_slvint_t *out_int_m… in sdio_slave_hal_slvint_fetch_clear() argument
721 sdio_slave_ll_slvint_fetch_clear(hal->slc, out_int_mask); in sdio_slave_hal_slvint_fetch_clear()