diff options
author | Jay Monkman <jtm@smoothsmoothie.com> | 2004-07-15 06:25:44 +0000 |
---|---|---|
committer | Jay Monkman <jtm@smoothsmoothie.com> | 2004-07-15 06:25:44 +0000 |
commit | 1cfcfd3cfbf65c0d3171e8939134329db4539f08 (patch) | |
tree | 4fc330538ceb7df944fb7ebaffb42aef6b5649eb /c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c | |
parent | 2004-07-15 Jay Monkman (diff) | |
download | rtems-1cfcfd3cfbf65c0d3171e8939134329db4539f08.tar.bz2 |
2004-07-15 Jay Monkman
* ChangeLog, Makefile.am, clock/.cvsignore, clock/clockdrv.c,
include/mc9328mxl.h, irq/.cvsignore, irq/bsp_irq_asm.S,
irq/bsp_irq_init.c, irq/irq.c, irq/irq.h, timer/.cvsignore,
timer/timer.c: New files.
Diffstat (limited to 'c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c')
-rw-r--r-- | c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c b/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c new file mode 100644 index 0000000000..4d26cb0251 --- /dev/null +++ b/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c @@ -0,0 +1,145 @@ +/* + * MC9328MXL clock specific using the System Timer + * + * This is hardware specific part of the clock driver. At the end of this + * file, the generic part of the driver is #included. + * + * Copyright (c) 2004 by Cogent Computer Systems + * Written by Jay Monkman <jtm@lopingdog.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * + * http://www.OARcorp.com/rtems/license.html. + * + * + * clockdrv.c,v 1.1 2002/11/13 17:55:04 joel Exp +*/ +#include <rtems.h> +#include <bsp.h> +#include <irq.h> +#include <mc9328mxl.h> + +/* this is defined in ../../../shared/clockdrv_shell.c */ +rtems_isr Clock_isr(rtems_vector_number vector); +static void clock_isr_on(const rtems_irq_connect_data *unused); +static void clock_isr_off(const rtems_irq_connect_data *unused); +static int clock_isr_is_on(const rtems_irq_connect_data *irq); + +/* Replace the first value with the clock's interrupt name. */ +rtems_irq_connect_data clock_isr_data = {BSP_INT_TIMER1, + (rtems_irq_hdl)Clock_isr, + clock_isr_on, + clock_isr_off, + clock_isr_is_on, + 3, /* unused for ARM cpus */ + 0 }; /* unused for ARM cpus */ + +/* If you follow the code, this is never used, so any value + * should work + */ +#define CLOCK_VECTOR 0 + + +/** + * When we get the clock interrupt + * - clear the interrupt bit? + * - restart the timer? + */ +#define Clock_driver_support_at_tick() \ + do { \ + uint32_t reg; \ + reg = MC9328MXL_TMR1_TSTAT; \ + MC9328MXL_TMR1_TSTAT = 0; \ + } while(0) + + +/** + * Installs the clock ISR. You shouldn't need to change this. + */ +#define Clock_driver_support_install_isr( _new, _old ) \ + do { \ + BSP_install_rtems_irq_handler(&clock_isr_data); \ + } while(0) + + +/** + * Initialize the hardware for the clock + * - Set the frequency + * - enable it + * - clear any pending interrupts + * + * Since you may want the clock always running, you can + * enable interrupts here. If you do so, the clock_isr_on(), + * clock_isr_off(), and clock_isr_is_on() functions can be + * NOPs. + */ +#define Clock_driver_support_initialize_hardware() \ + do { \ + int freq; \ + int cnt; \ + freq = get_perclk1_freq(); \ + printk("perclk1 freq is %d\n", freq); \ + cnt = ((freq / 1000) * BSP_Configuration.microseconds_per_tick) / 1000;\ + printk("cnt freq is %d\n", cnt); \ + MC9328MXL_TMR1_TCMP = cnt; \ + /* use PERCLK1 as input, enable timer */ \ + MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \ + MC9328MXL_TMR_TCTL_TEN | \ + MC9328MXL_TMR_TCTL_IRQEN); \ + /* set prescaler to 1 (register value + 1) */ \ + MC9328MXL_TMR1_TPRER = 0; \ + } while (0) + +/** + * Do whatever you need to shut the clock down and remove the + * interrupt handler. Since this normally only gets called on + * RTEMS shutdown, you may not need to do anything other than + * remove the ISR. + */ +#define Clock_driver_support_shutdown_hardware() \ + do { \ + /* Disable timer */ \ + MC9328MXL_TMR1_TCTL = 0; \ + BSP_remove_rtems_irq_handler(&clock_isr_data); \ + } while (0) + +/** + * Enables clock interrupt. + * + * If the interrupt is always on, this can be a NOP. + */ +static void clock_isr_on(const rtems_irq_connect_data *unused) +{ + MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN; + MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1; + + return; +} + +/** + * Disables clock interrupts + * + * If the interrupt is always on, this can be a NOP. + */ +static void clock_isr_off(const rtems_irq_connect_data *unused) +{ + MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN; + MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1; + return; +} + +/** + * Tests to see if clock interrupt is enabled, and returns 1 if so. + * If interrupt is not enabled, returns 0. + * + * If the interrupt is always on, this always returns 1. + */ +static int clock_isr_is_on(const rtems_irq_connect_data *irq) +{ + return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN; +} + + +/* Make sure to include this, and only at the end of the file */ +#include "../../../../libbsp/shared/clockdrv_shell.c" |