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

4.11
Last change on this file since 1401076 was 1401076, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 19, 2012 at 6:15:34 PM

at91rm9200 shared: Clock driver clean up and ISR Handler Prototype Correction.

  • Property mode set to 100644
File size: 3.0 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#include <rtems.h>
15#include <rtems/clockdrv.h>
16#include <rtems/libio.h>
17
18#include <stdlib.h>
19#include <bsp.h>
20#include <bsp/irq.h>
21#include <at91rm9200.h>
22#include <at91rm9200_pmc.h>
23
24static unsigned long st_pimr_reload;
25
26/**
27 * Enables clock interrupt.
28 *
29 * If the interrupt is always on, this can be a NOP.
30 */
31static void clock_isr_on(const rtems_irq_connect_data *unused)
32{
33  /* enable timer interrupt */
34  ST_REG(ST_IER) = ST_SR_PITS;
35}
36
37/**
38 * Disables clock interrupts
39 *
40 * If the interrupt is always on, this can be a NOP.
41 */
42static void clock_isr_off(const rtems_irq_connect_data *unused)
43{
44  /* disable timer interrupt */
45  ST_REG(ST_IDR) = ST_SR_PITS;
46}
47
48/**
49 * Tests to see if clock interrupt is enabled, and returns 1 if so.
50 * If interrupt is not enabled, returns 0.
51 *
52 * If the interrupt is always on, this always returns 1.
53 */
54static int clock_isr_is_on(const rtems_irq_connect_data *irq)
55{
56  /* check timer interrupt */
57  return ST_REG(ST_IMR) & ST_SR_PITS;
58}
59
60void Clock_isr(rtems_irq_hdl_param arg);
61
62/* Replace the first value with the clock's interrupt name. */
63rtems_irq_connect_data clock_isr_data = {
64  .name   = AT91RM9200_INT_SYSIRQ,
65  .hdl    = Clock_isr,
66  .handle = NULL,
67  .on     = clock_isr_on,
68  .off    = clock_isr_off,
69  .isOn   = clock_isr_is_on,
70};
71
72
73#define Clock_driver_support_install_isr( _new, _old ) \
74  do {                                                 \
75      (_old) = NULL;                                   \
76      BSP_install_rtems_irq_handler(&clock_isr_data);  \
77  } while(0)
78
79uint16_t st_pimr_value;
80void Clock_driver_support_initialize_hardware(void)
81{
82  uint32_t st_str;
83  int slck;
84
85  /* the system timer is driven from SLCK */
86  slck = at91rm9200_get_slck();
87  st_pimr_value = (((rtems_configuration_get_microseconds_per_tick() * slck) +
88                      (1000000/2))/ 1000000);
89  st_pimr_reload = st_pimr_value;
90
91  /* read the status to clear the int */
92  st_str = ST_REG(ST_SR);
93
94  /* set priority */
95  AIC_SMR_REG(AIC_SMR_SYSIRQ) = AIC_SMR_PRIOR(0x7);
96
97  /* set the timer value */
98  ST_REG(ST_PIMR) = st_pimr_reload;
99}
100
101uint32_t bsp_clock_nanoseconds_since_last_tick(void)
102{
103  uint16_t slck_counts;
104
105  slck_counts = st_pimr_value - st_pimr_reload;
106  return (rtems_configuration_get_microseconds_per_tick() * slck_counts * 1000)
107     / st_pimr_value;
108}
109
110#define Clock_driver_nanoseconds_since_last_tick \
111  bsp_clock_nanoseconds_since_last_tick
112
113#define Clock_driver_support_at_tick() \
114  do { \
115    uint32_t st_str; \
116    \
117    /* read the status to clear the int */ \
118    st_str = ST_REG(ST_SR); \
119  } while (0)
120
121void Clock_driver_support_shutdown_hardware( void )
122{
123  BSP_remove_rtems_irq_handler(&clock_isr_data);
124}
125
126#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.