amiro-os / os / core / src / aos_interrupts.c @ 2c99037f
History | View | Annotate | Download (2.798 KB)
1 | 0128be0f | Marc Rothmann | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #include <aos_interrupts.h> |
||
20 | |||
21 | /**
|
||
22 | * @brief Initializes the interrupt driver.
|
||
23 | *
|
||
24 | * @param[out] intd Interrupt driver object.
|
||
25 | * @param[in] interrupt_cfg Interrupt configuration to be used to initialize the driver.
|
||
26 | */
|
||
27 | void aosIntDriverInit(aos_interrupt_driver_t *intd, aos_interrupt_cfg_t *interrupt_cfg) {
|
||
28 | intd->interrupts = interrupt_cfg; |
||
29 | } |
||
30 | |||
31 | /**
|
||
32 | * @brief Starts the interrupt system by setting the pad callbacks and starting the pad events.
|
||
33 | *
|
||
34 | * @param[in] intd Interrupt driver with an interrupt configuration that specifies which interrupts to start.
|
||
35 | */
|
||
36 | void aosIntDriverStart(aos_interrupt_driver_t *intd) {
|
||
37 | irqInit(); |
||
38 | for (uint8_t i = 0; i < intd->len; i++) { |
||
39 | chSysLock(); |
||
40 | palSetPadCallbackI(intd->interrupts[i].port, intd->interrupts[i].pad, intd->interrupts[i].cb, &intd->interrupts[i].cb_arg); |
||
41 | if (intd->interrupts[i].flags & AOS_INTERRUPT_AUTOSTART) {
|
||
42 | palEnablePadEventI(intd->interrupts[i].port, intd->interrupts[i].pad, intd->interrupts[i].eventmode); |
||
43 | } |
||
44 | chSysUnlock(); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /**
|
||
49 | * @brief Stops the interrupt system.
|
||
50 | *
|
||
51 | * @param[in] intd All events associated with this driver will be disabled.
|
||
52 | */
|
||
53 | void aosIntDriverStop(aos_interrupt_driver_t *intd) {
|
||
54 | for (uint8_t i = 0; i < intd->len; i++) { |
||
55 | palDisablePadEvent(intd->interrupts[i].port, intd->interrupts[i].pad); |
||
56 | } |
||
57 | irqDeinit(); |
||
58 | } |
||
59 | |||
60 | /**
|
||
61 | * @brief Enables the events on a specified channel.
|
||
62 | *
|
||
63 | * @param[in] intd Interrupt driver object.
|
||
64 | * @param[in] channel Channel of the interrupt to enable.
|
||
65 | */
|
||
66 | void aosIntEnable(aos_interrupt_driver_t *intd, uint8_t channel) {
|
||
67 | channel -= 1;
|
||
68 | palEnablePadEvent(intd->interrupts[channel].port, intd->interrupts[channel].pad, intd->interrupts[channel].eventmode); |
||
69 | } |
||
70 | |||
71 | /**
|
||
72 | * @brief Disables the events on a specified channel.
|
||
73 | *
|
||
74 | * @param[in] intd Interrupt driver object.
|
||
75 | * @param[in] channel Channel of the interrupt to disable.
|
||
76 | */
|
||
77 | void aosIntDisable(aos_interrupt_driver_t *intd, uint8_t channel) {
|
||
78 | channel -= 1;
|
||
79 | palDisablePadEvent(intd->interrupts[channel].port, intd->interrupts[channel].pad); |
||
80 | } |