#include #include #include #include #include #include "xperipherals_adat.h" // 256-Bit ADAT Packet // // The packet structure below shows [Channel Number]:[Sample Bit Pos] for audio samples. // The 256-bit sequence is NRZI encoded when transmitting and NRZI decoded when receiving. // Samples are serialized MSB first (:00 represents MSB and :23 represents LSB) // // Note: Bit stuffing with 'ones' every fifth bit and NRZI encoding prevents long runs // of zeros. The zero's at the end of the frame are used for frame synchronization. // // 0 |one |0:00|0:01|0:02|0:03|one |0:04|0:05|0:06|0:07|one |0:08|0:09|0:10|0:11|one | // |0:12|0:13|0:14|0:15|one |0:16|0:17|0:18|0:19|one |0:20|0:21|0:22|0:23|one |1:00| // 1 |1:01|1:02|1:03|one |1:04|1:05|1:06|1:07|one |1:08|1:09|1:10|1:11|one |1:12|1:13| // |1:14|1:15|one |1:16|1:17|1:18|1:19|one |1:20|1:21|1:22|1:23|one |2:00|2:01|2:02| // 2 |2:03|one |2:04|2:05|2:06|2:07|one |2:08|2:09|2:10|2:11|one |2:12|2:13|2:14|2:15| // |one |2:16|2:17|2:18|2:19|one |2:20|2:21|2:22|2:23|one |3:00|3:01|3:02|3:03|one | // 3 |3:04|3:05|3:06|3:07|one |3:08|3:09|3:10|3:11|one |3:12|3:13|3:14|3:15|one |3:16| // |3:17|3:18|3:19|one |3:20|3:21|3:22|3:23|one |4:00|4:01|4:02|4:03|one |4:04|4:05| // 4 |4:06|4:07|one |4:08|4:09|4:10|4:11|one |4:12|4:13|4:14|4:15|one |4:16|4:17|4:18| // |4:19|one |4:20|4:21|4:22|4:23|one |5:00|5:01|5:02|5:03|one |5:04|5:05|5:06|5:07| // 5 |one |5:08|5:09|5:10|5:11|one |5:12|5:13|5:14|5:15|one |5:16|5:17|5:18|5:19|one | // |5:20|5:21|5:22|5:23|one |6:00|6:01|6:02|6:03|one |6:04|6:05|6:06|6:07|one |6:08| // 6 |6:09|6:10|6:11|one |6:12|6:13|6:14|6:15|one |6:16|6:17|6:18|6:19|one |6:20|6:21| // |6:22|6:23|one |7:00|7:01|7:02|7:03|one |7:04|7:05|7:06|7:07|one |7:08|7:09|7:10| // 7 |7:11|one |7:12|7:13|7:14|7:15|one |7:16|7:17|7:18|7:19|one |7:20|7:21|7:22|7:23| // |one |zero|zero|zero|zero|zero|zero|zero|zero|zero|zero|one |usr0|usr1|usr2|usr3| #ifdef XPERIPHERALS_ADAT_RX_1 on tile[XPERIPHERALS_ADAT_RX_1__TILE_NUMBER] : out buffered port:32 _xperipherals_adat_rx_1__port_rxd = XPERIPHERALS_ADAT_RX_1__RXD_PORT; static xuint _bclk_divider; static xuint _encode_lut[256]; static xuint _enc_word; static xuint _tx_carry; void xperipherals_adat_rx_1__init( xuint bclk_divider ) { _bclk_divider = bclk_divider; _enc_word = _tx_carry = 0; switch( _bclk_divider ) { case 1: // bit clock frequency = 1 * ADAT bit rate = 12.288 / 11.2896 MHz for( int j = 0; j < 256; ++j ) { xuint carry = 0; xuint data = 0b1000010000 | ((j & 0xF0) << 1) | (j & 0x0F); _encode_lut[j] = 0; for( int i = 0; i < 10; ++i, data <<= 1 ) { if( data & 0b1000000000 ) carry = !carry; _encode_lut[j] = (_encode_lut[j] << 1) | carry; } } break; case 2: // bit clock frequency = 2 * ADAT bit rate = 24.576 / 22.5792 MHz // TODO break; case 4: // bit clock frequency = 4 * ADAT bit rate = 49.152 / 45.1584 MHz // TODO break; } } void xperipherals_adat_rx_1__config( clock bit_clock ) { configure_out_port_no_ready( _xperipherals_adat_rx_1__port_rxd, bit_clock, 0 ); clearbuf( _xperipherals_adat_rx_1__port_rxd ); } #pragma unsafe arrays static void _decode_data( xuint sample, xuint shift ) { } // |one |0:00|0:01|0:02|0:03|one |0:04|0:05|0:06|0:07|one |0:08|0:09|0:10|0:11|one | // |0:12|0:13|0:14|0:15|one |0:16|0:17|0:18|0:19|one |0:20|0:21|0:22|0:23|one |1:00| void xperipherals_adat_rx_1__phase0( xsint& sample_0, xsint& sample_1 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |1:01|1:02|1:03|one |1:04|1:05|1:06|1:07|one |1:08|1:09|1:10|1:11|one |1:12|1:13| // |1:14|1:15|one |1:16|1:17|1:18|1:19|one |1:20|1:21|1:22|1:23|one |2:00|2:01|2:02| void xperipherals_adat_rx_1__phase1( xsint& sample_1, xsint& sample_2 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |2:03|one |2:04|2:05|2:06|2:07|one |2:08|2:09|2:10|2:11|one |2:12|2:13|2:14|2:15| // |one |2:16|2:17|2:18|2:19|one |2:20|2:21|2:22|2:23|one |3:00|3:01|3:02|3:03|one | void xperipherals_adat_rx_1__phase2( xsint& sample_2, xsint& sample_3 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |3:04|3:05|3:06|3:07|one |3:08|3:09|3:10|3:11|one |3:12|3:13|3:14|3:15|one |3:16| // |3:17|3:18|3:19|one |3:20|3:21|3:22|3:23|one |4:00|4:01|4:02|4:03|one |4:04|4:05| void xperipherals_adat_rx_1__phase3( xsint& sample_3, xsint& sample_4 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |4:06|4:07|one |4:08|4:09|4:10|4:11|one |4:12|4:13|4:14|4:15|one |4:16|4:17|4:18| // |4:19|one |4:20|4:21|4:22|4:23|one |5:00|5:01|5:02|5:03|one |5:04|5:05|5:06|5:07| void xperipherals_adat_rx_1__phase4( xsint& sample_4, xsint& sample_5 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |one |5:08|5:09|5:10|5:11|one |5:12|5:13|5:14|5:15|one |5:16|5:17|5:18|5:19|one | // |5:20|5:21|5:22|5:23|one |6:00|6:01|6:02|6:03|one |6:04|6:05|6:06|6:07|one |6:08| void xio_adat_tx_1__phase5( xsint& sample_5, xsint& sample_6 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |6:09|6:10|6:11|one |6:12|6:13|6:14|6:15|one |6:16|6:17|6:18|6:19|one |6:20|6:21| // |6:22|6:23|one |7:00|7:01|7:02|7:03|one |7:04|7:05|7:06|7:07|one |7:08|7:09|7:10| void xio_adat_tx_1__phase6( xsint& sample_6, xsint& sample_7 ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } // |7:11|one |7:12|7:13|7:14|7:15|one |7:16|7:17|7:18|7:19|one |7:20|7:21|7:22|7:23| // |one |zero|zero|zero|zero|zero|zero|zero|zero|zero|zero|one |Usr0|Usr1|Usr2|Usr3| void xio_adat_tx_1__phase7( xsint& sample_7, xuint& userdata ) { xuint data; _xperipherals_adat_rx_1__port_rxd :> data; data = bitrev( data ); } #endif