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