Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
timer_irq.c File Reference
#include <LPC17xx.h>
#include <stdlib.h>
#include "timer.h"

Go to the source code of this file.

Functions

_PRIVATE bool who_did_interrupt (u8 which, u8 source)
 Checks the TIMER's Interrupt Register and returns whether the interrupt was triggered by the specified source, which is of type TIMER_Interrupt_Source.
 
_PRIVATE void clear_interrupt (u8 which, u8 source)
 Clears the interrupt flag for the specified source.
 
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 and 2 capture channels (enum TIMER_InterruptSource).
 
void TIMER_UnsetInterruptHandler (TIMER timer, u8 source)
 Unsets the interrupt handler for a TIMER peripheral, on a specific source between the 4 match registers and 2 capture channels (enum TIMER_InterruptSource).
 
void TIMER0_IRQHandler (void)
 
void TIMER1_IRQHandler (void)
 
void TIMER2_IRQHandler (void)
 
void TIMER3_IRQHandler (void)
 

Variables

_PRIVATE TIMER_InterruptHandler handlers [TIM_COUNT *TIM_INT_SRC_COUNT] = {NULL}
 Array of function pointers to the interrupt handlers for each TIMER peripheral. The array is of size TIM_COUNT * TIM_INT_SRC_COUNT, where TIM_COUNT is 4 and TIM_INT_SRC_COUNT is the number of interrupt sources (4 match registers and 2 capture channels, although the latter are not implemented in this library).
 

Function Documentation

◆ clear_interrupt()

_PRIVATE void clear_interrupt ( u8  which,
u8  source 
)

Clears the interrupt flag for the specified source.

Note
IR expects a 1 to clear the interrupt flag.

Definition at line 39 of file timer_irq.c.

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}
#define SET_BIT(reg, bit)
Definition types.h:26

◆ TIMER0_IRQHandler()

void TIMER0_IRQHandler ( void  )
extern

Definition at line 72 of file timer_irq.c.

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}
_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
_PRIVATE void clear_interrupt(u8 which, u8 source)
Clears the interrupt flag for the specified source.
Definition timer_irq.c:39
_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_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

◆ TIMER1_IRQHandler()

void TIMER1_IRQHandler ( void  )
extern

Definition at line 103 of file timer_irq.c.

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}

◆ TIMER2_IRQHandler()

void TIMER2_IRQHandler ( void  )
extern

Definition at line 134 of file timer_irq.c.

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}

◆ TIMER3_IRQHandler()

void TIMER3_IRQHandler ( void  )
extern

Definition at line 165 of file timer_irq.c.

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}

◆ TIMER_SetInterruptHandler()

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 and 2 capture channels (enum TIMER_InterruptSource).

Parameters
timerTIMER peripheral
sourceInterrupt source (enum TIMER_InterruptSource)
handlerFunction pointer to the interrupt handler: void function(void)

Definition at line 60 of file timer_irq.c.

61{
62 handlers[timer.which * TIM_INT_SRC_COUNT + source] = handler;
63}
u8 which
Definition timer_types.h:44
@ TIM_INT_SRC_COUNT
Definition timer_types.h:63

◆ TIMER_UnsetInterruptHandler()

void TIMER_UnsetInterruptHandler ( TIMER  timer,
u8  source 
)

Unsets the interrupt handler for a TIMER peripheral, on a specific source between the 4 match registers and 2 capture channels (enum TIMER_InterruptSource).

Parameters
timerTIMER peripheral
sourceInterrupt source (enum TIMER_InterruptSource)

Definition at line 65 of file timer_irq.c.

66{
67 handlers[timer.which * TIM_INT_SRC_COUNT + source] = NULL;
68}

◆ who_did_interrupt()

_PRIVATE bool who_did_interrupt ( u8  which,
u8  source 
)

Checks the TIMER's Interrupt Register and returns whether the interrupt was triggered by the specified source, which is of type TIMER_Interrupt_Source.

Parameters
sourceA TIMER_Interrupt_Source object
Note
IR has bits [0..3] for the 4 MR available, and 2 bits [4, 5] for the 2 capture channels, that have NOT been implemented in this library yet. Hence, although they've been added to the enum for completeness, they won't work (return false).

Definition at line 20 of file timer_irq.c.

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}

Variable Documentation

◆ handlers

Array of function pointers to the interrupt handlers for each TIMER peripheral. The array is of size TIM_COUNT * TIM_INT_SRC_COUNT, where TIM_COUNT is 4 and TIM_INT_SRC_COUNT is the number of interrupt sources (4 match registers and 2 capture channels, although the latter are not implemented in this library).

Note
This array is updated by TIMER_SetInterruptHandler() and TIMER_UnsetInterruptHandler().

Definition at line 10 of file timer_irq.c.

10{NULL};