/**************************************************************************** * DESCRIPTION: * Sample program for the eZdsp33. This example can generate * loop the analog input to output. * The eZdsp33 operates the VC33 in Microcontroller/Bootloader mode. * This means that interrupts are double vectored with user interrupts * located on-chip at addresses 0x809FC1-0x809FFF. ****************************************************************************/ #define vc33dsk_c #include /*---------------------------------------------------------------------------- * Serial port 0 regisiter addresses *---------------------------------------------------------------------------*/ #define SP0_BASE 0x808040 #define SP_GLB_CNTL 0x0 #define SP_FSX_CNTL 0x2 #define SP_FSR_CNTL 0x3 #define SP_RX_TIM_CNTL 0x4 #define SP_RX_TIM_CNTR 0x5 #define SP_RX_TIM_PRD 0x6 #define SP_XMIT 0x8 #define SP_RECV 0xC #define SP_RESET 0x00170300 #define SP_AD50_GLB_CNTL 0x4E170300 #define SP_AD50_FSX_CNTL 0x00000111 #define SP_AD50_FSR_CNTL 0x00000111 #define ISR_BASE 0x00809FC0 /* Base of VC33 redir. int. table*/ /*-- Redirected interrupt offset for basic interrupts. --------------------*/ enum WHICH_ISR { Reset = 0, Int0, Int1, Int2, Int3, Xint0, Rint0, Resv0, Resv1, Tint0, Tint1, Dint0, Dint1 }; /*---- data declarations ---------------------------------------------------*/ volatile unsigned int Data_rx = 0; volatile unsigned int Data_tx = 0; /*--------------------------------------------------------------------------- * PUBLIC FUNCTION DEFINITIONS *---------------------------------------------------------------------------- * NAME: void IsrInstall( int IsrNum, void( *Isr)( void) ) * Install an interrupt into ISR table. *---------------------------------------------------------------------------*/ void IsrInstall( int IsrNum, void( *Isr)( void) ) { unsigned * IsrBase = (unsigned *)ISR_BASE; unsigned IsrAddr = (unsigned)Isr; IsrAddr &= 0x00FFFFFF; IsrAddr |= 0x60000000; IsrBase[IsrNum] = IsrAddr; } /*------------------------------------------------------------------------- * NAME: interrupt void isrAdcLoopBack( void ) * Loop back the analog input to output. Also stuff the receive * value in the RecvData buffer. *--------------------------------------------------------------------------*/ interrupt void isrAdcLoopBack( void ) { /*----------------------------------------------------------------------- * Loop AIN to AOUT.We are masking the upper 16 b. of the data. *----------------------------------------------------------------------*/ register unsigned *pSport = (unsigned *)(SP0_BASE); Data_rx = pSport[SP_RECV] & 0x0000fffe; pSport[SP_XMIT] = Data_tx; } /*----------------------------------------------------------------------- * NAME: interrupt void FalseInt( void ) * Just a safety valve. *-----------------------------------------------------------------------*/ interrupt void FalseInt( void ) { while( 1 ); } /*----------------------------------------------------------------------- * NAME: int SetupSerialPort( void ) * Setup the VC33 serial port to work with the AD50. *-----------------------------------------------------------------------*/ int SetupSerialPort( void ) { register unsigned *pSport = (unsigned *)SP0_BASE; volatile register unsigned Rrdy; volatile unsigned Dummy; int i; /*-- AD50 setup variables. ---------------------------------------------*/ unsigned Control[4]; Control[0] = 0x0100; Control[1] = 0x0200; Control[2] = 0x0300; Control[3] = 0x04C0; /*-- Set the initial values while in reset -----------------------------*/ pSport[SP_GLB_CNTL] = SP_RESET; asm( " NOP " ); asm( " NOP " ); pSport[SP_FSX_CNTL] = SP_AD50_FSX_CNTL; pSport[SP_FSR_CNTL] = SP_AD50_FSR_CNTL; /*----------------------------------------------------------------------- * The AD50 is the master and continously sends a frame sync. * Testing has shown that while the serial port is in reset *-----------------------------------------------------------------------*/ do { Rrdy = pSport[SP_FSR_CNTL] & 0x800 ; }while( Rrdy != 0); do { Rrdy = pSport[SP_FSR_CNTL] & 0x800 ; }while( Rrdy == 0); pSport[SP_GLB_CNTL] = SP_AD50_GLB_CNTL; Dummy = pSport[SP_RECV]; pSport[SP_XMIT] = 0; /*----------------------------------------------------------------------- * Send the 4 control words to the AD50. *----------------------------------------------------------------------*/ for( i=0; i<4; i++ ) { /*-- Secondary request. -------------------------------------------*/ do { Rrdy = pSport[SP_GLB_CNTL]; }while( ( Rrdy & 1 ) == 0); Dummy = pSport[SP_RECV]; pSport[SP_XMIT] = 1; asm( " NOP " ); asm( " NOP " ); asm( " NOP " ); /*-- Control word ------------------------------------------------*/ do { Rrdy = pSport[SP_GLB_CNTL]; }while( ( Rrdy & 1 ) == 0); Dummy = pSport[SP_RECV]; pSport[SP_XMIT] = Control[i]; } /*----------------------------------------------------------------------- * Dummy cycle to get xmitter filled with 0 and empty * the receiver. *----------------------------------------------------------------------*/ do { Rrdy = pSport[SP_GLB_CNTL]; }while( ( Rrdy & 1 ) == 0); Dummy = pSport[SP_RECV]; pSport[SP_XMIT] = 0; return(0); } /*----------------------------------------------------------------------------- * NAME: void MemSetWaitStates( int WaitStates ) * Set the VC33 primary-bus control register. *-----------------------------------------------------------------------------*/ void MemSetWaitStates( int WaitStates ) { unsigned *pMemCntl = (unsigned *)0x808064; unsigned MemCntl; MemCntl = *pMemCntl; MemCntl &= ~( 7<<5); MemCntl |= (WaitStates & 7) << 5; *pMemCntl = MemCntl; } /*----------------------------------------------------------------------------- * NAME: void main( void ) * The main example. *-----------------------------------------------------------------------------*/ void main( void ) { float prom = 0.0 ; IsrInstall( Rint0, isrAdcLoopBack ); /*-- Set up the serial port for use with the AD50. ---------------------*/ SetupSerialPort(); /*-- Enable interrupts. ------------------------------------------------*/ asm( " xor ie,ie "); asm( " xor if,if "); asm( " or 00320h,ie "); asm( " or 02000h,st "); /*-- Loop processing interrupts. ---------------------------------------*/ while( 1 ) { /* prom = prom + 0.1; Data_tx = (unsigned int) prom; */ Data_tx = Data_tx + 10; if (Data_tx > 32000) { Data_tx = 0; } asm( " idle " ); } }