From c32b1efa43e31bd9a8a7eae3623664d00c34d842 Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Sat, 23 Mar 2013 19:13:07 +0100 Subject: bsp/raspberrypi: New BSP --- c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c | 91 +++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c (limited to 'c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c') diff --git a/c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c b/c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c new file mode 100644 index 0000000000..d50ae32d1e --- /dev/null +++ b/c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c @@ -0,0 +1,91 @@ +/* + * BCM2835 Clock driver + * + * Copyright (c) 2013 Alan Cudmore + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * + * http://www.rtems.com/license/LICENSE + * +*/ + +#include +#include +#include +#include + +/* This is defined in ../../../shared/clockdrv_shell.h */ +void Clock_isr(rtems_irq_hdl_param arg); + +static void raspberrypi_clock_at_tick(void) +{ + BCM2835_REG(BCM2835_TIMER_CLI) = 0; +} + +static void raspberrypi_clock_handler_install(void) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + + sc = rtems_interrupt_handler_install( + BCM2835_IRQ_ID_TIMER_0, + "Clock", + RTEMS_INTERRUPT_UNIQUE, + (rtems_interrupt_handler) Clock_isr, + NULL + ); + if (sc != RTEMS_SUCCESSFUL) { + rtems_fatal_error_occurred(0xdeadbeef); + } +} + +static void raspberrypi_clock_initialize(void) +{ + BCM2835_REG(BCM2835_TIMER_CTL) = 0x003E0000; + BCM2835_REG(BCM2835_TIMER_LOD) = 10000 - 1; + BCM2835_REG(BCM2835_TIMER_RLD) = 10000 - 1; + BCM2835_REG(BCM2835_TIMER_DIV) = BCM2835_TIMER_PRESCALE; + BCM2835_REG(BCM2835_TIMER_CLI) = 0; + BCM2835_REG(BCM2835_TIMER_CTL) = 0x003E00A2; +} + +static void raspberrypi_clock_cleanup(void) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + + /* Remove interrupt handler */ + sc = rtems_interrupt_handler_remove( + BCM2835_IRQ_ID_TIMER_0, + (rtems_interrupt_handler) Clock_isr, + NULL + ); + if (sc != RTEMS_SUCCESSFUL) { + rtems_fatal_error_occurred(0xdeadbeef); + } +} + +/* + * Return the nanoseconds since last tick + */ +static uint32_t raspberrypi_clock_nanoseconds_since_last_tick(void) +{ + return 0; +} + +#define Clock_driver_support_at_tick() raspberrypi_clock_at_tick() + +#define Clock_driver_support_initialize_hardware() raspberrypi_clock_initialize() + +#define Clock_driver_support_install_isr(isr, old_isr) \ + do { \ + raspberrypi_clock_handler_install(); \ + old_isr = NULL; \ + } while (0) + +#define Clock_driver_support_shutdown_hardware() raspberrypi_clock_cleanup() + +#define Clock_driver_nanoseconds_since_last_tick \ + raspberrypi_clock_nanoseconds_since_last_tick + + +#include "../../../shared/clockdrv_shell.h" -- cgit v1.2.3