+ ASSERT(buf);
+ ASSERT(len >= slice_len);
+ ASSERT(!(len % slice_len));
+
+ i2s->hw->end = false;
+
+ sample_buff = (uint8_t *)buf;
+ next_idx = 0;
+ chunk_size = slice_len;
+ remaing_size = len;
+
+ //Confing DMAC
+ uint32_t cfg = BV(DMAC_CFG_DST_H2SEL) |
+ ((3 << DMAC_CFG_DST_PER_SHIFT) & DMAC_CFG_DST_PER_MASK) | (3 & DMAC_CFG_SRC_PER_MASK);
+ uint32_t ctrla = DMAC_CTRLA_SRC_WIDTH_HALF_WORD | DMAC_CTRLA_DST_WIDTH_HALF_WORD;
+ uint32_t ctrlb = BV(DMAC_CTRLB_SRC_DSCR) |
+ DMAC_CTRLB_FC_MEM2PER_DMA_FC |
+ DMAC_CTRLB_DST_INCR_FIXED | DMAC_CTRLB_SRC_INCR_INCREMENTING;
+
+
+ /* Program the dma with the first and second chunk of samples and update counter */
+ i2s->ctx.tx_callback(i2s, &sample_buff[0], chunk_size);
+
+ curr = &lli0;
+ prev = &lli0;
+ next = &lli1;
+
+ dmac_setSourcesLLI(I2S_DMAC_CH, curr, (uint32_t)&sample_buff[0], (uint32_t)&SSC_THR,(uint32_t)next);
+ dmac_configureDmacLLI(I2S_DMAC_CH, curr, chunk_size / 2, cfg, ctrla, ctrlb);
+
+ remaing_size -= chunk_size;
+ next_idx += chunk_size;
+
+ if (chunk_size <= remaing_size)
+ {
+ i2s->ctx.tx_callback(i2s, &sample_buff[next_idx], chunk_size);
+
+ prev = curr;
+ curr = next;
+ next = prev;
+
+ dmac_setSourcesLLI(I2S_DMAC_CH, curr, (uint32_t)&sample_buff[next_idx], (uint32_t)&SSC_THR,(uint32_t)next);
+ dmac_configureDmacLLI(I2S_DMAC_CH, curr, chunk_size / 2, cfg, ctrla, ctrlb);
+
+ remaing_size -= chunk_size;
+ next_idx += chunk_size;
+ }
+
+ if (dmac_start(I2S_DMAC_CH) < 0)
+ kprintf("start erros[%x]\n", dmac_error(I2S_DMAC_CH));
+
+ SSC_CR = BV(SSC_TXEN);
+
+ while (1)
+ {
+ event_wait(&data_ready);
+ if (i2s->hw->end)
+ break;
+
+ remaing_size -= chunk_size;
+ next_idx += chunk_size;
+
+ if (remaing_size <= 0)
+ {
+ remaing_size = len;
+ next_idx = 0;
+ }
+
+ if (dmac_start(I2S_DMAC_CH) < 0)
+ kprintf("start erros[%x]\n", dmac_error(I2S_DMAC_CH));
+
+ i2s->ctx.tx_callback(i2s, &sample_buff[next_idx], chunk_size);
+ }