Skip to content

Commit 96fb750

Browse files
committed
Added interrupt header file for timer interrupt
1 parent 59184b1 commit 96fb750

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

include/interrupt.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef INTERRUPT_H
2+
#define INTERRUPT_H
3+
4+
#include <stdint.h>
5+
6+
#ifdef __cplusplus
7+
extern "C"
8+
{
9+
#endif
10+
11+
// PL190 VIC (interrupt controller)
12+
// ref: PrimeCell Vectored Interrupt Controller (PL190) TRM (Page3-7)
13+
#define VIC_BASE 0x10140000u
14+
#define VIC_INTSELECT (*(volatile uint32_t *)(VIC_BASE + 0x00C)) // 0=IRQ,1=FIQ
15+
#define VIC_INTENABLE (*(volatile uint32_t *)(VIC_BASE + 0x010)) // set bit=enable
16+
#define VIC_INT_ENCLR (*(volatile utin32_t *)(VIC_BASE + 0x014))
17+
#define VIC_SOFT_INT (*(volatile uint32_t *)(VIC_BASE + 0x018))
18+
#define VIC_SOFT_INTCLR (*(volatile uint32_t *)(VIC_BASE + 0x01C))
19+
20+
// SP804 Timer0 in the 0/1 block
21+
// ref: ARM Dual-Time Module (SP804) TRM (Page 3-2)
22+
#define T01_BASE 0x101E2000u
23+
#define T0_LOAD (*(volatile uint32_t *)(T01_BASE + 0x00))
24+
#define T0_VALUE (*(volatile uint32_t *)(T01_BASE + 0x04))
25+
#define T0_CONTROL (*(volatile uint32_t *)(T01_BASE + 0x08))
26+
#define T0_INTCLR (*(volatile uint32_t *)(T01_BASE + 0x0C))
27+
#define T0_MIS (*(volatile uint32_t *)(T01_BASE + 0x14))
28+
29+
// Bits for CONTROL (SP804)
30+
// ref: ARM Dual-Time Module (SP804) TRM (Page 3-5)
31+
#define TCTRL_ENABLE (1u << 7) // EN=bit7
32+
#define TCTRL_PERIODIC (1u << 6) // PERIODIC=bit6
33+
#define TCTRL_INTEN (1u << 5) // INTEN=bit5
34+
#define TCTRL_32BIT (1u << 1) // 32BIT=bit1
35+
36+
// VIC line number for Timer0/1 on Versatile
37+
#define IRQ_TIMER01 4
38+
39+
static inline void timer0_start_periodic(uint32_t load)
40+
{
41+
T0_CONTROL = 0; // disable while reconfig
42+
T0_LOAD = load; // ex: 10000 for ~100 Hz if TIMCLK≈1 MHz
43+
T0_INTCLR = 1; // clear any pending interrupt
44+
T0_CONTROL = TCTRL_32BIT | TCTRL_PERIODIC | TCTRL_INTEN | TCTRL_ENABLE;
45+
}
46+
47+
static inline void vic_enable_timer01_irq(void)
48+
{
49+
VIC_INTSELECT &= ~(1u << IRQ_TIMER01); // route to IRQ
50+
VIC_INTENABLE |= (1u << IRQ_TIMER01); // enable line 4
51+
}
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif // INTERRUPT_H

0 commit comments

Comments
 (0)