From: Nathael Pajani Date: Fri, 13 Dec 2013 10:18:06 +0000 (+0100) Subject: Adding timer mode to timer support Some modification of the timer functions. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=d4e3e539f5f3cac839165f431ee947d08364ac46;p=soft%2Flpc122x%2Fcore Adding timer mode to timer support Some modification of the timer functions. --- diff --git a/drivers/timers.c b/drivers/timers.c index 1e03277..21e2ab6 100644 --- a/drivers/timers.c +++ b/drivers/timers.c @@ -72,14 +72,22 @@ void timer_start(uint32_t timer_num) /* Remove reset flag and set timer enable flag */ timer_devices[timer_num].regs->timer_ctrl = LPC_TIMER_COUNTER_ENABLE; } -/* Stops the timer counter - * FIXME: Does not issue reset ... need to check whether it is reseted or not. - */ +void timer_continue(uint32_t timer_num) __attribute__ ((alias ("timer_start"))); +/* Pause the timer counter, does not reset */ +void timer_pause(uint32_t timer_num) +{ + if (timer_num >= NUM_TIMERS) + return; + /* Remove timer enable flag */ + timer_devices[timer_num].regs->timer_ctrl = 0; +} +/* Stops and resets the timer counter */ void timer_stop(uint32_t timer_num) { if (timer_num >= NUM_TIMERS) return; /* Remove timer enable flag */ + timer_devices[timer_num].regs->timer_ctrl |= LPC_TIMER_COUNTER_RESET; timer_devices[timer_num].regs->timer_ctrl = 0; } /* Resets the timer and lets it count again imediately */ @@ -99,6 +107,12 @@ uint32_t timer_get_capture_val(uint32_t timer_num, uint32_t channel) /* FIXME */ return 0; } +uint32_t timer_get_counter_val(uint32_t timer_num) +{ + if (timer_num >= NUM_TIMERS) + return 0; + return timer_devices[timer_num].regs->timer_counter; +} /* Change the match value of a single timer channel */ void timer_set_match(uint32_t timer_num, uint32_t channel, uint32_t val) @@ -133,12 +147,18 @@ int timer_setup(uint32_t timer_num, struct timer_config* conf) } switch (conf->mode) { + case LPC_TIMER_MODE_TIMER: + timer->regs->capture_ctrl = 0; /* Timer mode ! */ + timer->regs->count_ctrl = LPC_COUNTER_IS_TIMER; + break; case LPC_TIMER_MODE_COUNTER: if ((conf->config[0] & 0x03) == 0x00) { return -EINVAL; } /* Must set capture chanel N config to 0b000 in capture control register, - (see remarks in user manual UM10441 page 268 section 14.7.11) */ + * (see remarks in user manual UM10441 page 268 section 14.7.11) + * Use the LPC_COUNTER_INC_INPUT(x) set by the user to do so automatically + */ timer->regs->capture_ctrl &= ~LPC_TIMER_CAPTURE_ERASE(((conf->config[0] >> LPC_COUNTER_INC_INPUT_SHIFT) & 0x03) * 3); /* Configure the counter */ timer->regs->count_ctrl |= (conf->config[0] & 0x0F); diff --git a/include/drivers/timers.h b/include/drivers/timers.h index c2efe94..f562fb8 100644 --- a/include/drivers/timers.h +++ b/include/drivers/timers.h @@ -40,11 +40,14 @@ /* Timer modes for the "mode" timer config structure field */ -#define LPC_TIMER_MODE_COUNTER 1 -#define LPC_TIMER_MODE_CAPTURE 2 -#define LPC_TIMER_MODE_MATCH 3 -#define LPC_TIMER_MODE_PWM 4 /* Pulse Width Modulation */ -#define LPC_TIMER_MODE_PWD 5 /* Pulse Width Demodulation */ +enum lpc_timer_mode { + LPC_TIMER_MODE_TIMER = 0, + LPC_TIMER_MODE_COUNTER, + LPC_TIMER_MODE_CAPTURE, + LPC_TIMER_MODE_MATCH, + LPC_TIMER_MODE_PWM, /* Pulse Width Modulation */ + LPC_TIMER_MODE_PWD, /* Pulse Width Demodulation */ +}; /* Structure used to pass parameters to configure a timer */ /* Notes: @@ -68,10 +71,12 @@ struct timer_config * Timer must be turned on and configured (no checks done here). */ void timer_start(uint32_t timer_num); +void timer_continue(uint32_t timer_num); -/* Stops the timer counter - * FIXME: Does not issue reset ... need to check whether it is reseted or not. - */ +/* Pause the timer counter, does not reset */ +void timer_pause(uint32_t timer_num); + +/* Stop and reset the timer counter */ void timer_stop(uint32_t timer_num); /* Resets the timer and lets it count again imediately */ @@ -79,6 +84,7 @@ void timer_restart(uint32_t timer_num); uint32_t timer_get_capture_val(uint32_t timer_num, uint32_t channel); +uint32_t timer_get_counter_val(uint32_t timer_num); /* Change the match value of a single timer channel */ void timer_set_match(uint32_t timer_num, uint32_t channel, uint32_t val);