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 Aug 15 16:30:08 2014 +0100
Revision:
285:31249416b6f9
Parent:
270:e2babe29baf8
Child:
300:55638feb26a4
Synchronized with git revision 601712595f49bbd2a2771c52cf3e84c9c7a591af

Full URL: https://github.com/mbedmicro/mbed/commit/601712595f49bbd2a2771c52cf3e84c9c7a591af/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 85:e1a8e879a6a9 1 /* mbed Microcontroller Library
mbed_official 104:a6a92e2e5a92 2 * Copyright (c) 2013 Nordic Semiconductor
mbed_official 85:e1a8e879a6a9 3 *
mbed_official 85:e1a8e879a6a9 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 85:e1a8e879a6a9 5 * you may not use this file except in compliance with the License.
mbed_official 85:e1a8e879a6a9 6 * You may obtain a copy of the License at
mbed_official 85:e1a8e879a6a9 7 *
mbed_official 85:e1a8e879a6a9 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 85:e1a8e879a6a9 9 *
mbed_official 85:e1a8e879a6a9 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 85:e1a8e879a6a9 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 85:e1a8e879a6a9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 85:e1a8e879a6a9 13 * See the License for the specific language governing permissions and
mbed_official 85:e1a8e879a6a9 14 * limitations under the License.
mbed_official 85:e1a8e879a6a9 15 */
mbed_official 85:e1a8e879a6a9 16 #include <stddef.h>
mbed_official 85:e1a8e879a6a9 17 #include "cmsis.h"
mbed_official 85:e1a8e879a6a9 18
mbed_official 85:e1a8e879a6a9 19 #include "gpio_irq_api.h"
mbed_official 285:31249416b6f9 20 #include "mbed_error.h"
mbed_official 85:e1a8e879a6a9 21
mbed_official 85:e1a8e879a6a9 22 #define CHANNEL_NUM 31
mbed_official 85:e1a8e879a6a9 23
mbed_official 85:e1a8e879a6a9 24 static uint32_t channel_ids[CHANNEL_NUM] = {0}; //each pin will be given an id, if id is 0 the pin can be ignored.
mbed_official 85:e1a8e879a6a9 25 static uint8_t channel_enabled[CHANNEL_NUM] = {0};
mbed_official 85:e1a8e879a6a9 26 static uint32_t portRISE= 0;
mbed_official 85:e1a8e879a6a9 27 static uint32_t portFALL= 0;
mbed_official 85:e1a8e879a6a9 28 static gpio_irq_handler irq_handler;
mbed_official 85:e1a8e879a6a9 29
mbed_official 85:e1a8e879a6a9 30 #ifdef __cplusplus
mbed_official 85:e1a8e879a6a9 31 extern "C" {
mbed_official 85:e1a8e879a6a9 32 #endif
mbed_official 85:e1a8e879a6a9 33 void GPIOTE_IRQHandler(void){
mbed_official 85:e1a8e879a6a9 34 volatile uint32_t newVal = NRF_GPIO->IN;
mbed_official 85:e1a8e879a6a9 35
mbed_official 85:e1a8e879a6a9 36 if ( (NRF_GPIOTE->EVENTS_PORT != 0) && ( (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_PORT_Msk) != 0) ){
mbed_official 85:e1a8e879a6a9 37 NRF_GPIOTE->EVENTS_PORT = 0;
mbed_official 85:e1a8e879a6a9 38
mbed_official 85:e1a8e879a6a9 39 for(uint8_t i=0;i<31;i++){
mbed_official 85:e1a8e879a6a9 40 if(channel_ids[i]>0){
mbed_official 85:e1a8e879a6a9 41 if(channel_enabled[i]){
mbed_official 85:e1a8e879a6a9 42 if( ((newVal>>i)&1) && ( ( (NRF_GPIO->PIN_CNF[i] >>GPIO_PIN_CNF_SENSE_Pos) & GPIO_PIN_CNF_SENSE_Low) != GPIO_PIN_CNF_SENSE_Low) && ( (portRISE>>i)&1) ){
mbed_official 85:e1a8e879a6a9 43 irq_handler(channel_ids[i], IRQ_RISE);
mbed_official 85:e1a8e879a6a9 44 }
mbed_official 85:e1a8e879a6a9 45 else if( ( ((newVal>>i)&1) == 0) && ( ( (NRF_GPIO->PIN_CNF[i] >>GPIO_PIN_CNF_SENSE_Pos)&GPIO_PIN_CNF_SENSE_Low) == GPIO_PIN_CNF_SENSE_Low) && ( (portFALL>>i)&1) ){
mbed_official 85:e1a8e879a6a9 46 irq_handler(channel_ids[i], IRQ_FALL);
mbed_official 85:e1a8e879a6a9 47 }
mbed_official 85:e1a8e879a6a9 48 }
mbed_official 85:e1a8e879a6a9 49
mbed_official 85:e1a8e879a6a9 50 if(NRF_GPIO->PIN_CNF[i] &GPIO_PIN_CNF_SENSE_Msk){
mbed_official 85:e1a8e879a6a9 51 NRF_GPIO->PIN_CNF[i] &= ~(GPIO_PIN_CNF_SENSE_Msk);
mbed_official 85:e1a8e879a6a9 52
mbed_official 85:e1a8e879a6a9 53 if(newVal>>i &1){
mbed_official 85:e1a8e879a6a9 54 NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos) ;
mbed_official 85:e1a8e879a6a9 55 }
mbed_official 85:e1a8e879a6a9 56 else{
mbed_official 85:e1a8e879a6a9 57 NRF_GPIO->PIN_CNF[i] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;
mbed_official 85:e1a8e879a6a9 58 }
mbed_official 85:e1a8e879a6a9 59 }
mbed_official 85:e1a8e879a6a9 60 }
mbed_official 85:e1a8e879a6a9 61 }
mbed_official 85:e1a8e879a6a9 62 }
mbed_official 85:e1a8e879a6a9 63 }
mbed_official 85:e1a8e879a6a9 64 #ifdef __cplusplus
mbed_official 85:e1a8e879a6a9 65 }
mbed_official 85:e1a8e879a6a9 66 #endif
mbed_official 85:e1a8e879a6a9 67
mbed_official 85:e1a8e879a6a9 68 int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
mbed_official 85:e1a8e879a6a9 69 if (pin == NC) {
mbed_official 85:e1a8e879a6a9 70 return -1;
mbed_official 85:e1a8e879a6a9 71 }
mbed_official 85:e1a8e879a6a9 72
mbed_official 85:e1a8e879a6a9 73 irq_handler = handler;
mbed_official 85:e1a8e879a6a9 74 obj->ch = pin;
mbed_official 85:e1a8e879a6a9 75 NRF_GPIOTE->EVENTS_PORT = 0;
mbed_official 85:e1a8e879a6a9 76 channel_ids[pin] = id;
mbed_official 85:e1a8e879a6a9 77 channel_enabled[pin] = 1;
mbed_official 85:e1a8e879a6a9 78 NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set<<GPIOTE_INTENSET_PORT_Pos;
mbed_official 85:e1a8e879a6a9 79
mbed_official 85:e1a8e879a6a9 80 NVIC_SetPriority(GPIOTE_IRQn, 3);
mbed_official 85:e1a8e879a6a9 81 NVIC_EnableIRQ (GPIOTE_IRQn);
mbed_official 85:e1a8e879a6a9 82 return 0;
mbed_official 85:e1a8e879a6a9 83 }
mbed_official 85:e1a8e879a6a9 84
mbed_official 85:e1a8e879a6a9 85 void gpio_irq_free(gpio_irq_t *obj) {
mbed_official 85:e1a8e879a6a9 86 channel_ids[obj->ch] = 0;
mbed_official 85:e1a8e879a6a9 87 }
mbed_official 85:e1a8e879a6a9 88
mbed_official 85:e1a8e879a6a9 89 void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
mbed_official 85:e1a8e879a6a9 90 NRF_GPIO->PIN_CNF[obj->ch] &= ~(GPIO_PIN_CNF_SENSE_Msk);
mbed_official 85:e1a8e879a6a9 91 if(enable){
mbed_official 85:e1a8e879a6a9 92 if(event == IRQ_RISE){
mbed_official 85:e1a8e879a6a9 93 portRISE |= (1<<obj->ch);
mbed_official 85:e1a8e879a6a9 94 }
mbed_official 85:e1a8e879a6a9 95 else if(event == IRQ_FALL){
mbed_official 85:e1a8e879a6a9 96 portFALL |= (1<<obj->ch);
mbed_official 85:e1a8e879a6a9 97 }
mbed_official 85:e1a8e879a6a9 98 }
mbed_official 85:e1a8e879a6a9 99 else{
mbed_official 85:e1a8e879a6a9 100 if(event == IRQ_RISE){
mbed_official 85:e1a8e879a6a9 101 portRISE &= ~(1<<obj->ch);
mbed_official 85:e1a8e879a6a9 102 }
mbed_official 85:e1a8e879a6a9 103 else if(event == IRQ_FALL){
mbed_official 85:e1a8e879a6a9 104 portFALL &= ~(1<<obj->ch);
mbed_official 85:e1a8e879a6a9 105 }
mbed_official 85:e1a8e879a6a9 106
mbed_official 85:e1a8e879a6a9 107 }
mbed_official 85:e1a8e879a6a9 108
mbed_official 85:e1a8e879a6a9 109 if( ( (portRISE>>obj->ch) & 1) || ( (portFALL>>obj->ch) & 1) ){
mbed_official 85:e1a8e879a6a9 110 if((NRF_GPIO->IN>>obj->ch)&1){
mbed_official 85:e1a8e879a6a9 111 NRF_GPIO->PIN_CNF[obj->ch] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);// | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
mbed_official 85:e1a8e879a6a9 112 }
mbed_official 85:e1a8e879a6a9 113 else{
mbed_official 85:e1a8e879a6a9 114 NRF_GPIO->PIN_CNF[obj->ch] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos) ;//| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos);
mbed_official 85:e1a8e879a6a9 115 }
mbed_official 85:e1a8e879a6a9 116 }
mbed_official 85:e1a8e879a6a9 117 }
mbed_official 85:e1a8e879a6a9 118
mbed_official 85:e1a8e879a6a9 119 void gpio_irq_enable(gpio_irq_t *obj) {
mbed_official 85:e1a8e879a6a9 120 channel_enabled[obj->ch] = 1;
mbed_official 85:e1a8e879a6a9 121 }
mbed_official 85:e1a8e879a6a9 122
mbed_official 85:e1a8e879a6a9 123 void gpio_irq_disable(gpio_irq_t *obj) {
mbed_official 85:e1a8e879a6a9 124 channel_enabled[obj->ch] = 0;
mbed_official 85:e1a8e879a6a9 125 }