1 #include <system_def.h>
6 // -------------------------------------------------------------------------
9 // Return value of VPBDIV register. According to errata doc
10 // we need to read twice consecutively to get correct value
11 uint32_t lpc_get_vpbdiv(void)
22 // -------------------------------------------------------------------------
23 // This routine is called to respond to a hardware interrupt (IRQ). It
24 // should interrogate the hardware and return the IRQ vector number.
25 int hal_IRQ_handler(void)
27 uint32_t irq_num, irq_stat;
29 irq_stat=VICIRQStatus;
30 for (irq_num = 0; irq_num < 32; irq_num++)
31 if (irq_stat & (1 << irq_num))
34 // If not a valid interrrupt source, treat as spurious interrupt
35 if (irq_num < HAL_ISR_MIN || irq_num > HAL_ISR_MAX)
36 irq_num = HAL_INTERRUPT_NONE;
42 // -------------------------------------------------------------------------
46 // Block the the interrupt associated with the vector
47 void hal_interrupt_mask(int vector)
49 VICIntEnClear = 1 << vector;
52 // Unblock the the interrupt associated with the vector
53 void hal_interrupt_unmask(int vector)
55 VICIntEnable = 1 << vector;
58 // Acknowledge the the interrupt associated with the vector. This
59 // clears the interrupt but may result in another interrupt being
61 void hal_interrupt_acknowledge(int vector)
64 // External interrupts have to be cleared from the EXTINT register
65 if (vector >= HAL_INTERRUPT_EINT0 &&
66 vector <= HAL_INTERRUPT_EINT3)
68 // Map int vector to corresponding bit (0..3)
69 vector = 1 << (vector - HAL_INTERRUPT_EINT0);
71 // Clear the external interrupt
75 // Acknowledge interrupt in the VIC
79 // This provides control over how an interrupt signal is detected.
80 // Options are between level or edge sensitive (level) and high/low
81 // level or rising/falling edge triggered (up).
83 // This should be simple, but unfortunately on some processor revisions,
84 // it trips up on two errata issues (for the LPC2294 Rev.A these are
85 // EXTINT.1 and VPBDIV.1) and so on these devices a somewhat convoluted
86 // sequence in order to work properly. There is nothing in the errata
87 // sequence that won't work on a processor without these issues.
88 void hal_interrupt_configure(int vector, int level, int up)
91 #ifdef HAL_ARM_LPC2XXX_EXTINT_ERRATA
92 uint32_t saved_vpbdiv;
95 // Map int vector to corresponding bit (0..3)
96 vector = 1 << (vector - HAL_INTERRUPT_EINT0);
98 #ifdef HAL_ARM_LPC2XXX_EXTINT_ERRATA
99 // From discussions with the Philips applications engineers on the
100 // Yahoo LPC2000 forum, it appears that in order up change both
101 // EXTMODE and EXTPOLAR, the operations have to be performed in
102 // two passes as follows:
104 // VPBDIV=0, EXTMODE=n, VPBDIV=n, VPBDIV=0, EXTPOLAR=y, VPBDIV=y
107 // Save current VPBDIV register settings
108 saved_vpbdiv = lpc_get_vpbdiv();
110 // Clear VPBDIV register
113 // Read current mode and update for level (0) or edge detection (1)
121 // Set VPBDIV register to same value as mode
124 // Clear VPBDIV register
127 // Read current polarity and update for trigger level or edge
128 // level: high (1), low (0) edge: rising (1), falling (0)
137 // Set VPBDIV register to same value as mode
140 // Restore saved VPBDIV register
143 // Read current mode and update for level (0) or edge detection (1)
151 // Read current polarity and update for trigger level or edge
152 // level: high (1), low (0) edge: rising (1), falling (0)
160 // Clear any spurious interrupt that might have been generated
164 // Change interrupt level. This is a non-operation on the LPC2XXX
165 void hal_interrupt_set_level(int vector, int level)
169 uint32_t hal_default_isr(int vector, uint32_t data)
174 uint32_t hal_interrupt_handlers[HAL_ISR_COUNT]={[0 ... HAL_ISR_COUNT-1]=(uint32_t)hal_default_isr};
175 uint32_t hal_interrupt_data[HAL_ISR_COUNT];
177 void irq_handler_resolver(void) __attribute__ ((interrupt));
178 void irq_handler_resolver(void)
184 if (v==HAL_INTERRUPT_NONE) return;
185 f=hal_interrupt_handlers[v];
186 d=hal_interrupt_data[v];
188 hal_interrupt_acknowledge(v);