00001 #include "timer.h"
00002 #include "../usart/usart.h"
00003 #include "../debug/print_funcs.h"
00004 #include "../pio/pio.h"
00005
00006 #define CPU_HZ 20000000
00007
00008
00009
00010
00011 #define NOOP 0
00012 #define SET 1
00013 #define CLEAR 2
00014 #define TOGGLE 3
00015
00016
00017 #define TRUE 1
00018 #define FALSE 0
00019
00020 void timer_delay( void );
00021
00022 int main( int argc, char * argv[] )
00023 {
00024
00025 struct timer_waveform_opt_t waveform_opt;
00026 struct usart_options_t usart_opt;
00027
00028 avr32_pio_t *piob = (void *) AVR32_PIOB_ADDRESS;
00029 avr32_usart_t *usart = (void *) AVR32_USART1_ADDRESS;
00030
00031 avr32_piomap_t usart_piomap = { \
00032 {AVR32_USART1_RXD_0_PIN, AVR32_USART1_RXD_0_FUNCTION}, \
00033 {AVR32_USART1_TXD_0_PIN, AVR32_USART1_TXD_0_FUNCTION} \
00034 };
00035
00036
00037
00038 int channel = 1;
00039 int timer_instance = 1;
00040
00041
00042 piob->pdr = 0x0003ffff;
00043 piob->asr = 0x0003ffff;
00044
00045
00046 waveform_opt.channel = channel;
00047 waveform_opt.tcclks = TIMER_CLOCK_SOURCE_TC5;
00048 waveform_opt.clki = FALSE;
00049 waveform_opt.burst = FALSE;
00050
00051 waveform_opt.cpcstop = FALSE;
00052 waveform_opt.cpcdis = FALSE;
00053 waveform_opt.eevtedg = FALSE;
00054 waveform_opt.eevt = 0;
00055 waveform_opt.enetrg = FALSE;
00056 waveform_opt.wavsel = TIMER_WAVEFORM_SEL_UPDOWN_MODE;
00057
00058 waveform_opt.acpa = SET;
00059 waveform_opt.acpc = CLEAR;
00060 waveform_opt.aeevt = NOOP;
00061 waveform_opt.aswtrg = NOOP;
00062
00063 waveform_opt.bcpb = NOOP;
00064 waveform_opt.bcpc = NOOP;
00065 waveform_opt.beevt = NOOP;
00066 waveform_opt.bswtrg = NOOP;
00067
00068
00069 usart_opt.baudrate = 115200;
00070 usart_opt.charlength = 8;
00071 usart_opt.paritytype = USART_NO_PARITY;
00072 usart_opt.stopbits = USART_1_STOPBIT;
00073 usart_opt.channelmode = USART_NORMAL_CHMODE;
00074
00075
00076 pio_enable_module(usart_piomap, 2);
00077 usart_init_rs232(usart, &usart_opt, CPU_HZ);
00078
00079 print(usart, "Timer / Counter test...\n");
00080
00081
00082 timer_init_waveform(timer_instance, &waveform_opt);
00083 timer_write_ra(timer_instance, channel, 0x0055 );
00084 timer_write_rb(timer_instance, channel, 0x00aa );
00085 timer_write_rc(timer_instance, channel, 0x00ff );
00086 timer_start(timer_instance, channel);
00087
00088 while(1){
00089 printf("TC: 0x%x \n", timer_read_tc(timer_instance,channel) );
00090 timer_delay();
00091 }
00092 return 0;
00093 }
00094
00095 void timer_delay( void )
00096 {
00097 unsigned long i;
00098
00099 for(i=0; i<CPU_HZ/8; i++);
00100 }