From: Nathael Pajani Date: Wed, 17 Dec 2014 01:22:23 +0000 (+0100) Subject: Change variable and function name as it counts clock cycles and not ticks. Add comments X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=a2630857a39d27233d2c880438d57c29fc67edde;p=soft%2Flpc122x%2Fcore Change variable and function name as it counts clock cycles and not ticks. Add comments --- diff --git a/core/systick.c b/core/systick.c index 18fdc1e..a157ea5 100644 --- a/core/systick.c +++ b/core/systick.c @@ -37,9 +37,9 @@ static volatile uint32_t systick_running = 0; static volatile uint32_t tick_reload = 0; /* Wraps every 50 days or so with a 1ms tick */ -static volatile uint32_t global_wrapping_system_ticks_cycles; -/* The systick cycles run at get_main_clock(), and would wrap more often! */ static volatile uint32_t global_wrapping_system_ticks = 0; +/* The systick cycles run at get_main_clock(), and would wrap more often! */ +static volatile uint32_t global_wrapping_system_clock_cycles = 0; struct systick_callback { @@ -54,7 +54,7 @@ void SysTick_Handler(void) { int i = 0; global_wrapping_system_ticks++; - global_wrapping_system_ticks_cycles += tick_reload; + global_wrapping_system_clock_cycles += tick_reload; if (sleep_count != 0) { sleep_count--; } @@ -138,15 +138,20 @@ static uint32_t systick_counted_to_zero(void) } +/* Get the number of system ticks ... since last wrapping of the counter, which + * is about 50 days with a 1ms system tick. */ uint32_t systick_get_tick_count(void) { return global_wrapping_system_ticks; } -uint32_t systick_get_tick_cycles(void) +/* Get the number of clock cycles ... since last wrapping of the counter. */ +uint32_t systick_get_clock_cycles(void) { struct lpc_system_tick* systick = LPC_SYSTICK; - return global_wrapping_system_ticks_cycles - systick->value; + /* global_wrapping_system_clock_cycles has been initialised to reload value, thus there is + * no need to add it here, making the call quicker */ + return global_wrapping_system_clock_cycles - systick->value; } /***************************************************************************** */ @@ -173,8 +178,9 @@ void systick_timer_on(uint32_t ms) tick_reload = systick->reload_val; /* Start counting from the reload value, writting anything would do ... */ - global_wrapping_system_ticks_cycles = tick_reload; systick->value = reload; + /* Consider we already counted one cycle, making further reading of this count easier */ + global_wrapping_system_clock_cycles = tick_reload; /* And enable counter interrupt */ systick->control = LPC_SYSTICK_CTRL_TICKINT; diff --git a/include/core/system.h b/include/core/system.h index e1f5a7b..2cea777 100644 --- a/include/core/system.h +++ b/include/core/system.h @@ -124,13 +124,16 @@ void systick_start(void); void systick_stop(void); /* Reset the system tick timer, making it count down from the reload value again */ void systick_reset(void); + /* Get system tick timer current value */ uint32_t systick_get_timer_val(void); -/* Get the system tick */ +/* Get the number of system ticks ... since last wrapping of the counter, which + * is about 50 days with a 1ms system tick. */ uint32_t systick_get_tick_count(void); -/* Get the systick cycles since start */ -uint32_t systick_get_tick_cycles(void); + +/* Get the number of clock cycles ... since last wrapping of the counter. */ +uint32_t systick_get_clock_cycles(void); /* Power up the system tick timer. * ms is the interval between system tick timer interrupts. If set to 0, the default