source: rtems/c/src/lib/libcpu/arm/at91rm9200/clock/clock.c @ c193baad

4.104.11
Last change on this file since c193baad was c193baad, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Apr 9, 2010 at 8:24:57 PM

unify irq data types and code, merge s3c2400/s3c2410 support

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 *  AT91RM9200 clock specific using the System Timer
3 *
4 *  Copyright (c) 2003 by Cogent Computer Systems
5 *  Written by Mike Kelly <mike@cogcomp.com>
6 *         and Jay Monkman <jtm@lopingdog.com>
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *
14 *  $Id$
15 */
16#include <rtems.h>
17#include <rtems/clockdrv.h>
18#include <rtems/libio.h>
19
20#include <stdlib.h>
21#include <bsp.h>
22#include <irq.h>
23#include <at91rm9200.h>
24#include <at91rm9200_pmc.h>
25
26
27static unsigned long st_pimr_reload;
28
29/**
30 * Enables clock interrupt.
31 *
32 * If the interrupt is always on, this can be a NOP.
33 */
34static void clock_isr_on(const rtems_irq_connect_data *unused)
35{
36    /* enable timer interrupt */
37    ST_REG(ST_IER) = ST_SR_PITS;
38}
39
40/**
41 * Disables clock interrupts
42 *
43 * If the interrupt is always on, this can be a NOP.
44 */
45static void clock_isr_off(const rtems_irq_connect_data *unused)
46{
47    /* disable timer interrupt */
48    ST_REG(ST_IDR) = ST_SR_PITS;
49    return;
50}
51
52/**
53 * Tests to see if clock interrupt is enabled, and returns 1 if so.
54 * If interrupt is not enabled, returns 0.
55 *
56 * If the interrupt is always on, this always returns 1.
57 */
58static int clock_isr_is_on(const rtems_irq_connect_data *irq)
59{
60    /* check timer interrupt */
61    return ST_REG(ST_IMR) & ST_SR_PITS;
62}
63
64rtems_isr Clock_isr(rtems_vector_number vector);
65
66/* Replace the first value with the clock's interrupt name. */
67rtems_irq_connect_data clock_isr_data = {AT91RM9200_INT_SYSIRQ,
68                                         (rtems_irq_hdl)Clock_isr,
69                                         NULL,
70                                         clock_isr_on,
71                                         clock_isr_off,
72                                         clock_isr_is_on};
73
74
75#define Clock_driver_support_install_isr( _new, _old ) \
76  do {                                                 \
77      (_old) = NULL;                                   \
78      BSP_install_rtems_irq_handler(&clock_isr_data);  \
79  } while(0)
80
81uint16_t st_pimr_value;
82void Clock_driver_support_initialize_hardware(void)
83{
84  uint32_t st_str;
85  int slck;
86
87  /* the system timer is driven from SLCK */
88  slck = at91rm9200_get_slck();
89  st_pimr_value =
90    (((rtems_configuration_get_microseconds_per_tick() * slck) + (1000000/2))/ 1000000);
91  st_pimr_reload = st_pimr_value;
92
93  /* read the status to clear the int */
94  st_str = ST_REG(ST_SR);
95
96  /* set priority */
97  AIC_SMR_REG(AIC_SMR_SYSIRQ) = AIC_SMR_PRIOR(0x7);
98
99  /* set the timer value */
100  ST_REG(ST_PIMR) = st_pimr_reload;
101}
102
103uint32_t bsp_clock_nanoseconds_since_last_tick(void)
104{
105  uint16_t slck_counts;
106
107  slck_counts = st_pimr_value - st_pimr_reload;
108  return (rtems_configuration_get_microseconds_per_tick() * slck_counts * 1000)
109     / st_pimr_value;
110}
111
112#define Clock_driver_nanoseconds_since_last_tick \
113  bsp_clock_nanoseconds_since_last_tick
114
115#define CLOCK_VECTOR 0
116
117#define Clock_driver_support_at_tick() \
118  do { \
119    uint32_t st_str; \
120    \
121    /* read the status to clear the int */ \
122    st_str = ST_REG(ST_SR); \
123  } while (0)
124
125void Clock_driver_support_shutdown_hardware( void )
126{
127    BSP_remove_rtems_irq_handler(&clock_isr_data);
128}
129
130#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.