/************************************************************************** Program: codec.c This program demonstrates how analog input and output is done. This program can compiled to be Interrupt or Polling Mode based by setting the macro INTERRUPT_MODE to 0 or 1. This program may also be compiled to use either the Buffered or TDM Serial Port by setting the macro USE_BUFFERED_SERIAL_PORT to 0 or 1. By default this program uses Interrupt Mode and the Buffered Serial Port. **************************************************************************/ #include #include #include #include #include "t549.h" /*set the following macro to 0 to use the tdm serial port */ #define USE_BUFFERED_SERIAL_PORT 0 /*set the following macro to 0 to use polling mode */ #define INTERRUPT_MODE 1 /*the following macro causes ISR's to be defined as regular functions */ /* #if !(INTERRUPT_MODE) #define interrupt #endif */ #if USE_BUFFERED_SERIAL_PORT /*Buffered Serial Port Settings */ #define SERIAL_TRANSMIT C5XX_BDXR0 #define SERIAL_RECEIVE C5XX_BDRR0 #define SERIAL_CONTROL C5XX_BSPC0 #define SERP_BIT 0x0000 #define SXINT BXINT0 #define SRINT BRINT0 #else /*TDM SERIAL PORT SETTINGS */ #define SERIAL_TRANSMIT C5XX_TDXR #define SERIAL_RECEIVE C5XX_TRCV #define SERIAL_CONTROL C5XX_TSPC #define SERP_BIT 0x0002 #define SXINT TXINT #define SRINT TRINT #endif #define RCHAN 0x0004 /*Right Channel */ #define LCHAN 0x0008 /*Left Channel */ #define CCS 0x0010 /*Codec Command Select */ #define OSCSEL 0x0020 /*Oscillator frequency select */ /* 0 gives 11.2895 MHz */ /* 1 gives 12.2880 MHz */ #define MF6 0x0040 /*Sample Rate Bits */ #define MF7 0x0080 /* See Table 7-15, p. 7-9 of */ #define MF8 0x0100 /* Tiger Manual */ #define BIT_SPC_RRDY 0x0400 /* Receive Ready */ #define BIT_SPC_XRDY 0x0800 /* Transmit Ready */ unsigned int TIG_SetSampleRate(unsigned int rate); unsigned long TIG_CodecControl(unsigned long cdin); void T5XX_delay_us(unsigned long t); unsigned long cdout; unsigned long cdin; volatile unsigned long tmp = 0; volatile int _d; main() { /**********************************************************************/ /* Note: The state of the C549 is initialized by Code Composer when */ /* it starts up and executes the GEL file init_tig.gel which */ /* is listed here: */ /*--------------------------------------------------------------------*/ /*> This GEL file is loaded on the command line of Code Composer */ /*> The StartUp() function is called every time you start */ /*> Code Composer. You can customize this function to */ /*> initialize wait states or to perform other initialization. */ /*> */ /*> StartUp() */ /*> { */ /*> PMST = 0xFFE0; */ /* Interrupt tables at FF80 - FFFF, MP = 1, */ /*> */ /* OVLY = 1 */ /*> */ /*> SWWSR = 0x2249;*/ /* I/O = 2, External Mem = 1 wait states */ /*> BSCR = 0x0002; */ /* no bank switching, BH set */ /*> GEL_XMDef(0, 0x1E, 1, 0x8000, 0x7F); */ /*> */ /* 0 Program Space Memory */ /*> */ /* 0x1E Mapper Register Address */ /*> */ /* 1 Mapper Register in Data Space */ /*> */ /* 0x8000 Start of extended memory */ /*> */ /* 0x7F Mask for Map Register size */ /*> GEL_XMOn(); */ /* Enable extended memory */ /*> } */ /**********************************************************************/ unsigned int rate; int i; asm(" SSBX INTM "); /*Disable interrupts */ _d = 0; T5XX_control0(~0, 0x5); /* remove CTFCLR and disable EPROM */ #if INTERRUPT_MODE puts("INTERRUPT MODE. "); #else puts("POLLING MODE. "); #endif #if USE_BUFFERED_SERIAL_PORT puts("BUFFERED SERIAL PORT."); #else puts("TDM SERIAL PORT."); #endif #if INTERRUPT_MODE #if USE_BUFFERED_SERIAL_PORT C5XX_IMR = 0x0030; /*Set bits for buffered serial port interrupts */ #else C5XX_IMR = 0x00c0; /*Set bits for tdm serial port interrupts */ #endif #endif /* END OF INTERRUPT MODE */ T5XX_control1(SERP_BIT | RCHAN | LCHAN, SERP_BIT | RCHAN | LCHAN); T5XX_control0(0x40, 0x40); /* Turn on LED 2 (RED) */ /* Program and reset the serial port */ SERIAL_CONTROL = 0x4008; /* Put TX and RX in reset */ C5XX_IFR = 0xffff; /* clear IFR register */ T5XX_delay_us(50000); /* Tiger says delay is needed */ SERIAL_CONTROL = 0x40c8; /* Take TX and RX out of reset */ cdin = 0; #if 0 /* Set A/D GAINS in cdin */ /* The A/D gains are adjustable from 0 to 22.5 dB in 1.5 dB */ /* steps with 0000 giving 0 dB gain and 0xF 22.5 dB gain. */ /* bits 11 - 8 Right A/D gain */ /* bits 15 - 12 Left A/D gain */ cdin |= 0xff00L; /* crank up to max gain */ #endif rate = TIG_SetSampleRate(44100); /*set sample rate to 44.1 khz */ printf("Sampling rate = %u Hz\n",rate); /* Program Codec */ do { cdout = TIG_CodecControl(cdin); while (! (cdout & 0x04L)) ; /*!cdout._bitval.ADV (A/D valid) */ while (! (cdout & 0x00400000L)) ; /*!cdout._bitval.ADV_ */ /* Note: A/D Valid is repeated in the lower and upper 16 bits.*/ /* See the Crystal Codec data sheet for details. */ /*cdout._bitval.res2 !=1 */ } while ((cdout & 0xe00L) || ! (cdout & 0x100L)); /* Note: cdout & 0xe00L should be 0 when a valid word received */ /* cdout & 0x100L should be 0x100 for valid word. */ SERIAL_TRANSMIT = _d; /*start transmission */ #if INTERRUPT_MODE C5XX_IFR = 0xffff; /*clear IFR register */ _d = SERIAL_RECEIVE; /*clear junk in DRR */ asm(" RSBX INTM "); /*enable interrupts */ #endif for (;;) /* Main Endless Loop */ { #if !(INTERRUPT_MODE) while(!(SERIAL_CONTROL & BIT_SPC_RRDY)) ; _d = SERIAL_RECEIVE; while(!(SERIAL_CONTROL & BIT_SPC_XRDY) ); SERIAL_TRANSMIT = _d; #else tmp++; #endif } /* for (;;) */ } /* main() */ /********************************************************************** * Interrupt Handlers * ***********************************************************************/ interrupt void c_INT0() /* External user interrupt 0 */ { } interrupt void c_INT1() /* External user interrput 1 */ { } interrupt void c_INT2() /* External user interrupt 2 */ { } interrupt void c_TINT() /* Timer interrupt */ { } interrupt void c_BRINT0() /* BSP 0 receive interrupt */ { _d = SERIAL_RECEIVE; } interrupt void c_BXINT0() /* BSP 0 transmit interrupt */ { SERIAL_TRANSMIT = _d; } interrupt void c_TRNT() /* TDM receive interrupt */ { _d = SERIAL_RECEIVE; } interrupt void c_TXNT() /* TDM transmit interrupt */ { SERIAL_TRANSMIT = _d; } interrupt void c_INT3() /* External user interrupt 3 */ { } interrupt void c_HPINT() /* HPI interrupt */ { } interrupt void c_BRINT1() /* BSP 1 receive interrupt */ { } interrupt void c_BXINT1() /* BSP 1 transmit interrupt */ { } interrupt void c_BMINT0() /* BSP 0 mis-alignment detection int */ { } interrupt void c_BMINT1() /* BSP 1 mis-alignment detection int */ { }