1 | /* |
---|
2 | * PXA255 clock specific using the System Timer |
---|
3 | * |
---|
4 | * RTEMS uses IRQ 26 as Clock Source |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * By Yang Xi <hiyangxi@gmail.com> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems.h> |
---|
16 | #include <rtems/clockdrv.h> |
---|
17 | #include <rtems/libio.h> |
---|
18 | |
---|
19 | #include <stdlib.h> |
---|
20 | #include <bsp.h> |
---|
21 | #include <bspopts.h> |
---|
22 | #include <bsp/irq.h> |
---|
23 | #include <pxa255.h> |
---|
24 | |
---|
25 | #if ON_SKYEYE==1 |
---|
26 | #define CLOCK_DRIVER_USE_FAST_IDLE 1 |
---|
27 | #endif |
---|
28 | |
---|
29 | static unsigned long period_num; |
---|
30 | |
---|
31 | /** |
---|
32 | * Enables clock interrupt. |
---|
33 | * |
---|
34 | * If the interrupt is always on, this can be a NOP. |
---|
35 | */ |
---|
36 | static void clock_isr_on(const rtems_irq_connect_data *unused) |
---|
37 | { |
---|
38 | /*Clear the interrupt bit */ |
---|
39 | XSCALE_OS_TIMER_TSR = 0x1; |
---|
40 | |
---|
41 | /* enable timer interrupt */ |
---|
42 | XSCALE_OS_TIMER_IER |= 0x1; |
---|
43 | |
---|
44 | #if ON_SKYEYE==1 |
---|
45 | period_num = (TIMER_RATE* rtems_configuration_get_microseconds_per_tick())/100000; |
---|
46 | #else |
---|
47 | period_num = (TIMER_RATE* rtems_configuration_get_microseconds_per_tick())/10000; |
---|
48 | #endif |
---|
49 | |
---|
50 | XSCALE_OS_TIMER_MR0 = XSCALE_OS_TIMER_TCR + period_num; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Disables clock interrupts |
---|
55 | * |
---|
56 | * If the interrupt is always on, this can be a NOP. |
---|
57 | */ |
---|
58 | static void clock_isr_off(const rtems_irq_connect_data *unused) |
---|
59 | { |
---|
60 | /*Clear the interrupt bit */ |
---|
61 | XSCALE_OS_TIMER_TSR = 0x1; |
---|
62 | /* disable timer interrupt*/ |
---|
63 | XSCALE_OS_TIMER_IER &= ~0x1; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Tests to see if clock interrupt is enabled, and returns 1 if so. |
---|
68 | * If interrupt is not enabled, returns 0. |
---|
69 | * |
---|
70 | * If the interrupt is always on, this always returns 1. |
---|
71 | */ |
---|
72 | static int clock_isr_is_on(const rtems_irq_connect_data *irq) |
---|
73 | { |
---|
74 | /* check timer interrupt */ |
---|
75 | return XSCALE_OS_TIMER_IER & 0x1; |
---|
76 | } |
---|
77 | |
---|
78 | void Clock_isr(rtems_irq_hdl_param arg); |
---|
79 | |
---|
80 | rtems_irq_connect_data clock_isr_data = { |
---|
81 | .name = XSCALE_IRQ_OS_TIMER, |
---|
82 | .hdl = Clock_isr, |
---|
83 | .handle = NULL, |
---|
84 | .on = clock_isr_on, |
---|
85 | .off = clock_isr_off, |
---|
86 | .isOn = clock_isr_is_on, |
---|
87 | }; |
---|
88 | |
---|
89 | #define Clock_driver_support_install_isr( _new, _old ) \ |
---|
90 | do { \ |
---|
91 | _old = NULL; \ |
---|
92 | BSP_install_rtems_irq_handler(&clock_isr_data); \ |
---|
93 | } while (0) |
---|
94 | |
---|
95 | static void Clock_driver_support_initialize_hardware(void) |
---|
96 | { |
---|
97 | period_num = TIMER_RATE* rtems_configuration_get_microseconds_per_tick(); |
---|
98 | #if ON_SKYEYE==1 |
---|
99 | period_num /= 100000; |
---|
100 | #else |
---|
101 | period_num /= 10000; |
---|
102 | #endif |
---|
103 | } |
---|
104 | |
---|
105 | #define Clock_driver_support_at_tick() \ |
---|
106 | do { \ |
---|
107 | /* read the status to clear the int */ \ |
---|
108 | XSCALE_OS_TIMER_TSR = 0x1; \ |
---|
109 | \ |
---|
110 | /*Add the match register*/ \ |
---|
111 | XSCALE_OS_TIMER_MR0 = XSCALE_OS_TIMER_TCR + period_num; \ |
---|
112 | } while (0) |
---|
113 | |
---|
114 | static void Clock_driver_support_shutdown_hardware( void ) |
---|
115 | { |
---|
116 | BSP_remove_rtems_irq_handler(&clock_isr_data); |
---|
117 | } |
---|
118 | |
---|
119 | #include "../../../../libbsp/shared/clockdrv_shell.h" |
---|