forked from iorodeo/panels_g3_firmware
/
single_handler.c
104 lines (77 loc) · 2.48 KB
/
single_handler.c
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
/*
Interrupt Handler Routines
By Robert Bailey
Revision History:
11.15.02 RB Created
03.05.04 Modified by MBR to function as only the handler for a single interrupt
to cut down on overhead.
*/
/*
Description: This file contains the interrupt handler for the system. The registered interrupts are called according to their time interval.
The units of time are the overflow of the 8 bit counter.
*/
#include "single_handler.h"
//#include <avr/signal.h> - obsolete
#include <avr/interrupt.h>
/* Handler Routine Variables */
volatile unsigned long count; /* functions counts */
unsigned long start_count; /* functions start counts */
void (*p_handler_func)(void); /* handler function pointers */
unsigned char mask; /* interrupt mask */
/* Handler Routines */
/*
Function Name: Handler_Init
Description: Initializes routines and timer for the interrupt handler.
Arguments: none
Return Values: none
Limitations:
Notes:
*/
void Handler_Init(void)
{
cli();
mask = FALSE; /* Initialize mask to FALSE */
outp(TCCR0_VAL,TCCR0B); /* write timer prescaler */
sbi(TIMSK0,TOIE0); /* enable timer ovf irq */
sei(); /* enable interrupts */
}
/*
Function Name: SIG_OVERFLOW0
Description: The interrupt handler function of the timer0 interrupt.
Arguments: none
Return Values: none
Limitations:
Notes:
*/
SIGNAL(TIMER0_OVF_vect) /* timer 0 ovf int handler */
{
cbi(TIMSK0,TOIE0); /* disable timer ovf irq */
if(mask==TRUE) /* if int enabled check count */
count--;
if(count==0) /* if count=0, perform function call and reset */
{
count=start_count;
(*p_handler_func) ();
}
sbi(TIMSK0,TOIE0); /* enable timer ovf irq */
}
/*
Function Name: Reg_Handler
Description: Registers a timed interrupt request with the interrupt handler.
Arguments:
void* fptr = function pointer to the handler function
long s_cnt = start count of the timer
unsigned char priority = priority of the interrupt request
unsigned char msk = the mask of the interrupt. TRUE/FALSE value
Return Values: none
Limitations:
Notes:
*/
void Reg_Handler(void* fptr,unsigned long s_cnt,unsigned char msk)
{
mask = FALSE; /* disable while modifying vector */
p_handler_func =fptr; /* set function pointer */
start_count =s_cnt; /* set start count */
count=s_cnt; /* set count */
mask =msk; /* set interrupt mask */
}