Lancaster University's (short term!) clone of mbed-src for micro:bit. This is a copy of the github branch https://github.com/lancaster-university/mbed-classic
Fork of mbed-src by
common/board.c@641:be9b2017785a, 2016-07-13 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Jul 13 12:52:54 2016 +0100
- Revision:
- 641:be9b2017785a
- Parent:
- 604:19d487c995ec
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?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 4:c4bfb462ca53 | 1 | /* mbed Microcontroller Library |
emilmont | 4:c4bfb462ca53 | 2 | * Copyright (c) 2006-2013 ARM Limited |
emilmont | 4:c4bfb462ca53 | 3 | * |
emilmont | 4:c4bfb462ca53 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
emilmont | 4:c4bfb462ca53 | 5 | * you may not use this file except in compliance with the License. |
emilmont | 4:c4bfb462ca53 | 6 | * You may obtain a copy of the License at |
emilmont | 4:c4bfb462ca53 | 7 | * |
emilmont | 4:c4bfb462ca53 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
emilmont | 4:c4bfb462ca53 | 9 | * |
emilmont | 4:c4bfb462ca53 | 10 | * Unless required by applicable law or agreed to in writing, software |
emilmont | 4:c4bfb462ca53 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
emilmont | 4:c4bfb462ca53 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
emilmont | 4:c4bfb462ca53 | 13 | * See the License for the specific language governing permissions and |
emilmont | 4:c4bfb462ca53 | 14 | * limitations under the License. |
emilmont | 4:c4bfb462ca53 | 15 | */ |
emilmont | 4:c4bfb462ca53 | 16 | #include "gpio_api.h" |
emilmont | 4:c4bfb462ca53 | 17 | #include "wait_api.h" |
emilmont | 4:c4bfb462ca53 | 18 | #include "toolchain.h" |
mbed_official | 228:85a676113daa | 19 | #include "mbed_interface.h" |
emilmont | 4:c4bfb462ca53 | 20 | |
emilmont | 4:c4bfb462ca53 | 21 | WEAK void mbed_die(void) { |
mbed_official | 604:19d487c995ec | 22 | #if !defined (NRF51_H) && !defined(TARGET_EFM32) |
mbed_official | 79:6fdc4ea80ae0 | 23 | __disable_irq(); // dont allow interrupts to disturb the flash pattern |
mbed_official | 127:ce7cebc0511f | 24 | #endif |
mbed_official | 79:6fdc4ea80ae0 | 25 | #if (DEVICE_ERROR_RED == 1) |
mbed_official | 113:65a335a675de | 26 | gpio_t led_red; gpio_init_out(&led_red, LED_RED); |
mbed_official | 79:6fdc4ea80ae0 | 27 | #elif (DEVICE_ERROR_PATTERN == 1) |
mbed_official | 113:65a335a675de | 28 | gpio_t led_1; gpio_init_out(&led_1, LED1); |
mbed_official | 113:65a335a675de | 29 | gpio_t led_2; gpio_init_out(&led_2, LED2); |
mbed_official | 113:65a335a675de | 30 | gpio_t led_3; gpio_init_out(&led_3, LED3); |
mbed_official | 113:65a335a675de | 31 | gpio_t led_4; gpio_init_out(&led_4, LED4); |
emilmont | 4:c4bfb462ca53 | 32 | #endif |
mbed_official | 221:8276e3a4886f | 33 | |
emilmont | 4:c4bfb462ca53 | 34 | while (1) { |
mbed_official | 79:6fdc4ea80ae0 | 35 | #if (DEVICE_ERROR_RED == 1) |
emilmont | 4:c4bfb462ca53 | 36 | gpio_write(&led_red, 1); |
emilmont | 4:c4bfb462ca53 | 37 | |
mbed_official | 79:6fdc4ea80ae0 | 38 | #elif (DEVICE_ERROR_PATTERN == 1) |
emilmont | 4:c4bfb462ca53 | 39 | gpio_write(&led_1, 1); |
emilmont | 4:c4bfb462ca53 | 40 | gpio_write(&led_2, 0); |
emilmont | 4:c4bfb462ca53 | 41 | gpio_write(&led_3, 0); |
emilmont | 4:c4bfb462ca53 | 42 | gpio_write(&led_4, 1); |
emilmont | 4:c4bfb462ca53 | 43 | #endif |
mbed_official | 221:8276e3a4886f | 44 | |
emilmont | 4:c4bfb462ca53 | 45 | wait_ms(150); |
emilmont | 4:c4bfb462ca53 | 46 | |
mbed_official | 79:6fdc4ea80ae0 | 47 | #if (DEVICE_ERROR_RED == 1) |
emilmont | 4:c4bfb462ca53 | 48 | gpio_write(&led_red, 0); |
emilmont | 4:c4bfb462ca53 | 49 | |
mbed_official | 79:6fdc4ea80ae0 | 50 | #elif (DEVICE_ERROR_PATTERN == 1) |
emilmont | 4:c4bfb462ca53 | 51 | gpio_write(&led_1, 0); |
emilmont | 4:c4bfb462ca53 | 52 | gpio_write(&led_2, 1); |
emilmont | 4:c4bfb462ca53 | 53 | gpio_write(&led_3, 1); |
emilmont | 4:c4bfb462ca53 | 54 | gpio_write(&led_4, 0); |
emilmont | 4:c4bfb462ca53 | 55 | #endif |
mbed_official | 221:8276e3a4886f | 56 | |
emilmont | 4:c4bfb462ca53 | 57 | wait_ms(150); |
emilmont | 4:c4bfb462ca53 | 58 | } |
emilmont | 4:c4bfb462ca53 | 59 | } |