+ ASSERT(dac);
+ ASSERT(len >= slice_len);
+
+ /* Reset the previous status. */
+ dac->hw->end = false;
+
+ sample_buff = (uint16_t *)_buf;
+ next_idx = 0;
+ chunk_size = slice_len;
+ remaing_size = len;
+
+
+ /* Program the dma with the first and second chunk of samples and update counter */
+ dac->ctx.callback(dac, &sample_buff[0], chunk_size);
+ DACC_TPR = (uint32_t)&sample_buff[0];
+ DACC_TCR = chunk_size;
+ remaing_size -= chunk_size;
+ next_idx += chunk_size;
+
+ if (chunk_size <= remaing_size)
+ {
+ dac->ctx.callback(dac, &sample_buff[next_idx], chunk_size);
+
+ DACC_TNPR = (uint32_t)&sample_buff[next_idx];
+ DACC_TNCR = chunk_size;
+
+ remaing_size -= chunk_size;
+ next_idx += chunk_size;
+
+ }
+
+ DACC_PTCR |= BV(DACC_PTCR_TXTEN);
+ DACC_IER = BV(DACC_ENDTX);
+
+ /* Set up timer and trig the conversions */
+ tc_setup(dac->hw->rate, len);
+ tc_start();
+
+ while (1)
+ {
+ event_wait(&buff_emtpy);
+ if (remaing_size <= 0)
+ {
+ DAC_TC_CCR = BV(TC_CCR_CLKDIS);
+ dac->hw->end = true;
+ next_idx = 0;
+ chunk_size = 0;
+ remaing_size = 0;
+ break;
+ }
+
+ dac->ctx.callback(dac, &sample_buff[next_idx], chunk_size);
+ }