RTC auf true
drivers/InterruptIn.cpp@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2013 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | #include "drivers/InterruptIn.h" |
kevman | 0:38ceb79fef03 | 17 | |
kevman | 0:38ceb79fef03 | 18 | #if DEVICE_INTERRUPTIN |
kevman | 0:38ceb79fef03 | 19 | |
kevman | 0:38ceb79fef03 | 20 | namespace mbed { |
kevman | 0:38ceb79fef03 | 21 | |
kevman | 0:38ceb79fef03 | 22 | // Note: This single-parameter constructor exists to maintain binary |
kevman | 0:38ceb79fef03 | 23 | // compatibility. |
kevman | 0:38ceb79fef03 | 24 | // If not for that, we could simplify by having only the 2-param |
kevman | 0:38ceb79fef03 | 25 | // constructor, with a default value for the PinMode. |
kevman | 0:38ceb79fef03 | 26 | InterruptIn::InterruptIn(PinName pin) : gpio(), |
kevman | 0:38ceb79fef03 | 27 | gpio_irq(), |
kevman | 0:38ceb79fef03 | 28 | _rise(NULL), |
kevman | 0:38ceb79fef03 | 29 | _fall(NULL) |
kevman | 0:38ceb79fef03 | 30 | { |
kevman | 0:38ceb79fef03 | 31 | // No lock needed in the constructor |
kevman | 0:38ceb79fef03 | 32 | irq_init(pin); |
kevman | 0:38ceb79fef03 | 33 | gpio_init_in(&gpio, pin); |
kevman | 0:38ceb79fef03 | 34 | } |
kevman | 0:38ceb79fef03 | 35 | |
kevman | 0:38ceb79fef03 | 36 | InterruptIn::InterruptIn(PinName pin, PinMode mode) : |
kevman | 0:38ceb79fef03 | 37 | gpio(), |
kevman | 0:38ceb79fef03 | 38 | gpio_irq(), |
kevman | 0:38ceb79fef03 | 39 | _rise(NULL), |
kevman | 0:38ceb79fef03 | 40 | _fall(NULL) |
kevman | 0:38ceb79fef03 | 41 | { |
kevman | 0:38ceb79fef03 | 42 | // No lock needed in the constructor |
kevman | 0:38ceb79fef03 | 43 | irq_init(pin); |
kevman | 0:38ceb79fef03 | 44 | gpio_init_in_ex(&gpio, pin, mode); |
kevman | 0:38ceb79fef03 | 45 | } |
kevman | 0:38ceb79fef03 | 46 | |
kevman | 0:38ceb79fef03 | 47 | void InterruptIn::irq_init(PinName pin) |
kevman | 0:38ceb79fef03 | 48 | { |
kevman | 0:38ceb79fef03 | 49 | gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); |
kevman | 0:38ceb79fef03 | 50 | } |
kevman | 0:38ceb79fef03 | 51 | |
kevman | 0:38ceb79fef03 | 52 | InterruptIn::~InterruptIn() |
kevman | 0:38ceb79fef03 | 53 | { |
kevman | 0:38ceb79fef03 | 54 | // No lock needed in the destructor |
kevman | 0:38ceb79fef03 | 55 | gpio_irq_free(&gpio_irq); |
kevman | 0:38ceb79fef03 | 56 | } |
kevman | 0:38ceb79fef03 | 57 | |
kevman | 0:38ceb79fef03 | 58 | int InterruptIn::read() |
kevman | 0:38ceb79fef03 | 59 | { |
kevman | 0:38ceb79fef03 | 60 | // Read only |
kevman | 0:38ceb79fef03 | 61 | return gpio_read(&gpio); |
kevman | 0:38ceb79fef03 | 62 | } |
kevman | 0:38ceb79fef03 | 63 | |
kevman | 0:38ceb79fef03 | 64 | void InterruptIn::mode(PinMode pull) |
kevman | 0:38ceb79fef03 | 65 | { |
kevman | 0:38ceb79fef03 | 66 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 67 | gpio_mode(&gpio, pull); |
kevman | 0:38ceb79fef03 | 68 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 69 | } |
kevman | 0:38ceb79fef03 | 70 | |
kevman | 0:38ceb79fef03 | 71 | void InterruptIn::rise(Callback<void()> func) |
kevman | 0:38ceb79fef03 | 72 | { |
kevman | 0:38ceb79fef03 | 73 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 74 | if (func) { |
kevman | 0:38ceb79fef03 | 75 | _rise = func; |
kevman | 0:38ceb79fef03 | 76 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
kevman | 0:38ceb79fef03 | 77 | } else { |
kevman | 0:38ceb79fef03 | 78 | _rise = NULL; |
kevman | 0:38ceb79fef03 | 79 | gpio_irq_set(&gpio_irq, IRQ_RISE, 0); |
kevman | 0:38ceb79fef03 | 80 | } |
kevman | 0:38ceb79fef03 | 81 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 82 | } |
kevman | 0:38ceb79fef03 | 83 | |
kevman | 0:38ceb79fef03 | 84 | void InterruptIn::fall(Callback<void()> func) |
kevman | 0:38ceb79fef03 | 85 | { |
kevman | 0:38ceb79fef03 | 86 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 87 | if (func) { |
kevman | 0:38ceb79fef03 | 88 | _fall = func; |
kevman | 0:38ceb79fef03 | 89 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
kevman | 0:38ceb79fef03 | 90 | } else { |
kevman | 0:38ceb79fef03 | 91 | _fall = NULL; |
kevman | 0:38ceb79fef03 | 92 | gpio_irq_set(&gpio_irq, IRQ_FALL, 0); |
kevman | 0:38ceb79fef03 | 93 | } |
kevman | 0:38ceb79fef03 | 94 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 95 | } |
kevman | 0:38ceb79fef03 | 96 | |
kevman | 0:38ceb79fef03 | 97 | void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) |
kevman | 0:38ceb79fef03 | 98 | { |
kevman | 0:38ceb79fef03 | 99 | InterruptIn *handler = (InterruptIn *)id; |
kevman | 0:38ceb79fef03 | 100 | switch (event) { |
kevman | 0:38ceb79fef03 | 101 | case IRQ_RISE: |
kevman | 0:38ceb79fef03 | 102 | if (handler->_rise) { |
kevman | 0:38ceb79fef03 | 103 | handler->_rise(); |
kevman | 0:38ceb79fef03 | 104 | } |
kevman | 0:38ceb79fef03 | 105 | break; |
kevman | 0:38ceb79fef03 | 106 | case IRQ_FALL: |
kevman | 0:38ceb79fef03 | 107 | if (handler->_fall) { |
kevman | 0:38ceb79fef03 | 108 | handler->_fall(); |
kevman | 0:38ceb79fef03 | 109 | } |
kevman | 0:38ceb79fef03 | 110 | break; |
kevman | 0:38ceb79fef03 | 111 | case IRQ_NONE: |
kevman | 0:38ceb79fef03 | 112 | break; |
kevman | 0:38ceb79fef03 | 113 | } |
kevman | 0:38ceb79fef03 | 114 | } |
kevman | 0:38ceb79fef03 | 115 | |
kevman | 0:38ceb79fef03 | 116 | void InterruptIn::enable_irq() |
kevman | 0:38ceb79fef03 | 117 | { |
kevman | 0:38ceb79fef03 | 118 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 119 | gpio_irq_enable(&gpio_irq); |
kevman | 0:38ceb79fef03 | 120 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 121 | } |
kevman | 0:38ceb79fef03 | 122 | |
kevman | 0:38ceb79fef03 | 123 | void InterruptIn::disable_irq() |
kevman | 0:38ceb79fef03 | 124 | { |
kevman | 0:38ceb79fef03 | 125 | core_util_critical_section_enter(); |
kevman | 0:38ceb79fef03 | 126 | gpio_irq_disable(&gpio_irq); |
kevman | 0:38ceb79fef03 | 127 | core_util_critical_section_exit(); |
kevman | 0:38ceb79fef03 | 128 | } |
kevman | 0:38ceb79fef03 | 129 | |
kevman | 0:38ceb79fef03 | 130 | InterruptIn::operator int() |
kevman | 0:38ceb79fef03 | 131 | { |
kevman | 0:38ceb79fef03 | 132 | // Underlying call is atomic |
kevman | 0:38ceb79fef03 | 133 | return read(); |
kevman | 0:38ceb79fef03 | 134 | } |
kevman | 0:38ceb79fef03 | 135 | |
kevman | 0:38ceb79fef03 | 136 | } // namespace mbed |
kevman | 0:38ceb79fef03 | 137 | |
kevman | 0:38ceb79fef03 | 138 | #endif |