|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
-
-
- #include <Arduino.h>
- #include "input_i2s_oct.h"
- #include "output_i2s.h"
-
- DMAMEM __attribute__((aligned(32))) static uint32_t i2s_rx_buffer[AUDIO_BLOCK_SAMPLES*4];
- audio_block_t * AudioInputI2SOct::block_ch1 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch2 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch3 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch4 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch5 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch6 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch7 = NULL;
- audio_block_t * AudioInputI2SOct::block_ch8 = NULL;
- uint16_t AudioInputI2SOct::block_offset = 0;
- bool AudioInputI2SOct::update_responsibility = false;
- DMAChannel AudioInputI2SOct::dma(false);
-
- #if defined(__IMXRT1062__)
-
- void AudioInputI2SOct::begin(void)
- {
- dma.begin(true);
-
- AudioOutputI2S::config_i2s();
- I2S1_RCR3 = I2S_RCR3_RCE_4CH;
- CORE_PIN8_CONFIG = 3;
- CORE_PIN6_CONFIG = 3;
- CORE_PIN9_CONFIG = 3;
- CORE_PIN32_CONFIG = 3;
- IOMUXC_SAI1_RX_DATA0_SELECT_INPUT = 2;
- IOMUXC_SAI1_RX_DATA1_SELECT_INPUT = 1;
- IOMUXC_SAI1_RX_DATA2_SELECT_INPUT = 1;
- IOMUXC_SAI1_RX_DATA3_SELECT_INPUT = 1;
-
- dma.TCD->SADDR = (void *)((uint32_t)&I2S1_RDR0 + 2);
- dma.TCD->SOFF = 4;
- dma.TCD->ATTR = DMA_TCD_ATTR_SSIZE(1) | DMA_TCD_ATTR_DSIZE(1);
- dma.TCD->NBYTES_MLOFFYES = DMA_TCD_NBYTES_SMLOE |
- DMA_TCD_NBYTES_MLOFFYES_MLOFF(-16) |
- DMA_TCD_NBYTES_MLOFFYES_NBYTES(8);
- dma.TCD->SLAST = -16;
- dma.TCD->DADDR = i2s_rx_buffer;
- dma.TCD->DOFF = 2;
- dma.TCD->CITER_ELINKNO = AUDIO_BLOCK_SAMPLES * 2;
- dma.TCD->DLASTSGA = -sizeof(i2s_rx_buffer);
- dma.TCD->BITER_ELINKNO = AUDIO_BLOCK_SAMPLES * 2;
- dma.TCD->CSR = DMA_TCD_CSR_INTHALF | DMA_TCD_CSR_INTMAJOR;
- dma.triggerAtHardwareEvent(DMAMUX_SOURCE_SAI1_RX);
-
- I2S1_RCSR = I2S_RCSR_RE | I2S_RCSR_BCE | I2S_RCSR_FRDE | I2S_RCSR_FR;
- update_responsibility = update_setup();
- dma.enable();
- dma.attachInterrupt(isr);
- }
-
- void AudioInputI2SOct::isr(void)
- {
- uint32_t daddr, offset;
- const int16_t *src;
- int16_t *dest1, *dest2, *dest3, *dest4, *dest5, *dest6, *dest7, *dest8;
-
-
- daddr = (uint32_t)(dma.TCD->DADDR);
- dma.clearInterrupt();
-
- if (daddr < (uint32_t)i2s_rx_buffer + sizeof(i2s_rx_buffer) / 2) {
-
-
- src = (int16_t *)((uint32_t)i2s_rx_buffer + sizeof(i2s_rx_buffer) / 2);
- if (update_responsibility) update_all();
- } else {
-
-
- src = (int16_t *)&i2s_rx_buffer[0];
- }
- if (block_ch1) {
- offset = block_offset;
- if (offset <= AUDIO_BLOCK_SAMPLES/2) {
- arm_dcache_delete((void *)src, sizeof(i2s_rx_buffer) / 2);
- block_offset = offset + AUDIO_BLOCK_SAMPLES/2;
- dest1 = &(block_ch1->data[offset]);
- dest2 = &(block_ch2->data[offset]);
- dest3 = &(block_ch3->data[offset]);
- dest4 = &(block_ch4->data[offset]);
- dest5 = &(block_ch5->data[offset]);
- dest6 = &(block_ch6->data[offset]);
- dest7 = &(block_ch7->data[offset]);
- dest8 = &(block_ch8->data[offset]);
- for (int i=0; i < AUDIO_BLOCK_SAMPLES/2; i++) {
- *dest1++ = *src++;
- *dest3++ = *src++;
- *dest5++ = *src++;
- *dest7++ = *src++;
- *dest2++ = *src++;
- *dest4++ = *src++;
- *dest6++ = *src++;
- *dest8++ = *src++;
- }
- }
- }
-
- }
-
-
- void AudioInputI2SOct::update(void)
- {
- audio_block_t *new1, *new2, *new3, *new4, *new5, *new6, *new7, *new8;
- audio_block_t *out1, *out2, *out3, *out4, *out5, *out6, *out7, *out8;
-
-
- new1 = allocate();
- new2 = allocate();
- new3 = allocate();
- new4 = allocate();
- new5 = allocate();
- new6 = allocate();
- new7 = allocate();
- new8 = allocate();
-
- if (!new1 || !new2 || !new3 || !new4 || !new5 || !new6 || !new7 || !new8) {
- if (new1) {
- release(new1);
- new1 = NULL;
- }
- if (new2) {
- release(new2);
- new2 = NULL;
- }
- if (new3) {
- release(new3);
- new3 = NULL;
- }
- if (new4) {
- release(new4);
- new4 = NULL;
- }
- if (new5) {
- release(new5);
- new5 = NULL;
- }
- if (new6) {
- release(new6);
- new6 = NULL;
- }
- if (new7) {
- release(new7);
- new7 = NULL;
- }
- if (new8) {
- release(new8);
- new8 = NULL;
- }
- }
- __disable_irq();
- if (block_offset >= AUDIO_BLOCK_SAMPLES) {
-
-
- out1 = block_ch1;
- block_ch1 = new1;
- out2 = block_ch2;
- block_ch2 = new2;
- out3 = block_ch3;
- block_ch3 = new3;
- out4 = block_ch4;
- block_ch4 = new4;
- out5 = block_ch5;
- block_ch5 = new5;
- out6 = block_ch6;
- block_ch6 = new6;
- out7 = block_ch7;
- block_ch7 = new7;
- out8 = block_ch8;
- block_ch8 = new8;
- block_offset = 0;
- __enable_irq();
-
- transmit(out1, 0);
- release(out1);
- transmit(out2, 1);
- release(out2);
- transmit(out3, 2);
- release(out3);
- transmit(out4, 3);
- release(out4);
- transmit(out5, 4);
- release(out5);
- transmit(out6, 5);
- release(out6);
- transmit(out7, 6);
- release(out7);
- transmit(out8, 7);
- release(out8);
- } else if (new1 != NULL) {
-
- if (block_ch1 == NULL) {
-
-
- block_ch1 = new1;
- block_ch2 = new2;
- block_ch3 = new3;
- block_ch4 = new4;
- block_ch5 = new5;
- block_ch6 = new6;
- block_ch7 = new7;
- block_ch8 = new8;
- block_offset = 0;
- __enable_irq();
- } else {
-
- __enable_irq();
- release(new1);
- release(new2);
- release(new3);
- release(new4);
- release(new5);
- release(new6);
- release(new7);
- release(new8);
- }
- } else {
-
-
-
- __enable_irq();
- }
- }
-
- #else
-
- void AudioInputI2SOct::begin(void)
- {
- }
-
-
-
- #endif
-
|