1 | /* |
---|
2 | * Use the last periodic interval timer (PIT2) as the system clock. |
---|
3 | */ |
---|
4 | |
---|
5 | #include <rtems.h> |
---|
6 | #include <bsp.h> |
---|
7 | |
---|
8 | /* |
---|
9 | * Use INTC1 base |
---|
10 | */ |
---|
11 | #define CLOCK_VECTOR (128+46) |
---|
12 | |
---|
13 | static uint32_t s_pcntrAtTick = 0; |
---|
14 | static uint32_t s_nanoScale = 0; |
---|
15 | |
---|
16 | /* |
---|
17 | * Provide nanosecond extension |
---|
18 | */ |
---|
19 | static uint32_t bsp_clock_nanoseconds_since_last_tick(void) |
---|
20 | { |
---|
21 | uint32_t i; |
---|
22 | |
---|
23 | if (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) { |
---|
24 | i = s_pcntrAtTick + (MCF_PIT3_PMR - MCF_PIT3_PCNTR); |
---|
25 | } else { |
---|
26 | i = s_pcntrAtTick - MCF_PIT3_PCNTR; |
---|
27 | } |
---|
28 | return i * s_nanoScale; |
---|
29 | } |
---|
30 | |
---|
31 | #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick |
---|
32 | |
---|
33 | /* |
---|
34 | * Periodic interval timer interrupt handler |
---|
35 | */ |
---|
36 | #define Clock_driver_support_at_tick() \ |
---|
37 | do { \ |
---|
38 | s_pcntrAtTick = MCF_PIT3_PCNTR; \ |
---|
39 | MCF_PIT3_PCSR |= MCF_PIT_PCSR_PIF; \ |
---|
40 | } while (0) \ |
---|
41 | |
---|
42 | |
---|
43 | /* |
---|
44 | * Attach clock interrupt handler |
---|
45 | */ |
---|
46 | #define Clock_driver_support_install_isr( _new, _old ) \ |
---|
47 | do { \ |
---|
48 | _old = (rtems_isr_entry)set_vector(_new, CLOCK_VECTOR, 1); \ |
---|
49 | } while(0) |
---|
50 | |
---|
51 | /* |
---|
52 | * Turn off the clock |
---|
53 | */ |
---|
54 | static void Clock_driver_support_shutdown_hardware(void) |
---|
55 | { |
---|
56 | MCF_PIT3_PCSR &= ~MCF_PIT_PCSR_EN; |
---|
57 | } |
---|
58 | |
---|
59 | /* |
---|
60 | * Set up the clock hardware |
---|
61 | * |
---|
62 | * We need to have 1 interrupt every rtems_configuration_get_microseconds_per_tick() |
---|
63 | */ |
---|
64 | static void Clock_driver_support_initialize_hardware(void) |
---|
65 | { |
---|
66 | int level; |
---|
67 | uint32_t pmr; |
---|
68 | uint32_t preScaleCode = 0; |
---|
69 | uint32_t clk = bsp_get_BUS_clock_speed(); |
---|
70 | uint32_t tps = 1000000 / rtems_configuration_get_microseconds_per_tick(); |
---|
71 | |
---|
72 | while (preScaleCode < 15) { |
---|
73 | pmr = (clk >> preScaleCode) / tps; |
---|
74 | if (pmr < (1 << 15)) |
---|
75 | break; |
---|
76 | preScaleCode++; |
---|
77 | } |
---|
78 | s_nanoScale = 1000000000 / (clk >> preScaleCode); |
---|
79 | |
---|
80 | MCF_INTC1_ICR46 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL); |
---|
81 | |
---|
82 | rtems_interrupt_disable(level); |
---|
83 | MCF_INTC1_IMRH &= ~MCF_INTC_IMRH_INT_MASK46; |
---|
84 | MCF_PIT3_PCSR &= ~MCF_PIT_PCSR_EN; |
---|
85 | rtems_interrupt_enable(level); |
---|
86 | |
---|
87 | MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) | |
---|
88 | MCF_PIT_PCSR_OVW | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD; |
---|
89 | MCF_PIT3_PMR = pmr; |
---|
90 | MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) | |
---|
91 | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN; |
---|
92 | s_pcntrAtTick = MCF_PIT3_PCNTR; |
---|
93 | } |
---|
94 | |
---|
95 | #include "../../../shared/clockdrv_shell.h" |
---|