interrupt-sender.c 898 Bytes
Newer Older
1 2 3 4
#include "api/interrupt-sender.h"
#include "api/common.h"
#include "tmr_utils.h"

5
static bool int_enabled[EPIC_INT_NUM];
6

7
int api_interrupt_trigger(api_int_id_t id)
8
{
9
	if (id >= EPIC_INT_NUM) {
10
		return -EINVAL;
11
	}
12

13
	if (int_enabled[id]) {
14
		while (API_CALL_MEM->int_id != (-1))
15
			;
16

17
		API_CALL_MEM->int_id = id;
18
		TMR_TO_Start(MXC_TMR3, 1, 0);
19 20
	}
	return 0;
21 22 23 24
}

void api_interrupt_init(void)
{
25
	API_CALL_MEM->int_id = (-1);
26

27 28
	for (int i = 0; i < EPIC_INT_NUM; i++) {
		int_enabled[i] = false;
29
	}
30 31 32

	/* Reset interrupt is always enabled */
	int_enabled[EPIC_INT_RESET] = true;
33 34
}

35
int epic_interrupt_enable(api_int_id_t int_id)
36
{
37
	if (int_id >= EPIC_INT_NUM) {
38
		return -EINVAL;
39
	}
40

41
	int_enabled[int_id] = true;
42
	return 0;
43 44
}

45
int epic_interrupt_disable(api_int_id_t int_id)
46
{
47
	if (int_id >= EPIC_INT_NUM || int_id == EPIC_INT_RESET) {
48
		return -EINVAL;
49
	}
50

51
	int_enabled[int_id] = false;
52
	return 0;
53
}