source: rtems/c/src/lib/libcpu/powerpc/mpc83xx/gtm/gtm.c @ 602aee20

4.104.115
Last change on this file since 602aee20 was 602aee20, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 10/10/08 at 15:50:15

shared/include/utility.h: Removed file.

shared/include/powerpc-utility.h: Use constraint "b" for address
base registers in inline assembler statements.
Update for status-checks.h changes.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Source file for timer functions.
5 */
6
7/*
8 * Copyright (c) 2008
9 * Embedded Brains GmbH
10 * Obere Lagerstr. 30
11 * D-82178 Puchheim
12 * Germany
13 * rtems@embedded-brains.de
14 *
15 * The license and distribution terms for this file may be found in the file
16 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
17 */
18
19#include <rtems/bspIo.h>
20
21#include <mpc83xx/mpc83xx.h>
22#include <mpc83xx/gtm.h>
23
24#define RTEMS_STATUS_CHECKS_USE_PRINTK
25
26#include <rtems/status-checks.h>
27
28#define MPC83XX_GTM_CHECK_INDEX( timer) \
29        if (( timer) < 0 || ( timer) >= MPC83XX_GTM_NUMBER) { \
30                return RTEMS_INVALID_NUMBER; \
31        }
32
33#define MPC83XX_GTM_VARIABLES( timer) \
34        int module = (timer) / 4; \
35        int module_timer = (timer) % 4; \
36        int high = module_timer / 2; \
37        int low = module_timer % 2; \
38        rtems_interrupt_level level;
39
40#define MPC83XX_GTM_CLOCK_MASK MPC83XX_GTM_CLOCK_EXTERN
41
42static const uint8_t mpc83xx_gmt_interrupt_vector_table [MPC83XX_GTM_NUMBER] = { 90, 78, 84, 72, 91, 79, 85, 73 };
43
44static const uint8_t mpc83xx_gmt_interrupt_priority_table [MPC83XX_GTM_NUMBER] = { 113, 77, 95, 59, 116, 80, 98, 62 };
45
46rtems_status_code mpc83xx_gtm_initialize( int timer, int clock)
47{
48        rtems_status_code sc = RTEMS_SUCCESSFUL;
49
50        MPC83XX_GTM_VARIABLES( timer);
51
52        unsigned mask = 0xfU << (low * 4);
53        unsigned flags = 0x3U << (low * 4);
54        uint8_t reg = 0;
55
56        MPC83XX_GTM_CHECK_INDEX( timer);
57
58        rtems_interrupt_disable( level);
59
60        reg = mpc83xx.gtm [module].gtcfr [high].reg;
61        mpc83xx.gtm [module].gtcfr [high].reg = (uint8_t) ((reg & ~mask) | flags);
62
63        mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] = 0;
64
65        rtems_interrupt_enable( level);
66
67        sc = mpc83xx_gtm_set_clock( timer, clock);
68        RTEMS_CHECK_SC( sc, "Set clock");
69
70        sc = mpc83xx_gtm_set_value( timer, 0);
71        RTEMS_CHECK_SC( sc, "Set value");
72
73        sc = mpc83xx_gtm_set_reference( timer, 0);
74        RTEMS_CHECK_SC( sc, "Set reference");
75
76        sc = mpc83xx_gtm_set_prescale( timer, 0);
77        RTEMS_CHECK_SC( sc, "Set prescale");
78
79        return RTEMS_SUCCESSFUL;
80}
81
82rtems_status_code mpc83xx_gtm_enable_restart( int timer, bool enable)
83{
84        MPC83XX_GTM_VARIABLES( timer);
85
86        MPC83XX_GTM_CHECK_INDEX( timer);
87
88        rtems_interrupt_disable( level);
89
90        if (enable) {
91                mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] |= 0x0008;
92        } else {
93                mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] &= ~0x0008;
94        }
95
96        rtems_interrupt_enable( level);
97
98        return RTEMS_SUCCESSFUL;
99}
100
101rtems_status_code mpc83xx_gtm_set_clock( int timer, int clock)
102{
103        MPC83XX_GTM_VARIABLES( timer);
104
105        uint16_t reg = 0;
106
107        MPC83XX_GTM_CHECK_INDEX( timer);
108
109        if (clock & ~MPC83XX_GTM_CLOCK_MASK) {
110                return RTEMS_INVALID_CLOCK;
111        }
112
113        rtems_interrupt_disable( level);
114
115        reg = mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low];
116        mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] = (reg & ~MPC83XX_GTM_CLOCK_MASK) | clock;
117
118        rtems_interrupt_enable( level);
119
120        return RTEMS_SUCCESSFUL;
121}
122
123rtems_status_code mpc83xx_gtm_get_clock( int timer, int *clock)
124{
125        MPC83XX_GTM_VARIABLES( timer);
126
127        MPC83XX_GTM_CHECK_INDEX( timer);
128
129        *clock = mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] & MPC83XX_GTM_CLOCK_MASK;
130
131        return RTEMS_SUCCESSFUL;
132}
133
134rtems_status_code mpc83xx_gtm_start( int timer)
135{
136        MPC83XX_GTM_VARIABLES( timer);
137
138        uint8_t flags = 0x2 << (low * 4);
139
140        MPC83XX_GTM_CHECK_INDEX( timer);
141
142        rtems_interrupt_disable( level);
143        mpc83xx.gtm [module].gtcfr [high].reg &= ~flags;
144        rtems_interrupt_enable( level);
145
146        return RTEMS_SUCCESSFUL;
147}
148
149rtems_status_code mpc83xx_gtm_stop( int timer)
150{
151        MPC83XX_GTM_VARIABLES( timer);
152
153        uint8_t flags = 0x2 << (low * 4);
154
155        MPC83XX_GTM_CHECK_INDEX( timer);
156
157        rtems_interrupt_disable( level);
158        mpc83xx.gtm [module].gtcfr [high].reg |= flags;
159        rtems_interrupt_enable( level);
160
161        return RTEMS_SUCCESSFUL;
162}
163
164rtems_status_code mpc83xx_gtm_set_value( int timer, uint16_t value)
165{
166        MPC83XX_GTM_VARIABLES( timer);
167
168        MPC83XX_GTM_CHECK_INDEX( timer);
169
170        mpc83xx.gtm [module].gt_tim_regs [high].gtcnr [low] = value;
171
172        return RTEMS_SUCCESSFUL;
173}
174
175rtems_status_code mpc83xx_gtm_get_value( int timer, uint16_t *value)
176{
177        MPC83XX_GTM_VARIABLES( timer);
178
179        MPC83XX_GTM_CHECK_INDEX( timer);
180
181        *value = mpc83xx.gtm [module].gt_tim_regs [high].gtcnr [low];
182
183        return RTEMS_SUCCESSFUL;
184}
185
186rtems_status_code mpc83xx_gtm_set_reference( int timer, uint16_t reference)
187{
188        MPC83XX_GTM_VARIABLES( timer);
189
190        MPC83XX_GTM_CHECK_INDEX( timer);
191
192        mpc83xx.gtm [module].gt_tim_regs [high].gtrfr [low] = reference;
193
194        return RTEMS_SUCCESSFUL;
195}
196
197rtems_status_code mpc83xx_gtm_get_reference( int timer, uint16_t *reference)
198{
199        MPC83XX_GTM_VARIABLES( timer);
200
201        MPC83XX_GTM_CHECK_INDEX( timer);
202
203        *reference = mpc83xx.gtm [module].gt_tim_regs [high].gtrfr [low];
204
205        return RTEMS_SUCCESSFUL;
206}
207
208rtems_status_code mpc83xx_gtm_set_prescale( int timer, uint8_t prescale)
209{
210        MPC83XX_GTM_VARIABLES( timer);
211
212        MPC83XX_GTM_CHECK_INDEX( timer);
213
214        mpc83xx.gtm [module].gtpsr [module_timer] = prescale;
215
216        return RTEMS_SUCCESSFUL;
217}
218
219rtems_status_code mpc83xx_gtm_get_prescale( int timer, uint8_t *prescale)
220{
221        MPC83XX_GTM_VARIABLES( timer);
222
223        MPC83XX_GTM_CHECK_INDEX( timer);
224
225        *prescale = mpc83xx.gtm [module].gtpsr [module_timer];
226
227        return RTEMS_SUCCESSFUL;
228}
229
230rtems_status_code mpc83xx_gtm_interrupt_get_vector( int timer, rtems_vector_number *vector)
231{
232        MPC83XX_GTM_CHECK_INDEX( timer);
233
234        *vector = mpc83xx_gmt_interrupt_vector_table [timer];
235
236        return RTEMS_SUCCESSFUL;
237}
238
239rtems_status_code mpc83xx_gtm_interrupt_enable( int timer)
240{
241        MPC83XX_GTM_VARIABLES( timer);
242
243        MPC83XX_GTM_CHECK_INDEX( timer);
244
245        rtems_interrupt_disable( level);
246        mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] |= 0x0010;
247        rtems_interrupt_enable( level);
248
249        return RTEMS_SUCCESSFUL;
250}
251
252rtems_status_code mpc83xx_gtm_interrupt_disable( int timer)
253{
254        MPC83XX_GTM_VARIABLES( timer);
255
256        MPC83XX_GTM_CHECK_INDEX( timer);
257
258        rtems_interrupt_disable( level);
259        mpc83xx.gtm [module].gt_tim_regs [high].gtmdr [low] &= ~0x0010;
260        rtems_interrupt_enable( level);
261
262        return RTEMS_SUCCESSFUL;
263}
264
265rtems_status_code mpc83xx_gtm_interrupt_clear( int timer)
266{
267        MPC83XX_GTM_VARIABLES( timer);
268
269        MPC83XX_GTM_CHECK_INDEX( timer);
270
271        mpc83xx.gtm [module].gtevr [module_timer] = 0x0002;
272
273        return RTEMS_SUCCESSFUL;
274}
Note: See TracBrowser for help on using the repository browser.