The unified diff between revisions [d8ed90db..] and [08a35a66..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'timer.h'
# # old_revision [d8ed90db2d4284a290224447c40a0d9cef3fbc31] # new_revision [08a35a6680cdf8985cfb16fa6779ee6db7202a9c] # # add_file "timer.h" # content [77f91cb86b26421f2d28236d25d384e9a025e939] # ============================================================ --- /dev/null +++ timer.h 77f91cb86b26421f2d28236d25d384e9a025e939 @@ -0,0 +1,51 @@ +#ifndef __TIMER_H +#define __TIMER_H + +#include "types.h" + +#define TIMER_PCLK 58982400 +#define TIMER_PRESCALE 36863 +#define TIMER0_PRESCALE 3 + +#define TIMER_SECOND (TIMER_PCLK/(TIMER_PRESCALE+1)) +/* Since we're using awkward numbers, this gives better accuracy */ +#define TIMER_MS(x) ((x) * TIMER_SECOND / 1000) +#define TIMER_US(x) ((x) * TIMER_SECOND / 1000000) + +#define TIMER0_SECOND (TIMER_PCLK/(TIMER0_PRESCALE+1)) +#define TIMER0_MS (TIMER0_SECOND/1000) +#define TIMER0_US (TIMER0_SECOND/1000000) + +#define PWM_MAX 14745 +#if 0 +#define PWM_PERIOD 58980 +#endif +#define PWM_PERIOD ((4*PWM_MAX)+1) + +#define TIMER_INPUT_TIMEOUT (TIMER0_SECOND/10) +#define TIMER_CPPM_SYNC 40000 + +#define TIMER_CH(x) (timer_map[x]) + +extern volatile unsigned int timer0_width[]; +extern volatile unsigned int timer0_cppm[]; +extern unsigned int timer_map[]; + +void init_timer(void); +unsigned int timer_read(void); +void timer_delay_clocks(unsigned int clocks); +void timer_set_period(unsigned int period); +void timer_set_pwm_value(int channel, int value); +void timer_set_pwm_invalid(int channel); +bool timer_valid(int channel); +bool timer_allvalid(void); + +#define timer_delay_us(x) timer_delay_clocks((x)*TIMER0_US) +#define timer_delay_ms(x) timer_delay_clocks((x)*TIMER0_MS) + +#ifdef TIMER_CPPM +#define timer_input(ch) (timer0_cppm[TIMER_CH(ch)]) +#else +#define timer_input(ch) (timer0_width[TIMER_CH(ch)]) +#endif +#endif /* __TIMER_H */