source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/clock/clock-config.c @ 6b150cc

4.104.11
Last change on this file since 6b150cc was 6b150cc, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Mar 27, 2010 at 8:41:45 PM

fixed some warnings

  • Property mode set to 100644
File size: 3.9 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( rtems_isr_entry isr, 
47                                           rtems_isr_entry *old_isr)
48{
49  rtems_status_code sc = RTEMS_SUCCESSFUL;
50
51  sc = mpc55xx_interrupt_handler_install(
52    MPC55XX_IRQ_EMIOS_GET_REQUEST( MPC55XX_CLOCK_EMIOS_CHANNEL),
53    "clock",
54    RTEMS_INTERRUPT_UNIQUE,
55    MPC55XX_INTC_MIN_PRIORITY,
56    (rtems_interrupt_handler) isr,
57    NULL
58  );
59 *old_isr = NULL;
60  RTEMS_CHECK_SC_VOID( sc, "install clock interrupt handler");
61}
62
63static void mpc55xx_clock_initialize( void)
64{
65  volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
66  union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS;
67  union EMIOS_CSR_tag csr = MPC55XX_ZERO_FLAGS;
68  unsigned prescaler = mpc55xx_emios_global_prescaler();
69  uint64_t interval = ((uint64_t) bsp_clock_speed
70    * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000;
71
72  /* Apply prescaler */
73  if (prescaler > 0) {
74    interval /= (uint64_t) prescaler;
75  } else {
76    RTEMS_SYSLOG_ERROR( "unexpected global eMIOS prescaler\n");
77  }
78
79  /* Check interval */
80  if (interval == 0 || interval > MPC55XX_EMIOS_VALUE_MAX) {
81    interval = MPC55XX_EMIOS_VALUE_MAX;
82    RTEMS_SYSLOG_ERROR( "clock timer interval out of range\n");
83  }
84
85  /* Configure eMIOS channel */
86
87  /* Set channel in GPIO mode */
88  ccr.B.MODE = MPC55XX_EMIOS_MODE_GPIO_INPUT;
89  regs->CCR.R = ccr.R;
90
91  /* Clear status flags */
92  csr.B.OVR = 1;
93  csr.B.OVFL = 1;
94  csr.B.FLAG = 1;
95  regs->CSR.R = csr.R;
96
97  /* Set timer period */
98  regs->CADR.R = (uint32_t) interval - 1;
99
100  /* Set unused registers */
101  regs->CBDR.R = 0;
102  regs->CCNTR.R = 0;
103  regs->ALTCADR.R = 0;
104
105  /* Set control register */
106  ccr.B.MODE = MPC55XX_EMIOS_MODE_MC_UP_INT_CLK;
107  ccr.B.UCPREN = 1;
108  ccr.B.FEN = 1;
109  ccr.B.FREN = 1;
110  regs->CCR.R = ccr.R;
111}
112
113static void mpc55xx_clock_cleanup( void)
114{
115  rtems_status_code sc = RTEMS_SUCCESSFUL;
116  volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];
117  union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS;
118
119  /* Set channel in GPIO mode */
120  ccr.B.MODE = MPC55XX_EMIOS_MODE_GPIO_INPUT;
121  regs->CCR.R = ccr.R;
122
123  /* Remove interrupt handler */
124  sc = rtems_interrupt_handler_remove(
125    MPC55XX_IRQ_EMIOS_GET_REQUEST( MPC55XX_CLOCK_EMIOS_CHANNEL),
126    (rtems_interrupt_handler) Clock_isr,
127    NULL
128  );
129  RTEMS_CHECK_SC_VOID( sc, "remove clock interrupt handler");
130}
131
132static uint32_t mpc55xx_clock_nanoseconds_since_last_tick( void)
133{
134  uint64_t clicks = EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CCNTR.R;
135  uint64_t clock = bsp_clock_speed;
136  uint64_t ns = (clicks * 1000000000) / clock;
137
138  return (uint32_t) ns;
139}
140
141#define Clock_driver_support_initialize_hardware() mpc55xx_clock_initialize()
142
143#define Clock_driver_support_install_isr( isr, old_isr) \
144  mpc55xx_clock_handler_install(isr,&old_isr)
145
146#define Clock_driver_support_shutdown_hardware() mpc55xx_clock_cleanup()
147
148#define Clock_driver_nanoseconds_since_last_tick \
149  mpc55xx_clock_nanoseconds_since_last_tick
150
151/* Include shared source clock driver code */
152#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.