Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:48

0001 /*
0002  *  MC9328MXL clock specific using the System Timer
0003  */
0004 
0005 /*
0006  *  Copyright (c) 2004 by Cogent Computer Systems
0007  *  Written by Jay Monkman <jtm@lopingdog.com>
0008  *
0009  *  The license and distribution terms for this file may be
0010  *  found in the file LICENSE in this distribution or at
0011  *  http://www.rtems.org/license/LICENSE.
0012  */
0013 
0014 #include <rtems.h>
0015 #include <bsp.h>
0016 #include <bsp/irq.h>
0017 #include <mc9328mxl.h>
0018 #include <rtems/bspIo.h>  /* for printk */
0019 
0020 /* this is defined in ../../../shared/dev/clock/clockimpl.h */
0021 void Clock_isr(rtems_irq_hdl_param arg);
0022 static void clock_isr_on(const rtems_irq_connect_data *unused);
0023 static void clock_isr_off(const rtems_irq_connect_data *unused);
0024 static int clock_isr_is_on(const rtems_irq_connect_data *irq);
0025 
0026 /* Replace the first value with the clock's interrupt name. */
0027 rtems_irq_connect_data clock_isr_data = {
0028   .name   = BSP_INT_TIMER1,
0029   .hdl    = Clock_isr,
0030   .handle = (void *)BSP_INT_TIMER1,
0031   .on     = clock_isr_on,
0032   .off    = clock_isr_off,
0033   .isOn   = clock_isr_is_on,
0034 };
0035 
0036 /**
0037  * When we get the clock interrupt
0038  *    - clear the interrupt bit?
0039  *    - restart the timer?
0040  */
0041 #define Clock_driver_support_at_tick(arg)            \
0042   do {                                               \
0043     uint32_t reg;                                    \
0044                                                      \
0045     reg = MC9328MXL_TMR1_TSTAT;                      \
0046     (void) reg; /* avoid set but not used warning */ \
0047     MC9328MXL_TMR1_TSTAT = 0;                        \
0048   } while(0)
0049 
0050 /**
0051  * Installs the clock ISR. You shouldn't need to change this.
0052  */
0053 #define Clock_driver_support_install_isr( _new ) \
0054   BSP_install_rtems_irq_handler(&clock_isr_data)
0055 
0056 /**
0057  * Initialize the hardware for the clock
0058  *   - Set the frequency
0059  *   - enable it
0060  *   - clear any pending interrupts
0061  *
0062  * Since you may want the clock always running, you can
0063  * enable interrupts here. If you do so, the clock_isr_on(),
0064  * clock_isr_off(), and clock_isr_is_on() functions can be
0065  * NOPs.
0066  */
0067 #define Clock_driver_support_initialize_hardware() \
0068   do { \
0069         int freq; \
0070         int cnt; \
0071         freq = get_perclk1_freq(); \
0072         printk("perclk1 freq is %d\n", freq); \
0073         cnt = ((long long)freq * rtems_configuration_get_microseconds_per_tick() + 500000) / 1000000;\
0074         printk("cnt freq is %d\n", cnt); \
0075         MC9328MXL_TMR1_TCMP = cnt; \
0076         /* use PERCLK1 as input, enable timer */ \
0077         MC9328MXL_TMR1_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 | \
0078                                MC9328MXL_TMR_TCTL_TEN | \
0079                                MC9328MXL_TMR_TCTL_IRQEN); \
0080         /* set prescaler to 1 (register value + 1) */ \
0081         MC9328MXL_TMR1_TPRER = 0; \
0082      } while (0)
0083 
0084 /**
0085  * Enables clock interrupt.
0086  *
0087  * If the interrupt is always on, this can be a NOP.
0088  */
0089 static void clock_isr_on(const rtems_irq_connect_data *unused)
0090 {
0091   MC9328MXL_TMR1_TCTL |= MC9328MXL_TMR_TCTL_IRQEN;
0092   MC9328MXL_AITC_INTENNUM = MC9328MXL_INT_TIMER1;
0093 }
0094 
0095 /**
0096  * Disables clock interrupts
0097  *
0098  * If the interrupt is always on, this can be a NOP.
0099  */
0100 static void clock_isr_off(const rtems_irq_connect_data *unused)
0101 {
0102   MC9328MXL_TMR1_TCTL &= ~MC9328MXL_TMR_TCTL_IRQEN;
0103   MC9328MXL_AITC_INTDISNUM = MC9328MXL_INT_TIMER1;
0104 }
0105 
0106 /**
0107  * Tests to see if clock interrupt is enabled, and returns 1 if so.
0108  * If interrupt is not enabled, returns 0.
0109  *
0110  * If the interrupt is always on, this always returns 1.
0111  */
0112 static int clock_isr_is_on(const rtems_irq_connect_data *irq)
0113 {
0114   return MC9328MXL_TMR1_TCTL & MC9328MXL_TMR_TCTL_IRQEN;
0115 }
0116 
0117 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
0118 
0119 /* Make sure to include this, and only at the end of the file */
0120 
0121 #include "../../../shared/dev/clock/clockimpl.h"