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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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