1 |
198 |
zero_gravi |
// #################################################################################################
|
2 |
|
|
// # < External Interrupts Controller test program > #
|
3 |
|
|
// # ********************************************************************************************* #
|
4 |
|
|
// # BSD 3-Clause License #
|
5 |
|
|
// # #
|
6 |
|
|
// # Copyright (c) 2020, Stephan Nolting. All rights reserved. #
|
7 |
|
|
// # #
|
8 |
|
|
// # Redistribution and use in source and binary forms, with or without modification, are #
|
9 |
|
|
// # permitted provided that the following conditions are met: #
|
10 |
|
|
// # #
|
11 |
|
|
// # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
12 |
|
|
// # conditions and the following disclaimer. #
|
13 |
|
|
// # #
|
14 |
|
|
// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
15 |
|
|
// # conditions and the following disclaimer in the documentation and/or other materials #
|
16 |
|
|
// # provided with the distribution. #
|
17 |
|
|
// # #
|
18 |
|
|
// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
19 |
|
|
// # endorse or promote products derived from this software without specific prior written #
|
20 |
|
|
// # permission. #
|
21 |
|
|
// # #
|
22 |
|
|
// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
23 |
|
|
// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
24 |
|
|
// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
25 |
|
|
// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
26 |
|
|
// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
27 |
|
|
// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
28 |
|
|
// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
29 |
|
|
// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
30 |
|
|
// # OF THE POSSIBILITY OF SUCH DAMAGE. #
|
31 |
|
|
// # ********************************************************************************************* #
|
32 |
|
|
// # The NEO430 Processor - https://github.com/stnolting/neo430 #
|
33 |
|
|
// #################################################################################################
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
// Libraries
|
37 |
|
|
#include <neo430.h>
|
38 |
|
|
|
39 |
|
|
// Configuration
|
40 |
|
|
#define BAUD_RATE 19200
|
41 |
|
|
|
42 |
|
|
// Prototypes
|
43 |
|
|
void ext_irq_ch0_handler(void);
|
44 |
|
|
void ext_irq_ch1_handler(void);
|
45 |
|
|
void ext_irq_ch2_handler(void);
|
46 |
|
|
void ext_irq_ch3_handler(void);
|
47 |
|
|
|
48 |
|
|
void ext_irq_ch7_handler(void);
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
/* ------------------------------------------------------------
|
52 |
|
|
* INFO Main function
|
53 |
|
|
* ------------------------------------------------------------ */
|
54 |
|
|
int main(void) {
|
55 |
|
|
|
56 |
|
|
// setup UART
|
57 |
|
|
neo430_uart_setup(BAUD_RATE);
|
58 |
|
|
|
59 |
|
|
// intro text
|
60 |
|
|
neo430_uart_br_print("\n<<< EXIRQ Test >>>\n");
|
61 |
|
|
|
62 |
|
|
// check if EXIRQ was synthesized, exit if not available
|
63 |
|
|
if (!(SYS_FEATURES & (1<<SYS_EXIRQ_EN))) {
|
64 |
|
|
neo430_uart_br_print("Error! No EXIRQ synthesized!");
|
65 |
|
|
return 1;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
neo430_uart_br_print("\nTrigger the external interrupt pin (set high) or perform a manual\n"
|
69 |
|
|
"triggering (sw interrupt) by pressing key 0 to 7.\n");
|
70 |
|
|
|
71 |
|
|
// clear output port
|
72 |
|
|
neo430_gpio_port_set(0);
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
// use this predefined struct for configuring the EXIRQ controller
|
76 |
|
|
struct neo430_exirq_config_t exirq_config;
|
77 |
|
|
|
78 |
|
|
// initialise handler addresses
|
79 |
|
|
exirq_config.address[0] = (uint16_t)(&ext_irq_ch0_handler);
|
80 |
|
|
exirq_config.address[1] = (uint16_t)(&ext_irq_ch1_handler);
|
81 |
|
|
exirq_config.address[2] = (uint16_t)(&ext_irq_ch2_handler);
|
82 |
|
|
exirq_config.address[3] = (uint16_t)(&ext_irq_ch3_handler);
|
83 |
|
|
exirq_config.address[4] = 0; // set unused vectors to zero
|
84 |
|
|
exirq_config.address[5] = 0;
|
85 |
|
|
exirq_config.address[6] = 0;
|
86 |
|
|
exirq_config.address[7] = (uint16_t)(&ext_irq_ch7_handler);
|
87 |
|
|
|
88 |
|
|
// only enable the actually used IRQ channels
|
89 |
|
|
exirq_config.enable = 0b10001111; // each bit represents the according channel
|
90 |
|
|
|
91 |
|
|
// program configuration and activate EXIRQ controller
|
92 |
|
|
neo430_exirq_config(exirq_config);
|
93 |
|
|
neo430_exirq_enable();
|
94 |
|
|
|
95 |
|
|
// enable global interrupts
|
96 |
|
|
neo430_eint();
|
97 |
|
|
|
98 |
|
|
// trigger EXIRQ channel 0 IRQ by software just for fun
|
99 |
|
|
neo430_exirq_sw_irq(0);
|
100 |
|
|
|
101 |
|
|
// wait for key input
|
102 |
|
|
while(1) {
|
103 |
|
|
char c = neo430_uart_getc();
|
104 |
|
|
if ((c >= '0') && (c <= '7')) {
|
105 |
|
|
c = c - '0';
|
106 |
|
|
neo430_exirq_sw_irq((uint8_t)c); // trigger according IRQ by software
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
return 0;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
// handler functions for the external interrupt channels:
|
115 |
|
|
// - must not have parameters nor a return value
|
116 |
|
|
// - should not use the interrupt attribute, as they can be normal functions called by the actual interrupt handler
|
117 |
|
|
|
118 |
|
|
void ext_irq_ch0_handler(void) {
|
119 |
|
|
|
120 |
|
|
neo430_gpio_pin_toggle(0);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
void ext_irq_ch1_handler(void) {
|
125 |
|
|
|
126 |
|
|
neo430_gpio_pin_toggle(1);
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
void ext_irq_ch2_handler(void) {
|
131 |
|
|
|
132 |
|
|
neo430_gpio_pin_toggle(2);
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
void ext_irq_ch3_handler(void) {
|
137 |
|
|
|
138 |
|
|
neo430_gpio_pin_toggle(3);
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
void ext_irq_ch7_handler(void) {
|
143 |
|
|
|
144 |
|
|
neo430_gpio_pin_toggle(7);
|
145 |
|
|
}
|
146 |
|
|
|