1 | /* RTEMS Clock Tick Driver for Blackfin. Uses Blackfin Core Timer. |
---|
2 | * |
---|
3 | * Copyright (c) 2008 Kallisti Labs, Los Gatos, CA, USA |
---|
4 | * written by Allan Hessenflow <allanh@kallisti.com> |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.com/license/LICENSE. |
---|
9 | * |
---|
10 | * $Id$ |
---|
11 | */ |
---|
12 | |
---|
13 | |
---|
14 | #include <rtems.h> |
---|
15 | #include <stdlib.h> |
---|
16 | #include <rtems/libio.h> |
---|
17 | #include <bsp.h> |
---|
18 | |
---|
19 | #include <libcpu/cecRegs.h> |
---|
20 | #include <libcpu/coreTimerRegs.h> |
---|
21 | |
---|
22 | |
---|
23 | volatile uint32_t Clock_driver_ticks; |
---|
24 | |
---|
25 | void Clock_exit(void); |
---|
26 | |
---|
27 | /* |
---|
28 | * Major and minor number. |
---|
29 | */ |
---|
30 | |
---|
31 | rtems_device_major_number rtems_clock_major = ~0; |
---|
32 | rtems_device_minor_number rtems_clock_minor; |
---|
33 | |
---|
34 | static rtems_isr clockISR(rtems_vector_number vector) { |
---|
35 | |
---|
36 | Clock_driver_ticks += 1; |
---|
37 | |
---|
38 | #ifdef CLOCK_DRIVER_USE_FAST_IDLE |
---|
39 | do { |
---|
40 | rtems_clock_tick(); |
---|
41 | } while (_Thread_Executing == _Thread_Idle && |
---|
42 | _Thread_Heir == _Thread_Executing); |
---|
43 | #else |
---|
44 | rtems_clock_tick(); |
---|
45 | #endif |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | /* |
---|
50 | * Clock_exit |
---|
51 | * |
---|
52 | * This routine allows the clock driver to exit by masking the interrupt and |
---|
53 | * disabling the clock's counter. |
---|
54 | * |
---|
55 | * Input parameters: NONE |
---|
56 | * |
---|
57 | * Output parameters: NONE |
---|
58 | * |
---|
59 | * Return values: NONE |
---|
60 | * |
---|
61 | */ |
---|
62 | |
---|
63 | void Clock_exit(void) { |
---|
64 | |
---|
65 | *(uint32_t volatile *) TCNTL = 0; |
---|
66 | } |
---|
67 | |
---|
68 | /* |
---|
69 | * Clock_initialize |
---|
70 | * |
---|
71 | * This routine initializes the clock driver. |
---|
72 | * |
---|
73 | * Input parameters: |
---|
74 | * major - clock device major number |
---|
75 | * minor - clock device minor number |
---|
76 | * parg - pointer to optional device driver arguments |
---|
77 | * |
---|
78 | * Output parameters: NONE |
---|
79 | * |
---|
80 | * Return values: |
---|
81 | * rtems_device_driver status code |
---|
82 | */ |
---|
83 | |
---|
84 | rtems_device_driver Clock_initialize(rtems_device_major_number major, |
---|
85 | rtems_device_minor_number minor, |
---|
86 | void *pargp) { |
---|
87 | |
---|
88 | Clock_driver_ticks = 0; |
---|
89 | |
---|
90 | set_vector(clockISR, CEC_CORE_TIMER_VECTOR, 1); |
---|
91 | |
---|
92 | *(uint32_t volatile *) TCNTL = TCNTL_TMPWR | TCNTL_TAUTORLD; |
---|
93 | *(uint32_t volatile *) TSCALE = 0; |
---|
94 | *(uint32_t volatile *) TPERIOD = CCLK / 1000000 * |
---|
95 | rtems_configuration_get_microseconds_per_tick(); |
---|
96 | *(uint32_t volatile *) TCNTL = TCNTL_TMPWR | TCNTL_TAUTORLD | TCNTL_TMREN; |
---|
97 | |
---|
98 | atexit(Clock_exit); |
---|
99 | /* |
---|
100 | * make major/minor avail to others such as shared memory driver |
---|
101 | */ |
---|
102 | |
---|
103 | rtems_clock_major = major; |
---|
104 | rtems_clock_minor = minor; |
---|
105 | |
---|
106 | return RTEMS_SUCCESSFUL; |
---|
107 | } |
---|
108 | |
---|
109 | /* |
---|
110 | * Clock_control |
---|
111 | * |
---|
112 | * This routine is the clock device driver control entry point. |
---|
113 | * |
---|
114 | * Input parameters: |
---|
115 | * major - clock device major number |
---|
116 | * minor - clock device minor number |
---|
117 | * parg - pointer to optional device driver arguments |
---|
118 | * |
---|
119 | * Output parameters: NONE |
---|
120 | * |
---|
121 | * Return values: |
---|
122 | * rtems_device_driver status code |
---|
123 | */ |
---|
124 | |
---|
125 | rtems_device_driver Clock_control(rtems_device_major_number major, |
---|
126 | rtems_device_minor_number minor, |
---|
127 | void *pargp) { |
---|
128 | rtems_interrupt_level isrLevel; |
---|
129 | rtems_libio_ioctl_args_t *args = pargp; |
---|
130 | |
---|
131 | if (args == 0) |
---|
132 | goto done; |
---|
133 | |
---|
134 | /* |
---|
135 | * This is hokey, but until we get a defined interface |
---|
136 | * to do this, it will just be this simple... |
---|
137 | */ |
---|
138 | |
---|
139 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) { |
---|
140 | clockISR(CEC_CORE_TIMER_VECTOR); |
---|
141 | } else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) { |
---|
142 | rtems_interrupt_disable(isrLevel); |
---|
143 | set_vector(args->buffer, CEC_CORE_TIMER_VECTOR, 1); |
---|
144 | rtems_interrupt_enable(isrLevel); |
---|
145 | } |
---|
146 | |
---|
147 | done: |
---|
148 | return RTEMS_SUCCESSFUL; |
---|
149 | } |
---|
150 | |
---|