diff options
author | Alexander Krutwig <alexander.krutwig@embedded-brains.de> | 2015-04-01 15:33:25 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-05-20 08:40:34 +0200 |
commit | 75acd9e69f906cbd880a17ee4ca705ad7caa92c0 (patch) | |
tree | 71529028154cb323286b02392def2e5277eed312 /c/src/lib/libcpu/arm | |
parent | timecounter: Use in RTEMS (diff) | |
download | rtems-75acd9e69f906cbd880a17ee4ca705ad7caa92c0.tar.bz2 |
bsps: Convert clock drivers to use a timecounter
Update #2271.
Diffstat (limited to 'c/src/lib/libcpu/arm')
-rw-r--r-- | c/src/lib/libcpu/arm/at91rm9200/clock/clock.c | 23 | ||||
-rw-r--r-- | c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c | 53 | ||||
-rw-r--r-- | c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c | 3 | ||||
-rw-r--r-- | c/src/lib/libcpu/arm/pxa255/clock/clock.c | 2 | ||||
-rw-r--r-- | c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c | 14 |
5 files changed, 51 insertions, 44 deletions
diff --git a/c/src/lib/libcpu/arm/at91rm9200/clock/clock.c b/c/src/lib/libcpu/arm/at91rm9200/clock/clock.c index 16cf145b37..42b85f3f98 100644 --- a/c/src/lib/libcpu/arm/at91rm9200/clock/clock.c +++ b/c/src/lib/libcpu/arm/at91rm9200/clock/clock.c @@ -22,8 +22,6 @@ #include <at91rm9200.h> #include <at91rm9200_pmc.h> -static unsigned long st_pimr_reload; - /** * Enables clock interrupt. * @@ -77,17 +75,16 @@ rtems_irq_connect_data clock_isr_data = { BSP_install_rtems_irq_handler(&clock_isr_data); \ } while(0) -uint16_t st_pimr_value; static void Clock_driver_support_initialize_hardware(void) { uint32_t st_str; int slck; + unsigned long value; /* the system timer is driven from SLCK */ slck = at91rm9200_get_slck(); - st_pimr_value = (((rtems_configuration_get_microseconds_per_tick() * slck) + + value = (((rtems_configuration_get_microseconds_per_tick() * slck) + (1000000/2))/ 1000000); - st_pimr_reload = st_pimr_value; /* read the status to clear the int */ st_str = ST_REG(ST_SR); @@ -97,21 +94,9 @@ static void Clock_driver_support_initialize_hardware(void) AIC_SMR_REG(AIC_SMR_SYSIRQ) = AIC_SMR_PRIOR(0x7); /* set the timer value */ - ST_REG(ST_PIMR) = st_pimr_reload; + ST_REG(ST_PIMR) = value; } -static uint32_t bsp_clock_nanoseconds_since_last_tick(void) -{ - uint16_t slck_counts; - - slck_counts = st_pimr_value - st_pimr_reload; - return (rtems_configuration_get_microseconds_per_tick() * slck_counts * 1000) - / st_pimr_value; -} - -#define Clock_driver_nanoseconds_since_last_tick \ - bsp_clock_nanoseconds_since_last_tick - #define Clock_driver_support_at_tick() \ do { \ uint32_t st_str; \ @@ -126,4 +111,6 @@ static void Clock_driver_support_shutdown_hardware( void ) BSP_remove_rtems_irq_handler(&clock_isr_data); } +#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER + #include "../../../../libbsp/shared/clockdrv_shell.h" diff --git a/c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c b/c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c index 02f5b8c5ea..e75fed8a9e 100644 --- a/c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c +++ b/c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c @@ -17,12 +17,39 @@ #include <bsp/irq.h> #include <lpc22xx.h> #include <rtems/bspIo.h> /* for printk */ +#include <rtems/timecounter.h> void Clock_isr(rtems_irq_hdl_param arg); static void clock_isr_on(const rtems_irq_connect_data *unused); static void clock_isr_off(const rtems_irq_connect_data *unused); static int clock_isr_is_on(const rtems_irq_connect_data *irq); +static rtems_timecounter_simple lpc22xx_tc; + +static uint32_t lpc22xx_tc_get(rtems_timecounter_simple *tc) +{ + return T0TC; +} + +static bool lpc22xx_tc_is_pending(rtems_timecounter_simple *tc) +{ + return (T0IR & 0x1) != 0; +} + +static uint32_t lpc22xx_tc_get_timecount(struct timecounter *tc) +{ + return rtems_timecounter_simple_upcounter_get( + tc, + lpc22xx_tc_get, + lpc22xx_tc_is_pending + ); +} + +static void lpc22xx_tc_tick(void) +{ + rtems_timecounter_simple_upcounter_tick(&lpc22xx_tc, lpc22xx_tc_get); +} + /* Replace the first value with the clock's interrupt name. */ rtems_irq_connect_data clock_isr_data = { .name = LPC22xx_INTERRUPT_TIMER0, @@ -74,9 +101,10 @@ rtems_irq_connect_data clock_isr_data = { */ #define Clock_driver_support_initialize_hardware() \ do { \ + uint32_t mask; \ /* disable and clear timer 0, set to */ \ T0TCR &= 0; \ - /* TC is incrementet on every pclk.*/ \ + /* TC is incremented on every pclk.*/ \ T0PC = 0; \ /* initialize the timer period and prescaler */ \ T0MR0 = ((LPC22xx_Fpclk/1000 * \ @@ -89,6 +117,13 @@ rtems_irq_connect_data clock_isr_data = { T0TCR = 1; \ /* enable interrupt, skyeye will check this*/ \ T0IR |= 0x01; \ + /* install timecounter */ \ + rtems_timecounter_simple_install( \ + &lpc22xx_tc, \ + LPC22xx_Fpclk, \ + T0MR0, \ + lpc22xx_tc_get_timecount \ + ); \ } while (0) /** @@ -104,20 +139,6 @@ rtems_irq_connect_data clock_isr_data = { BSP_remove_rtems_irq_handler(&clock_isr_data); \ } while (0) -static uint32_t bsp_clock_nanoseconds_since_last_tick(void) -{ - uint32_t clicks; - uint32_t microseconds; - - clicks = T0TC; /* T0TC is the 32bit time counter 0 */ - - microseconds = (rtems_configuration_get_microseconds_per_tick() - clicks); - return microseconds * 1000; -} - -#define Clock_driver_nanoseconds_since_last_tick \ - bsp_clock_nanoseconds_since_last_tick - /** * Enables clock interrupt. * @@ -149,6 +170,8 @@ static int clock_isr_is_on(const rtems_irq_connect_data *irq) return T0IR & 0x01; /* MR0 mask */ } +#define Clock_driver_timecounter_tick() lpc22xx_tc_tick() + /* Make sure to include this, and only at the end of the file */ #include "../../../../libbsp/shared/clockdrv_shell.h" diff --git a/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c b/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c index 0c3ab5dd93..d5dc69c9a0 100644 --- a/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c +++ b/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c @@ -130,5 +130,8 @@ static int clock_isr_is_on(const rtems_irq_connect_data *irq) return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN; } +#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER + /* Make sure to include this, and only at the end of the file */ + #include "../../../../libbsp/shared/clockdrv_shell.h" diff --git a/c/src/lib/libcpu/arm/pxa255/clock/clock.c b/c/src/lib/libcpu/arm/pxa255/clock/clock.c index 92d9b21d2b..69b684926c 100644 --- a/c/src/lib/libcpu/arm/pxa255/clock/clock.c +++ b/c/src/lib/libcpu/arm/pxa255/clock/clock.c @@ -116,4 +116,6 @@ static void Clock_driver_support_shutdown_hardware( void ) BSP_remove_rtems_irq_handler(&clock_isr_data); } +#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER + #include "../../../../libbsp/shared/clockdrv_shell.h" diff --git a/c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c b/c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c index 519d3f850d..a92dc607a3 100644 --- a/c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c +++ b/c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c @@ -28,17 +28,6 @@ rtems_irq_connect_data clock_isr_data = { }; /** - * Return the nanoseconds since last tick - */ -static uint32_t clock_driver_get_nanoseconds_since_last_tick(void) -{ - return 0; -} - -#define Clock_driver_nanoseconds_since_last_tick \ - clock_driver_get_nanoseconds_since_last_tick - -/** * When we get the clock interrupt * - clear the interrupt bit? * - restart the timer? @@ -74,6 +63,7 @@ static uint32_t clock_driver_get_nanoseconds_since_last_tick(void) do { \ uint32_t cr; \ uint32_t freq; \ + uint32_t mask; \ /* set MUX for Timer4 to 1/16 */ \ cr=rTCFG1 & 0xFFF0FFFF; \ rTCFG1=(cr | (3<<16)); \ @@ -131,5 +121,7 @@ static int clock_isr_is_on(const rtems_irq_connect_data *irq) return 1; } +#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER + /* Make sure to include this, and only at the end of the file */ #include "../../../../libbsp/shared/clockdrv_shell.h" |