source: rtems/bsps/powerpc/gen83xx/dev/gtm.c

Last change on this file was e560ee85, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:55

bsps/powerpc/: Scripted embedded brains header file clean up

Updates #4625.

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