summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/raspberrypi/irq/irq.c
blob: ce5b363f5d101bfa35a24f4c625ef4d16eaf8fcd (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
 * @file
 *
 * @ingroup raspberrypi_interrupt
 *
 * @brief Interrupt support.
 */

/*
 * Copyright (c) 2009
 * embedded brains GmbH
 * Obere Lagerstr. 30
 * D-82178 Puchheim
 * Germany
 * <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#include <rtems/score/armv4.h>

#include <bsp.h>
#include <bsp/irq.h>
#include <bsp/irq-generic.h>
#include <bsp/raspberrypi.h>
#include <bsp/linker-symbols.h>
#include <bsp/mmu.h>

/*
** Determine the source of the interrupt and dispatch the correct handler.
*/
void bsp_interrupt_dispatch(void)
{
  rtems_vector_number vector = 255;

  /* ARM timer */
  if (BCM2835_REG(BCM2835_IRQ_BASIC) && 0x1)
  {
      vector = BCM2835_IRQ_ID_TIMER_0;

  }
  /* UART 0 */
  else if ( BCM2835_REG(BCM2835_IRQ_BASIC) && BCM2835_BIT(19))
  {
      vector = BCM2835_IRQ_ID_UART;
  }

  if ( vector < 255 )
  {
      bsp_interrupt_handler_dispatch(vector);
  }

}

rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)
{
  rtems_interrupt_level  level;

  rtems_interrupt_disable(level);

   /* ARM Timer */
  if ( vector == BCM2835_IRQ_ID_TIMER_0 )
  {
      BCM2835_REG(BCM2835_IRQ_ENABLE_BASIC) = 0x1;
  }
  /* UART 0 */
  else if ( vector == BCM2835_IRQ_ID_UART )
  {
      BCM2835_REG(BCM2835_IRQ_ENABLE2) =  BCM2835_BIT(25);

  }
  rtems_interrupt_enable(level);

  return RTEMS_SUCCESSFUL;
}

rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)
{
  rtems_interrupt_level level;

  rtems_interrupt_disable(level);

  if ( vector == BCM2835_IRQ_ID_TIMER_0 )
  {
      BCM2835_REG(BCM2835_IRQ_DISABLE_BASIC) = 0x1;
  }
  else if ( vector == BCM2835_IRQ_ID_UART )
  {
      BCM2835_REG(BCM2835_IRQ_DISABLE2) = BCM2835_BIT(25);
  }
  rtems_interrupt_enable(level);

  return RTEMS_SUCCESSFUL;
}


void bsp_interrupt_handler_default(rtems_vector_number vector)
{
    printk("spurious interrupt: %u\n", vector);
}

rtems_status_code bsp_interrupt_facility_initialize(void)
{
   BCM2835_REG(BCM2835_IRQ_DISABLE1) = 0xffffffff;
   BCM2835_REG(BCM2835_IRQ_DISABLE2) = 0xffffffff;
   BCM2835_REG(BCM2835_IRQ_DISABLE_BASIC) = 0xffffffff;
   BCM2835_REG(BCM2835_IRQ_FIQ_CTRL) = 0;
   return RTEMS_SUCCESSFUL;
}