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

5
Last change on this file since bb99cd0d was bb99cd0d, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 5, 2019 at 6:22:33 PM

clock: Simplify driver initialization

Use a system initialization handler instead of a legacy IO driver.

Update #3834.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * This routine initializes the MC68340/349 Periodic Interval Timer
3 */
4
5/*
6 * Based on the `gen68360' board support package, and covered by the
7 * original distribution terms.
8 *
9 * Geoffroy Montel
10 * France Telecom - CNET/DSM/TAM/CAT
11 * 4, rue du Clos Courtel
12 * 35512 CESSON-SEVIGNE
13 * FRANCE
14 *
15 * e-mail: g_montel@yahoo.com
16 */
17
18/*
19 * COPYRIGHT (c) 1989-2014.
20 * On-Line Applications Research Corporation (OAR).
21 *
22 * The license and distribution terms for this file may be
23 * found in the file LICENSE in this distribution or at
24 * http://www.rtems.org/license/LICENSE.
25 */
26
27#include <stdlib.h>       /* for atexit() */
28#include <bsp.h>
29#include <m68340.h>
30#include <rtems/clockdrv.h>
31
32#define CLOCK_VECTOR     120 /* clock isr routine vector in the vbr */
33#define CLOCK_IRQ_LEVEL  6   /* clock isr level */
34
35/*
36 * Clock_driver_ticks is a monotonically increasing counter of the
37 * number of clock ticks since the driver was initialized.
38 */
39volatile uint32_t         Clock_driver_ticks;
40
41/*
42 * Periodic interval timer interrupt handler
43 */
44static rtems_isr
45Clock_isr (rtems_vector_number vector)
46{
47  /*
48   * Announce the clock tick
49   */
50  Clock_driver_ticks++;
51  rtems_clock_tick();
52}
53
54static void
55Clock_exit (void)
56{
57  /*
58   * Turn off periodic interval timer
59   */
60  SIMPITR = 0;
61}
62
63static void
64Install_clock (rtems_isr_entry clock_isr)
65{
66  uint32_t   pitr_tmp;
67  uint32_t   usecs_per_tick;
68
69  Clock_driver_ticks = 0;
70
71  set_vector (clock_isr, CLOCK_VECTOR, 1);
72
73  /* sets the Periodic Interrupt Control Register PICR */
74  SIMPICR = ( CLOCK_IRQ_LEVEL << 8 ) | ( CLOCK_VECTOR );
75
76  /* sets the PITR count value */
77  /* this assumes a 32.765 kHz crystal */
78
79  usecs_per_tick = rtems_configuration_get_microseconds_per_tick();
80  /* find out whether prescaler should be enabled or not */
81  if ( usecs_per_tick <= 31128 ) {
82     pitr_tmp = ( usecs_per_tick * 8192 ) / 1000000 ;
83  } else {
84     pitr_tmp = ( usecs_per_tick / 1000000 ) * 16;
85     /* enable it */
86     pitr_tmp |= 0x100;
87  }
88
89  SIMPITR = (unsigned char) pitr_tmp;
90
91  atexit (Clock_exit);
92}
93
94void _Clock_Initialize( void )
95{
96  Install_clock (Clock_isr);
97}
Note: See TracBrowser for help on using the repository browser.