Lines Matching refs:strm
118 static inline void i2s_purge_stream_buffers(struct stream *strm, struct k_mem_slab *mem_slab, in i2s_purge_stream_buffers() argument
124 while (k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT) == 0) { in i2s_purge_stream_buffers()
130 while (k_msgq_get(&strm->out_queue, &buffer, K_NO_WAIT) == 0) { in i2s_purge_stream_buffers()
139 struct stream *strm = &dev_data->tx; in i2s_tx_stream_disable() local
143 LOG_DBG("Stopping DMA channel %u for TX stream", strm->dma_channel); in i2s_tx_stream_disable()
148 dma_stop(dev_dma, strm->dma_channel); in i2s_tx_stream_disable()
169 i2s_purge_stream_buffers(strm, dev_data->tx.cfg.mem_slab, true, true); in i2s_tx_stream_disable()
176 struct stream *strm = &dev_data->rx; in i2s_rx_stream_disable() local
180 LOG_DBG("Stopping RX stream & DMA channel %u", strm->dma_channel); in i2s_rx_stream_disable()
181 dma_stop(dev_dma, strm->dma_channel); in i2s_rx_stream_disable()
202 i2s_purge_stream_buffers(strm, dev_data->rx.cfg.mem_slab, in_drop, out_drop); in i2s_rx_stream_disable()
211 struct stream *strm = &dev_data->tx; in i2s_tx_reload_multiple_dma_blocks() local
221 while (strm->free_tx_dma_blocks) { in i2s_tx_reload_multiple_dma_blocks()
223 ret = k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_tx_reload_multiple_dma_blocks()
231 ret = dma_reload(dev_data->dev_dma, strm->dma_channel, (uint32_t)buffer, in i2s_tx_reload_multiple_dma_blocks()
232 (uint32_t)&base->TDR[strm->start_channel], strm->cfg.block_size); in i2s_tx_reload_multiple_dma_blocks()
238 (strm->free_tx_dma_blocks)--; in i2s_tx_reload_multiple_dma_blocks()
240 ret = k_msgq_put(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_tx_reload_multiple_dma_blocks()
242 LOG_ERR("buffer %p -> out %p err %d", buffer, &strm->out_queue, ret); in i2s_tx_reload_multiple_dma_blocks()
259 struct stream *strm = &dev_data->tx; in i2s_dma_tx_callback() local
266 ret = k_msgq_get(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_dma_tx_callback()
269 k_mem_slab_free(strm->cfg.mem_slab, buffer); in i2s_dma_tx_callback()
270 (strm->free_tx_dma_blocks)++; in i2s_dma_tx_callback()
275 if (strm->free_tx_dma_blocks > MAX_TX_DMA_BLOCKS) { in i2s_dma_tx_callback()
276 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
277 LOG_ERR("free_tx_dma_blocks exceeded maximum, now %d", strm->free_tx_dma_blocks); in i2s_dma_tx_callback()
282 if (strm->last_block) { in i2s_dma_tx_callback()
283 strm->state = I2S_STATE_READY; in i2s_dma_tx_callback()
290 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
294 switch (strm->state) { in i2s_dma_tx_callback()
300 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
304 if (blocks_queued || (strm->free_tx_dma_blocks < MAX_TX_DMA_BLOCKS)) { in i2s_dma_tx_callback()
308 if (strm->state == I2S_STATE_STOPPING) { in i2s_dma_tx_callback()
310 strm->state = I2S_STATE_READY; in i2s_dma_tx_callback()
313 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
343 struct stream *strm = &dev_data->rx; in i2s_dma_rx_callback() local
349 switch (strm->state) { in i2s_dma_rx_callback()
353 ret = k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_dma_rx_callback()
357 ret = k_msgq_put(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_dma_rx_callback()
359 LOG_ERR("buffer %p -> out_queue %p err %d", buffer, &strm->out_queue, ret); in i2s_dma_rx_callback()
361 strm->state = I2S_STATE_ERROR; in i2s_dma_rx_callback()
364 if (strm->state == I2S_STATE_RUNNING) { in i2s_dma_rx_callback()
366 ret = k_mem_slab_alloc(strm->cfg.mem_slab, &buffer, K_NO_WAIT); in i2s_dma_rx_callback()
368 LOG_ERR("buffer alloc from slab %p err %d", strm->cfg.mem_slab, in i2s_dma_rx_callback()
371 strm->state = I2S_STATE_ERROR; in i2s_dma_rx_callback()
373 uint32_t data_path = strm->start_channel; in i2s_dma_rx_callback()
375 ret = dma_reload(dev_data->dev_dma, strm->dma_channel, in i2s_dma_rx_callback()
377 strm->cfg.block_size); in i2s_dma_rx_callback()
381 strm->state = I2S_STATE_ERROR; in i2s_dma_rx_callback()
386 ret = k_msgq_put(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_dma_rx_callback()
388 LOG_ERR("%p -> in_queue %p err %d", buffer, &strm->in_queue, in i2s_dma_rx_callback()
396 strm->state = I2S_STATE_READY; in i2s_dma_rx_callback()
701 struct stream *strm = &dev_data->tx; in i2s_tx_stream_start() local
707 ret = k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_tx_stream_start()
716 strm->free_tx_dma_blocks = MAX_TX_DMA_BLOCKS; in i2s_tx_stream_start()
719 struct dma_block_config *blk_cfg = &strm->dma_block; in i2s_tx_stream_start()
723 uint32_t data_path = strm->start_channel; in i2s_tx_stream_start()
727 blk_cfg->block_size = strm->cfg.block_size; in i2s_tx_stream_start()
730 strm->dma_cfg.block_count = 1; in i2s_tx_stream_start()
732 strm->dma_cfg.head_block = &strm->dma_block; in i2s_tx_stream_start()
733 strm->dma_cfg.user_data = (void *)dev; in i2s_tx_stream_start()
735 (strm->free_tx_dma_blocks)--; in i2s_tx_stream_start()
736 dma_config(dev_dma, strm->dma_channel, &strm->dma_cfg); in i2s_tx_stream_start()
739 ret = k_msgq_put(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_tx_stream_start()
753 ret = dma_start(dev_dma, strm->dma_channel); in i2s_tx_stream_start()
763 base->TCR3 |= I2S_TCR3_TCE(1UL << strm->start_channel); in i2s_tx_stream_start()
776 struct stream *strm = &dev_data->rx; in i2s_rx_stream_start() local
782 num_of_bufs = k_mem_slab_num_free_get(strm->cfg.mem_slab); in i2s_rx_stream_start()
793 ret = k_mem_slab_alloc(strm->cfg.mem_slab, &buffer, K_NO_WAIT); in i2s_rx_stream_start()
800 struct dma_block_config *blk_cfg = &strm->dma_block; in i2s_rx_stream_start()
804 uint32_t data_path = strm->start_channel; in i2s_rx_stream_start()
808 blk_cfg->block_size = strm->cfg.block_size; in i2s_rx_stream_start()
812 strm->dma_cfg.block_count = 1; in i2s_rx_stream_start()
813 strm->dma_cfg.head_block = &strm->dma_block; in i2s_rx_stream_start()
814 strm->dma_cfg.user_data = (void *)dev; in i2s_rx_stream_start()
816 dma_config(dev_dma, strm->dma_channel, &strm->dma_cfg); in i2s_rx_stream_start()
819 ret = k_msgq_put(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_rx_stream_start()
829 ret = k_mem_slab_alloc(strm->cfg.mem_slab, &buffer, K_NO_WAIT); in i2s_rx_stream_start()
835 ret = dma_reload(dev_dma, strm->dma_channel, (uint32_t)&base->RDR[data_path], in i2s_rx_stream_start()
843 ret = k_msgq_put(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_rx_stream_start()
850 LOG_DBG("Starting DMA Ch%u", strm->dma_channel); in i2s_rx_stream_start()
851 ret = dma_start(dev_dma, strm->dma_channel); in i2s_rx_stream_start()
853 LOG_ERR("Failed to start DMA Ch%d (%d)", strm->dma_channel, ret); in i2s_rx_stream_start()
861 base->RCR3 |= I2S_RCR3_RCE(1UL << strm->start_channel); in i2s_rx_stream_start()
872 struct stream *strm; in i2s_mcux_trigger() local
880 strm = (dir == I2S_DIR_TX) ? &dev_data->tx : &dev_data->rx; in i2s_mcux_trigger()
885 if (strm->state != I2S_STATE_READY) { in i2s_mcux_trigger()
886 LOG_ERR("START trigger: invalid state %u", strm->state); in i2s_mcux_trigger()
903 strm->state = I2S_STATE_RUNNING; in i2s_mcux_trigger()
904 strm->last_block = false; in i2s_mcux_trigger()
908 if (strm->state == I2S_STATE_NOT_READY) { in i2s_mcux_trigger()
909 LOG_ERR("DROP trigger: invalid state %d", strm->state); in i2s_mcux_trigger()
914 strm->state = I2S_STATE_READY; in i2s_mcux_trigger()
923 if (strm->state != I2S_STATE_RUNNING) { in i2s_mcux_trigger()
924 LOG_ERR("STOP trigger: invalid state %d", strm->state); in i2s_mcux_trigger()
929 strm->state = I2S_STATE_STOPPING; in i2s_mcux_trigger()
930 strm->last_block = true; in i2s_mcux_trigger()
934 if (strm->state != I2S_STATE_RUNNING) { in i2s_mcux_trigger()
935 LOG_ERR("DRAIN/STOP trigger: invalid state %d", strm->state); in i2s_mcux_trigger()
940 strm->state = I2S_STATE_STOPPING; in i2s_mcux_trigger()
944 if (strm->state != I2S_STATE_ERROR) { in i2s_mcux_trigger()
945 LOG_ERR("PREPARE trigger: invalid state %d", strm->state); in i2s_mcux_trigger()
949 strm->state = I2S_STATE_READY; in i2s_mcux_trigger()
969 struct stream *strm = &dev_data->rx; in i2s_mcux_read() local
974 if (strm->state == I2S_STATE_NOT_READY) { in i2s_mcux_read()
975 LOG_ERR("invalid state %d", strm->state); in i2s_mcux_read()
979 status = k_msgq_get(&strm->out_queue, &buffer, SYS_TIMEOUT_MS(strm->cfg.timeout)); in i2s_mcux_read()
981 if (strm->state == I2S_STATE_ERROR) { in i2s_mcux_read()
991 *size = strm->cfg.block_size; in i2s_mcux_read()
998 struct stream *strm = &dev_data->tx; in i2s_mcux_write() local
1002 if (strm->state != I2S_STATE_RUNNING && strm->state != I2S_STATE_READY) { in i2s_mcux_write()
1003 LOG_ERR("invalid state (%d)", strm->state); in i2s_mcux_write()
1007 ret = k_msgq_put(&strm->in_queue, &mem_block, SYS_TIMEOUT_MS(strm->cfg.timeout)); in i2s_mcux_write()