1 | /* RTEMS Clock Tick Driver for Blackfin. Uses Blackfin Core Timer. |
---|
2 | */ |
---|
3 | |
---|
4 | /* |
---|
5 | * Copyright (c) 2008 Kallisti Labs, Los Gatos, CA, USA |
---|
6 | * written by Allan Hessenflow <allanh@kallisti.com> |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.org/license/LICENSE. |
---|
11 | */ |
---|
12 | |
---|
13 | |
---|
14 | #include <rtems.h> |
---|
15 | #include <stdlib.h> |
---|
16 | #include <rtems/libio.h> |
---|
17 | #include <rtems/score/percpu.h> |
---|
18 | #include <bsp.h> |
---|
19 | #include <rtems/clockdrv.h> |
---|
20 | |
---|
21 | |
---|
22 | #include <libcpu/cecRegs.h> |
---|
23 | #include <libcpu/coreTimerRegs.h> |
---|
24 | |
---|
25 | #if (BFIN_ON_SKYEYE) |
---|
26 | #define CLOCK_DRIVER_USE_FAST_IDLE 1 |
---|
27 | #endif |
---|
28 | |
---|
29 | volatile uint32_t Clock_driver_ticks; |
---|
30 | |
---|
31 | void Clock_exit(void); |
---|
32 | |
---|
33 | static rtems_isr clockISR(rtems_vector_number vector) { |
---|
34 | |
---|
35 | Clock_driver_ticks += 1; |
---|
36 | |
---|
37 | #if CLOCK_DRIVER_USE_FAST_IDLE |
---|
38 | do { |
---|
39 | rtems_clock_tick(); |
---|
40 | } while ( |
---|
41 | _Thread_Heir == _Thread_Executing |
---|
42 | && _Thread_Executing->Start.Entry.Kinds.Idle.entry |
---|
43 | == rtems_configuration_get_idle_task() |
---|
44 | ); |
---|
45 | #else |
---|
46 | rtems_clock_tick(); |
---|
47 | #endif |
---|
48 | } |
---|
49 | |
---|
50 | /* |
---|
51 | * Clock_exit |
---|
52 | * |
---|
53 | * This routine allows the clock driver to exit by masking the interrupt and |
---|
54 | * disabling the clock's counter. |
---|
55 | */ |
---|
56 | void Clock_exit(void) |
---|
57 | { |
---|
58 | *(uint32_t volatile *) TCNTL = 0; |
---|
59 | } |
---|
60 | |
---|
61 | /* |
---|
62 | * Clock_initialize |
---|
63 | * |
---|
64 | * This routine initializes the clock driver. |
---|
65 | */ |
---|
66 | rtems_device_driver Clock_initialize( |
---|
67 | rtems_device_major_number major, |
---|
68 | rtems_device_minor_number minor, |
---|
69 | void *pargp |
---|
70 | ) |
---|
71 | { |
---|
72 | Clock_driver_ticks = 0; |
---|
73 | |
---|
74 | set_vector(clockISR, CEC_CORE_TIMER_VECTOR, 1); |
---|
75 | |
---|
76 | *(uint32_t volatile *) TCNTL = TCNTL_TMPWR | TCNTL_TAUTORLD; |
---|
77 | *(uint32_t volatile *) TSCALE = 0; |
---|
78 | *(uint32_t volatile *) TPERIOD = CCLK / 1000000 * |
---|
79 | rtems_configuration_get_microseconds_per_tick(); |
---|
80 | *(uint32_t volatile *) TCNTL = TCNTL_TMPWR | TCNTL_TAUTORLD | TCNTL_TMREN; |
---|
81 | |
---|
82 | atexit(Clock_exit); |
---|
83 | |
---|
84 | return RTEMS_SUCCESSFUL; |
---|
85 | } |
---|