/**** * ITU-DMA-TPU-DAC example code. * * rev1.0 - Last modified by bunnie@mit.edu Mon Jan 11 23:39:17 1999 ****/ /* includes */ #include "sh1def.h" #include "io.h" #include "dac.h" /* defines */ /* typedefs */ /* func protos */ void setvals( char array[50], unsigned int ramp ); /* init and main MUST be at the top of the file, in this order. This is due to the way the linker links things together, and where the entry point is expected to be in ROM */ /* init function--sets up the stack pointer */ void init() { /* init */ /* body */ asm ("mov.l stack_loc,r15"); main(); asm (".align 2"); asm( "stack_loc: .long _stack_top" ); /* functional body is a placeholder for in-lined code */ } /* init */ /* main -- entry point of your code reached via init() */ main() { /* main */ /* locals */ unsigned char array[128]; int i; unsigned int ramp; /* body */ /* compiler compatibility */ asm( ".align 4" ); asm( ".global _the_main" ); asm( "_the_main: nop" ); /* pb13 is clock pb14 is din pb15 is cs */ /* initialize the array first time through */ for( i = 0; i < 50; i++ ) { if( i & 0x1 ) { if( i == (24 * 2 - 1) ) { array[i] = 0x80; } array[i] = 0x00; } else { if( i == (24 * 2) ) { array[i] = 0x00; } array[i] = 0x20; } } /* for */ mon_printf( "setting up registers\n" ); ITU_TSNC = 0x0; ITU_TMDR = 0x0; mon_printf( "setting up ITU0 registers\n" ); /* roughly 65 us per 24-bit transfer */ /* or about 15.4 kHz */ /* most time is spent in filling the array, though */ ITU_TCNT0 = 0x0; /* clear count value */ ITU_GRA0 = 0x100; /* clear on count to 0x100 */ ITU_GRA0 = 0x001; /* clear on count to 0x1 -- weirdism of compiler */ ITU_TCR0 = 0x20; /* 0010 0000 -- set clock source, phi = 12 MHz */ ITU_TIOR0 = 0x0; /* disable external outputs */ ITU_TSR0 = 0x0; /* clear bits in status register */ ITU_TIER0 = 0x1; /* enable interrupts from IMIA */ mon_printf( "setting up TPC registers\n" ); PBDR = 0x0; PFC_PBCR1 |= 0xFC00; /* set output from TPC */ TPC_NDRB = 0x0; /* init next data to 0 */ TPC_NDERB = 0xE0; /* enable 15-13 */ TPC_TPCR = 0x0; /* triggered by compare match on ITU0 */ TPC_TPMR = 0x0; /* normal mode output */ mon_printf( "setting up DMA registers\n" ); DMA_SAR0 = (unsigned long) array; DMA_DAR0 = (unsigned long) 0x05ffffF4; DMA_TCR0 = 50; DMAOR = 0x1; mon_printf( "ITU is about to start\n" ); ITU_TSTR = 0x1; /* start ITU counting */ /* fixed dest, source increment by 1, IMIA0 source, dont' care about DACK, DREQ, byte transfers, no interrupt on xfer done, clear done, start xfer */ /* 00 01 1000 0000 0 0 0 1 */ mon_printf( "DMA is about to start\n" ); DMA_CHCR0 = 0x1801; /* dma is now happening */ mon_printf( "DMA is now happening\n" ); while(1) { if( (DMA_CHCR0) & 0x0002 ) { ramp++; setvals( array, ramp ); /* 0000 1000 0000 0000 */ /* actually, every time through the loop you probably have to init less than this */ DMA_SAR0 = (unsigned long) array; DMA_DAR0 = (unsigned long) 0x05ffffF4; DMA_TCR0 = 50; DMA_CHCR0 = 0x1801; DMAOR = 0x1; } } } /* main */ void setvals( char array[50], unsigned int ramp ) { unsigned long bitval = 0; unsigned int dinval = 0; unsigned int arrayval = 0; int i; /* this function creates an array in memory that the ITU-DMAC-TPC-DAC example can use to set the DAC value. The value to be output is put in ramp; the DAC 2 output is hashed to help measurements on code performance */ bitval = ramp; for( i = 0; i < 50; i++ ) { if( i == 24 ) bitval = (ramp * 5309) & 0xFFF; arrayval = 0; if( (i & 0x1) == 0 ) { /* starts with clock low */ arrayval = 0x00; /* clock low */ if( bitval & 0x800 ) dinval = 0x40; else dinval = 0x00; bitval <<= 1; arrayval |= dinval; if( i == 48 ) arrayval |= 0x80; /* toggle CS */ array[i] = arrayval; } else { arrayval = 0x20; /* clock high */ if( i > 47 ) { arrayval = 0x00; /* clock low for last cycle */ } arrayval |= dinval; array[i] = arrayval; } } /* for */ } /*** dummy funcs--compiler wants these to be happy ***/ int __main() { /* hack to clean up compiler problems */ asm( "mov.l _mainlabel, r1" ); asm( "jsr @r1" ); asm( ".align 4" ); asm( "_mainlabel: .long _the_main" ); } /* now required by compiler; see release notes */ void edata (void) { } /* end - edata */