Lines Matching refs:strm

119 static inline void i2s_purge_stream_buffers(struct stream *strm,  in i2s_purge_stream_buffers()  argument
126 while (k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT) == 0) { in i2s_purge_stream_buffers()
132 while (k_msgq_get(&strm->out_queue, &buffer, K_NO_WAIT) == 0) { in i2s_purge_stream_buffers()
141 struct stream *strm = &dev_data->tx; in i2s_tx_stream_disable() local
145 LOG_DBG("Stopping DMA channel %u for TX stream", strm->dma_channel); in i2s_tx_stream_disable()
151 dma_stop(dev_dma, strm->dma_channel); in i2s_tx_stream_disable()
172 i2s_purge_stream_buffers(strm, dev_data->tx.cfg.mem_slab, in i2s_tx_stream_disable()
181 struct stream *strm = &dev_data->rx; in i2s_rx_stream_disable() local
185 LOG_DBG("Stopping RX stream & DMA channel %u", strm->dma_channel); in i2s_rx_stream_disable()
186 dma_stop(dev_dma, strm->dma_channel); in i2s_rx_stream_disable()
207 i2s_purge_stream_buffers(strm, dev_data->rx.cfg.mem_slab, in i2s_rx_stream_disable()
218 struct stream *strm = &dev_data->tx; in i2s_tx_reload_multiple_dma_blocks() local
228 while (strm->free_tx_dma_blocks) { in i2s_tx_reload_multiple_dma_blocks()
230 ret = k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_tx_reload_multiple_dma_blocks()
238 ret = dma_reload(dev_data->dev_dma, strm->dma_channel, in i2s_tx_reload_multiple_dma_blocks()
240 (uint32_t)&base->TDR[strm->start_channel], in i2s_tx_reload_multiple_dma_blocks()
241 strm->cfg.block_size); in i2s_tx_reload_multiple_dma_blocks()
247 (strm->free_tx_dma_blocks)--; in i2s_tx_reload_multiple_dma_blocks()
249 ret = k_msgq_put(&strm->out_queue, in i2s_tx_reload_multiple_dma_blocks()
253 buffer, &strm->out_queue, ret); in i2s_tx_reload_multiple_dma_blocks()
270 struct stream *strm = &dev_data->tx; in i2s_dma_tx_callback() local
277 ret = k_msgq_get(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_dma_tx_callback()
280 k_mem_slab_free(strm->cfg.mem_slab, buffer); in i2s_dma_tx_callback()
281 (strm->free_tx_dma_blocks)++; in i2s_dma_tx_callback()
286 if (strm->free_tx_dma_blocks > MAX_TX_DMA_BLOCKS) { in i2s_dma_tx_callback()
287 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
289 strm->free_tx_dma_blocks); in i2s_dma_tx_callback()
294 if (strm->last_block) { in i2s_dma_tx_callback()
295 strm->state = I2S_STATE_READY; in i2s_dma_tx_callback()
302 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
306 switch (strm->state) { in i2s_dma_tx_callback()
312 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
315 dma_start(dev_data->dev_dma, strm->dma_channel); in i2s_dma_tx_callback()
318 (strm->free_tx_dma_blocks < MAX_TX_DMA_BLOCKS)) { in i2s_dma_tx_callback()
322 if (strm->state == I2S_STATE_STOPPING) { in i2s_dma_tx_callback()
324 strm->state = I2S_STATE_READY; in i2s_dma_tx_callback()
327 strm->state = I2S_STATE_ERROR; in i2s_dma_tx_callback()
357 struct stream *strm = &dev_data->rx; in i2s_dma_rx_callback() local
363 switch (strm->state) { in i2s_dma_rx_callback()
367 ret = k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_dma_rx_callback()
371 ret = k_msgq_put(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_dma_rx_callback()
375 &strm->out_queue, ret); in i2s_dma_rx_callback()
377 strm->state = I2S_STATE_ERROR; in i2s_dma_rx_callback()
380 if (strm->state == I2S_STATE_RUNNING) { in i2s_dma_rx_callback()
382 ret = k_mem_slab_alloc(strm->cfg.mem_slab, in i2s_dma_rx_callback()
386 strm->cfg.mem_slab, ret); in i2s_dma_rx_callback()
388 strm->state = I2S_STATE_ERROR; in i2s_dma_rx_callback()
390 uint32_t data_path = strm->start_channel; in i2s_dma_rx_callback()
393 strm->dma_channel, in i2s_dma_rx_callback()
396 strm->cfg.block_size); in i2s_dma_rx_callback()
402 strm->state = I2S_STATE_ERROR; in i2s_dma_rx_callback()
407 ret = k_msgq_put(&strm->in_queue, in i2s_dma_rx_callback()
411 buffer, &strm->in_queue, in i2s_dma_rx_callback()
416 strm->dma_channel); in i2s_dma_rx_callback()
421 strm->state = I2S_STATE_READY; in i2s_dma_rx_callback()
760 struct stream *strm = &dev_data->tx; in i2s_tx_stream_start() local
766 ret = k_msgq_get(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_tx_stream_start()
775 strm->free_tx_dma_blocks = MAX_TX_DMA_BLOCKS; in i2s_tx_stream_start()
778 struct dma_block_config *blk_cfg = &strm->dma_block; in i2s_tx_stream_start()
782 uint32_t data_path = strm->start_channel; in i2s_tx_stream_start()
786 blk_cfg->block_size = strm->cfg.block_size; in i2s_tx_stream_start()
789 strm->dma_cfg.block_count = 1; in i2s_tx_stream_start()
791 strm->dma_cfg.head_block = &strm->dma_block; in i2s_tx_stream_start()
792 strm->dma_cfg.user_data = (void *)dev; in i2s_tx_stream_start()
795 (strm->free_tx_dma_blocks)--; in i2s_tx_stream_start()
796 dma_config(dev_dma, strm->dma_channel, &strm->dma_cfg); in i2s_tx_stream_start()
799 ret = k_msgq_put(&strm->out_queue, &buffer, K_NO_WAIT); in i2s_tx_stream_start()
813 ret = dma_start(dev_dma, strm->dma_channel); in i2s_tx_stream_start()
823 base->TCR3 |= I2S_TCR3_TCE(1UL << strm->start_channel); in i2s_tx_stream_start()
836 struct stream *strm = &dev_data->rx; in i2s_rx_stream_start() local
842 num_of_bufs = k_mem_slab_num_free_get(strm->cfg.mem_slab); in i2s_rx_stream_start()
853 ret = k_mem_slab_alloc(strm->cfg.mem_slab, &buffer, in i2s_rx_stream_start()
861 struct dma_block_config *blk_cfg = &strm->dma_block; in i2s_rx_stream_start()
865 uint32_t data_path = strm->start_channel; in i2s_rx_stream_start()
869 blk_cfg->block_size = strm->cfg.block_size; in i2s_rx_stream_start()
873 strm->dma_cfg.block_count = 1; in i2s_rx_stream_start()
874 strm->dma_cfg.head_block = &strm->dma_block; in i2s_rx_stream_start()
875 strm->dma_cfg.user_data = (void *)dev; in i2s_rx_stream_start()
877 dma_config(dev_dma, strm->dma_channel, &strm->dma_cfg); in i2s_rx_stream_start()
880 ret = k_msgq_put(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_rx_stream_start()
890 ret = k_mem_slab_alloc(strm->cfg.mem_slab, &buffer, in i2s_rx_stream_start()
897 ret = dma_reload(dev_dma, strm->dma_channel, in i2s_rx_stream_start()
906 ret = k_msgq_put(&strm->in_queue, &buffer, K_NO_WAIT); in i2s_rx_stream_start()
914 LOG_DBG("Starting DMA Ch%u", strm->dma_channel); in i2s_rx_stream_start()
915 ret = dma_start(dev_dma, strm->dma_channel); in i2s_rx_stream_start()
917 LOG_ERR("Failed to start DMA Ch%d (%d)", strm->dma_channel, in i2s_rx_stream_start()
926 base->RCR3 |= I2S_RCR3_RCE(1UL << strm->start_channel); in i2s_rx_stream_start()
938 struct stream *strm; in i2s_mcux_trigger() local
946 strm = (dir == I2S_DIR_TX) ? &dev_data->tx : &dev_data->rx; in i2s_mcux_trigger()
951 if (strm->state != I2S_STATE_READY) { in i2s_mcux_trigger()
953 strm->state); in i2s_mcux_trigger()
970 strm->state = I2S_STATE_RUNNING; in i2s_mcux_trigger()
971 strm->last_block = false; in i2s_mcux_trigger()
975 if (strm->state == I2S_STATE_NOT_READY) { in i2s_mcux_trigger()
977 strm->state); in i2s_mcux_trigger()
982 strm->state = I2S_STATE_READY; in i2s_mcux_trigger()
991 if (strm->state != I2S_STATE_RUNNING) { in i2s_mcux_trigger()
992 LOG_ERR("STOP trigger: invalid state %d", strm->state); in i2s_mcux_trigger()
997 strm->state = I2S_STATE_STOPPING; in i2s_mcux_trigger()
998 strm->last_block = true; in i2s_mcux_trigger()
1002 if (strm->state != I2S_STATE_RUNNING) { in i2s_mcux_trigger()
1004 strm->state); in i2s_mcux_trigger()
1009 strm->state = I2S_STATE_STOPPING; in i2s_mcux_trigger()
1013 if (strm->state != I2S_STATE_ERROR) { in i2s_mcux_trigger()
1015 strm->state); in i2s_mcux_trigger()
1019 strm->state = I2S_STATE_READY; in i2s_mcux_trigger()
1040 struct stream *strm = &dev_data->rx; in i2s_mcux_read() local
1045 if (strm->state == I2S_STATE_NOT_READY) { in i2s_mcux_read()
1046 LOG_ERR("invalid state %d", strm->state); in i2s_mcux_read()
1050 status = k_msgq_get(&strm->out_queue, &buffer, in i2s_mcux_read()
1051 SYS_TIMEOUT_MS(strm->cfg.timeout)); in i2s_mcux_read()
1053 if (strm->state == I2S_STATE_ERROR) { in i2s_mcux_read()
1063 *size = strm->cfg.block_size; in i2s_mcux_read()
1071 struct stream *strm = &dev_data->tx; in i2s_mcux_write() local
1075 if (strm->state != I2S_STATE_RUNNING && in i2s_mcux_write()
1076 strm->state != I2S_STATE_READY) { in i2s_mcux_write()
1077 LOG_ERR("invalid state (%d)", strm->state); in i2s_mcux_write()
1081 ret = k_msgq_put(&strm->in_queue, &mem_block, in i2s_mcux_write()
1082 SYS_TIMEOUT_MS(strm->cfg.timeout)); in i2s_mcux_write()