Lancaster University / mbed-src

Fork of mbed-src by mbed official

Committer:
LancasterUniversity
Date:
Wed Jul 13 12:52:54 2016 +0100
Revision:
641:be9b2017785a
Parent:
395:bfce16e86ea4
Synchronized with git rev 1fb8ab4c
Author: James Devine
mbed-classic: BUGFIX for timer when using wait_ms from interrupt context

Previously if a user used wait[_ms,_us] in interrupt context the device would
hang indefinitely. This was due to incrementing overflowCount from
interrupt context only.

This meant that if a user used wait[_ms,_us] in an ISR with
the same or greater interrupt priority, it would result in an infinite
loop as the overflowCount variable would never be incremented, and
wait[_ms,_us] would never return.

This patch simply applies a better solution for the race condition
mentioned in the previous commit. It instead disables the timer1
interrupt and increments the overflowCount variable, preventing
the race condition whilst supporting wait[_ms,_us] in interrupt
context.

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 #ifndef MBED_OBJECTS_H
mbed_official 85:e1a8e879a6a9 17 #define MBED_OBJECTS_H
mbed_official 85:e1a8e879a6a9 18
mbed_official 85:e1a8e879a6a9 19 #include "cmsis.h"
mbed_official 85:e1a8e879a6a9 20 #include "PortNames.h"
mbed_official 85:e1a8e879a6a9 21 #include "PeripheralNames.h"
mbed_official 85:e1a8e879a6a9 22 #include "PinNames.h"
mbed_official 85:e1a8e879a6a9 23
mbed_official 85:e1a8e879a6a9 24 #ifdef __cplusplus
mbed_official 85:e1a8e879a6a9 25 extern "C" {
mbed_official 85:e1a8e879a6a9 26 #endif
mbed_official 85:e1a8e879a6a9 27
mbed_official 395:bfce16e86ea4 28 #define I2C_SPI_PERIPHERAL_FOR_I2C 1
mbed_official 395:bfce16e86ea4 29 #define I2C_SPI_PERIPHERAL_FOR_SPI 2
mbed_official 395:bfce16e86ea4 30
mbed_official 395:bfce16e86ea4 31 typedef struct {
mbed_official 395:bfce16e86ea4 32 uint8_t usage; // I2C: 1, SPI: 2
mbed_official 395:bfce16e86ea4 33 uint8_t sda_mosi;
mbed_official 395:bfce16e86ea4 34 uint8_t scl_miso;
mbed_official 395:bfce16e86ea4 35 uint8_t sclk;
mbed_official 395:bfce16e86ea4 36 } i2c_spi_peripheral_t;
mbed_official 395:bfce16e86ea4 37
mbed_official 85:e1a8e879a6a9 38 struct serial_s {
mbed_official 85:e1a8e879a6a9 39 NRF_UART_Type *uart;
mbed_official 85:e1a8e879a6a9 40 int index;
mbed_official 85:e1a8e879a6a9 41 };
mbed_official 85:e1a8e879a6a9 42
mbed_official 85:e1a8e879a6a9 43 struct spi_s {
mbed_official 85:e1a8e879a6a9 44 NRF_SPI_Type *spi;
mbed_official 85:e1a8e879a6a9 45 NRF_SPIS_Type *spis;
mbed_official 395:bfce16e86ea4 46 uint8_t peripheral;
mbed_official 85:e1a8e879a6a9 47 };
mbed_official 85:e1a8e879a6a9 48
mbed_official 85:e1a8e879a6a9 49 struct port_s {
mbed_official 85:e1a8e879a6a9 50 __IO uint32_t *reg_cnf;
mbed_official 85:e1a8e879a6a9 51 __IO uint32_t *reg_out;
mbed_official 85:e1a8e879a6a9 52 __I uint32_t *reg_in;
mbed_official 85:e1a8e879a6a9 53 PortName port;
mbed_official 85:e1a8e879a6a9 54 uint32_t mask;
mbed_official 85:e1a8e879a6a9 55 };
mbed_official 85:e1a8e879a6a9 56
mbed_official 85:e1a8e879a6a9 57 struct pwmout_s {
mbed_official 85:e1a8e879a6a9 58 PWMName pwm;
mbed_official 85:e1a8e879a6a9 59 PinName pin;
mbed_official 85:e1a8e879a6a9 60 };
mbed_official 85:e1a8e879a6a9 61
mbed_official 85:e1a8e879a6a9 62 struct i2c_s {
mbed_official 85:e1a8e879a6a9 63 NRF_TWI_Type *i2c;
mbed_official 85:e1a8e879a6a9 64 PinName sda;
mbed_official 85:e1a8e879a6a9 65 PinName scl;
mbed_official 85:e1a8e879a6a9 66 int freq;
mbed_official 314:b682143dd337 67 uint8_t address_set;
mbed_official 395:bfce16e86ea4 68 uint8_t peripheral;
mbed_official 85:e1a8e879a6a9 69 };
mbed_official 85:e1a8e879a6a9 70
mbed_official 85:e1a8e879a6a9 71 struct analogin_s {
mbed_official 85:e1a8e879a6a9 72 ADCName adc;
mbed_official 217:d0ccc61c1fd4 73 uint8_t adc_pin;
mbed_official 85:e1a8e879a6a9 74 };
mbed_official 85:e1a8e879a6a9 75
mbed_official 85:e1a8e879a6a9 76 struct gpio_irq_s {
mbed_official 85:e1a8e879a6a9 77 uint32_t ch;
mbed_official 85:e1a8e879a6a9 78 };
mbed_official 85:e1a8e879a6a9 79
mbed_official 85:e1a8e879a6a9 80 #include "gpio_object.h"
mbed_official 85:e1a8e879a6a9 81
mbed_official 85:e1a8e879a6a9 82 #ifdef __cplusplus
mbed_official 85:e1a8e879a6a9 83 }
mbed_official 85:e1a8e879a6a9 84 #endif
mbed_official 85:e1a8e879a6a9 85
mbed_official 85:e1a8e879a6a9 86 #endif