1 | /** |
---|
2 | * @file clock.c |
---|
3 | * |
---|
4 | * @ingroup tms570 |
---|
5 | * |
---|
6 | * @brief clock functions definitions. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> |
---|
11 | * |
---|
12 | * Google Summer of Code 2014 at |
---|
13 | * Czech Technical University in Prague |
---|
14 | * Zikova 1903/4 |
---|
15 | * 166 36 Praha 6 |
---|
16 | * Czech Republic |
---|
17 | * |
---|
18 | * Based on LPC24xx and LPC1768 BSP |
---|
19 | * by embedded brains GmbH and others |
---|
20 | * |
---|
21 | * The license and distribution terms for this file may be |
---|
22 | * found in the file LICENSE in this distribution or at |
---|
23 | * http://www.rtems.org/license/LICENSE. |
---|
24 | */ |
---|
25 | |
---|
26 | #include <stdlib.h> |
---|
27 | |
---|
28 | #include <rtems.h> |
---|
29 | #include <bsp.h> |
---|
30 | #include <bsp/irq.h> |
---|
31 | #include <bsp/tms570-rti.h> |
---|
32 | #include <rtems/counter.h> |
---|
33 | #include <rtems/timecounter.h> |
---|
34 | |
---|
35 | static struct timecounter tms570_rti_tc; |
---|
36 | |
---|
37 | static uint32_t tms570_rti_get_timecount(struct timecounter *tc) |
---|
38 | { |
---|
39 | return TMS570_RTI.RTIFRC0; |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * @brief Initialize the HW peripheral for clock driver |
---|
44 | * |
---|
45 | * Clock driver is implemented by RTI module |
---|
46 | * |
---|
47 | * @retval Void |
---|
48 | */ |
---|
49 | static void tms570_clock_driver_support_initialize_hardware( void ) |
---|
50 | { |
---|
51 | |
---|
52 | uint32_t microsec_per_tick = rtems_configuration_get_microseconds_per_tick(); |
---|
53 | |
---|
54 | rtems_counter_initialize_converter(BSP_PLL_OUT_CLOCK); |
---|
55 | |
---|
56 | /* Hardware specific initialize */ |
---|
57 | TMS570_RTI.RTIGCTRL = 0; |
---|
58 | TMS570_RTI.RTICPUC0 = BSP_PLL_OUT_CLOCK /1000000 / 2; /* prescaler */ |
---|
59 | TMS570_RTI.RTITBCTRL = 2; |
---|
60 | TMS570_RTI.RTICAPCTRL = 0; |
---|
61 | TMS570_RTI.RTICOMPCTRL = 0; |
---|
62 | /* set counter to zero */ |
---|
63 | TMS570_RTI.RTIUC0 = 0; |
---|
64 | TMS570_RTI.RTIFRC0 = 0; |
---|
65 | /* clear interrupts*/ |
---|
66 | TMS570_RTI.RTICLEARINTENA = 0x00070f0f; |
---|
67 | TMS570_RTI.RTIINTFLAG = 0x0007000f; |
---|
68 | /* set timer */ |
---|
69 | TMS570_RTI.RTICOMP0 = TMS570_RTI.RTIFRC0 + microsec_per_tick; |
---|
70 | TMS570_RTI.RTICOMP0CLR = TMS570_RTI.RTICOMP0 + microsec_per_tick / 2; |
---|
71 | TMS570_RTI.RTIUDCP0 = microsec_per_tick; |
---|
72 | /* enable interupt */ |
---|
73 | TMS570_RTI.RTISETINTENA = 0x1; |
---|
74 | /* enable timer */ |
---|
75 | TMS570_RTI.RTIGCTRL = 1; |
---|
76 | /* set timecounter */ |
---|
77 | tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount; |
---|
78 | tms570_rti_tc.tc_counter_mask = 0xffffffff; |
---|
79 | tms570_rti_tc.tc_frequency = BSP_PLL_OUT_CLOCK; |
---|
80 | tms570_rti_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; |
---|
81 | rtems_timecounter_install(&tms570_rti_tc); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * @brief Clears interrupt source |
---|
86 | * |
---|
87 | * @retval Void |
---|
88 | */ |
---|
89 | static void tms570_clock_driver_support_at_tick( void ) |
---|
90 | { |
---|
91 | TMS570_RTI.RTIINTFLAG = 0x00000001; |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * @brief registers RTI interrupt handler |
---|
96 | * |
---|
97 | * @param[in] Clock_isr new ISR handler |
---|
98 | * @param[in] Old_ticker old ISR handler (unused and type broken) |
---|
99 | * |
---|
100 | * @retval Void |
---|
101 | */ |
---|
102 | static void tms570_clock_driver_support_install_isr( |
---|
103 | rtems_isr_entry Clock_isr |
---|
104 | ) |
---|
105 | { |
---|
106 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
107 | |
---|
108 | sc = rtems_interrupt_handler_install( |
---|
109 | TMS570_IRQ_TIMER_0, |
---|
110 | "Clock", |
---|
111 | RTEMS_INTERRUPT_UNIQUE, |
---|
112 | (rtems_interrupt_handler) Clock_isr, |
---|
113 | NULL |
---|
114 | ); |
---|
115 | if ( sc != RTEMS_SUCCESSFUL ) { |
---|
116 | rtems_fatal_error_occurred(0xdeadbeef); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * @brief disables RTI interrupt |
---|
122 | * |
---|
123 | * Called when closing clock driver |
---|
124 | * |
---|
125 | * @retval Void |
---|
126 | */ |
---|
127 | static void tms570_clock_driver_support_shutdown_hardware( void ) |
---|
128 | { |
---|
129 | /* turn off the timer interrupts */ |
---|
130 | TMS570_RTI.RTICLEARINTENA = 0x20000; |
---|
131 | } |
---|
132 | |
---|
133 | #define Clock_driver_support_initialize_hardware \ |
---|
134 | tms570_clock_driver_support_initialize_hardware |
---|
135 | #define Clock_driver_support_at_tick \ |
---|
136 | tms570_clock_driver_support_at_tick |
---|
137 | #define Clock_driver_support_initialize_hardware \ |
---|
138 | tms570_clock_driver_support_initialize_hardware |
---|
139 | #define Clock_driver_support_shutdown_hardware \ |
---|
140 | tms570_clock_driver_support_shutdown_hardware |
---|
141 | |
---|
142 | #define Clock_driver_support_install_isr(Clock_isr, Old_ticker ) \ |
---|
143 | tms570_clock_driver_support_install_isr( Clock_isr ) |
---|
144 | |
---|
145 | void Clock_isr(void *arg); /* to supress warning */ |
---|
146 | |
---|
147 | #include "../../../shared/clockdrv_shell.h" |
---|