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

4.115
Last change on this file since 1401076 was 1401076, checked in by Joel Sherrill <joel.sherrill@…>, on 04/19/12 at 18:15:34

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

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[af85485]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 *
[93f4a906]11 *  http://www.rtems.com/license/LICENSE.
[af85485]12 */
[1401076]13
[af85485]14#include <rtems.h>
15#include <rtems/clockdrv.h>
16#include <rtems/libio.h>
17
18#include <stdlib.h>
19#include <bsp.h>
[f4dc319a]20#include <bsp/irq.h>
[af85485]21#include <at91rm9200.h>
[aaca942]22#include <at91rm9200_pmc.h>
[af85485]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{
[1401076]33  /* enable timer interrupt */
34  ST_REG(ST_IER) = ST_SR_PITS;
[af85485]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{
[1401076]44  /* disable timer interrupt */
45  ST_REG(ST_IDR) = ST_SR_PITS;
[af85485]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{
[1401076]56  /* check timer interrupt */
57  return ST_REG(ST_IMR) & ST_SR_PITS;
[af85485]58}
[5c89efa]59
[1401076]60void Clock_isr(rtems_irq_hdl_param arg);
[5c89efa]61
62/* Replace the first value with the clock's interrupt name. */
[1401076]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};
[5c89efa]71
72
73#define Clock_driver_support_install_isr( _new, _old ) \
[c193baad]74  do {                                                 \
75      (_old) = NULL;                                   \
76      BSP_install_rtems_irq_handler(&clock_isr_data);  \
77  } while(0)
[5c89efa]78
[8d64f08e]79uint16_t st_pimr_value;
[5c89efa]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();
[1401076]87  st_pimr_value = (((rtems_configuration_get_microseconds_per_tick() * slck) +
88                      (1000000/2))/ 1000000);
[8d64f08e]89  st_pimr_reload = st_pimr_value;
[5c89efa]90
[359e537]91  /* read the status to clear the int */
[5c89efa]92  st_str = ST_REG(ST_SR);
[359e537]93
[5c89efa]94  /* set priority */
[359e537]95  AIC_SMR_REG(AIC_SMR_SYSIRQ) = AIC_SMR_PRIOR(0x7);
[5c89efa]96
97  /* set the timer value */
98  ST_REG(ST_PIMR) = st_pimr_reload;
99}
100
[8d64f08e]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
[5c89efa]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{
[1401076]123  BSP_remove_rtems_irq_handler(&clock_isr_data);
[5c89efa]124}
125
[052534c2]126#include "../../../../libbsp/shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.