test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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