aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/AVR/MEGA/LLD/TIMv1
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/AVR/MEGA/LLD/TIMv1')
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.c59
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.h48
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.c51
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.h34
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.c58
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.h42
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.c103
-rw-r--r--os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.h55
8 files changed, 237 insertions, 213 deletions
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.c b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.c
index 9940a6017..1f32bbef6 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.c
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.c
@@ -31,14 +31,14 @@
#if HAL_USE_GPT || defined(__DOXYGEN__)
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local definitions. */
+/*==========================================================================*/
#define PRESCALER_SIZE_BASE 5
#define PRESCALER_SIZE_EXTENDED 7
-// FIXME: could use better names here!
+/* FIXME: could use better names here! */
typedef struct {
volatile uint8_t *tccra;
volatile uint8_t *tccrb;
@@ -68,9 +68,9 @@ const timer_registers_t regs_table[] = {
#endif
};
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported variables. */
+/*==========================================================================*/
#if AVR_GPT_USE_TIM1 || defined(__DOXYGEN__)
GPTDriver GPTD1;
@@ -88,19 +88,27 @@ GPTDriver GPTD4;
GPTDriver GPTD5;
#endif
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local variables. */
+/*==========================================================================*/
static uint16_t ratio_base[] = { 1024, 256, 64, 8, 1 };
static uint8_t clock_source_base[]= { 5, 4, 3, 2, 1 };
//static uint16_t ratio_extended[] = { 1024, 256, 128, 64, 32, 8, 1 };
//static uint8_t clock_source_extended[] = { 7, 6, 5, 4, 3, 2, 1 };
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local functions. */
+/*==========================================================================*/
+/**
+ * @brief TODO: Comment this function.
+ *
+ * @param[in] freq
+ * @param[in] ratio pointer to the ratio used to calculate the prescaler
+ * @param[in] n ....
+ * @return ....
+ */
static uint8_t prescaler(uint16_t freq, uint16_t *ratio, uint8_t n) {
uint8_t i;
@@ -112,9 +120,14 @@ static uint8_t prescaler(uint16_t freq, uint16_t *ratio, uint8_t n) {
if ((result * ratio[i] * freq) == F_CPU)
return i;
}
- return -1; // TO check
+ return -1;
}
+/**
+ * @brief TODO: Comment this function.
+ *
+ * @param[in] gptp pointer to the General Purpose Timer driver.
+ */
static void gpt_lld_serve_interrupt(GPTDriver *gptp) {
gptp->counter++;
@@ -128,9 +141,19 @@ static void gpt_lld_serve_interrupt(GPTDriver *gptp) {
}
}
+/**
+ * @brief GPT low level driver dummy callback.
+ *
+ * @param[in] gptp pointer to the General Purpose Timer driver.
+ */
static void gpt_lld_dummy_callback(GPTDriver *gptp) {
}
+/**
+ * @brief Get the timer index.
+ *
+ * @param[in] gptp pointer to the General Purpose Timer driver.
+ */
static uint8_t getTimerIndex(GPTDriver *gptp) {
uint8_t index = 0;
@@ -155,7 +178,7 @@ static uint8_t getTimerIndex(GPTDriver *gptp) {
if (gptp == &GPTD5) return index;
else index++;
#endif
- return -1; // To check
+ return -1;
}
/*===========================================================================*/
@@ -232,9 +255,9 @@ OSAL_IRQ_HANDLER(TIMER5_COMPA_vect) {
}
#endif
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported functions. */
+/*==========================================================================*/
/**
* @brief Low level GPT driver initialization.
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.h b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.h
index be535234e..2ee88484e 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.h
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_gpt_lld.h
@@ -34,13 +34,13 @@
#include "avr_timers.h"
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver constants. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver pre-compile time settings. */
+/*==========================================================================*/
/**
* @brief GPT1 driver enable switch.
@@ -87,13 +87,13 @@
#define AVR_GPT_USE_TIM5 FALSE
#endif
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Derived constants and error checks. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver data structures and types. */
+/*==========================================================================*/
/**
* @brief GPT frequency type.
@@ -121,7 +121,7 @@ typedef struct {
* @note This callback is invoked on GPT counter events.
*/
gptcallback_t callback;
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
} GPTConfig;
/**
@@ -141,13 +141,13 @@ struct GPTDriver {
GPT_DRIVER_EXT_FIELDS
#endif
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
/**
- * @brief input clock from prescaler
+ * @brief input clock from prescaler.
*/
uint8_t clock_source;
/**
- * @brief Lenght of the period in clock ticks
+ * @brief Lenght of the period in clock ticks.
*/
gptcnt_t period;
/**
@@ -155,14 +155,14 @@ struct GPTDriver {
*/
gptcnt_t counter;
/**
- * @brief Function called from the interrupt service routine
+ * @brief Function called from the interrupt service routine.
*/
gptcallback_t callback;
};
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver macros. */
+/*==========================================================================*/
/**
* @brief Changes the interval of GPT peripheral.
@@ -178,12 +178,12 @@ struct GPTDriver {
* @notapi
*/
-// FIXME: placeholder to enable compile, should be implemented!
+/* FIXME: placeholder to enable compile, should be implemented! */
#define gpt_lld_change_interval(gptp, interval)
-/*===========================================================================*/
-/* External declarations. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* External declarations. */
+/*==========================================================================*/
#if AVR_GPT_USE_TIM1 || defined(__DOXYGEN__)
extern GPTDriver GPTD1;
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.c b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.c
index e5f654cf4..54ac737f4 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.c
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.c
@@ -26,10 +26,13 @@
#if HAL_USE_ICU || defined(__DOXYGEN__)
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local definitions. */
+/*==========================================================================*/
+/**
+ * @brief ICU driver type.
+ */
typedef struct {
volatile uint8_t *tccra;
volatile uint8_t *tccrb;
@@ -53,9 +56,9 @@ static icu_registers_t regs_table[]=
#endif
};
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported variables. */
+/*==========================================================================*/
/**
* @brief ICU1 driver identifier.
@@ -82,14 +85,15 @@ ICUDriver ICUD4;
ICUDriver ICUD5;
#endif
-/*===========================================================================*/
-/* Driver local variables and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local variables and types. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local functions. */
+/*==========================================================================*/
+/* TODO: Comment. */
static inline void handle_capture_isr(ICUDriver *icup,
volatile uint16_t *icr,
volatile uint8_t *tccrb,
@@ -107,11 +111,12 @@ static inline void handle_capture_isr(ICUDriver *icup,
icup->period = value;
if (icup->config->period_cb != NULL)
icup->config->period_cb(icup);
- /* Reset counter at the end of every cycle */
+ /* Reset counter at the end of every cycle. */
*tcnt = 0;
}
}
+/* TODO: Comment. */
static uint8_t tmrIndex(ICUDriver *icup) {
uint8_t index = 0;
@@ -134,9 +139,9 @@ static uint8_t tmrIndex(ICUDriver *icup) {
return 255;
}
-/*===========================================================================*/
-/* Driver interrupt handlers. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver interrupt handlers. */
+/*==========================================================================*/
#if AVR_ICU_USE_TIM1 || defined(__DOXYGEN__)
OSAL_IRQ_HANDLER(TIMER1_CAPT_vect) {
@@ -202,9 +207,9 @@ OSAL_IRQ_HANDLER(TIMER5_OVF_vect) {
}
#endif
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported functions. */
+/*==========================================================================*/
/**
* @brief Low level ICU driver initialization.
@@ -238,10 +243,10 @@ void icu_lld_start(ICUDriver *icup) {
if (icup->state == ICU_STOP) {
uint8_t i = tmrIndex(icup);
- /* Normal waveform generation (counts from 0 to 0xFFFF) */
+ /* Normal waveform generation (counts from 0 to 0xFFFF). */
*regs_table[i].tccra &= ~((1 << WGM11) | (1 << WGM10));
*regs_table[i].tccrb &= ~((1 << WGM13) | (1 << WGM12));
- /* Enable noise canceler, set prescale to CLK/1024 */
+ /* Enable noise canceler, set prescale to CLK/1024. */
*regs_table[i].tccrb |= (1 << ICNC1) | (1 << CS12) | (1 << CS10);
if (icup->config->mode == ICU_INPUT_ACTIVE_HIGH)
*regs_table[i].tccrb |= (1 << ICES1);
@@ -260,9 +265,9 @@ void icu_lld_start(ICUDriver *icup) {
void icu_lld_stop(ICUDriver *icup) {
if (icup->state == ICU_READY) {
- /* Resets the peripheral.*/
+ /* Resets the peripheral. */
- /* Disables the peripheral.*/
+ /* Disables the peripheral. */
#if AVR_ICU_USE_TIM1
if (&ICUD1 == icup) {
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.h b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.h
index e0dfd2b6b..61f0c5915 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.h
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_icu_lld.h
@@ -29,13 +29,13 @@
#include "avr_timers.h"
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver constants. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver pre-compile time settings. */
+/*==========================================================================*/
/**
* @name Configuration options
@@ -71,13 +71,13 @@
#endif
/** @} */
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Derived constants and error checks. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver data structures and types. */
+/*==========================================================================*/
/**
* @brief ICU driver mode.
@@ -124,7 +124,7 @@ typedef struct {
* @brief Callback for timer overflow.
*/
icucallback_t overflow_cb;
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
} ICUConfig;
/**
@@ -142,7 +142,7 @@ struct ICUDriver {
#if defined(ICU_DRIVER_EXT_FIELDS)
ICU_DRIVER_EXT_FIELDS
#endif
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
/**
* @brief Width value read by ISR.
*/
@@ -153,9 +153,9 @@ struct ICUDriver {
icucnt_t period;
};
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver macros. */
+/*==========================================================================*/
/**
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.c b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.c
index a1179c4fe..24465fe1d 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.c
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.c
@@ -31,9 +31,9 @@
#if HAL_USE_PWM || defined(__DOXYGEN__)
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local definitions. */
+/*==========================================================================*/
#define TIM1_CS_OFFSET CS10
#define TIM1_WGM_OFFSET1 WGM10
@@ -82,9 +82,9 @@ static timer_registers_t regs_table[]=
#endif
};
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported variables. */
+/*==========================================================================*/
/** @brief PWM driver identifiers.*/
#if AVR_PWM_USE_TIM1 || defined(__DOXYGEN__)
@@ -103,13 +103,13 @@ PWMDriver PWMD4;
PWMDriver PWMD5;
#endif
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local variables. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local functions. */
+/*==========================================================================*/
static void config_channel(volatile uint8_t *tccra,
uint8_t com1,
@@ -118,9 +118,9 @@ static void config_channel(volatile uint8_t *tccra,
*tccra &= ~((1 << com1) | (1 << com0));
if (mode == PWM_OUTPUT_ACTIVE_HIGH)
- *tccra |= ((1 << com1) | (0 << com0)); /* non inverting mode */
+ *tccra |= ((1 << com1) | (0 << com0)); /* Non inverting mode. */
else if (mode == PWM_OUTPUT_ACTIVE_LOW)
- *tccra |= (1 << com1) | (1 << com0); /* inverting mode */
+ *tccra |= (1 << com1) | (1 << com0); /* Inverting mode. */
}
static uint8_t timer_index(PWMDriver *pwmp) {
@@ -152,12 +152,12 @@ static uint8_t timer_index(PWMDriver *pwmp) {
return index;
}
-/*===========================================================================*/
-/* Driver interrupt handlers. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver interrupt handlers. */
+/*==========================================================================*/
/*
- * interrupt for compare1&2 and clock overflow. pwmd1 & pwmd2
+ * Interrupt for compare1&2 and clock overflow. pwmd1 & pwmd2.
*/
#if AVR_PWM_USE_TIM1 || defined(__DOXYGEN__)
OSAL_IRQ_HANDLER(TIMER1_OVF_vect) {
@@ -303,9 +303,9 @@ OSAL_IRQ_HANDLER(TIMER5_COMPC_vect) {
}
#endif
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported functions. */
+/*==========================================================================*/
/**
* @brief Low level PWM driver initialization.
@@ -343,7 +343,7 @@ void pwm_lld_init(void) {
/**
* @brief Configures and activates the PWM peripheral.
* @note We do not use the period value in Timer2 in order to
- * be able to use both PWM channels
+ * be able to use both PWM channels.
*
* @param[in] pwmp pointer to the @p PWMDriver object
*
@@ -356,17 +356,17 @@ void pwm_lld_start(PWMDriver *pwmp) {
#if AVR_PWM_USE_TIM2 || defined(__DOXYGEN__)
if (pwmp == &PWMD2) {
- /* for now only fast pwm is supported */
+ /* For now only fast pwm is supported. */
wgm_value = 0x3;
cs_value = 1;
- /* period is fixed for timer2 */
+ /* Period is fixed for timer2. */
PWMD2.period = 0xFF;
/* A prescaler value can only be a suitable power of 2 (1, 8, 32,
64, 128 256 or 1024), so we choose the one that makes F_CPU
divided by it equal to the given frequency (fallback value is
- 1, to keep compatibility with old code */
+ 1, to keep compatibility with old code. */
const uint8_t log_ratio_timer2[] = {0, 3, 5, 6, 7, 8, 10};
uint8_t n;
for (n=0; n<sizeof(log_ratio_timer2)/sizeof(uint8_t); n++) {
@@ -385,14 +385,14 @@ void pwm_lld_start(PWMDriver *pwmp) {
}
#endif
- /* for now only fast pwm is supported */
+ /* For now only fast pwm is supported. */
wgm_value = 0xE;
cs_value = 0x5;
/* A prescaler value can only be a suitable power of 2 (1, 8, 64,
256 or 1024), so we choose the one that makes F_CPU divided by
it equal to the given frequency (fallback value is 1024, to
- keep compatibility with old code */
+ keep compatibility with old code. */
const uint8_t log_ratio_timer1[] = {0, 3, 6, 8, 10};
uint8_t n;
for (n=0; n<sizeof(log_ratio_timer1)/sizeof(uint8_t); n++) {
@@ -455,7 +455,7 @@ void pwm_lld_stop(PWMDriver *pwmp) {
void pwm_lld_change_period(PWMDriver *pwmp, pwmcnt_t period) {
#if AVR_PWM_USE_TIM2 || defined(__DOXYGEN__)
- /* Can't change period in timer2 */
+ /* Can't change period in timer2. */
if (pwmp == &PWMD2) {
PWMD2.period = 0xFF;
return;
@@ -491,7 +491,7 @@ void pwm_lld_enable_channel(PWMDriver *pwmp,
7 - 2*channel,
6 - 2*channel,
pwmp->config->channels[channel].mode);
- /* Timer 2 is 8 bit */
+ /* Timer 2 is 8 bit. */
if (val > 0xFF)
val = 0xFF;
switch (channel) {
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.h b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.h
index 262cbe716..784e9124a 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.h
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_pwm_lld.h
@@ -34,9 +34,9 @@
#include "avr_timers.h"
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver constants. */
+/*==========================================================================*/
#if !defined(AVR_PWM_USE_TIM1)
#define AVR_PWM_USE_TIM1 FALSE
@@ -54,9 +54,9 @@
#define AVR_PWM_USE_TIM5 FALSE
#endif
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver pre-compile time settings. */
+/*==========================================================================*/
/**
* @brief Number of PWM channels per PWM driver.
@@ -69,13 +69,13 @@
#endif
#endif
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Derived constants and error checks. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver data structures and types. */
+/*==========================================================================*/
/**
* @brief PWM mode type.
@@ -113,7 +113,7 @@ typedef struct {
* @p NULL then the callback is disabled.
*/
pwmcallback_t callback;
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
} PWMChannelConfig;
/**
@@ -144,7 +144,7 @@ typedef struct {
* @brief Channels configurations.
*/
PWMChannelConfig channels[PWM_CHANNELS];
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
} PWMConfig;
/**
@@ -176,16 +176,16 @@ struct PWMDriver {
#if defined(PWM_DRIVER_EXT_FIELDS)
PWM_DRIVER_EXT_FIELDS
#endif
- /* End of the mandatory fields.*/
+ /* End of the mandatory fields. */
};
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver macros. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* External declarations. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* External declarations. */
+/*==========================================================================*/
#if AVR_PWM_USE_TIM1 || defined(__DOXYGEN__)
extern PWMDriver PWMD1;
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.c b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.c
index bad3101a9..c685a6f5c 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.c
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.c
@@ -26,30 +26,30 @@
#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local definitions. */
+/*==========================================================================*/
/**
* @brief Timer maximum value
*/
#define AVR_TIMER_COUNTER_MAX 255
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported variables. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver local types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local types. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver local variables and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local variables and types. */
+/*==========================================================================*/
#if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__)
-/* Work out what the timer interrupt is called on this MCU */
+/* Work out what the timer interrupt is called on this MCU. */
#ifdef TIMER0_COMPA_vect
#define AVR_TIMER_VECT TIMER0_COMPA_vect
#elif defined(TIMER_COMPA_vect)
@@ -60,16 +60,16 @@
#error "Cannot find interrupt vector name for timer"
#endif
-/* Find the most suitable prescaler setting for the desired OSAL_ST_FREQUENCY */
+/* Find the most suitable prescaler setting for the desired OSAL_ST_FREQUENCY*/
#if ((F_CPU / OSAL_ST_FREQUENCY) <= AVR_TIMER_COUNTER_MAX)
#define AVR_TIMER_PRESCALER 1
- #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(0<<CS01)|(1<<CS00)) /* CLK */
+ #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(0<<CS01)|(1<<CS00)) /* CLK */
#elif ((F_CPU / OSAL_ST_FREQUENCY / 8) <= AVR_TIMER_COUNTER_MAX)
#define AVR_TIMER_PRESCALER 8
- #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(1<<CS01)|(0<<CS00)) /* CLK/8 */
+ #define AVR_TIMER_PRESCALER_BITS ((0<<CS02)|(1<<CS01)|(0<<CS00)) /* CLK/8 */
#elif ((F_CPU / OSAL_ST_FREQUENCY / 64) <= AVR_TIMER_COUNTER_MAX)
@@ -107,7 +107,7 @@
#define AVR_TIMER_COUNTER (F_CPU / OSAL_ST_FREQUENCY / AVR_TIMER_PRESCALER)
-/* Test if OSAL_ST_FREQUENCY can be matched exactly using this timer */
+/* Test if OSAL_ST_FREQUENCY can be matched exactly using this timer. */
#define F_CPU_ (AVR_TIMER_COUNTER * AVR_TIMER_PRESCALER * OSAL_ST_FREQUENCY)
#if (F_CPU_ != F_CPU)
#warning "OSAL_ST_FREQUENCY cannot be generated exactly using timer"
@@ -126,13 +126,13 @@
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver local functions. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver interrupt handlers. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver interrupt handlers. */
+/*==========================================================================*/
#if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__)
@@ -161,7 +161,7 @@ OSAL_IRQ_HANDLER(TIMER1_COMPA_vect) {
OSAL_IRQ_PROLOGUE();
- // TODO: reset status if required
+ /* TODO: reset status if required. */
osalSysLockFromISR();
osalOsTimerHandlerI();
@@ -172,9 +172,9 @@ OSAL_IRQ_HANDLER(TIMER1_COMPA_vect) {
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver exported functions. */
+/*==========================================================================*/
/**
* @brief Low level ST driver initialization.
@@ -189,15 +189,15 @@ void st_lld_init(void) {
* Periodic mode uses Timer 1 (16 bit).
*/
- /* CTC mode, no clock source */
+ /* CTC mode, no clock source. */
TCCR1A = 0;
TCCR1B = _BV(WGM12);
- /* start disabled */
+ /* start disabled. */
TCCR1C = 0;
OCR1A = 0;
TCNT1 = 0;
- TIFR_REG = _BV(OCF1A); /* Reset pending. */
+ TIFR_REG = _BV(OCF1A); /* Reset pending. */
TIMSK_REG = 0;
TCCR1B = PRESCALER;
@@ -208,32 +208,33 @@ void st_lld_init(void) {
/*
* Periodic mode uses Timer 0 (8 bit).
*/
-#if defined(TCCR0B) /* Timer has multiple output comparators */
- TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
- (0 << COM0A1) | (0 << COM0A0) | /* OC0A disabled. */
- (0 << COM0B1) | (0 << COM0B0); /* OC0B disabled. */
- TCCR0B = (0 << WGM02) | AVR_TIMER_PRESCALER_BITS; /* CTC mode. */
+#if defined(TCCR0B) /* Timer has multiple output comparators. */
+ TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
+ (0 << COM0A1) | (0 << COM0A0) | /* OC0A disabled. */
+ (0 << COM0B1) | (0 << COM0B0); /* OC0B disabled. */
+ TCCR0B = (0 << WGM02) | AVR_TIMER_PRESCALER_BITS; /* CTC mode. */
OCR0A = AVR_TIMER_COUNTER - 1;
- TCNT0 = 0; /* Reset counter. */
- TIFR0 = (1 << OCF0A); /* Reset pending. */
- TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
-
-#elif defined(TCCR0A) /* AT90CAN doesn't have TCCR0B and slightly different TCCR0A */
- TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
- (0 << COM0A1) | (0 << COM0A0); /* OC0A disabled. */
+ TCNT0 = 0; /* Reset counter. */
+ TIFR0 = (1 << OCF0A); /* Reset pending. */
+ TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
+
+#elif defined(TCCR0A) /* AT90CAN doesn't have TCCR0B and slightly different */
+ /* TCCR0A. */
+ TCCR0A = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
+ (0 << COM0A1) | (0 << COM0A0); /* OC0A disabled. */
OCR0A = AVR_TIMER_COUNTER - 1;
- TCNT0 = 0; /* Reset counter. */
- TIFR0 = (1 << OCF0A); /* Reset pending. */
- TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
+ TCNT0 = 0; /* Reset counter. */
+ TIFR0 = (1 << OCF0A); /* Reset pending. */
+ TIMSK0 = (1 << OCIE0A); /* IRQ on compare. */
-#elif defined(TCCR0) /* Timer has single output comparator */
- TCCR0 = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
- (0 << COM01) | (0 << COM00) | /* OC0A disabled. */
+#elif defined(TCCR0) /* Timer has single output comparator */
+ TCCR0 = (1 << WGM01) | (0 << WGM00) | /* CTC mode. */
+ (0 << COM01) | (0 << COM00) | /* OC0A disabled. */
AVR_TIMER_PRESCALER_BITS;
OCR0 = AVR_TIMER_COUNTER - 1;
- TCNT0 = 0; /* Reset counter. */
- TIFR = (1 << OCF0); /* Reset pending. */
- TIMSK = (1 << OCIE0); /* IRQ on compare. */
+ TCNT0 = 0; /* Reset counter. */
+ TIFR = (1 << OCF0); /* Reset pending. */
+ TIMSK = (1 << OCIE0); /* IRQ on compare. */
#else
#error "Neither TCCR0A nor TCCR0 registers are defined"
#endif
diff --git a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.h b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.h
index 5ef56a897..b37dabdf3 100644
--- a/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.h
+++ b/os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.h
@@ -29,38 +29,33 @@
#include <avr/io.h>
-/*===========================================================================*/
-/* Driver constants. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver constants. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver pre-compile time settings. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver pre-compile time settings. */
+/*==========================================================================*/
-/*
- * TODO: for models that have many timers,
- * could add AVR_ST_USE_TIMER
- */
+/* TODO: for models that have many timers, could add AVR_ST_USE_TIMER. */
-/*===========================================================================*/
-/* Derived constants and error checks. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Derived constants and error checks. */
+/*==========================================================================*/
-/*
- * TODO: error checks for valid timer selected
- */
+/* TODO: error checks for valid timer selected. */
-/*===========================================================================*/
-/* Driver data structures and types. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver data structures and types. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* Driver macros. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver macros. */
+/*==========================================================================*/
-/*===========================================================================*/
-/* External declarations. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* External declarations. */
+/*==========================================================================*/
#ifdef __cplusplus
extern "C" {
@@ -78,9 +73,9 @@ extern "C" {
#define TIMSK_REG TIMSK1
#endif
-/*===========================================================================*/
-/* Driver inline functions. */
-/*===========================================================================*/
+/*==========================================================================*/
+/* Driver inline functions. */
+/*==========================================================================*/
/**
* @brief Returns the time counter value.
@@ -110,7 +105,7 @@ static inline void st_lld_start_alarm(systime_t time) {
/* Reset pending. */
TIFR_REG = _BV(OCF1A);
- /* enable interrupt */
+ /* Enable interrupt. */
TIMSK_REG = _BV(OCIE1A);
}
@@ -153,7 +148,7 @@ static inline systime_t st_lld_get_alarm(void) {
*
* @return The alarm status.
* @retval false if the alarm is not active.
- * @retval true is the alarm is active
+ * @retval true is the alarm is active.
*
* @notapi
*/