aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/e300/battery/interrupt.c
blob: f0daeddcdc7907b917f5a5052edc6733289580a0 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* USRP E310 Firmware Interrupt Management
 * Copyright (C) 2014 Ettus Research
 * This file is part of the USRP E310 Firmware
 * The USRP E310 Firmware is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 * The USRP E310 Firmware is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with the USRP E310 Firmware. If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdint.h>
#include <avr/interrupt.h>

#include "utils.h"
#include "interrupt.h"

#include "bq2419x.h"
#include "tps54478.h"
#include "ltc3675.h"
#include "ltc294x.h"
#include "pmu.h"
#include "led.h"

static const irq_handler_t pcint0_irqs[] = {bq2419x_irq_handler};
static const irq_handler_t pcint1_irqs[] = {NULL};
static const irq_handler_t pcint2_irqs[] = {NULL};
static const irq_handler_t pcint3_irqs[] = {NULL};
static const irq_handler_t int0_handler = ltc3675_button_wakeup_irq_handler;
static const irq_handler_t int1_handler = ltc3675_button_change_irq_handler;
//static const irq_handler_t timer0_comp_a_handler = pmu_led_timer_comp_a_irq_handler;
//static const irq_handler_t timer0_comp_b_handler = pmu_led_timer_comp_b_irq_handler;
static const irq_handler_t timer1_handler = ltc3675_button_timer_irq_handler;
static const irq_handler_t wdt_handler = {led_wdt_handler};

void interrupt_init(void)
{
	/* rising edge for WAKEUP and any change for ONSWITCH_DB */
	EICRA = BIT(ISC01) | BIT(ISC00) | BIT(ISC10);

	/* enable interrupt for WAKE  */
	EIMSK = BIT(INT1) | BIT(INT0);

	/* enable interrupt for CORE_PGOOD and CHG_IRQ */
	PCMSK0 = /*BIT(PCINT0) | */ BIT(PCINT1);

	/* enable interrupts for PWR_IRQ and AVR_IRQ */
	PCMSK2 = BIT(PCINT16) | BIT(PCINT21);

	/* enable interrupts for FC_ALn_CC */
	//PCMSK3 = BIT(PCINT24);

	/* unmask IRQs for PC[23:16] and PC[7:0] */
	PCICR = BIT(PCIE3) | BIT(PCIE2) | BIT(PCIE0);
}

ISR(PCINT0_vect)
{
	uint8_t i;
	irqreturn_t ret;

	for (i = 0; i < ARRAY_SIZE(pcint0_irqs); i++) {
		irq_handler_t handler = pcint0_irqs[i];
		if (handler != NULL) {
			ret = handler();
			if (ret == IRQ_HANDLED)
				break;
		}
	}
}

ISR(PCINT1_vect)
{
	uint8_t i;
	irqreturn_t ret;

	for (i = 0; i < ARRAY_SIZE(pcint1_irqs); i++) {
		irq_handler_t handler = pcint1_irqs[i];
		if (handler != NULL) {
			ret = handler();
			if (ret == IRQ_HANDLED)
				break;
		}
	}
}

ISR(PCINT2_vect)
{
	uint8_t i;
	irqreturn_t ret;

	for (i = 0; i < ARRAY_SIZE(pcint2_irqs); i++) {
		irq_handler_t handler = pcint2_irqs[i];
		if (handler != NULL) {
			ret = handler();
			if (ret == IRQ_HANDLED)
				break;
		}
	}
}

ISR(PCINT3_vect)
{
	uint8_t i;
	irqreturn_t ret;

	for (i = 0; i < ARRAY_SIZE(pcint3_irqs); i++) {
		irq_handler_t handler = pcint3_irqs[i];
		if (handler != NULL) {
			ret = handler();
			if (ret == IRQ_HANDLED)
				break;
		}
	}
}

ISR(INT0_vect)
{
	if (int0_handler)
		int0_handler();
}

ISR(INT1_vect)
{
	if (int1_handler) {
		int1_handler();
	}
}

/*
ISR(TIMER0_COMPA_vect)
{
	timer0_comp_a_handler();
}

ISR(TIMER0_COMPB_vect)
{
	timer0_comp_b_handler();
}
*/

ISR(TIMER1_COMPA_vect)
{
	timer1_handler();
}

ISR(WDT_vect)
{
	wdt_handler();
}