source: rtems/c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup bsp_clock
5 *
6 * @brief Raspberry Pi clock support.
7 */
8
9/*
10 * BCM2835 Clock driver
11 *
12 * Copyright (c) 2013 Alan Cudmore
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *
17 *  http://www.rtems.org/license/LICENSE
18 *
19*/
20
21#include <rtems.h>
22#include <bsp.h>
23#include <bsp/irq.h>
24#include <bsp/raspberrypi.h>
25
26/* This is defined in ../../../shared/clockdrv_shell.h */
27void Clock_isr(rtems_irq_hdl_param arg);
28
29static void raspberrypi_clock_at_tick(void)
30{
31   BCM2835_REG(BCM2835_TIMER_CLI) = 0;
32}
33
34static void raspberrypi_clock_handler_install(void)
35{
36  rtems_status_code sc = RTEMS_SUCCESSFUL;
37
38  sc = rtems_interrupt_handler_install(
39    BCM2835_IRQ_ID_TIMER_0,
40    "Clock",
41    RTEMS_INTERRUPT_UNIQUE,
42    (rtems_interrupt_handler) Clock_isr,
43    NULL
44  );
45  if (sc != RTEMS_SUCCESSFUL) {
46    rtems_fatal_error_occurred(0xdeadbeef);
47  }
48}
49
50static void raspberrypi_clock_initialize(void)
51{
52   BCM2835_REG(BCM2835_TIMER_CTL) = 0x003E0000;
53   BCM2835_REG(BCM2835_TIMER_LOD) = 10000 - 1;
54   BCM2835_REG(BCM2835_TIMER_RLD) = 10000 - 1;
55   BCM2835_REG(BCM2835_TIMER_DIV) = BCM2835_TIMER_PRESCALE;
56   BCM2835_REG(BCM2835_TIMER_CLI) = 0;
57   BCM2835_REG(BCM2835_TIMER_CTL) = 0x003E00A2;
58}
59
60static void raspberrypi_clock_cleanup(void)
61{
62  rtems_status_code sc = RTEMS_SUCCESSFUL;
63
64  /* Remove interrupt handler */
65  sc = rtems_interrupt_handler_remove(
66    BCM2835_IRQ_ID_TIMER_0,
67    (rtems_interrupt_handler) Clock_isr,
68    NULL
69  );
70  if (sc != RTEMS_SUCCESSFUL) {
71    rtems_fatal_error_occurred(0xdeadbeef);
72  }
73}
74
75/*
76 *  Return the nanoseconds since last tick
77 */
78static uint32_t raspberrypi_clock_nanoseconds_since_last_tick(void)
79{
80  return 0;
81}
82
83#define Clock_driver_support_at_tick() raspberrypi_clock_at_tick()
84
85#define Clock_driver_support_initialize_hardware() raspberrypi_clock_initialize()
86
87#define Clock_driver_support_install_isr(isr, old_isr) \
88  do {                                                 \
89    raspberrypi_clock_handler_install();               \
90    old_isr = NULL;                                    \
91  } while (0)
92
93#define Clock_driver_support_shutdown_hardware() raspberrypi_clock_cleanup()
94
95#define Clock_driver_nanoseconds_since_last_tick \
96  raspberrypi_clock_nanoseconds_since_last_tick
97
98
99#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.