source: rtems/c/src/lib/libcpu/sh/sh7045/clock/ckinit.c @ 4172cf1b

4.115
Last change on this file since 4172cf1b was 4172cf1b, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/14 at 20:37:33

libcpu/sh/sh7045/clock/ckinit.c: Fix warnings

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 *  This file contains the clock driver the Hitachi SH 704X
3 */
4
5/*
6 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
7 *           Bernd Becker (becker@faw.uni-ulm.de)
8 *
9 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 *  COPYRIGHT (c) 1998.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 *      Modified to reflect registers of sh7045 processor:
19 *      John M. Mills (jmills@tga.com)
20 *      TGA Technologies, Inc.
21 *      100 Pinnacle Way, Suite 140
22 *      Norcross, GA 30071 U.S.A.
23 *      August, 1999
24 *
25 *      This modified file may be copied and distributed in accordance
26 *      the above-referenced license. It is provided for critique and
27 *      developmental purposes without any warranty nor representation
28 *      by the authors or by TGA Technologies.
29 *
30 *  The license and distribution terms for this file may be
31 *  found in the file LICENSE in this distribution or at
32 *  http://www.rtems.org/license/LICENSE.
33 */
34
35#include <rtems.h>
36
37#include <stdlib.h>
38
39#include <rtems/clockdrv.h>
40#include <rtems/score/sh_io.h>
41#include <rtems/score/sh.h>
42#include <rtems/score/ispsh7045.h>
43#include <rtems/score/iosh7045.h>
44
45extern uint32_t bsp_clicks_per_second;
46
47#define _MTU_COUNTER0_MICROSECOND (Clock_MHZ/16)
48
49#ifndef CLOCKPRIO
50#define CLOCKPRIO 10
51#endif
52
53#define MTU0_STARTMASK  0xfe
54#define MTU0_SYNCMASK   0xfe
55#define MTU0_MODEMASK   0xc0
56#define MTU0_TCRMASK    0x22 /* bit 7 also used, vs 703x */
57#define MTU0_STAT_MASK  0xc0
58#define MTU0_IRQMASK    0xfe
59#define MTU0_TIERMASK   0x01
60#define IPRC_MTU0_MASK  0xff0f
61#define MTU0_TIORVAL    0x08
62
63/*
64 *  The interrupt vector number associated with the clock tick device
65 *  driver.
66 */
67
68#define CLOCK_VECTOR MTUA0_ISP_V
69
70/*
71 *  Clock_driver_ticks is a monotonically increasing counter of the
72 *  number of clock ticks since the driver was initialized.
73 */
74volatile uint32_t   Clock_driver_ticks;
75
76static rtems_isr Clock_isr( rtems_vector_number vector );
77static uint32_t   Clock_MHZ ;
78
79/*
80 *  Clock_isrs is the number of clock ISRs until the next invocation of
81 *  the RTEMS clock tick routine.  The clock tick device driver
82 *  gets an interrupt once a millisecond and counts down until the
83 *  length of time between the user configured microseconds per tick
84 *  has passed.
85 */
86uint32_t   Clock_isrs;              /* ISRs until next tick */
87static uint32_t   Clock_isrs_const;        /* only calculated once */
88
89/*
90 *  The previous ISR on this clock tick interrupt vector.
91 */
92rtems_isr_entry  Old_ticker;
93
94/*
95 *  Isr Handler
96 */
97static rtems_isr Clock_isr(
98  rtems_vector_number vector
99)
100{
101  /*
102   * bump the number of clock driver ticks since initialization
103   *
104
105   * determine if it is time to announce the passing of tick as configured
106   * to RTEMS through the rtems_clock_tick directive
107   *
108   * perform any timer dependent tasks
109   */
110  uint8_t   temp;
111
112  /* reset the flags of the status register */
113  temp = read8( MTU_TSR0) & MTU0_STAT_MASK;
114  write8( temp, MTU_TSR0);
115
116  Clock_driver_ticks++ ;
117
118  if( Clock_isrs == 1)
119    {
120      rtems_clock_tick();
121      Clock_isrs = Clock_isrs_const;
122    }
123  else
124    {
125      Clock_isrs-- ;
126    }
127}
128
129/*
130 *  Install_clock
131 *
132 *  Install a clock tick handler and reprograms the chip.  This
133 *  is used to initially establish the clock tick.
134 */
135static void Install_clock(
136  rtems_isr_entry clock_isr
137)
138{
139  uint8_t   temp8 = 0;
140  uint32_t   factor = 1000000;
141
142  /*
143   *  Initialize the clock tick device driver variables
144   */
145
146  Clock_driver_ticks = 0;
147  Clock_isrs_const = rtems_configuration_get_microseconds_per_tick() / 10000;
148  Clock_isrs = Clock_isrs_const;
149
150  factor /= rtems_configuration_get_microseconds_per_tick(); /* minimalization of integer division error */
151  Clock_MHZ = bsp_clicks_per_second / factor ;
152
153  rtems_interrupt_catch( Clock_isr, CLOCK_VECTOR, &Old_ticker );
154
155  /*
156   *  Hardware specific initialize goes here
157   */
158
159  /* stop Timer 0 */
160  temp8 = read8( MTU_TSTR) & MTU0_STARTMASK;
161  write8( temp8, MTU_TSTR);
162
163  /* set initial counter value to 0 */
164  write16( 0, MTU_TCNT0);
165
166  /* Timer 0 runs independent */
167  temp8 = read8( MTU_TSYR) & MTU0_SYNCMASK;
168  write8( temp8, MTU_TSYR);
169
170  /* Timer 0 normal mode */
171  temp8 = read8( MTU_TMDR0) & MTU0_MODEMASK;
172  write8( temp8, MTU_TMDR0);
173
174  /* TCNT is cleared by GRA ; internal clock /16 */
175  write8( MTU0_TCRMASK , MTU_TCR0);
176
177  /* use GRA without I/O - pins  */
178  write8( MTU0_TIORVAL, MTU_TIORL0);
179
180  /* reset flags of the status register */
181  temp8 = read8( MTU_TSR0) & MTU0_STAT_MASK;
182  write8( temp8, MTU_TSR0);
183
184  /* Irq if is equal GRA */
185  temp8 = read8( MTU_TIER0) | MTU0_TIERMASK;
186  write8( temp8, MTU_TIER0);
187
188  /* set interrupt priority */
189  if( sh_set_irq_priority( CLOCK_VECTOR, CLOCKPRIO ) != RTEMS_SUCCESSFUL)
190    rtems_fatal_error_occurred( RTEMS_NOT_CONFIGURED);
191
192  /* set counter limits */
193  write16( _MTU_COUNTER0_MICROSECOND, MTU_GR0A);
194
195  /* start counter */
196  temp8 = read8( MTU_TSTR) |~MTU0_STARTMASK;
197  write8( temp8, MTU_TSTR);
198
199  /*
200   *  Schedule the clock cleanup routine to execute if the application exits.
201   */
202  atexit( Clock_exit );
203}
204
205/*
206 *  Clean up before the application exits
207 */
208void Clock_exit( void )
209{
210  uint8_t   temp8 = 0;
211
212  /* turn off the timer interrupts */
213  /* set interrupt priority to 0 */
214  if( sh_set_irq_priority( CLOCK_VECTOR, 0 ) != RTEMS_SUCCESSFUL)
215    rtems_fatal_error_occurred( RTEMS_UNSATISFIED);
216
217/*
218 *   temp16 = read16( MTU_TIER0) & IPRC_MTU0_IRQMASK;
219 *   write16( temp16, MTU_TIER0);
220 */
221
222  /* stop counter */
223  temp8 = read8( MTU_TSTR) & MTU0_STARTMASK;
224  write8( temp8, MTU_TSTR);
225
226  /* old vector shall not be installed */
227}
228
229/*
230 *  Clock_initialize
231 *
232 *  Device driver entry point for clock tick driver initialization.
233 */
234rtems_device_driver Clock_initialize(
235  rtems_device_major_number major,
236  rtems_device_minor_number minor,
237  void *pargp
238)
239{
240  Install_clock( Clock_isr );
241
242  return RTEMS_SUCCESSFUL;
243}
Note: See TracBrowser for help on using the repository browser.