source: rtems/bsps/powerpc/gen83xx/dev/gtm.c @ 0cab067

5
Last change on this file since 0cab067 was 0cab067, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 23, 2018 at 2:54:12 PM

bsps/powerpc: Move libcpu content to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

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