diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-04-20 12:08:42 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-04-20 13:52:19 +0200 |
commit | e0dd8a5ad830798bc8082b03b8c42c32fb9660e0 (patch) | |
tree | d147bfc4d670fcdfbd2e2d2e75eb209f92e07df1 /bsps/arm | |
parent | bsps: Move startup files to bsps (diff) | |
download | rtems-e0dd8a5ad830798bc8082b03b8c42c32fb9660e0.tar.bz2 |
bsps: Move benchmark timer to bsps
This patch is a part of the BSP source reorganization.
Update #3285.
Diffstat (limited to 'bsps/arm')
-rw-r--r-- | bsps/arm/csb336/btimer/btimer.c | 93 | ||||
-rw-r--r-- | bsps/arm/csb337/btimer/btimer.c | 91 | ||||
-rw-r--r-- | bsps/arm/edb7312/btimer/btimer.c | 80 | ||||
-rw-r--r-- | bsps/arm/gumstix/btimer/btimer.c | 75 | ||||
-rw-r--r-- | bsps/arm/lpc176x/btimer/btimer.c | 407 | ||||
-rw-r--r-- | bsps/arm/rtl22xx/btimer/btimer.c | 65 | ||||
-rw-r--r-- | bsps/arm/rtl22xx/btimer/lpc_timer.h | 48 | ||||
-rw-r--r-- | bsps/arm/smdk2410/btimer/btimer.c | 100 |
8 files changed, 959 insertions, 0 deletions
diff --git a/bsps/arm/csb336/btimer/btimer.c b/bsps/arm/csb336/btimer/btimer.c new file mode 100644 index 0000000000..66ff4a0bf4 --- /dev/null +++ b/bsps/arm/csb336/btimer/btimer.c @@ -0,0 +1,93 @@ +/** + * @file + * @brief Cogent CSB336 Timer driver + * + * This uses timer 2 for timing measurments. + */ + +/* + * Copyright (c) 2004 Cogent Computer Systems + * Written by Jay Monkman <jtm@lopingdog.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <rtems.h> +#include <bsp.h> +#include <rtems/btimer.h> +#include <mc9328mxl.h> + +uint32_t g_start; +uint32_t g_freq; + +bool benchmark_timer_find_average_overhead; + + +/* + * Set up Timer 1 + */ +void benchmark_timer_initialize( void ) +{ + MC9328MXL_TMR2_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | + MC9328MXL_TMR_TCTL_FRR | + MC9328MXL_TMR_TCTL_TEN); + /* set prescaler to 1 (register value + 1) */ \ + MC9328MXL_TMR2_TPRER = 0; + + /* get freq of counter in KHz */ + g_freq = get_perclk1_freq() / 1000; + + g_start = MC9328MXL_TMR2_TCN; +} + +/* + * The following controls the behavior of benchmark_timer_read(). + * + * AVG_OVEREHAD is the overhead for starting and stopping the timer. It + * is usually deducted from the number returned. + * + * LEAST_VALID is the lowest number this routine should trust. Numbers + * below this are "noise" and zero is returned. + */ + +#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ + /* (Y countdowns) to start/stop the timer. */ + /* This value is in microseconds. */ +#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ + +benchmark_timer_t benchmark_timer_read( void ) +{ + uint32_t t; + unsigned long long total; + + t = MC9328MXL_TMR2_TCN; + /* + * Total is calculated by taking into account the number of timer overflow + * interrupts since the timer was initialized and clicks since the last + * interrupts. + */ + + total = (t - g_start); + + /* convert to nanoseconds */ + total = (total * 1000)/ g_freq; + + if ( benchmark_timer_find_average_overhead == 1 ) { + return (int) total; + } else if ( total < LEAST_VALID ) { + return 0; + } + /* + * Somehow convert total into microseconds + */ + + return (total - AVG_OVERHEAD); +} + +void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) +{ + benchmark_timer_find_average_overhead = find_flag; +} + diff --git a/bsps/arm/csb337/btimer/btimer.c b/bsps/arm/csb337/btimer/btimer.c new file mode 100644 index 0000000000..c65dd8096a --- /dev/null +++ b/bsps/arm/csb337/btimer/btimer.c @@ -0,0 +1,91 @@ +/** + * @file + * @brief Cogent CSB337 Timer driver + * + * This uses timer 0 for timing measurments. + */ + +/* + * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <rtems.h> +#include <rtems/btimer.h> +#include <at91rm9200.h> +#include <at91rm9200_pmc.h> + +uint16_t tstart; +bool benchmark_timer_find_average_overhead; +uint32_t tick_time; +/* + * Set up TC0 - + * timer_clock2 (MCK/8) + * capture mode - this shouldn't matter + */ +void benchmark_timer_initialize( void ) +{ + uint32_t tmr_freq; + + /* since we are using timer_clock2, divide mck by 8 */ + tmr_freq = at91rm9200_get_mck() / 8; + + TC_TC0_REG(TC_CMR) = TC_CMR_TCCLKS(1); /* timer_clock2 */ + TC_TC0_REG(TC_CCR) = (TC_CCR_CLKEN /* enable the counter */ + | TC_CCR_SWTRG); /* start it up */ + + /* tick time in nanoseconds */ + tick_time = 1000000000/tmr_freq; + +} + +/* + * The following controls the behavior of benchmark_timer_read(). + * + * AVG_OVEREHAD is the overhead for starting and stopping the timer. It + * is usually deducted from the number returned. + * + * LEAST_VALID is the lowest number this routine should trust. Numbers + * below this are "noise" and zero is returned. + */ + +#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ + /* (Y countdowns) to start/stop the timer. */ + /* This value is in microseconds. */ +#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ + +benchmark_timer_t benchmark_timer_read( void ) +{ + uint16_t t; + uint32_t total; + t = TC_TC0_REG(TC_CV); + + /* + * Total is calculated by taking into account the number of timer overflow + * interrupts since the timer was initialized and clicks since the last + * interrupts. + */ + + total = t * tick_time; + + if ( benchmark_timer_find_average_overhead == 1 ) + return total; /* in nanosecond units */ + else { + if ( total < LEAST_VALID ) + return 0; /* below timer resolution */ + /* + * Somehow convert total into microseconds + */ + return (total - AVG_OVERHEAD); + } +} + +void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) +{ + benchmark_timer_find_average_overhead = find_flag; +} + diff --git a/bsps/arm/edb7312/btimer/btimer.c b/bsps/arm/edb7312/btimer/btimer.c new file mode 100644 index 0000000000..b795122ff3 --- /dev/null +++ b/bsps/arm/edb7312/btimer/btimer.c @@ -0,0 +1,80 @@ +/* + * Cirrus EP7312 Timer driver + * + * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + * + * Notes: + * This file manages the benchmark timer used by the RTEMS Timing Test + * Suite. Each measured time period is demarcated by calls to + * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns + * the number of microseconds since benchmark_timer_initialize() exitted. + * + * It is important that the timer start/stop overhead be determined + * when porting or modifying this code. +*/ + +#include <rtems.h> +#include <bsp.h> +#include <rtems/btimer.h> +#include <ep7312.h> + +uint16_t tstart; +bool benchmark_timer_find_average_overhead; + +void benchmark_timer_initialize( void ) +{ + *EP7312_SYSCON1 |= EP7312_SYSCON1_TC2_512KHZ; + *EP7312_TC2D = 0xffff; +} + +/* + * The following controls the behavior of benchmark_timer_read(). + * + * AVG_OVEREHAD is the overhead for starting and stopping the timer. It + * is usually deducted from the number returned. + * + * LEAST_VALID is the lowest number this routine should trust. Numbers + * below this are "noise" and zero is returned. + */ + +#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ + /* (Y countdowns) to start/stop the timer. */ + /* This value is in microseconds. */ +#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ + +benchmark_timer_t benchmark_timer_read( void ) +{ + uint16_t t; + uint32_t total; + t = *EP7312_TC2D; + + /* + * Total is calculated by taking into account the number of timer overflow + * interrupts since the timer was initialized and clicks since the last + * interrupts. + */ + + total = (uint32_t)0x0000ffff - t; /* result is 1/512000 = ~2 uS */ + total = (total * 1953) / 1000; /* convert to uS */ + if ( benchmark_timer_find_average_overhead == true ) + return total; /* in XXX microsecond units */ + else { + if ( total < LEAST_VALID ) + return 0; /* below timer resolution */ + /* + * Somehow convert total into microseconds + */ + return (total - AVG_OVERHEAD); + } +} + +void benchmark_timer_disable_subtracting_average_overhead( + bool find_flag +) +{ + benchmark_timer_find_average_overhead = find_flag; +} diff --git a/bsps/arm/gumstix/btimer/btimer.c b/bsps/arm/gumstix/btimer/btimer.c new file mode 100644 index 0000000000..7eb3d5b811 --- /dev/null +++ b/bsps/arm/gumstix/btimer/btimer.c @@ -0,0 +1,75 @@ +/** + * @file + * @brief PXA255 timer + */ + +/* + * PXA255 timer by Yang Xi <hiyangxi@gmail.com> + * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <rtems.h> +#include <rtems/btimer.h> +#include <pxa255.h> + +uint32_t tstart; +static uint32_t tick_time; +bool benchmark_timer_find_average_overhead; + +bool benchmark_timer_is_initialized = false; + +/* + * Use the timer count register to measure. + * The frequency of it is 3.4864MHZ + * The longest period we are able to capture is 4G/3.4864MHZ + */ +void benchmark_timer_initialize(void) +{ + tick_time = XSCALE_OS_TIMER_TCR; +} + +/* + * The following controls the behavior of Read_timer(). + * + * AVG_OVEREHAD is the overhead for starting and stopping the timer. It + * is usually deducted from the number returned. + * + * LEAST_VALID is the lowest number this routine should trust. Numbers + * below this are "noise" and zero is returned. + */ + +#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ + /* (Y countdowns) to start/stop the timer. */ + /* This value is in microseconds. */ +#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ + +benchmark_timer_t benchmark_timer_read(void) +{ + + uint32_t total; + total = XSCALE_OS_TIMER_TCR; + if(total>=tick_time) + total -= tick_time; + else + total += 0xffffffff - tick_time; /*Round up but not overflow*/ + + if ( benchmark_timer_find_average_overhead == true ) + return total; /*Counter cycles*/ + + if ( total < LEAST_VALID ) + return 0; /* below timer resolution */ + + return total; +} + +void benchmark_timer_disable_subtracting_average_overhead( + bool find_flag +) +{ + benchmark_timer_find_average_overhead = find_flag; +} diff --git a/bsps/arm/lpc176x/btimer/btimer.c b/bsps/arm/lpc176x/btimer/btimer.c new file mode 100644 index 0000000000..36c720b4fb --- /dev/null +++ b/bsps/arm/lpc176x/btimer/btimer.c @@ -0,0 +1,407 @@ +/** + * @file timer.c + * + * @ingroup lpc176x + * + * @brief Timer controller for the mbed lpc1768 board. + */ + +/* + * Copyright (c) 2014 Taller Technologies. + * + * @author Boretto Martin (martin.boretto@tallertechnologies.com) + * @author Diaz Marcos (marcos.diaz@tallertechnologies.com) + * @author Lenarduzzi Federico (federico.lenarduzzi@tallertechnologies.com) + * @author Daniel Chicco (daniel.chicco@tallertechnologies.com) + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <stdio.h> +#include <rtems/status-checks.h> +#include <bsp.h> +#include <bsp/irq.h> +#include <bsp/io.h> +#include <bsp/timer.h> + +/** + * @brief Represents all the timers. + */ +const lpc176x_timer timers[ LPC176X_TIMER_COUNT ] = +{ + { + .device = (lpc176x_timer_device *) LPC176X_TMR0_BASE_ADDR, + .module = LPC176X_MODULE_TIMER_0, + .pinselcap = LPC176X_TIMER0_CAPTURE_PORTS, + .pinselemat = LPC176X_TIMER0_EMATCH_PORTS, + }, + { + .device = (lpc176x_timer_device *) LPC176X_TMR1_BASE_ADDR, + .module = LPC176X_MODULE_TIMER_1, + .pinselcap = LPC176X_TIMER1_CAPTURE_PORTS, + .pinselemat = LPC176X_TIMER1_EMATCH_PORTS, + }, + { + .device = (lpc176x_timer_device *) LPC176X_TMR2_BASE_ADDR, + .module = LPC176X_MODULE_TIMER_2, + .pinselcap = LPC176X_TIMER2_CAPTURE_PORTS, + .pinselemat = LPC176X_TIMER2_EMATCH_PORTS, + }, + { + .device = (lpc176x_timer_device *) LPC176X_TMR3_BASE_ADDR, + .module = LPC176X_MODULE_TIMER_3, + .pinselcap = LPC176X_TIMER3_CAPTURE_PORTS, + .pinselemat = LPC176X_TIMER3_EMATCH_PORTS, + } +}; + +/** + * @brief Represents all the functions according to the timers. + */ +lpc176x_timer_functions functions_vector[ LPC176X_TIMER_COUNT ] = +{ + { + .funct_vector = NULL + }, + { + .funct_vector = NULL + }, + { + .funct_vector = NULL + }, + { + .funct_vector = NULL + } +}; + +/** + * @brief Calls the corresponding interrupt function and pass the timer + * as parameter. + * + * @param timer The specific device. + * @param interruptnumber Interrupt number. + */ +static inline void lpc176x_call_desired_isr( + const lpc176x_timer_number number, + const lpc176x_isr_function interruptfunction +) +{ + if ( ( *functions_vector[ number ].funct_vector )[ interruptfunction ] != + NULL ) { + ( *functions_vector[ number ].funct_vector )[ interruptfunction ]( number ); + } + + /* else implies that the function vector points NULL. Also, + there is nothing to do. */ +} + +/** + * @brief Gets true if the selected interrupt is pending + * + * @param number: the number of the timer. + * @param interrupt: the interrupt we are checking for. + * @return TRUE if the interrupt is pending. + */ +static inline bool lpc176x_timer_interrupt_is_pending( + const lpc176x_timer_number tnumber, + const lpc176x_isr_function function +) +{ + assert( ( tnumber < LPC176X_TIMER_COUNT ) + && ( function < LPC176X_ISR_FUNCTIONS_COUNT ) ); + + return ( timers[ tnumber ].device->IR & + LPC176X_TIMER_INTERRUPT_SOURCE_BIT( function ) ); +} + +/** + * @brief Resets interrupt status for the selected interrupt + * + * @param tnumber: the number of the timer + * @param interrupt: the interrupt we are resetting + */ +static inline void lpc176x_timer_reset_interrupt( + const lpc176x_timer_number tnumber, + const lpc176x_isr_function function +) +{ + assert( ( tnumber < LPC176X_TIMER_COUNT ) + && ( function < LPC176X_ISR_FUNCTIONS_COUNT ) ); + timers[ tnumber ].device->IR = + LPC176X_TIMER_INTERRUPT_SOURCE_BIT( function ); +} + +inline rtems_status_code lpc176x_timer_reset( + const lpc176x_timer_number tnumber ) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + timers[ tnumber ].device->TCR = LPC176X_TIMER_RESET; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +inline rtems_status_code lpc176x_timer_set_mode( + const lpc176x_timer_number tnumber, + const lpc176x_timer_mode mode +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + timers[ tnumber ].device->CTCR = mode; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +inline rtems_status_code lpc176x_timer_start( + const lpc176x_timer_number tnumber ) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + timers[ tnumber ].device->TCR = LPC176X_TIMER_START; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +inline rtems_status_code lpc176x_timer_is_started( + const lpc176x_timer_number tnumber, + bool *is_started +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + *is_started = ( timers[ tnumber ].device->TCR & LPC176X_TIMER_START ) == + LPC176X_TIMER_START; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +inline rtems_status_code lpc176x_timer_set_resolution( + const lpc176x_timer_number tnumber, + const lpc176x_microseconds resolution +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + timers[ tnumber ].device->PR = ( LPC176X_CCLK / + LPC176X_TIMER_PRESCALER_DIVISOR ) * + resolution; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +rtems_status_code lpc176x_timer_match_config( + const lpc176x_timer_number tnumber, + const lpc176x_match_port match_port, + const lpc176x_match_function function, + const uint32_t match_value +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( ( tnumber < LPC176X_TIMER_COUNT ) + && ( match_port < LPC176X_EMATCH_PORTS_COUNT ) + && ( function < LPC176X_TIMER_MATCH_FUNCTION_COUNT ) ) { + timers[ tnumber ].device->MCR = + LPC176X_SET_MCR( timers[ tnumber ].device->MCR, + match_port, function ); + timers[ tnumber ].device->MR[ match_port ] = match_value; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number, or a match port or a function + is invalid. Also, an invalid number is returned. */ + + return status_code; +} + +inline rtems_status_code lpc176x_timer_capture_config( + const lpc176x_timer_number tnumber, + const lpc176x_capture_port capture_port, + const lpc176x_capture_function function +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( ( tnumber < LPC176X_TIMER_COUNT ) + && ( capture_port < LPC176X_CAPTURE_PORTS_COUNT ) + && ( function < LPC176X_TIMER_CAPTURE_FUNCTION_COUNT ) ) { + timers[ tnumber ].device->CCR = + LPC176X_SET_CCR( timers[ tnumber ].device->CCR, + capture_port, function ); + lpc176x_pin_select( timers[ tnumber ].pinselcap[ capture_port ], + LPC176X_PIN_FUNCTION_11 ); + } + + /* else implies that the timer number or the capture port is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +inline rtems_status_code lpc176x_timer_external_match_config( + const lpc176x_timer_number number, + const lpc176x_match_port match_port, + const lpc176x_ext_match_function function +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( ( number < LPC176X_TIMER_COUNT ) + && ( match_port < LPC176X_EMATCH_PORTS_COUNT ) ) { + timers[ number ].device->EMR = + LPC176X_SET_EMR( timers[ number ].device->EMR, + match_port, function ); + lpc176x_pin_select( timers[ number ].pinselemat[ match_port ], + LPC176X_PIN_FUNCTION_11 ); + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number or the match port is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +inline uint32_t lpc176x_timer_get_capvalue( + const lpc176x_timer_number number, + const lpc176x_capture_port capture_port +) +{ + assert( ( number < LPC176X_TIMER_COUNT ) + && ( capture_port < LPC176X_CAPTURE_PORTS_COUNT ) ); + + return timers[ number ].device->CR[ capture_port ]; +} + +inline uint32_t lpc176x_timer_get_timer_value( + const lpc176x_timer_number tnumber ) +{ + assert( tnumber < LPC176X_TIMER_COUNT ); + + return timers[ tnumber ].device->TC; +} + +inline rtems_status_code lpc176x_timer_set_timer_value( + const lpc176x_timer_number tnumber, + const uint32_t timer_value +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + timers[ tnumber ].device->TC = timer_value; + status_code = RTEMS_SUCCESSFUL; + } + + /* else implies that the timer number is invalid. Also, + an invalid number is returned. */ + + return status_code; +} + +void lpc176x_timer_isr( void *arg ) +{ + const lpc176x_timer_number tnumber = (lpc176x_timer_number) arg; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + lpc176x_isr_function i; + + for ( i = 0; i < LPC176X_ISR_FUNCTIONS_COUNT; ++i ) { + if ( lpc176x_timer_interrupt_is_pending( tnumber, i ) ) { + lpc176x_call_desired_isr( tnumber, i ); + lpc176x_timer_reset_interrupt( tnumber, i ); + } + + /* else implies that the current timer is not pending. Also, + there is nothing to do. */ + } + } + + /* else implies that the timer number is not valid. Also, + there is nothing to do. */ +} + +rtems_status_code lpc176x_timer_init( const lpc176x_timer_number tnumber ) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + if ( tnumber < LPC176X_TIMER_COUNT ) { + status_code = lpc176x_module_enable( timers[ tnumber ].module, + LPC176X_MODULE_PCLK_DEFAULT ); + RTEMS_CHECK_SC( status_code, "Enabling the timer module." ); + + status_code = lpc176x_timer_reset( tnumber ); + status_code = lpc176x_timer_set_mode( tnumber, + LPC176X_TIMER_MODE_TIMER ); + status_code = lpc176x_timer_set_resolution( tnumber, + LPC176X_TIMER_DEFAULT_RESOLUTION ); + + timers[ tnumber ].device->MCR = LPC176X_TIMER_CLEAR_FUNCTION; + timers[ tnumber ].device->CCR = LPC176X_TIMER_CLEAR_FUNCTION; + timers[ tnumber ].device->EMR = LPC176X_TIMER_CLEAR_FUNCTION; + } + + /* else implies that the timer number is not valid. Also, + an invalid number is returned. */ + + return status_code; +} + +rtems_status_code lpc176x_timer_init_with_interrupt( + const lpc176x_timer_number tnumber, + const lpc176x_isr_funct_vector *const vector +) +{ + rtems_status_code status_code = RTEMS_INVALID_NUMBER; + + char isrname[ LPC176X_ISR_NAME_STRING_SIZE ]; + + snprintf( isrname, LPC176X_ISR_NAME_STRING_SIZE, "TimerIsr%d", tnumber ); + + if ( tnumber < LPC176X_TIMER_COUNT && vector != NULL ) { + functions_vector[ tnumber ].funct_vector = vector; + + status_code = lpc176x_timer_init( tnumber ); + status_code = rtems_interrupt_handler_install( + LPC176X_TIMER_VECTOR_NUMBER( tnumber ), + isrname, + RTEMS_INTERRUPT_UNIQUE, + lpc176x_timer_isr, + (void *) tnumber ); + } + + return status_code; +}
\ No newline at end of file diff --git a/bsps/arm/rtl22xx/btimer/btimer.c b/bsps/arm/rtl22xx/btimer/btimer.c new file mode 100644 index 0000000000..ad73aeda3c --- /dev/null +++ b/bsps/arm/rtl22xx/btimer/btimer.c @@ -0,0 +1,65 @@ +/** + * @file + * @brief RTL22xx board Timer driver + * + * This uses Timer1 for timing measurments. + */ + +/* + * By Ray Xu <rayx.cn@gmail.com>, modify form Mc9328mxl RTEMS DSP + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <rtems.h> +#include <rtems/btimer.h> +#include <lpc22xx.h> +#include "lpc_timer.h" + +uint32_t g_start; +uint32_t g_freq; + +bool benchmark_timer_find_average_overhead; + + +/* + * Set up Timer 1 + */ +void benchmark_timer_initialize( void ) +{ + g_freq = LPC22xx_Fpclk / 1000; +} + +/* + * The following controls the behavior of benchmark_timer_read(). + * + * AVG_OVEREHAD is the overhead for starting and stopping the timer. It + * is usually deducted from the number returned. + * + * LEAST_VALID is the lowest number this routine should trust. Numbers + * below this are "noise" and zero is returned. + */ + +#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ + /* (Y countdowns) to start/stop the timer. */ + /* This value is in microseconds. */ +#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ + +benchmark_timer_t benchmark_timer_read( void ) +{ + return (T0TC/(LPC22xx_Fpclk/1000000)); + /* + * Total is calculated by taking into account the number of timer overflow + * interrupts since the timer was initialized and clicks since the last + * interrupts. + */ +} + +void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) +{ + benchmark_timer_find_average_overhead = find_flag; +} + diff --git a/bsps/arm/rtl22xx/btimer/lpc_timer.h b/bsps/arm/rtl22xx/btimer/lpc_timer.h new file mode 100644 index 0000000000..364812ddb8 --- /dev/null +++ b/bsps/arm/rtl22xx/btimer/lpc_timer.h @@ -0,0 +1,48 @@ +#ifndef __LPC_TIMER_H +#define __LPC_TIMER_H + +/************************************************************************* + * + * File name : Timer.h + * + **************************************************************************/ + +/* Timer Control register bit descriptions */ +#define TCR_ENABLE_BIT 0 +#define TCR_RESET_BIT 1 + +// The channel name which is used in matching, in fact they represent +// corresponding Match Register +#define CH_MAXNUM 4 +#define CH0 0 +#define CH1 1 +#define CH2 2 +#define CH3 3 + +// The channel name which is used in capturing, in fact they represent +// corresponding Capture Register +#define CPCH_MAXNUM 4 +#define CPCH0 0 +#define CPCH1 1 +#define CPCH2 2 +#define CPCH3 3 + +//The actions when matching +#define TimerAction_Interrupt 0x1 +#define TimerAction_ResetTimer 0x2 +#define TimerAction_StopTimer 0x4 + +//Interrupt source type +#define TIMERMR0Int 0x01 +#define TIMERMR1Int 0x02 +#define TIMERMR2Int 0x04 +#define TIMERMR3Int 0x08 +#define TIMERCR0Int 0x10 +#define TIMERCR1Int 0x20 +#define TIMERCR2Int 0x40 +#define TIMERCR3Int 0x80 + +#define TIMERALLInt 0xFF + +#endif //__LPC_Timer_H + diff --git a/bsps/arm/smdk2410/btimer/btimer.c b/bsps/arm/smdk2410/btimer/btimer.c new file mode 100644 index 0000000000..2bc599df75 --- /dev/null +++ b/bsps/arm/smdk2410/btimer/btimer.c @@ -0,0 +1,100 @@ +/** + * @file + * @brief S3C2400 Timer driver + * + * This uses timer 1 for timing measurments. + */ + +/* + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <rtems.h> +#include <rtems/btimer.h> +#include <s3c24xx.h> + +uint32_t g_start; +uint32_t g_freq; + +bool benchmark_timer_find_average_overhead; + + +/* + * Set up Timer 1 + */ +void benchmark_timer_initialize( void ) +{ + uint32_t cr; + + /* stop TIMER1*/ + cr=rTCON & 0xFFFFF0FF; + rTCON=(cr | (0x0 << 8)); + + /* set MUX for Timer1 to 1/2 */ + cr=rTCFG1 & 0xFFFFFF0F; + rTCFG1=(cr | (0<<4)); + + /* input freq=PLCK/2 Mhz*/ + g_freq = get_PCLK() / 2000; + rTCNTB1 = 0xFFFF; + + /* start TIMER1 with manual reload */ + cr=rTCON & 0xFFFFF0FF; + rTCON=(cr | (0x1 << 9)); + rTCON=(cr | (0x1 << 8)); + + g_start = rTCNTO1; +} + +/* + * The following controls the behavior of benchmark_timer_read(). + * + * AVG_OVEREHAD is the overhead for starting and stopping the timer. It + * is usually deducted from the number returned. + * + * LEAST_VALID is the lowest number this routine should trust. Numbers + * below this are "noise" and zero is returned. + */ + +#define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ + /* (Y countdowns) to start/stop the timer. */ + /* This value is in microseconds. */ +#define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ + +benchmark_timer_t benchmark_timer_read( void ) +{ + uint32_t t; + unsigned long long total; + + t = rTCNTO1; + /* + * Total is calculated by taking into account the number of timer overflow + * interrupts since the timer was initialized and clicks since the last + * interrupts. + */ + + total = (g_start - t); + + /* convert to microseconds */ + total = (total*1000) / g_freq; + + if ( benchmark_timer_find_average_overhead == 1 ) { + return (int) total; + } else if ( total < LEAST_VALID ) { + return 0; + } + + /* + * Somehow convert total into microseconds + */ + return (total - AVG_OVERHEAD); +} + +void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) +{ + benchmark_timer_find_average_overhead = find_flag; +} + |