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