mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Sep 04 09:30:10 2015 +0100
Revision:
619:034e698bc035
Parent:
567:a97fd0eca828
Synchronized with git revision 92d1bfad30082571776c810a56fd471d30514ccf

Full URL: https://github.com/mbedmicro/mbed/commit/92d1bfad30082571776c810a56fd471d30514ccf/

Change directory structure and move files.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 567:a97fd0eca828 1 /* mbed Microcontroller Library
mbed_official 567:a97fd0eca828 2 *******************************************************************************
mbed_official 567:a97fd0eca828 3 * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved.
mbed_official 567:a97fd0eca828 4 * All rights reserved.
mbed_official 567:a97fd0eca828 5 *
mbed_official 567:a97fd0eca828 6 * Redistribution and use in source and binary forms, with or without
mbed_official 567:a97fd0eca828 7 * modification, are permitted provided that the following conditions are met:
mbed_official 567:a97fd0eca828 8 *
mbed_official 567:a97fd0eca828 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 567:a97fd0eca828 10 * this list of conditions and the following disclaimer.
mbed_official 567:a97fd0eca828 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 567:a97fd0eca828 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 567:a97fd0eca828 13 * and/or other materials provided with the distribution.
mbed_official 567:a97fd0eca828 14 * 3. Neither the name of ARM Limited nor the names of its contributors
mbed_official 567:a97fd0eca828 15 * may be used to endorse or promote products derived from this software
mbed_official 567:a97fd0eca828 16 * without specific prior written permission.
mbed_official 567:a97fd0eca828 17 *
mbed_official 567:a97fd0eca828 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 567:a97fd0eca828 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 567:a97fd0eca828 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 567:a97fd0eca828 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 567:a97fd0eca828 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 567:a97fd0eca828 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 567:a97fd0eca828 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 567:a97fd0eca828 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 567:a97fd0eca828 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 567:a97fd0eca828 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 567:a97fd0eca828 28 *******************************************************************************
mbed_official 567:a97fd0eca828 29 */
mbed_official 567:a97fd0eca828 30
mbed_official 567:a97fd0eca828 31 #include <stddef.h>
mbed_official 567:a97fd0eca828 32 #include "cmsis.h"
mbed_official 567:a97fd0eca828 33 #include "gpio_irq_api.h"
mbed_official 567:a97fd0eca828 34 #include "pinmap.h"
mbed_official 567:a97fd0eca828 35 #include "mbed_error.h"
mbed_official 567:a97fd0eca828 36
mbed_official 567:a97fd0eca828 37 #define EDGE_NONE (0)
mbed_official 567:a97fd0eca828 38 #define EDGE_RISE (1)
mbed_official 567:a97fd0eca828 39 #define EDGE_FALL (2)
mbed_official 567:a97fd0eca828 40 #define EDGE_BOTH (3)
mbed_official 567:a97fd0eca828 41
mbed_official 567:a97fd0eca828 42 static gpio_irq_handler irq_handler;
mbed_official 567:a97fd0eca828 43
mbed_official 567:a97fd0eca828 44 static uint32_t channel_ids[4][16];
mbed_official 567:a97fd0eca828 45
mbed_official 567:a97fd0eca828 46 #ifdef __cplusplus
mbed_official 567:a97fd0eca828 47 extern "C"{
mbed_official 567:a97fd0eca828 48 #endif
mbed_official 619:034e698bc035 49 void port_generic_handler(GPIO_TypeDef* GPIOx, uint32_t port_num);
mbed_official 567:a97fd0eca828 50
mbed_official 567:a97fd0eca828 51 void PORT0_Handler(void)
mbed_official 567:a97fd0eca828 52 {
mbed_official 567:a97fd0eca828 53 port_generic_handler(GPIOA, 0);
mbed_official 567:a97fd0eca828 54 }
mbed_official 567:a97fd0eca828 55
mbed_official 567:a97fd0eca828 56 void PORT1_Handler(void)
mbed_official 567:a97fd0eca828 57 {
mbed_official 567:a97fd0eca828 58 port_generic_handler(GPIOB, 1);
mbed_official 567:a97fd0eca828 59 }
mbed_official 567:a97fd0eca828 60
mbed_official 567:a97fd0eca828 61 void PORT2_Handler(void)
mbed_official 567:a97fd0eca828 62 {
mbed_official 567:a97fd0eca828 63 port_generic_handler(GPIOC, 2);
mbed_official 567:a97fd0eca828 64 }
mbed_official 567:a97fd0eca828 65
mbed_official 567:a97fd0eca828 66 void PORT3_Handler(void)
mbed_official 567:a97fd0eca828 67 {
mbed_official 567:a97fd0eca828 68 port_generic_handler(GPIOD, 3);
mbed_official 567:a97fd0eca828 69 }
mbed_official 567:a97fd0eca828 70
mbed_official 567:a97fd0eca828 71 void port_generic_handler(GPIO_TypeDef* GPIOx, uint32_t port_num)
mbed_official 567:a97fd0eca828 72 {
mbed_official 567:a97fd0eca828 73 int i = 0;
mbed_official 567:a97fd0eca828 74 int loop = 16;
mbed_official 567:a97fd0eca828 75
mbed_official 567:a97fd0eca828 76 if(GPIOx == GPIOD) loop = 5;
mbed_official 567:a97fd0eca828 77
mbed_official 567:a97fd0eca828 78 for(i=0; i<loop; i++)
mbed_official 567:a97fd0eca828 79 {
mbed_official 567:a97fd0eca828 80 if(GPIOx->Interrupt.INTSTATUS & (1 << i))
mbed_official 567:a97fd0eca828 81 {
mbed_official 567:a97fd0eca828 82 GPIOx->Interrupt.INTCLEAR |= (1 << i);
mbed_official 567:a97fd0eca828 83 if(GPIOx->INTPOLSET >> i) //rising
mbed_official 567:a97fd0eca828 84 irq_handler(channel_ids[port_num][i], IRQ_RISE);
mbed_official 567:a97fd0eca828 85 else //falling
mbed_official 567:a97fd0eca828 86 irq_handler(channel_ids[port_num][i], IRQ_FALL);
mbed_official 567:a97fd0eca828 87 }
mbed_official 567:a97fd0eca828 88 }
mbed_official 567:a97fd0eca828 89 }
mbed_official 567:a97fd0eca828 90
mbed_official 567:a97fd0eca828 91 #ifdef __cplusplus
mbed_official 567:a97fd0eca828 92 }
mbed_official 567:a97fd0eca828 93 #endif
mbed_official 567:a97fd0eca828 94
mbed_official 567:a97fd0eca828 95
mbed_official 567:a97fd0eca828 96 int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
mbed_official 567:a97fd0eca828 97 {
mbed_official 567:a97fd0eca828 98 obj->port_num = WIZ_PORT(pin);
mbed_official 567:a97fd0eca828 99 obj->pin_num = WIZ_PIN_NUM(pin);
mbed_official 567:a97fd0eca828 100 obj->pin_index = WIZ_PIN_INDEX(pin);
mbed_official 567:a97fd0eca828 101
mbed_official 567:a97fd0eca828 102 if (pin == NC) return -1;
mbed_official 567:a97fd0eca828 103
mbed_official 567:a97fd0eca828 104 if(obj->port_num == 0)
mbed_official 567:a97fd0eca828 105 obj->irq_n = PORT0_IRQn;
mbed_official 567:a97fd0eca828 106 else if(obj->port_num == 1)
mbed_official 567:a97fd0eca828 107 obj->irq_n = PORT1_IRQn;
mbed_official 567:a97fd0eca828 108 else if(obj->port_num == 2)
mbed_official 567:a97fd0eca828 109 obj->irq_n = PORT2_IRQn;
mbed_official 567:a97fd0eca828 110 else
mbed_official 567:a97fd0eca828 111 obj->irq_n = PORT3_IRQn;
mbed_official 567:a97fd0eca828 112
mbed_official 567:a97fd0eca828 113 //obj->event = EDGE_FALL;
mbed_official 567:a97fd0eca828 114 obj->pin = pin;
mbed_official 567:a97fd0eca828 115
mbed_official 567:a97fd0eca828 116 // Enable EXTI interrupt
mbed_official 567:a97fd0eca828 117 NVIC_EnableIRQ(obj->irq_n);
mbed_official 567:a97fd0eca828 118
mbed_official 567:a97fd0eca828 119 channel_ids[obj->port_num][obj->pin_num] = id;
mbed_official 567:a97fd0eca828 120
mbed_official 567:a97fd0eca828 121 irq_handler = handler;
mbed_official 567:a97fd0eca828 122
mbed_official 567:a97fd0eca828 123 return 0;
mbed_official 567:a97fd0eca828 124 }
mbed_official 567:a97fd0eca828 125
mbed_official 567:a97fd0eca828 126 void gpio_irq_free(gpio_irq_t *obj)
mbed_official 567:a97fd0eca828 127 {
mbed_official 567:a97fd0eca828 128 channel_ids[obj->port_num][obj->pin_num] = 0;
mbed_official 567:a97fd0eca828 129
mbed_official 567:a97fd0eca828 130 obj->event = EDGE_NONE;
mbed_official 567:a97fd0eca828 131 }
mbed_official 567:a97fd0eca828 132
mbed_official 567:a97fd0eca828 133 void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
mbed_official 567:a97fd0eca828 134 {
mbed_official 567:a97fd0eca828 135 GPIO_TypeDef *gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(obj->port_num);
mbed_official 567:a97fd0eca828 136
mbed_official 567:a97fd0eca828 137 if (enable) {
mbed_official 567:a97fd0eca828 138 if (event == IRQ_RISE) {
mbed_official 567:a97fd0eca828 139 gpio->INTPOLSET |= obj->pin_index;
mbed_official 567:a97fd0eca828 140 obj->event = EDGE_RISE;
mbed_official 567:a97fd0eca828 141 obj->rise_null = 0;
mbed_official 567:a97fd0eca828 142 }
mbed_official 567:a97fd0eca828 143 else if (event == IRQ_FALL) {
mbed_official 567:a97fd0eca828 144 gpio->INTPOLSET &= ~obj->pin_index;
mbed_official 567:a97fd0eca828 145 obj->event = EDGE_FALL;
mbed_official 567:a97fd0eca828 146 obj->fall_null = 0;
mbed_official 567:a97fd0eca828 147 }
mbed_official 567:a97fd0eca828 148 gpio->INTTYPESET |= obj->pin_index;
mbed_official 567:a97fd0eca828 149 gpio->INTENSET |= obj->pin_index;
mbed_official 567:a97fd0eca828 150
mbed_official 567:a97fd0eca828 151
mbed_official 567:a97fd0eca828 152 } else {
mbed_official 567:a97fd0eca828 153 if (event == IRQ_RISE) {
mbed_official 567:a97fd0eca828 154 obj->rise_null = 1;
mbed_official 567:a97fd0eca828 155 if(obj->fall_null)
mbed_official 567:a97fd0eca828 156 gpio->INTENCLR |= obj->pin_index;
mbed_official 567:a97fd0eca828 157 }
mbed_official 567:a97fd0eca828 158 else if (event == IRQ_FALL) {
mbed_official 567:a97fd0eca828 159 obj->fall_null = 1;
mbed_official 567:a97fd0eca828 160 if(obj->rise_null)
mbed_official 567:a97fd0eca828 161 gpio->INTENCLR |= obj->pin_index;
mbed_official 567:a97fd0eca828 162 }
mbed_official 567:a97fd0eca828 163 }
mbed_official 567:a97fd0eca828 164 }
mbed_official 567:a97fd0eca828 165
mbed_official 567:a97fd0eca828 166 void gpio_irq_enable(gpio_irq_t *obj)
mbed_official 567:a97fd0eca828 167 {
mbed_official 567:a97fd0eca828 168 NVIC_EnableIRQ(obj->irq_n);
mbed_official 567:a97fd0eca828 169 }
mbed_official 567:a97fd0eca828 170
mbed_official 567:a97fd0eca828 171 void gpio_irq_disable(gpio_irq_t *obj)
mbed_official 567:a97fd0eca828 172 {
mbed_official 567:a97fd0eca828 173 NVIC_DisableIRQ(obj->irq_n);
mbed_official 567:a97fd0eca828 174 obj->event = EDGE_NONE;
mbed_official 567:a97fd0eca828 175 }