source: rtems/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  MC9328MXL clock specific using the System Timer
3 *
4 *  This is hardware specific part of the clock driver. At the end of this
5 *  file, the generic part of the driver is #included.
6 *
7 *  Copyright (c) 2004 by Cogent Computer Systems
8 *  Written by Jay Monkman <jtm@lopingdog.com>
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.org/license/LICENSE.
13 */
14
15#include <rtems.h>
16#include <bsp.h>
17#include <bsp/irq.h>
18#include <mc9328mxl.h>
19#include <rtems/bspIo.h>  /* for printk */
20
21/* this is defined in ../../../shared/clockdrv_shell.h */
22void Clock_isr(rtems_irq_hdl_param arg);
23static void clock_isr_on(const rtems_irq_connect_data *unused);
24static void clock_isr_off(const rtems_irq_connect_data *unused);
25static int clock_isr_is_on(const rtems_irq_connect_data *irq);
26
27/* Replace the first value with the clock's interrupt name. */
28rtems_irq_connect_data clock_isr_data = {
29  .name   = BSP_INT_TIMER1,
30  .hdl    = Clock_isr,
31  .handle = (void *)BSP_INT_TIMER1,
32  .on     = clock_isr_on,
33  .off    = clock_isr_off,
34  .isOn   = clock_isr_is_on,
35};
36
37/**
38 * When we get the clock interrupt
39 *    - clear the interrupt bit?
40 *    - restart the timer?
41 */
42#define Clock_driver_support_at_tick()                \
43  do {                                                \
44        uint32_t reg;                                 \
45        reg = MC9328MXL_TMR1_TSTAT;                   \
46        MC9328MXL_TMR1_TSTAT = 0;                     \
47  } while(0)
48
49/**
50 * Installs the clock ISR. You shouldn't need to change this.
51 */
52#define Clock_driver_support_install_isr( _new, _old ) \
53  do {                                                 \
54      (_old) = NULL;                                   \
55      BSP_install_rtems_irq_handler(&clock_isr_data);  \
56  } while(0)
57
58
59/**
60 * Initialize the hardware for the clock
61 *   - Set the frequency
62 *   - enable it
63 *   - clear any pending interrupts
64 *
65 * Since you may want the clock always running, you can
66 * enable interrupts here. If you do so, the clock_isr_on(),
67 * clock_isr_off(), and clock_isr_is_on() functions can be
68 * NOPs.
69 */
70#define Clock_driver_support_initialize_hardware() \
71  do { \
72        int freq; \
73        int cnt; \
74        freq = get_perclk1_freq(); \
75        printk("perclk1 freq is %d\n", freq); \
76        cnt = ((long long)freq * rtems_configuration_get_microseconds_per_tick() + 500000) / 1000000;\
77        printk("cnt freq is %d\n", cnt); \
78        MC9328MXL_TMR1_TCMP = cnt; \
79        /* use PERCLK1 as input, enable timer */ \
80        MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \
81                               MC9328MXL_TMR_TCTL_TEN | \
82                               MC9328MXL_TMR_TCTL_IRQEN); \
83        /* set prescaler to 1 (register value + 1) */ \
84        MC9328MXL_TMR1_TPRER = 0; \
85     } while (0)
86
87/**
88 * Do whatever you need to shut the clock down and remove the
89 * interrupt handler. Since this normally only gets called on
90 * RTEMS shutdown, you may not need to do anything other than
91 * remove the ISR.
92 */
93#define Clock_driver_support_shutdown_hardware()                        \
94  do {                                                                  \
95    /* Disable timer */ \
96    MC9328MXL_TMR1_TCTL = 0; \
97    BSP_remove_rtems_irq_handler(&clock_isr_data);                  \
98  } while (0)
99
100/**
101 * Enables clock interrupt.
102 *
103 * If the interrupt is always on, this can be a NOP.
104 */
105static void clock_isr_on(const rtems_irq_connect_data *unused)
106{
107  MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN;
108  MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1;
109}
110
111/**
112 * Disables clock interrupts
113 *
114 * If the interrupt is always on, this can be a NOP.
115 */
116static void clock_isr_off(const rtems_irq_connect_data *unused)
117{
118  MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN;
119  MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1;
120}
121
122/**
123 * Tests to see if clock interrupt is enabled, and returns 1 if so.
124 * If interrupt is not enabled, returns 0.
125 *
126 * If the interrupt is always on, this always returns 1.
127 */
128static int clock_isr_is_on(const rtems_irq_connect_data *irq)
129{
130  return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN;
131}
132
133/* Make sure to include this, and only at the end of the file */
134#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.