/* 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 */
/* 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)
}
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);
/* 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:
* 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 */
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);