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 03/04/11 at 14:07:17

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
RevLine 
[7f96eef]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 *
[0e58c4f]10 *  COPYRIGHT (c) 1989-2008.
[7f96eef]11 *  On-Line Applications Research Corporation (OAR).
12 *
[98e4ebf5]13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
[7d2a0641]15 *  http://www.rtems.com/license/LICENSE.
[7f96eef]16 *
17 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
[6128a4a]18 *  Research Corporation (OAR) under contract to the European Space
[7f96eef]19 *  Agency (ESA).
20 *
[6128a4a]21 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
[7f96eef]22 *  European Space Agency.
23 *
24 *  $Id$
25 */
26
27#include <bsp.h>
[74b09f1]28#include <bspopts.h>
29
30#if SIMSPARC_FAST_IDLE==1
31#define CLOCK_DRIVER_USE_FAST_IDLE
32#endif
[7f96eef]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
[74b09f1]40#define Clock_driver_support_at_tick()
[7f96eef]41
[74b09f1]42#define Clock_driver_support_install_isr( _new, _old ) \
43  do { \
44    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
45  } while(0)
[7f96eef]46
47extern int CLOCK_SPEED;
48
[e907f7d9]49uint32_t bsp_clock_nanoseconds_since_last_tick(void)
50{
51  uint32_t clicks;
[9ec55e63]52  uint32_t usecs;
[e907f7d9]53
54  clicks = ERC32_MEC.Real_Time_Clock_Counter;
55
[9ec55e63]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;
[e907f7d9]63}
64
[b214b1ba]65#define Clock_driver_nanoseconds_since_last_tick \
66  bsp_clock_nanoseconds_since_last_tick
[e907f7d9]67
[74b09f1]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 = \
[2d25867]73      rtems_configuration_get_microseconds_per_tick(); \
[74b09f1]74    \
75    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
76      ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
[bf5ef93]77        ERC32_MEC_TIMER_COUNTER_LOAD_SCALER | \
78            ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER \
[74b09f1]79    ); \
80    \
81    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
82      ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
[bf5ef93]83            ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
[74b09f1]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"
[6128a4a]97
Note: See TracBrowser for help on using the repository browser.