Lines Matching full:stream

50 	void (*queue_drop)(struct i2s_esp32_stream *stream);
120 static void i2s_esp32_queue_drop(struct i2s_esp32_stream *stream) in i2s_esp32_queue_drop() argument
124 while (k_msgq_get(&stream->queue, &item, K_NO_WAIT) == 0) { in i2s_esp32_queue_drop()
125 k_mem_slab_free(stream->i2s_cfg.mem_slab, item.buffer); in i2s_esp32_queue_drop()
138 struct i2s_esp32_stream *stream; in i2s_esp32_restart_dma() local
143 stream = &dev_data->rx; in i2s_esp32_restart_dma()
144 dst = stream->mem_block; in i2s_esp32_restart_dma()
146 stream = &dev_data->tx; in i2s_esp32_restart_dma()
147 src = stream->mem_block; in i2s_esp32_restart_dma()
153 err = dma_reload(stream->dma_dev, stream->dma_channel, (uint32_t)src, (uint32_t)dst, in i2s_esp32_restart_dma()
154 stream->mem_block_len); in i2s_esp32_restart_dma()
156 LOG_ERR("Error reloading DMA channel[%d]: %d", (int)stream->dma_channel, err); in i2s_esp32_restart_dma()
161 i2s_ll_rx_set_eof_num(dev_cfg->hal_cxt.dev, stream->mem_block_len); in i2s_esp32_restart_dma()
164 err = dma_start(stream->dma_dev, stream->dma_channel); in i2s_esp32_restart_dma()
166 LOG_ERR("Error starting DMA channel[%d]: %d", (int)stream->dma_channel, err); in i2s_esp32_restart_dma()
177 struct i2s_esp32_stream *stream = NULL; in i2s_esp32_start_dma() local
184 stream = &dev_data->rx; in i2s_esp32_start_dma()
186 stream = &dev_data->tx; in i2s_esp32_start_dma()
194 dma_blk.block_size = stream->mem_block_len; in i2s_esp32_start_dma()
196 dma_blk.dest_address = (uint32_t)stream->mem_block; in i2s_esp32_start_dma()
200 dma_blk.source_address = (uint32_t)stream->mem_block; in i2s_esp32_start_dma()
210 err = dma_config(stream->dma_dev, stream->dma_channel, &dma_cfg); in i2s_esp32_start_dma()
212 LOG_ERR("Error configuring DMA channel[%d]: %d", (int)stream->dma_channel, err); in i2s_esp32_start_dma()
218 i2s_ll_rx_set_eof_num(dev_cfg->hal_cxt.dev, stream->mem_block_len); in i2s_esp32_start_dma()
221 err = dma_start(stream->dma_dev, stream->dma_channel); in i2s_esp32_start_dma()
223 LOG_ERR("Error starting DMA channel[%d]: %d", (int)stream->dma_channel, err); in i2s_esp32_start_dma()
237 struct i2s_esp32_stream *stream = &dev_data->rx; in i2s_esp32_rx_start_transfer() local
241 err = k_mem_slab_alloc(stream->i2s_cfg.mem_slab, &stream->mem_block, K_NO_WAIT); in i2s_esp32_rx_start_transfer()
245 stream->mem_block_len = stream->i2s_cfg.block_size; in i2s_esp32_rx_start_transfer()
266 struct i2s_esp32_stream *stream = &dev_data->tx; in i2s_esp32_tx_start_transfer() local
271 err = k_msgq_get(&stream->queue, &item, K_NO_WAIT); in i2s_esp32_tx_start_transfer()
276 stream->mem_block = item.buffer; in i2s_esp32_tx_start_transfer()
277 stream->mem_block_len = item.size; in i2s_esp32_tx_start_transfer()
297 struct i2s_esp32_stream *stream = &dev_data->rx; in i2s_esp32_rx_stop_transfer() local
299 dma_stop(stream->dma_dev, stream->dma_channel); in i2s_esp32_rx_stop_transfer()
301 if (stream->mem_block != NULL) { in i2s_esp32_rx_stop_transfer()
302 k_mem_slab_free(stream->i2s_cfg.mem_slab, stream->mem_block); in i2s_esp32_rx_stop_transfer()
303 stream->mem_block = NULL; in i2s_esp32_rx_stop_transfer()
304 stream->mem_block_len = 0; in i2s_esp32_rx_stop_transfer()
311 struct i2s_esp32_stream *stream = &dev_data->tx; in i2s_esp32_tx_stop_transfer() local
313 dma_stop(stream->dma_dev, stream->dma_channel); in i2s_esp32_tx_stop_transfer()
315 if (stream->mem_block != NULL) { in i2s_esp32_tx_stop_transfer()
316 k_mem_slab_free(stream->i2s_cfg.mem_slab, stream->mem_block); in i2s_esp32_tx_stop_transfer()
317 stream->mem_block = NULL; in i2s_esp32_tx_stop_transfer()
318 stream->mem_block_len = 0; in i2s_esp32_tx_stop_transfer()
327 struct i2s_esp32_stream *stream = &dev_data->rx; in i2s_esp32_rx_callback() local
331 stream->state = I2S_STATE_ERROR; in i2s_esp32_rx_callback()
336 if (stream->mem_block == NULL) { in i2s_esp32_rx_callback()
337 if (stream->state != I2S_STATE_READY) { in i2s_esp32_rx_callback()
338 stream->state = I2S_STATE_ERROR; in i2s_esp32_rx_callback()
346 struct queue_item item = {.buffer = stream->mem_block, .size = stream->mem_block_len}; in i2s_esp32_rx_callback()
348 err = k_msgq_put(&stream->queue, &item, K_NO_WAIT); in i2s_esp32_rx_callback()
350 stream->state = I2S_STATE_ERROR; in i2s_esp32_rx_callback()
354 if (stream->state == I2S_STATE_STOPPING) { in i2s_esp32_rx_callback()
355 stream->state = I2S_STATE_READY; in i2s_esp32_rx_callback()
359 err = k_mem_slab_alloc(stream->i2s_cfg.mem_slab, &stream->mem_block, K_NO_WAIT); in i2s_esp32_rx_callback()
361 stream->state = I2S_STATE_ERROR; in i2s_esp32_rx_callback()
364 stream->mem_block_len = stream->i2s_cfg.block_size; in i2s_esp32_rx_callback()
368 stream->state = I2S_STATE_ERROR; in i2s_esp32_rx_callback()
376 stream->stop_transfer(dev); in i2s_esp32_rx_callback()
384 struct i2s_esp32_stream *stream = &dev_data->tx; in i2s_esp32_tx_callback() local
390 stream->state = I2S_STATE_ERROR; in i2s_esp32_tx_callback()
395 if (stream->mem_block == NULL) { in i2s_esp32_tx_callback()
396 if (stream->state != I2S_STATE_READY) { in i2s_esp32_tx_callback()
397 stream->state = I2S_STATE_ERROR; in i2s_esp32_tx_callback()
405 if (stream->state == I2S_STATE_STOPPING) { in i2s_esp32_tx_callback()
406 if (k_msgq_num_used_get(&stream->queue) == 0) { in i2s_esp32_tx_callback()
407 stream->state = I2S_STATE_READY; in i2s_esp32_tx_callback()
409 } else if (stream->stop_without_draining == true) { in i2s_esp32_tx_callback()
410 stream->queue_drop(stream); in i2s_esp32_tx_callback()
411 stream->state = I2S_STATE_READY; in i2s_esp32_tx_callback()
417 if (stream->last_block) { in i2s_esp32_tx_callback()
418 stream->state = I2S_STATE_READY; in i2s_esp32_tx_callback()
422 err = k_msgq_get(&stream->queue, &item, K_NO_WAIT); in i2s_esp32_tx_callback()
424 stream->state = I2S_STATE_ERROR; in i2s_esp32_tx_callback()
428 mem_block_tmp = stream->mem_block; in i2s_esp32_tx_callback()
430 stream->mem_block = item.buffer; in i2s_esp32_tx_callback()
431 stream->mem_block_len = item.size; in i2s_esp32_tx_callback()
435 stream->state = I2S_STATE_ERROR; in i2s_esp32_tx_callback()
440 k_mem_slab_free(stream->i2s_cfg.mem_slab, mem_block_tmp); in i2s_esp32_tx_callback()
445 stream->stop_transfer(dev); in i2s_esp32_tx_callback()
504 struct i2s_esp32_stream *stream; in i2s_esp32_configure() local
509 stream = &dev_data->rx; in i2s_esp32_configure()
510 if (stream->dma_dev == NULL) { in i2s_esp32_configure()
516 stream = &dev_data->tx; in i2s_esp32_configure()
517 if (stream->dma_dev == NULL) { in i2s_esp32_configure()
530 if (stream->state != I2S_STATE_NOT_READY && stream->state != I2S_STATE_READY) { in i2s_esp32_configure()
531 LOG_ERR("Invalid state: %d", (int)stream->state); in i2s_esp32_configure()
536 stream->queue_drop(stream); in i2s_esp32_configure()
537 memset(&stream->i2s_cfg, 0, sizeof(struct i2s_config)); in i2s_esp32_configure()
538 stream->is_slave = false; in i2s_esp32_configure()
539 stream->state = I2S_STATE_NOT_READY; in i2s_esp32_configure()
575 stream->is_slave = true; in i2s_esp32_configure()
578 stream->is_slave = false; in i2s_esp32_configure()
621 if (stream->is_slave && !dev_data->rx.is_slave) { /*full duplex*/ in i2s_esp32_configure()
630 i2s_hal_std_set_tx_slot(hal_cxt, stream->is_slave, &slot_cfg); in i2s_esp32_configure()
641 if (stream->is_slave && dev_data->rx.is_slave) { in i2s_esp32_configure()
649 if (stream->is_slave && !dev_data->tx.is_slave) { /*full duplex*/ in i2s_esp32_configure()
658 i2s_hal_std_set_rx_slot(hal_cxt, stream->is_slave, &slot_cfg); in i2s_esp32_configure()
669 if (!stream->is_slave && !dev_data->tx.is_slave) { in i2s_esp32_configure()
676 memcpy(&stream->i2s_cfg, i2s_cfg, sizeof(struct i2s_config)); in i2s_esp32_configure()
678 stream->state = I2S_STATE_READY; in i2s_esp32_configure()
686 struct i2s_esp32_stream *stream; in i2s_esp32_config_get() local
689 stream = &dev_data->rx; in i2s_esp32_config_get()
691 stream = &dev_data->tx; in i2s_esp32_config_get()
694 if (stream->state == I2S_STATE_NOT_READY) { in i2s_esp32_config_get()
698 return &stream->i2s_cfg; in i2s_esp32_config_get()
704 struct i2s_esp32_stream *stream; in i2s_esp32_trigger() local
711 stream = &dev_data->rx; in i2s_esp32_trigger()
714 stream = &dev_data->tx; in i2s_esp32_trigger()
726 if (stream->state != I2S_STATE_READY) { in i2s_esp32_trigger()
727 LOG_ERR("START - Invalid state: %d", (int)stream->state); in i2s_esp32_trigger()
731 err = stream->start_transfer(dev); in i2s_esp32_trigger()
736 stream->last_block = false; in i2s_esp32_trigger()
737 stream->state = I2S_STATE_RUNNING; in i2s_esp32_trigger()
742 if (stream->state != I2S_STATE_RUNNING) { in i2s_esp32_trigger()
744 LOG_ERR("STOP - Invalid state: %d", (int)stream->state); in i2s_esp32_trigger()
748 err = dma_get_status(stream->dma_dev, stream->dma_channel, &dma_channel_status); in i2s_esp32_trigger()
752 (int)stream->dma_channel, err); in i2s_esp32_trigger()
757 stream->stop_without_draining = true; in i2s_esp32_trigger()
758 stream->state = I2S_STATE_STOPPING; in i2s_esp32_trigger()
760 stream->stop_transfer(dev); in i2s_esp32_trigger()
761 stream->last_block = true; in i2s_esp32_trigger()
762 stream->state = I2S_STATE_READY; in i2s_esp32_trigger()
770 if (stream->state != I2S_STATE_RUNNING) { in i2s_esp32_trigger()
772 LOG_ERR("DRAIN - Invalid state: %d", (int)stream->state); in i2s_esp32_trigger()
776 err = dma_get_status(stream->dma_dev, stream->dma_channel, &dma_channel_status); in i2s_esp32_trigger()
780 (int)stream->dma_channel, err); in i2s_esp32_trigger()
785 if (k_msgq_num_used_get(&stream->queue) > 0 || dma_channel_status.busy) { in i2s_esp32_trigger()
786 stream->stop_without_draining = false; in i2s_esp32_trigger()
787 stream->state = I2S_STATE_STOPPING; in i2s_esp32_trigger()
789 stream->stop_transfer(dev); in i2s_esp32_trigger()
790 stream->state = I2S_STATE_READY; in i2s_esp32_trigger()
794 stream->stop_without_draining = true; in i2s_esp32_trigger()
795 stream->state = I2S_STATE_STOPPING; in i2s_esp32_trigger()
797 stream->stop_transfer(dev); in i2s_esp32_trigger()
798 stream->last_block = true; in i2s_esp32_trigger()
799 stream->state = I2S_STATE_READY; in i2s_esp32_trigger()
811 if (stream->state == I2S_STATE_NOT_READY) { in i2s_esp32_trigger()
812 LOG_ERR("DROP - invalid state: %d", (int)stream->state); in i2s_esp32_trigger()
815 stream->stop_transfer(dev); in i2s_esp32_trigger()
816 stream->queue_drop(stream); in i2s_esp32_trigger()
817 stream->state = I2S_STATE_READY; in i2s_esp32_trigger()
821 if (stream->state != I2S_STATE_ERROR) { in i2s_esp32_trigger()
822 LOG_ERR("PREPARE - invalid state: %d", (int)stream->state); in i2s_esp32_trigger()
825 stream->queue_drop(stream); in i2s_esp32_trigger()
826 stream->state = I2S_STATE_READY; in i2s_esp32_trigger()