source: rtems/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c @ 9ec55e63

4.9
Last change on this file since 9ec55e63 was 9ec55e63, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 4, 2011 at 2:07:17 PM

2011-03-04 Joel Sherrill <joel.sherrilL@…>

PR 1748/bsps

  • clock/ckinit.c: When the clock tick generates an interrupt WHILE we have interrupts disabled doing a get TOD or uptime, the get nanoseconds handler was returning a bogusly large number.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  Clock Tick Device Driver
3 *
4 *  This routine initializes the Real Time Clock Counter Timer which is
5 *  part of the MEC on the ERC32 CPU.
6 *
7 *  The tick frequency is directly programmed to the configured number of
8 *  microseconds per tick.
9 *
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
18 *  Research Corporation (OAR) under contract to the European Space
19 *  Agency (ESA).
20 *
21 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
22 *  European Space Agency.
23 *
24 *  $Id$
25 */
26
27#include <bsp.h>
28#include <bspopts.h>
29
30#if SIMSPARC_FAST_IDLE==1
31#define CLOCK_DRIVER_USE_FAST_IDLE
32#endif
33
34/*
35 *  The Real Time Clock Counter Timer uses this trap type.
36 */
37
38#define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK )
39
40#define Clock_driver_support_at_tick()
41
42#define Clock_driver_support_install_isr( _new, _old ) \
43  do { \
44    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
45  } while(0)
46
47extern int CLOCK_SPEED;
48
49uint32_t bsp_clock_nanoseconds_since_last_tick(void)
50{
51  uint32_t clicks;
52  uint32_t usecs;
53
54  clicks = ERC32_MEC.Real_Time_Clock_Counter;
55
56  if ( ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ) ) {
57    clicks = ERC32_MEC.Real_Time_Clock_Counter;
58    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
59  } else {
60    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
61  }
62  return usecs * 1000;
63}
64
65#define Clock_driver_nanoseconds_since_last_tick \
66  bsp_clock_nanoseconds_since_last_tick
67
68#define Clock_driver_support_initialize_hardware() \
69  do { \
70    /* approximately 1 us per countdown */ \
71    ERC32_MEC.Real_Time_Clock_Scalar  = CLOCK_SPEED - 1; \
72    ERC32_MEC.Real_Time_Clock_Counter = \
73      rtems_configuration_get_microseconds_per_tick(); \
74    \
75    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
76      ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
77        ERC32_MEC_TIMER_COUNTER_LOAD_SCALER | \
78            ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER \
79    ); \
80    \
81    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
82      ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
83            ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
84    ); \
85  } while (0)
86
87#define Clock_driver_support_shutdown_hardware() \
88  do { \
89    ERC32_Mask_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK ); \
90     \
91    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
92      ERC32_MEC_TIMER_COUNTER_DISABLE_COUNTING \
93    ); \
94  } while (0)
95
96#include "../../../shared/clockdrv_shell.c"
97
Note: See TracBrowser for help on using the repository browser.