001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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