source: rtems/c/src/lib/libbsp/arm/smdk2410/timer/timer.c @ a1460043

5
Last change on this file since a1460043 was a1460043, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 8, 2017 at 6:57:21 AM

bsp/smdk2410: Move libcpu files to BSP

Update #3254.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 * @brief S3C2400 Timer driver
4 *
5 * This uses timer 1 for timing measurments.
6 */
7
8/*
9 * The license and distribution terms for this file may be
10 * found in the file LICENSE in this distribution or at
11 * http://www.rtems.org/license/LICENSE.
12 */
13
14#include <bsp.h>
15#include <rtems.h>
16#include <rtems/btimer.h>
17#include <s3c24xx.h>
18
19uint32_t g_start;
20uint32_t g_freq;
21
22bool benchmark_timer_find_average_overhead;
23
24
25/*
26 * Set up Timer 1
27 */
28void benchmark_timer_initialize( void )
29{
30    uint32_t cr;
31
32    /* stop TIMER1*/
33    cr=rTCON & 0xFFFFF0FF;
34    rTCON=(cr | (0x0 << 8));
35
36    /* set MUX for Timer1 to 1/2 */
37    cr=rTCFG1 & 0xFFFFFF0F;
38    rTCFG1=(cr | (0<<4));
39
40    /* input freq=PLCK/2 Mhz*/
41    g_freq = get_PCLK() / 2000;
42    rTCNTB1 = 0xFFFF;
43
44    /* start TIMER1 with manual reload */
45    cr=rTCON & 0xFFFFF0FF;
46    rTCON=(cr | (0x1 << 9));
47    rTCON=(cr | (0x1 << 8));
48
49    g_start =  rTCNTO1;
50}
51
52/*
53 *  The following controls the behavior of benchmark_timer_read().
54 *
55 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
56 *  is usually deducted from the number returned.
57 *
58 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
59 *  below this are "noise" and zero is returned.
60 */
61
62#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
63                             /* (Y countdowns) to start/stop the timer. */
64                             /* This value is in microseconds. */
65#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
66
67benchmark_timer_t benchmark_timer_read( void )
68{
69    uint32_t t;
70    unsigned long long total;
71
72    t =  rTCNTO1;
73    /*
74     *  Total is calculated by taking into account the number of timer overflow
75     *  interrupts since the timer was initialized and clicks since the last
76     *  interrupts.
77     */
78
79    total = (g_start - t);
80
81    /* convert to microseconds */
82    total = (total*1000) / g_freq;
83
84    if ( benchmark_timer_find_average_overhead == 1 ) {
85        return (int) total;
86    } else if ( total < LEAST_VALID ) {
87        return 0;
88    }
89
90    /*
91     *  Somehow convert total into microseconds
92     */
93    return (total - AVG_OVERHEAD);
94}
95
96void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
97{
98    benchmark_timer_find_average_overhead = find_flag;
99}
100
Note: See TracBrowser for help on using the repository browser.