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

5
Last change on this file since d7d66d7 was 7632906, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/18 at 04:35:52

bsps: Move clock drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 2.2 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
54void
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
94rtems_device_driver
95Clock_initialize(
96  rtems_device_major_number major,
97  rtems_device_minor_number minor,
98  void *pargp
99)
100{
101  Install_clock (Clock_isr);
102
103  return RTEMS_SUCCESSFUL;
104}
Note: See TracBrowser for help on using the repository browser.