source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/clock/clock-config.c @ 359e537

4.104.115
Last change on this file since 359e537 was ac7af4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 04:37:44

Whitespace removal.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief Clock driver configuration.
7 */
8
9/*
10 * Copyright (c) 2009
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#include <mpc55xx/regs.h>
23#include <mpc55xx/emios.h>
24
25#include <rtems.h>
26
27#include <bsp.h>
28#include <bsp/irq.h>
29
30#define RTEMS_STATUS_CHECKS_USE_PRINTK
31
32#include <rtems/status-checks.h>
33
34#define MPC55XX_CLOCK_EMIOS_CHANNEL (MPC55XX_EMIOS_CHANNEL_NUMBER - 1)
35
36/* This is defined in clockdrv_shell.h */
37rtems_isr Clock_isr( rtems_vector_number vector);
38
39#define Clock_driver_support_at_tick() \
40 do { \
41    union EMIOS_CSR_tag csr = MPC55XX_ZERO_FLAGS; \
42    csr.B.FLAG = 1; \
43    EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CSR.R = csr.R; \
44 } while (0)
45
46static void mpc55xx_clock_handler_install( void)
47{
48  rtems_status_code sc = RTEMS_SUCCESSFUL;
49
50  sc = mpc55xx_interrupt_handler_install(
51    MPC55XX_IRQ_EMIOS_GET_REQUEST( MPC55XX_CLOCK_EMIOS_CHANNEL),
52    "clock",
53    RTEMS_INTERRUPT_UNIQUE,
54    MPC55XX_INTC_MIN_PRIORITY,
55    (rtems_interrupt_handler) Clock_isr,
56    NULL
57  );
58  RTEMS_CHECK_SC_VOID( sc, "install clock interrupt handler");
59}
60
61static void mpc55xx_clock_initialize( void)
62{
63  volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
64  union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS;
65  union EMIOS_CSR_tag csr = MPC55XX_ZERO_FLAGS;
66  unsigned prescaler = mpc55xx_emios_global_prescaler();
67  uint64_t interval = ((uint64_t) bsp_clock_speed
68    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000;
69
70  /* Apply prescaler */
71  if (prescaler > 0) {
72    interval /= (uint64_t) prescaler;
73  } else {
74    RTEMS_SYSLOG_ERROR( "unexpected global eMIOS prescaler\n");
75  }
76
77  /* Check interval */
78  if (interval == 0 || interval > MPC55XX_EMIOS_VALUE_MAX) {
79    interval = MPC55XX_EMIOS_VALUE_MAX;
80    RTEMS_SYSLOG_ERROR( "clock timer interval out of range\n");
81  }
82
83  /* Configure eMIOS channel */
84
85  /* Set channel in GPIO mode */
86  ccr.B.MODE = MPC55XX_EMIOS_MODE_GPIO_INPUT;
87  regs->CCR.R = ccr.R;
88
89  /* Clear status flags */
90  csr.B.OVR = 1;
91  csr.B.OVFL = 1;
92  csr.B.FLAG = 1;
93  regs->CSR.R = csr.R;
94
95  /* Set timer period */
96  regs->CADR.R = (uint32_t) interval - 1;
97
98  /* Set unused registers */
99  regs->CBDR.R = 0;
100  regs->CCNTR.R = 0;
101  regs->ALTCADR.R = 0;
102
103  /* Set control register */
104  ccr.B.MODE = MPC55XX_EMIOS_MODE_MC_UP_INT_CLK;
105  ccr.B.UCPREN = 1;
106  ccr.B.FEN = 1;
107  ccr.B.FREN = 1;
108  regs->CCR.R = ccr.R;
109}
110
111static void mpc55xx_clock_cleanup( void)
112{
113  rtems_status_code sc = RTEMS_SUCCESSFUL;
114  volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
115  union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS;
116
117  /* Set channel in GPIO mode */
118  ccr.B.MODE = MPC55XX_EMIOS_MODE_GPIO_INPUT;
119  regs->CCR.R = ccr.R;
120
121  /* Remove interrupt handler */
122  sc = rtems_interrupt_handler_remove(
123    MPC55XX_IRQ_EMIOS_GET_REQUEST( MPC55XX_CLOCK_EMIOS_CHANNEL),
124    (rtems_interrupt_handler) Clock_isr,
125    NULL
126  );
127  RTEMS_CHECK_SC_VOID( sc, "remove clock interrupt handler");
128}
129
130static uint32_t mpc55xx_clock_nanoseconds_since_last_tick( void)
131{
132  uint64_t clicks = EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CCNTR.R;
133  uint64_t clock = bsp_clock_speed;
134  uint64_t ns = (clicks * 1000000000) / clock;
135
136  return (uint32_t) ns;
137}
138
139#define Clock_driver_support_initialize_hardware() mpc55xx_clock_initialize()
140
141#define Clock_driver_support_install_isr( isr, old_isr) \
142  mpc55xx_clock_handler_install()
143
144#define Clock_driver_support_shutdown_hardware() mpc55xx_clock_cleanup()
145
146#define Clock_driver_nanoseconds_since_last_tick \
147  mpc55xx_clock_nanoseconds_since_last_tick
148
149/* Include shared source clock driver code */
150#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.