/**** * PWM driver code. Drives channels 0-3 with 20 KHz PWM. All channels * identical in this code. * * rev1.0 - Last modified by bunnie@mit.edu Mon Jan 11 23:39:17 1999 ****/ /* includes */ #include "sh1def.h" #include "io.h" #include "test1.h" /* defines */ #define MOT_DEF (*(volatile unsigned short *) (0xA000000)) /* typedefs */ /* func protos */ /* 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 */ char input[32]; unsigned long value; /* body */ /* compiler compatibility */ asm( ".align 4" ); asm( ".global _the_main" ); asm( "_the_main: nop" ); mon_printf( "Hello World!\n" ); MOT_DEF = 0x0; /* want PA3 to be the output of ITU0 */ /* xxxx xxxx xxxx xx10 */ mon_printf( "Setting up PACR\n" ); /* ITU 0 */ PFC_PACR2 &= 0xFFFC; /* set bit 1,0 to 0 */ PFC_PACR2 |= 0x2; /* set to ITU */ PFC_PAIOR |= 0x1; /* ITU 1 */ PFC_PACR1 &= 0xFFCF; PFC_PACR1 |= 0x0020; /* 0000 0010 0000 0000 */ PFC_PAIOR |= 0x0400; /* ITU 2, 3 */ PFC_PBCR2 &= 0xFFCC; PFC_PBCR2 |= 0x0022; PFC_PBIOR |= 0x5; mon_printf( "Starting up ITU\n" ); ITU_TSTR = 0x0; /* no counting */ ITU_TFCR = 0x0; ITU_TCNT3 = 0x0; ITU_TCNT2 = 0x0; ITU_TCNT1 = 0x0; ITU_TCNT0 = 0x0; ITU_TSR3 = 0x0; ITU_TSR2 = 0x0; ITU_TSR1 = 0x0; ITU_TSR0 = 0x0; ITU_TIER3 = 0x0; ITU_TIER2 = 0x0; ITU_TIER1 = 0x0; ITU_TIER0 = 0x0; ITU_TSNC = 0x0; /* no sync */ ITU_GRA3 = 0x258; /* decimal 600, so at 12 MHz phi you get 20 KHz */ ITU_GRA2 = 0x258; /* decimal 600, so at 12 MHz phi you get 20 KHz */ ITU_GRA1 = 0x258; /* decimal 600, so at 12 MHz phi you get 20 KHz */ ITU_GRA0 = 0x258; /* decimal 600, so at 12 MHz phi you get 20 KHz */ /* 0 01 00 000 */ /* clear by GRA, count rising edges, internal phi clock */ ITU_TCR3 = 0x20; ITU_TCR2 = 0x20; ITU_TCR1 = 0x20; ITU_TCR0 = 0x20; /* 0 011 1 011 toggle on count match */ ITU_TIOR3 = 0x3B; ITU_TIOR2 = 0x3B; ITU_TIOR1 = 0x3B; ITU_TIOR0 = 0x3B; ITU_TMDR = 0xF; /* channel 0 is PWM mode */ ITU_GRB3 = 0x12C; ITU_GRB2 = 0x12C; ITU_GRB1 = 0x12C; ITU_GRB0 = 0x12C; mon_printf( "Starting ITU\n" ); ITU_TSTR = 0xF; /* start the count */ while(1) { mon_printf( "Please specify direction (0 or 1): " ); getline(input, 32); scannumber( input, 16, &value ); MOT_DEF = (unsigned short) value & 0xFFFF; mon_printf( "Please enter duty value (0 - 600, decimal): " ); getline(input, 32); scannumber( input, 10, &value ); ITU_GRB3 = (unsigned short) value & 0xFFFF; ITU_GRB2 = (unsigned short) value & 0xFFFF; ITU_GRB1 = (unsigned short) value & 0xFFFF; ITU_GRB0 = (unsigned short) value & 0xFFFF; } } /*** 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( "nop" ); asm( ".align 4" ); asm( "_mainlabel: .long _the_main" ); } /* now required by compiler; see release notes */ void edata (void) { } /* end - edata */