Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
timer_irq.c
Go to the documentation of this file.
1#include <LPC17xx.h>
2#include <stdlib.h>
3#include "timer.h"
4
11
12// PRIVATE FUNCTIONS
13
20_PRIVATE bool who_did_interrupt(u8 which, u8 source)
21{
22 switch (which)
23 {
24 case 0:
25 return LPC_TIM0->IR & (1 << source);
26 case 1:
27 return LPC_TIM1->IR & (1 << source);
28 case 2:
29 return LPC_TIM2->IR & (1 << source);
30 case 3:
31 return LPC_TIM3->IR & (1 << source);
32 }
33
34 return false;
35}
36
39_PRIVATE void clear_interrupt(u8 which, u8 source)
40{
41 switch (which)
42 {
43 case 0:
44 SET_BIT(LPC_TIM0->IR, source);
45 break;
46 case 1:
47 SET_BIT(LPC_TIM1->IR, source);
48 break;
49 case 2:
50 SET_BIT(LPC_TIM2->IR, source);
51 break;
52 case 3:
53 SET_BIT(LPC_TIM3->IR, source);
54 break;
55 }
56}
57
58// PUBLIC FUNCTIONS
59
61{
62 handlers[timer.which * TIM_INT_SRC_COUNT + source] = handler;
63}
64
66{
67 handlers[timer.which * TIM_INT_SRC_COUNT + source] = NULL;
68}
69
70// INTERRUPT HANDLERS.
71
72extern void TIMER0_IRQHandler(void)
73{
75 {
77 if (handlers[0])
78 handlers[0]();
79 }
80
82 {
84 if (handlers[1])
85 handlers[1]();
86 }
87
89 {
91 if (handlers[2])
92 handlers[2]();
93 }
94
96 {
98 if (handlers[3])
99 handlers[3]();
100 }
101}
102
103extern void TIMER1_IRQHandler(void)
104{
106 {
108 if (handlers[4])
109 handlers[4]();
110 }
111
113 {
115 if (handlers[5])
116 handlers[5]();
117 }
118
120 {
122 if (handlers[6])
123 handlers[6]();
124 }
125
127 {
129 if (handlers[7])
130 handlers[7]();
131 }
132}
133
134extern void TIMER2_IRQHandler(void)
135{
137 {
139 if (handlers[8])
140 handlers[8]();
141 }
142
144 {
146 if (handlers[9])
147 handlers[9]();
148 }
149
151 {
153 if (handlers[10])
154 handlers[10]();
155 }
156
158 {
160 if (handlers[11])
161 handlers[11]();
162 }
163}
164
165extern void TIMER3_IRQHandler(void)
166{
168 {
170 if (handlers[12])
171 handlers[12]();
172 }
173
175 {
177 if (handlers[13])
178 handlers[13]();
179 }
180
182 {
184 if (handlers[14])
185 handlers[14]();
186 }
187
189 {
191 if (handlers[15])
192 handlers[15]();
193 }
194}
u8 which
Definition timer_types.h:44
void TIMER2_IRQHandler(void)
Definition timer_irq.c:134
_PRIVATE bool who_did_interrupt(u8 which, u8 source)
Checks the TIMER's Interrupt Register and returns whether the interrupt was triggered by the specifie...
Definition timer_irq.c:20
void TIMER0_IRQHandler(void)
Definition timer_irq.c:72
_PRIVATE void clear_interrupt(u8 which, u8 source)
Clears the interrupt flag for the specified source.
Definition timer_irq.c:39
void TIMER1_IRQHandler(void)
Definition timer_irq.c:103
void TIMER3_IRQHandler(void)
Definition timer_irq.c:165
void TIMER_UnsetInterruptHandler(TIMER timer, u8 source)
Unsets the interrupt handler for a TIMER peripheral, on a specific source between the 4 match registe...
Definition timer_irq.c:65
void TIMER_SetInterruptHandler(TIMER timer, u8 source, TIMER_InterruptHandler handler)
Sets the interrupt handler for a TIMER peripheral, on a specific source between the 4 match registers...
Definition timer_irq.c:60
_PRIVATE TIMER_InterruptHandler handlers[TIM_COUNT *TIM_INT_SRC_COUNT]
Array of function pointers to the interrupt handlers for each TIMER peripheral. The array is of size ...
Definition timer_irq.c:10
@ TIM_COUNT
Definition timer_types.h:15
void(* TIMER_InterruptHandler)(void)
Definition timer_types.h:67
@ TIM_INT_SRC_COUNT
Definition timer_types.h:63
@ TIM_INT_SRC_MR2
Definition timer_types.h:57
@ TIM_INT_SRC_MR1
Definition timer_types.h:56
@ TIM_INT_SRC_MR3
Definition timer_types.h:58
@ TIM_INT_SRC_MR0
Definition timer_types.h:55
#define SET_BIT(reg, bit)
Definition types.h:26
uint8_t u8
Definition types.h:8
#define _PRIVATE
Definition types.h:37