BA
/
BaBoRo_test2
Backup 1
mbed-os/platform/mbed_board.c@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | /* mbed Microcontroller Library |
borlanic | 0:02dd72d1d465 | 2 | * Copyright (c) 2006-2013 ARM Limited |
borlanic | 0:02dd72d1d465 | 3 | * |
borlanic | 0:02dd72d1d465 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 6 | * You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 7 | * |
borlanic | 0:02dd72d1d465 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 9 | * |
borlanic | 0:02dd72d1d465 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 14 | * limitations under the License. |
borlanic | 0:02dd72d1d465 | 15 | */ |
borlanic | 0:02dd72d1d465 | 16 | #include <stdio.h> |
borlanic | 0:02dd72d1d465 | 17 | #include "hal/gpio_api.h" |
borlanic | 0:02dd72d1d465 | 18 | #include "platform/mbed_wait_api.h" |
borlanic | 0:02dd72d1d465 | 19 | #include "platform/mbed_toolchain.h" |
borlanic | 0:02dd72d1d465 | 20 | #include "platform/mbed_interface.h" |
borlanic | 0:02dd72d1d465 | 21 | #include "platform/mbed_critical.h" |
borlanic | 0:02dd72d1d465 | 22 | #include "hal/serial_api.h" |
borlanic | 0:02dd72d1d465 | 23 | |
borlanic | 0:02dd72d1d465 | 24 | #if DEVICE_SERIAL |
borlanic | 0:02dd72d1d465 | 25 | extern int stdio_uart_inited; |
borlanic | 0:02dd72d1d465 | 26 | extern serial_t stdio_uart; |
borlanic | 0:02dd72d1d465 | 27 | #endif |
borlanic | 0:02dd72d1d465 | 28 | |
borlanic | 0:02dd72d1d465 | 29 | WEAK void mbed_die(void) { |
borlanic | 0:02dd72d1d465 | 30 | #if !defined (NRF51_H) && !defined(TARGET_EFM32) |
borlanic | 0:02dd72d1d465 | 31 | core_util_critical_section_enter(); |
borlanic | 0:02dd72d1d465 | 32 | #endif |
borlanic | 0:02dd72d1d465 | 33 | gpio_t led_err; gpio_init_out(&led_err, LED1); |
borlanic | 0:02dd72d1d465 | 34 | |
borlanic | 0:02dd72d1d465 | 35 | while (1) { |
borlanic | 0:02dd72d1d465 | 36 | for (int i = 0; i < 4; ++i) { |
borlanic | 0:02dd72d1d465 | 37 | gpio_write(&led_err, 1); |
borlanic | 0:02dd72d1d465 | 38 | wait_ms(150); |
borlanic | 0:02dd72d1d465 | 39 | gpio_write(&led_err, 0); |
borlanic | 0:02dd72d1d465 | 40 | wait_ms(150); |
borlanic | 0:02dd72d1d465 | 41 | } |
borlanic | 0:02dd72d1d465 | 42 | |
borlanic | 0:02dd72d1d465 | 43 | for (int i = 0; i < 4; ++i) { |
borlanic | 0:02dd72d1d465 | 44 | gpio_write(&led_err, 1); |
borlanic | 0:02dd72d1d465 | 45 | wait_ms(400); |
borlanic | 0:02dd72d1d465 | 46 | gpio_write(&led_err, 0); |
borlanic | 0:02dd72d1d465 | 47 | wait_ms(400); |
borlanic | 0:02dd72d1d465 | 48 | } |
borlanic | 0:02dd72d1d465 | 49 | } |
borlanic | 0:02dd72d1d465 | 50 | } |
borlanic | 0:02dd72d1d465 | 51 | |
borlanic | 0:02dd72d1d465 | 52 | void mbed_error_printf(const char* format, ...) { |
borlanic | 0:02dd72d1d465 | 53 | va_list arg; |
borlanic | 0:02dd72d1d465 | 54 | va_start(arg, format); |
borlanic | 0:02dd72d1d465 | 55 | mbed_error_vfprintf(format, arg); |
borlanic | 0:02dd72d1d465 | 56 | va_end(arg); |
borlanic | 0:02dd72d1d465 | 57 | } |
borlanic | 0:02dd72d1d465 | 58 | |
borlanic | 0:02dd72d1d465 | 59 | void mbed_error_vfprintf(const char * format, va_list arg) { |
borlanic | 0:02dd72d1d465 | 60 | #if DEVICE_SERIAL |
borlanic | 0:02dd72d1d465 | 61 | #define ERROR_BUF_SIZE (128) |
borlanic | 0:02dd72d1d465 | 62 | core_util_critical_section_enter(); |
borlanic | 0:02dd72d1d465 | 63 | char buffer[ERROR_BUF_SIZE]; |
borlanic | 0:02dd72d1d465 | 64 | int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg); |
borlanic | 0:02dd72d1d465 | 65 | if (size > 0) { |
borlanic | 0:02dd72d1d465 | 66 | if (!stdio_uart_inited) { |
borlanic | 0:02dd72d1d465 | 67 | serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX); |
borlanic | 0:02dd72d1d465 | 68 | } |
borlanic | 0:02dd72d1d465 | 69 | #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES |
borlanic | 0:02dd72d1d465 | 70 | char stdio_out_prev = '\0'; |
borlanic | 0:02dd72d1d465 | 71 | for (int i = 0; i < size; i++) { |
borlanic | 0:02dd72d1d465 | 72 | if (buffer[i] == '\n' && stdio_out_prev != '\r') { |
borlanic | 0:02dd72d1d465 | 73 | serial_putc(&stdio_uart, '\r'); |
borlanic | 0:02dd72d1d465 | 74 | } |
borlanic | 0:02dd72d1d465 | 75 | serial_putc(&stdio_uart, buffer[i]); |
borlanic | 0:02dd72d1d465 | 76 | stdio_out_prev = buffer[i]; |
borlanic | 0:02dd72d1d465 | 77 | } |
borlanic | 0:02dd72d1d465 | 78 | #else |
borlanic | 0:02dd72d1d465 | 79 | for (int i = 0; i < size; i++) { |
borlanic | 0:02dd72d1d465 | 80 | serial_putc(&stdio_uart, buffer[i]); |
borlanic | 0:02dd72d1d465 | 81 | } |
borlanic | 0:02dd72d1d465 | 82 | #endif |
borlanic | 0:02dd72d1d465 | 83 | } |
borlanic | 0:02dd72d1d465 | 84 | core_util_critical_section_exit(); |
borlanic | 0:02dd72d1d465 | 85 | #endif |
borlanic | 0:02dd72d1d465 | 86 | } |