mbed library sources. Supersedes mbed-src. RTC working even after reset
Fork of mbed-dev by
common/InterruptIn.cpp@144:ef7eb2e8f9f7, 2016-09-02 (annotated)
- Committer:
- <>
- Date:
- Fri Sep 02 15:07:44 2016 +0100
- Revision:
- 144:ef7eb2e8f9f7
- Parent:
- 30:748c8b6e75b1
This updates the lib to the mbed lib v125
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* mbed Microcontroller Library |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 144:ef7eb2e8f9f7 | 5 | * you may not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 6 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 144:ef7eb2e8f9f7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 13 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 14 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 15 | */ |
<> | 144:ef7eb2e8f9f7 | 16 | #include "InterruptIn.h" |
<> | 144:ef7eb2e8f9f7 | 17 | |
<> | 144:ef7eb2e8f9f7 | 18 | #if DEVICE_INTERRUPTIN |
<> | 144:ef7eb2e8f9f7 | 19 | |
<> | 144:ef7eb2e8f9f7 | 20 | namespace mbed { |
<> | 144:ef7eb2e8f9f7 | 21 | |
<> | 144:ef7eb2e8f9f7 | 22 | InterruptIn::InterruptIn(PinName pin) : gpio(), |
<> | 144:ef7eb2e8f9f7 | 23 | gpio_irq(), |
<> | 144:ef7eb2e8f9f7 | 24 | _rise(), |
<> | 144:ef7eb2e8f9f7 | 25 | _fall() { |
<> | 144:ef7eb2e8f9f7 | 26 | // No lock needed in the constructor |
<> | 144:ef7eb2e8f9f7 | 27 | gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this); |
<> | 144:ef7eb2e8f9f7 | 28 | gpio_init_in(&gpio, pin); |
<> | 144:ef7eb2e8f9f7 | 29 | } |
<> | 144:ef7eb2e8f9f7 | 30 | |
<> | 144:ef7eb2e8f9f7 | 31 | InterruptIn::~InterruptIn() { |
<> | 144:ef7eb2e8f9f7 | 32 | // No lock needed in the destructor |
<> | 144:ef7eb2e8f9f7 | 33 | gpio_irq_free(&gpio_irq); |
<> | 144:ef7eb2e8f9f7 | 34 | } |
<> | 144:ef7eb2e8f9f7 | 35 | |
<> | 144:ef7eb2e8f9f7 | 36 | int InterruptIn::read() { |
<> | 144:ef7eb2e8f9f7 | 37 | // Read only |
<> | 144:ef7eb2e8f9f7 | 38 | return gpio_read(&gpio); |
<> | 144:ef7eb2e8f9f7 | 39 | } |
<> | 144:ef7eb2e8f9f7 | 40 | |
<> | 144:ef7eb2e8f9f7 | 41 | void InterruptIn::mode(PinMode pull) { |
<> | 144:ef7eb2e8f9f7 | 42 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 43 | gpio_mode(&gpio, pull); |
<> | 144:ef7eb2e8f9f7 | 44 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 45 | } |
<> | 144:ef7eb2e8f9f7 | 46 | |
<> | 144:ef7eb2e8f9f7 | 47 | void InterruptIn::rise(Callback<void()> func) { |
<> | 144:ef7eb2e8f9f7 | 48 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 49 | if (func) { |
<> | 144:ef7eb2e8f9f7 | 50 | _rise.attach(func); |
<> | 144:ef7eb2e8f9f7 | 51 | gpio_irq_set(&gpio_irq, IRQ_RISE, 1); |
<> | 144:ef7eb2e8f9f7 | 52 | } else { |
<> | 144:ef7eb2e8f9f7 | 53 | _rise.attach(NULL); |
<> | 144:ef7eb2e8f9f7 | 54 | gpio_irq_set(&gpio_irq, IRQ_RISE, 0); |
<> | 144:ef7eb2e8f9f7 | 55 | } |
<> | 144:ef7eb2e8f9f7 | 56 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 57 | } |
<> | 144:ef7eb2e8f9f7 | 58 | |
<> | 144:ef7eb2e8f9f7 | 59 | void InterruptIn::fall(Callback<void()> func) { |
<> | 144:ef7eb2e8f9f7 | 60 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 61 | if (func) { |
<> | 144:ef7eb2e8f9f7 | 62 | _fall.attach(func); |
<> | 144:ef7eb2e8f9f7 | 63 | gpio_irq_set(&gpio_irq, IRQ_FALL, 1); |
<> | 144:ef7eb2e8f9f7 | 64 | } else { |
<> | 144:ef7eb2e8f9f7 | 65 | _fall.attach(NULL); |
<> | 144:ef7eb2e8f9f7 | 66 | gpio_irq_set(&gpio_irq, IRQ_FALL, 0); |
<> | 144:ef7eb2e8f9f7 | 67 | } |
<> | 144:ef7eb2e8f9f7 | 68 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 69 | } |
<> | 144:ef7eb2e8f9f7 | 70 | |
<> | 144:ef7eb2e8f9f7 | 71 | void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) { |
<> | 144:ef7eb2e8f9f7 | 72 | InterruptIn *handler = (InterruptIn*)id; |
<> | 144:ef7eb2e8f9f7 | 73 | switch (event) { |
<> | 144:ef7eb2e8f9f7 | 74 | case IRQ_RISE: handler->_rise.call(); break; |
<> | 144:ef7eb2e8f9f7 | 75 | case IRQ_FALL: handler->_fall.call(); break; |
<> | 144:ef7eb2e8f9f7 | 76 | case IRQ_NONE: break; |
<> | 144:ef7eb2e8f9f7 | 77 | } |
<> | 144:ef7eb2e8f9f7 | 78 | } |
<> | 144:ef7eb2e8f9f7 | 79 | |
<> | 144:ef7eb2e8f9f7 | 80 | void InterruptIn::enable_irq() { |
<> | 144:ef7eb2e8f9f7 | 81 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 82 | gpio_irq_enable(&gpio_irq); |
<> | 144:ef7eb2e8f9f7 | 83 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 84 | } |
<> | 144:ef7eb2e8f9f7 | 85 | |
<> | 144:ef7eb2e8f9f7 | 86 | void InterruptIn::disable_irq() { |
<> | 144:ef7eb2e8f9f7 | 87 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 88 | gpio_irq_disable(&gpio_irq); |
<> | 144:ef7eb2e8f9f7 | 89 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 90 | } |
<> | 144:ef7eb2e8f9f7 | 91 | |
<> | 144:ef7eb2e8f9f7 | 92 | InterruptIn::operator int() { |
<> | 144:ef7eb2e8f9f7 | 93 | // Underlying call is atomic |
<> | 144:ef7eb2e8f9f7 | 94 | return read(); |
<> | 144:ef7eb2e8f9f7 | 95 | } |
<> | 144:ef7eb2e8f9f7 | 96 | |
<> | 144:ef7eb2e8f9f7 | 97 | } // namespace mbed |
<> | 144:ef7eb2e8f9f7 | 98 | |
<> | 144:ef7eb2e8f9f7 | 99 | #endif |