00001 #include "timer.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define NOOP 0
00020 #define SET 1
00021 #define CLEAR 2
00022 #define TOGGLE 3
00023
00024 #define NONE 0
00025 #define RISING_EDGE 1
00026 #define FALLING_EDGE 2
00027 #define EACH_EDGE 3
00028
00029
00030
00031 #define TRUE 1
00032 #define FALSE 0
00033
00034
00035
00036 void init_timer_input( unsigned int instance, unsigned int channel);
00037 void init_timer_output( unsigned int instance, unsigned int channel);
00038
00039 int main( int argc, char * argv[] )
00040 {
00041
00042 avr32_pio_t *piob = (void *) AVR32_PIOB_ADDRESS;
00043
00044
00045
00046
00047 int output_instance = 1;
00048 int output_channel = 1;
00049
00050 int input_instance = 2;
00051 int input_channel = 0;
00052
00053
00054 int ra=0;
00055
00056
00057 piob->pdr = 0x0000ffff;
00058 piob->asr = 0x0000ffff;
00059
00060
00061 init_timer_input(input_instance, input_channel);
00062 init_timer_output(output_instance, output_channel);
00063
00064
00065 timer_write_ra(output_instance, output_channel, 0x2000 );
00066
00067
00068 timer_start(output_instance, output_channel);
00069 timer_start(input_instance, input_channel);
00070
00071 while(1){
00072 ra = timer_read_ra(input_instance, input_channel);
00073 if(ra>0){
00074 timer_write_ra(output_instance, output_channel, ra);
00075 ra=0;
00076 }
00077 }
00078 return 0;
00079 }
00080
00081
00082 void init_timer_input( unsigned int instance, unsigned int channel)
00083 {
00084 struct timer_capture_opt_t capture_opt;
00085
00086
00087 capture_opt.channel = channel;
00088 capture_opt.tcclks = TIMER_CLOCK_SOURCE_TC5;
00089 capture_opt.clki = FALSE;
00090 capture_opt.burst = FALSE;
00091 capture_opt.ldbstop = FALSE;
00092 capture_opt.ldbdis = FALSE;
00093 capture_opt.etrgedg = FALLING_EDGE;
00094 capture_opt.abetrg = FALSE;
00095 capture_opt.cpctrg = TRUE;
00096 capture_opt.ldra = FALLING_EDGE;
00097 capture_opt.ldrb = NONE;
00098
00099
00100 timer_init_capture(instance, &capture_opt);
00101 }
00102
00103
00104 void init_timer_output( unsigned int instance, unsigned int channel)
00105 {
00106 struct timer_waveform_opt_t waveform_opt;
00107
00108
00109 waveform_opt.channel = channel;
00110 waveform_opt.tcclks = TIMER_CLOCK_SOURCE_TC4;
00111 waveform_opt.clki = FALSE;
00112 waveform_opt.burst = FALSE;
00113 waveform_opt.cpcstop = FALSE;
00114 waveform_opt.cpcdis = FALSE;
00115 waveform_opt.eevtedg = FALSE;
00116 waveform_opt.eevt = 0;
00117 waveform_opt.enetrg = FALSE;
00118 waveform_opt.wavsel = TIMER_WAVEFORM_SEL_UP_MODE;
00119
00120 waveform_opt.acpa = CLEAR;
00121 waveform_opt.acpc = SET;
00122 waveform_opt.aeevt = NOOP;
00123 waveform_opt.aswtrg = NOOP;
00124
00125 waveform_opt.bcpb = NOOP;
00126 waveform_opt.bcpc = NOOP;
00127 waveform_opt.beevt = NOOP;
00128 waveform_opt.bswtrg = NOOP;
00129
00130
00131 timer_init_waveform(instance, &waveform_opt);
00132 }