summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/lm32/shared/milkymist_clock/ckinit.c
blob: 10b86e2848755a78c44c1550ad3ba15d4a7ea63d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*  ckinit.c
 *
 *  Clock device driver for Lattice Mico32 (lm32).
 *
 *  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.
 *
 *  COPYRIGHT (c) Yann Sionneau <yann.sionneau@telecom-sudparis.eu> (GSoC 2010)
 *  Telecom SudParis
 */

#include <bsp.h>
#include <bsp/irq-generic.h>
#include "../include/system_conf.h"
#include "clock.h"
#include "bspopts.h"

#if ON_SIMULATOR
#define CLOCK_DRIVER_USE_FAST_IDLE
#endif

#define Clock_driver_support_at_tick() \
  do { \
    lm32_interrupt_ack(1 << MM_IRQ_TIMER0); \
  } while (0)

#define Clock_driver_support_install_isr(_new, _old ) \
  do { \
    rtems_interrupt_catch(_new, MM_IRQ_TIMER0, &_old); \
  } while (0)

void Clock_driver_support_initialize_hardware(void)
{
  MM_WRITE(MM_TIMER0_COMPARE, 
   (MM_READ(MM_FREQUENCY)/(1000000/rtems_configuration_get_microseconds_per_tick())));
  MM_WRITE(MM_TIMER0_COUNTER, 0);
  MM_WRITE(MM_TIMER0_CONTROL, TIMER_ENABLE | TIMER_AUTORESTART);
  bsp_interrupt_vector_enable(MM_IRQ_TIMER0);
}

void Clock_driver_support_shutdown_hardware(void)
{
  bsp_interrupt_vector_disable(MM_IRQ_TIMER0);
  MM_WRITE(MM_TIMER0_CONTROL, 0);
}

#include "../../../shared/clockdrv_shell.h"