source: rtems/bsps/m68k/gen68340/clock/ckinit.c

Last change on this file was f888837, checked in by Joel Sherrill <joel@…>, on 07/08/22 at 13:53:17

bsps/m68k/gen68340: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * This routine initializes the MC68340/349 Periodic Interval Timer
5 */
6
7/*
8 * Based on the `gen68360' board support package, and covered by the
9 * original distribution terms.
10 *
11 * Geoffroy Montel
12 * France Telecom - CNET/DSM/TAM/CAT
13 * 4, rue du Clos Courtel
14 * 35512 CESSON-SEVIGNE
15 * FRANCE
16 *
17 * e-mail: g_montel@yahoo.com
18 */
19
20/*
21 * COPYRIGHT (c) 1989-2014.
22 * On-Line Applications Research Corporation (OAR).
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 *    notice, this list of conditions and the following disclaimer.
29 * 2. Redistributions in binary form must reproduce the above copyright
30 *    notice, this list of conditions and the following disclaimer in the
31 *    documentation and/or other materials provided with the distribution.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
44 */
45
46#include <stdlib.h>       /* for atexit() */
47#include <bsp.h>
48#include <m68340.h>
49#include <rtems/clockdrv.h>
50
51#define CLOCK_VECTOR     120 /* clock isr routine vector in the vbr */
52#define CLOCK_IRQ_LEVEL  6   /* clock isr level */
53
54/*
55 * Clock_driver_ticks is a monotonically increasing counter of the
56 * number of clock ticks since the driver was initialized.
57 */
58volatile uint32_t         Clock_driver_ticks;
59
60/*
61 * Periodic interval timer interrupt handler
62 */
63static rtems_isr
64Clock_isr (rtems_vector_number vector)
65{
66  /*
67   * Announce the clock tick
68   */
69  Clock_driver_ticks++;
70  rtems_clock_tick();
71}
72
73static void
74Clock_exit (void)
75{
76  /*
77   * Turn off periodic interval timer
78   */
79  SIMPITR = 0;
80}
81
82static void
83Install_clock (rtems_isr_entry clock_isr)
84{
85  uint32_t   pitr_tmp;
86  uint32_t   usecs_per_tick;
87
88  Clock_driver_ticks = 0;
89
90  set_vector (clock_isr, CLOCK_VECTOR, 1);
91
92  /* sets the Periodic Interrupt Control Register PICR */
93  SIMPICR = ( CLOCK_IRQ_LEVEL << 8 ) | ( CLOCK_VECTOR );
94
95  /* sets the PITR count value */
96  /* this assumes a 32.765 kHz crystal */
97
98  usecs_per_tick = rtems_configuration_get_microseconds_per_tick();
99  /* find out whether prescaler should be enabled or not */
100  if ( usecs_per_tick <= 31128 ) {
101     pitr_tmp = ( usecs_per_tick * 8192 ) / 1000000 ;
102  } else {
103     pitr_tmp = ( usecs_per_tick / 1000000 ) * 16;
104     /* enable it */
105     pitr_tmp |= 0x100;
106  }
107
108  SIMPITR = (unsigned char) pitr_tmp;
109
110  atexit (Clock_exit);
111}
112
113void _Clock_Initialize( void )
114{
115  Install_clock (Clock_isr);
116}
Note: See TracBrowser for help on using the repository browser.