From: Nathael Pajani Date: Thu, 17 Apr 2014 08:59:27 +0000 (+0200) Subject: Systick code review and fix of systick timer frequency. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=e367603f5ea2031b45a133d29317dc037c46d8eb;p=soft%2Flpc122x%2Fcore Systick code review and fix of systick timer frequency. --- diff --git a/core/systick.c b/core/systick.c index 82672cb..bcf1ab5 100644 --- a/core/systick.c +++ b/core/systick.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/systick.c + * core/systick.c * * Copyright 2012 Nathael Pajani * @@ -120,6 +120,7 @@ uint32_t systick_get_timer_val(void) return systick->value; } /* Get the "timer wrapped" indicator. + * Used in usleep() function. * Note : the first to call this function will get the right information. * All subsequent calls will get wrong indication. * Thus this function is not exported to user space, user should compare global @@ -153,16 +154,19 @@ void systick_timer_on(uint32_t ms) reload = (get_main_clock() / 1000) - 1; ms = 1; } - systick->reload_val = reload; + /* For the LPC1224 the system tick clock is fixed to half the frequency of the system clock */ + reload = reload >> 1; /* Divide by 2 */ + systick->reload_val = (reload & 0xffffff); tick_ms = ms; /* Start counting from the reload value, writting anything would do ... */ - systick->value = 0; + systick->value = reload; /* And enable counter interrupt */ - systick->control = (LPC_SYSTICK_CTRL_TICKINT | LPC_SYSTICK_CTRL_CLKSOURCE); + systick->control = LPC_SYSTICK_CTRL_TICKINT; systick_running = 0; + /* FIXME : document this */ NVIC_SetPriority(SYSTICK_IRQ, ((1 << LPC_NVIC_PRIO_BITS) - 1)); } diff --git a/include/core/system.h b/include/core/system.h index 9f791db..9ebc2ee 100644 --- a/include/core/system.h +++ b/include/core/system.h @@ -160,7 +160,7 @@ uint32_t get_sleep(void); uint32_t sleep(void); void msleep(uint32_t ms); -void usleep(uint32_t ms); +void usleep(uint32_t us); #endif /* CORE_SYSTEM_H */