source: rtems/c/src/lib/libbsp/arm/csb336/clock/clockdrv.c @ 26ff9fd6

5
Last change on this file since 26ff9fd6 was 26ff9fd6, checked in by Sebastian Huber <sebastian.huber@…>, on 12/08/17 at 06:46:48

bsp/csb336: Move libcpu files to BSP

Update #3254.

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