Back to home page

LXR

 
 

    


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

0001 /*
0002  *  AT91RM9200 clock specific using the System Timer
0003  */
0004 
0005 /*
0006  *  Copyright (c) 2003 by Cogent Computer Systems
0007  *  Written by Mike Kelly <mike@cogcomp.com>
0008  *         and Jay Monkman <jtm@lopingdog.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 <bsp/irq.h>
0022 #include <at91rm9200.h>
0023 #include <at91rm9200_pmc.h>
0024 
0025 /**
0026  * Enables clock interrupt.
0027  *
0028  * If the interrupt is always on, this can be a NOP.
0029  */
0030 static void clock_isr_on(const rtems_irq_connect_data *unused)
0031 {
0032   /* enable timer interrupt */
0033   ST_REG(ST_IER) = ST_SR_PITS;
0034 }
0035 
0036 /**
0037  * Disables clock interrupts
0038  *
0039  * If the interrupt is always on, this can be a NOP.
0040  */
0041 static void clock_isr_off(const rtems_irq_connect_data *unused)
0042 {
0043   /* disable timer interrupt */
0044   ST_REG(ST_IDR) = ST_SR_PITS;
0045 }
0046 
0047 /**
0048  * Tests to see if clock interrupt is enabled, and returns 1 if so.
0049  * If interrupt is not enabled, returns 0.
0050  *
0051  * If the interrupt is always on, this always returns 1.
0052  */
0053 static int clock_isr_is_on(const rtems_irq_connect_data *irq)
0054 {
0055   /* check timer interrupt */
0056   return ST_REG(ST_IMR) & ST_SR_PITS;
0057 }
0058 
0059 void Clock_isr(rtems_irq_hdl_param arg);
0060 
0061 /* Replace the first value with the clock's interrupt name. */
0062 rtems_irq_connect_data clock_isr_data = {
0063   .name   = AT91RM9200_INT_SYSIRQ,
0064   .hdl    = Clock_isr,
0065   .handle = NULL,
0066   .on     = clock_isr_on,
0067   .off    = clock_isr_off,
0068   .isOn   = clock_isr_is_on,
0069 };
0070 
0071 
0072 #define Clock_driver_support_install_isr( _new ) \
0073   BSP_install_rtems_irq_handler(&clock_isr_data)
0074 
0075 static void Clock_driver_support_initialize_hardware(void)
0076 {
0077   uint32_t st_str;
0078   int slck;
0079   unsigned long value;
0080 
0081   /* the system timer is driven from SLCK */
0082   slck = at91rm9200_get_slck();
0083   value = (((rtems_configuration_get_microseconds_per_tick() * slck) +
0084                       (1000000/2))/ 1000000);
0085 
0086   /* read the status to clear the int */
0087   st_str = ST_REG(ST_SR);
0088   (void) st_str; /* avoid set but not used warning */ \
0089 
0090   /* set priority */
0091   AIC_SMR_REG(AIC_SMR_SYSIRQ) = AIC_SMR_PRIOR(0x7);
0092 
0093   /* set the timer value */
0094   ST_REG(ST_PIMR) = value;
0095 }
0096 
0097 #define Clock_driver_support_at_tick(arg) \
0098   do { \
0099     uint32_t st_str; \
0100     \
0101     /* read the status to clear the int */ \
0102     st_str = ST_REG(ST_SR); \
0103     (void) st_str; /* avoid set but not used warning */ \
0104   } while (0)
0105 
0106 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
0107 
0108 #include "../../../shared/dev/clock/clockimpl.h"