BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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