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