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

4.11
Last change on this file since 9f058fb was 9f058fb, checked in by Daniel Cederman <cederman@…>, on May 8, 2014 at 3:08:04 PM

bsps/sparc: Change tabs to spaces.

  • Property mode set to 100644
File size: 3.1 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.org/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
25#include <bsp.h>
26#include <bspopts.h>
27#include <rtems/counter.h>
28
29#if SIMSPARC_FAST_IDLE==1
30#define CLOCK_DRIVER_USE_FAST_IDLE 1
31#endif
32
33/*
34 *  The Real Time Clock Counter Timer uses this trap type.
35 */
36
37#define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK )
38
39#define Clock_driver_support_at_tick()
40
41#define Clock_driver_support_install_isr( _new, _old ) \
42  do { \
43    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
44  } while(0)
45
46extern int CLOCK_SPEED;
47
48uint32_t bsp_clock_nanoseconds_since_last_tick(void)
49{
50  uint32_t clicks;
51  uint32_t usecs;
52
53  clicks = ERC32_MEC.Real_Time_Clock_Counter;
54
55  if ( ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ) ) {
56    clicks = ERC32_MEC.Real_Time_Clock_Counter;
57    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
58  } else {
59    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
60  }
61  return usecs * 1000;
62}
63
64#define Clock_driver_nanoseconds_since_last_tick \
65  bsp_clock_nanoseconds_since_last_tick
66
67static CPU_Counter_ticks erc32_counter_difference(
68  CPU_Counter_ticks second,
69  CPU_Counter_ticks first
70)
71{
72  CPU_Counter_ticks period = rtems_configuration_get_microseconds_per_tick();
73
74  return (first + period - second) % period;
75}
76
77#define Clock_driver_support_initialize_hardware() \
78  do { \
79    /* approximately 1 us per countdown */ \
80    ERC32_MEC.Real_Time_Clock_Scalar  = CLOCK_SPEED - 1; \
81    ERC32_MEC.Real_Time_Clock_Counter = \
82      rtems_configuration_get_microseconds_per_tick(); \
83    \
84    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
85        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
86        ERC32_MEC_TIMER_COUNTER_LOAD_SCALER | \
87        ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER \
88    ); \
89    \
90    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
91        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
92        ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
93    ); \
94    _SPARC_Counter_initialize( \
95      &ERC32_MEC.Real_Time_Clock_Counter, \
96      erc32_counter_difference \
97    ); \
98    rtems_counter_initialize_converter(1000000); \
99  } while (0)
100
101#define Clock_driver_support_shutdown_hardware() \
102  do { \
103    ERC32_Mask_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK ); \
104     \
105    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
106      ERC32_MEC_TIMER_COUNTER_DISABLE_COUNTING \
107    ); \
108  } while (0)
109
110#include "../../../shared/clockdrv_shell.h"
111
Note: See TracBrowser for help on using the repository browser.