SDCard version

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

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