source: rtems/c/src/lib/libbsp/sparc/erc32/clock/ckinit.c @ 459ddfc0

4.11
Last change on this file since 459ddfc0 was 459ddfc0, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 12, 2014 at 6:58:23 PM

sparc/erc32/clock/ckinit.c: Fix warnings

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  This routine initializes the Real Time Clock Counter Timer which is
3 *  part of the MEC on the ERC32 CPU.
4 *
5 *  The tick frequency is directly programmed to the configured number of
6 *  microseconds per tick.
7 */
8
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#define CLOCK_VECTOR ERC32_TRAP_TYPE( ERC32_INTERRUPT_REAL_TIME_CLOCK )
37
38#define Clock_driver_support_at_tick()
39
40#define Clock_driver_support_install_isr( _new, _old ) \
41  do { \
42    _old = set_vector( _new, CLOCK_VECTOR, 1 ); \
43  } while(0)
44
45extern int CLOCK_SPEED;
46
47static uint32_t bsp_clock_nanoseconds_since_last_tick(void)
48{
49  uint32_t clicks;
50  uint32_t usecs;
51
52  clicks = ERC32_MEC.Real_Time_Clock_Counter;
53
54  if ( ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ) ) {
55    clicks = ERC32_MEC.Real_Time_Clock_Counter;
56    usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks);
57  } else {
58    usecs = (rtems_configuration_get_microseconds_per_tick() - clicks);
59  }
60  return usecs * 1000;
61}
62
63#define Clock_driver_nanoseconds_since_last_tick \
64  bsp_clock_nanoseconds_since_last_tick
65
66static CPU_Counter_ticks erc32_counter_difference(
67  CPU_Counter_ticks second,
68  CPU_Counter_ticks first
69)
70{
71  CPU_Counter_ticks period = rtems_configuration_get_microseconds_per_tick();
72
73  return (first + period - second) % period;
74}
75
76#define Clock_driver_support_initialize_hardware() \
77  do { \
78    /* approximately 1 us per countdown */ \
79    ERC32_MEC.Real_Time_Clock_Scalar  = CLOCK_SPEED - 1; \
80    ERC32_MEC.Real_Time_Clock_Counter = \
81      rtems_configuration_get_microseconds_per_tick(); \
82    \
83    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
84        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
85        ERC32_MEC_TIMER_COUNTER_LOAD_SCALER | \
86        ERC32_MEC_TIMER_COUNTER_LOAD_COUNTER \
87    ); \
88    \
89    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
90        ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \
91        ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \
92    ); \
93    _SPARC_Counter_initialize( \
94      &ERC32_MEC.Real_Time_Clock_Counter, \
95      erc32_counter_difference \
96    ); \
97    rtems_counter_initialize_converter(1000000); \
98  } while (0)
99
100#define Clock_driver_support_shutdown_hardware() \
101  do { \
102    ERC32_Mask_interrupt( ERC32_INTERRUPT_REAL_TIME_CLOCK ); \
103     \
104    ERC32_MEC_Set_Real_Time_Clock_Timer_Control( \
105      ERC32_MEC_TIMER_COUNTER_DISABLE_COUNTING \
106    ); \
107  } while (0)
108
109#include "../../../shared/clockdrv_shell.h"
110
Note: See TracBrowser for help on using the repository browser.