Back to home page

LXR

 
 

    


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

0001 /*
0002  *  PXA255 clock specific using the System Timer
0003  *
0004  *  RTEMS uses IRQ 26 as Clock Source
0005  */
0006 
0007 /*
0008  *  By Yang Xi <hiyangxi@gmail.com>
0009  *
0010  *  The license and distribution terms for this file may be
0011  *  found in the file LICENSE in this distribution or at
0012  *  http://www.rtems.org/license/LICENSE.
0013  */
0014 
0015 #include <rtems.h>
0016 #include <rtems/clockdrv.h>
0017 #include <rtems/libio.h>
0018 
0019 #include <stdlib.h>
0020 #include <bsp.h>
0021 #include <bspopts.h>
0022 #include <bsp/irq.h>
0023 #include <pxa255.h>
0024 
0025 #if ON_SKYEYE==1
0026   #define CLOCK_DRIVER_USE_FAST_IDLE 1
0027 #endif
0028 
0029 static unsigned long period_num;
0030 
0031 /**
0032  * Enables clock interrupt.
0033  *
0034  * If the interrupt is always on, this can be a NOP.
0035  */
0036 static void clock_isr_on(const rtems_irq_connect_data *unused)
0037 {
0038   /*Clear the interrupt bit */
0039   XSCALE_OS_TIMER_TSR = 0x1;
0040 
0041   /* enable timer interrupt */
0042   XSCALE_OS_TIMER_IER |= 0x1;
0043 
0044 #if ON_SKYEYE==1
0045   period_num = (TIMER_RATE* rtems_configuration_get_microseconds_per_tick())/100000;
0046 #else
0047   period_num = (TIMER_RATE* rtems_configuration_get_microseconds_per_tick())/10000;
0048 #endif
0049 
0050   XSCALE_OS_TIMER_MR0 = XSCALE_OS_TIMER_TCR + period_num;
0051 }
0052 
0053 /**
0054  * Disables clock interrupts
0055  *
0056  * If the interrupt is always on, this can be a NOP.
0057  */
0058 static void clock_isr_off(const rtems_irq_connect_data *unused)
0059 {
0060   /*Clear the interrupt bit */
0061   XSCALE_OS_TIMER_TSR = 0x1;
0062   /* disable timer interrupt*/
0063   XSCALE_OS_TIMER_IER &= ~0x1;
0064 }
0065 
0066 /**
0067  * Tests to see if clock interrupt is enabled, and returns 1 if so.
0068  * If interrupt is not enabled, returns 0.
0069  *
0070  * If the interrupt is always on, this always returns 1.
0071  */
0072 static int clock_isr_is_on(const rtems_irq_connect_data *irq)
0073 {
0074   /* check timer interrupt */
0075   return XSCALE_OS_TIMER_IER & 0x1;
0076 }
0077 
0078 void Clock_isr(rtems_irq_hdl_param arg);
0079 
0080 rtems_irq_connect_data clock_isr_data = {
0081   .name   = XSCALE_IRQ_OS_TIMER,
0082   .hdl    = Clock_isr,
0083   .handle = NULL,
0084   .on     = clock_isr_on,
0085   .off    = clock_isr_off,
0086   .isOn   = clock_isr_is_on,
0087 };
0088 
0089 #define Clock_driver_support_install_isr( _new ) \
0090   BSP_install_rtems_irq_handler(&clock_isr_data)
0091 
0092 static void Clock_driver_support_initialize_hardware(void)
0093 {
0094   period_num = TIMER_RATE* rtems_configuration_get_microseconds_per_tick();
0095 #if ON_SKYEYE==1
0096   period_num /= 100000;
0097 #else
0098   period_num /= 10000;
0099 #endif
0100 }
0101 
0102 #define Clock_driver_support_at_tick(arg) \
0103   do { \
0104     /* read the status to clear the int */ \
0105     XSCALE_OS_TIMER_TSR = 0x1; \
0106     \
0107     /*Add the match register*/ \
0108     XSCALE_OS_TIMER_MR0 = XSCALE_OS_TIMER_TCR + period_num; \
0109   } while (0)
0110 
0111 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
0112 
0113 #include "../../../shared/dev/clock/clockimpl.h"