mbed library sources. Supersedes mbed-src. RTC working even after reset
Fork of mbed-dev by
common/mbed_board.c@144:ef7eb2e8f9f7, 2016-09-02 (annotated)
- Committer:
- <>
- Date:
- Fri Sep 02 15:07:44 2016 +0100
- Revision:
- 144:ef7eb2e8f9f7
This updates the lib to the mbed lib v125
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* mbed Microcontroller Library |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 144:ef7eb2e8f9f7 | 5 | * you may not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 6 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 144:ef7eb2e8f9f7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 13 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 14 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 15 | */ |
<> | 144:ef7eb2e8f9f7 | 16 | #include <stdio.h> |
<> | 144:ef7eb2e8f9f7 | 17 | #include "gpio_api.h" |
<> | 144:ef7eb2e8f9f7 | 18 | #include "wait_api.h" |
<> | 144:ef7eb2e8f9f7 | 19 | #include "toolchain.h" |
<> | 144:ef7eb2e8f9f7 | 20 | #include "mbed_interface.h" |
<> | 144:ef7eb2e8f9f7 | 21 | #include "critical.h" |
<> | 144:ef7eb2e8f9f7 | 22 | #include "serial_api.h" |
<> | 144:ef7eb2e8f9f7 | 23 | |
<> | 144:ef7eb2e8f9f7 | 24 | #if DEVICE_SERIAL |
<> | 144:ef7eb2e8f9f7 | 25 | extern int stdio_uart_inited; |
<> | 144:ef7eb2e8f9f7 | 26 | extern serial_t stdio_uart; |
<> | 144:ef7eb2e8f9f7 | 27 | #endif |
<> | 144:ef7eb2e8f9f7 | 28 | |
<> | 144:ef7eb2e8f9f7 | 29 | WEAK void mbed_die(void) { |
<> | 144:ef7eb2e8f9f7 | 30 | #if !defined (NRF51_H) && !defined(TARGET_EFM32) |
<> | 144:ef7eb2e8f9f7 | 31 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 32 | #endif |
<> | 144:ef7eb2e8f9f7 | 33 | #if (DEVICE_ERROR_RED == 1) |
<> | 144:ef7eb2e8f9f7 | 34 | gpio_t led_red; gpio_init_out(&led_red, LED_RED); |
<> | 144:ef7eb2e8f9f7 | 35 | #elif (DEVICE_ERROR_PATTERN == 1) |
<> | 144:ef7eb2e8f9f7 | 36 | gpio_t led_1; gpio_init_out(&led_1, LED1); |
<> | 144:ef7eb2e8f9f7 | 37 | gpio_t led_2; gpio_init_out(&led_2, LED2); |
<> | 144:ef7eb2e8f9f7 | 38 | gpio_t led_3; gpio_init_out(&led_3, LED3); |
<> | 144:ef7eb2e8f9f7 | 39 | gpio_t led_4; gpio_init_out(&led_4, LED4); |
<> | 144:ef7eb2e8f9f7 | 40 | #endif |
<> | 144:ef7eb2e8f9f7 | 41 | |
<> | 144:ef7eb2e8f9f7 | 42 | while (1) { |
<> | 144:ef7eb2e8f9f7 | 43 | #if (DEVICE_ERROR_RED == 1) |
<> | 144:ef7eb2e8f9f7 | 44 | gpio_write(&led_red, 1); |
<> | 144:ef7eb2e8f9f7 | 45 | |
<> | 144:ef7eb2e8f9f7 | 46 | #elif (DEVICE_ERROR_PATTERN == 1) |
<> | 144:ef7eb2e8f9f7 | 47 | gpio_write(&led_1, 1); |
<> | 144:ef7eb2e8f9f7 | 48 | gpio_write(&led_2, 0); |
<> | 144:ef7eb2e8f9f7 | 49 | gpio_write(&led_3, 0); |
<> | 144:ef7eb2e8f9f7 | 50 | gpio_write(&led_4, 1); |
<> | 144:ef7eb2e8f9f7 | 51 | #endif |
<> | 144:ef7eb2e8f9f7 | 52 | |
<> | 144:ef7eb2e8f9f7 | 53 | wait_ms(150); |
<> | 144:ef7eb2e8f9f7 | 54 | |
<> | 144:ef7eb2e8f9f7 | 55 | #if (DEVICE_ERROR_RED == 1) |
<> | 144:ef7eb2e8f9f7 | 56 | gpio_write(&led_red, 0); |
<> | 144:ef7eb2e8f9f7 | 57 | |
<> | 144:ef7eb2e8f9f7 | 58 | #elif (DEVICE_ERROR_PATTERN == 1) |
<> | 144:ef7eb2e8f9f7 | 59 | gpio_write(&led_1, 0); |
<> | 144:ef7eb2e8f9f7 | 60 | gpio_write(&led_2, 1); |
<> | 144:ef7eb2e8f9f7 | 61 | gpio_write(&led_3, 1); |
<> | 144:ef7eb2e8f9f7 | 62 | gpio_write(&led_4, 0); |
<> | 144:ef7eb2e8f9f7 | 63 | #endif |
<> | 144:ef7eb2e8f9f7 | 64 | |
<> | 144:ef7eb2e8f9f7 | 65 | wait_ms(150); |
<> | 144:ef7eb2e8f9f7 | 66 | } |
<> | 144:ef7eb2e8f9f7 | 67 | } |
<> | 144:ef7eb2e8f9f7 | 68 | |
<> | 144:ef7eb2e8f9f7 | 69 | void mbed_error_printf(const char* format, ...) { |
<> | 144:ef7eb2e8f9f7 | 70 | va_list arg; |
<> | 144:ef7eb2e8f9f7 | 71 | va_start(arg, format); |
<> | 144:ef7eb2e8f9f7 | 72 | mbed_error_vfprintf(format, arg); |
<> | 144:ef7eb2e8f9f7 | 73 | va_end(arg); |
<> | 144:ef7eb2e8f9f7 | 74 | } |
<> | 144:ef7eb2e8f9f7 | 75 | |
<> | 144:ef7eb2e8f9f7 | 76 | void mbed_error_vfprintf(const char * format, va_list arg) { |
<> | 144:ef7eb2e8f9f7 | 77 | #if DEVICE_SERIAL |
<> | 144:ef7eb2e8f9f7 | 78 | core_util_critical_section_enter(); |
<> | 144:ef7eb2e8f9f7 | 79 | char buffer[128]; |
<> | 144:ef7eb2e8f9f7 | 80 | int size = vsprintf(buffer, format, arg); |
<> | 144:ef7eb2e8f9f7 | 81 | if (size > 0) { |
<> | 144:ef7eb2e8f9f7 | 82 | if (!stdio_uart_inited) { |
<> | 144:ef7eb2e8f9f7 | 83 | serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX); |
<> | 144:ef7eb2e8f9f7 | 84 | } |
<> | 144:ef7eb2e8f9f7 | 85 | for (int i = 0; i < size; i++) { |
<> | 144:ef7eb2e8f9f7 | 86 | serial_putc(&stdio_uart, buffer[i]); |
<> | 144:ef7eb2e8f9f7 | 87 | } |
<> | 144:ef7eb2e8f9f7 | 88 | } |
<> | 144:ef7eb2e8f9f7 | 89 | core_util_critical_section_exit(); |
<> | 144:ef7eb2e8f9f7 | 90 | #endif |
<> | 144:ef7eb2e8f9f7 | 91 | } |