mbed_board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #if DEVICE_SERIAL
  24. extern int stdio_uart_inited;
  25. extern serial_t stdio_uart;
  26. #endif
  27. WEAK void mbed_die(void)
  28. {
  29. #if !defined (NRF51_H) && !defined(TARGET_EFM32)
  30. core_util_critical_section_enter();
  31. #endif
  32. gpio_t led_err;
  33. gpio_init_out(&led_err, LED1);
  34. while (1) {
  35. for (int i = 0; i < 4; ++i) {
  36. gpio_write(&led_err, 1);
  37. wait_ms(150);
  38. gpio_write(&led_err, 0);
  39. wait_ms(150);
  40. }
  41. for (int i = 0; i < 4; ++i) {
  42. gpio_write(&led_err, 1);
  43. wait_ms(400);
  44. gpio_write(&led_err, 0);
  45. wait_ms(400);
  46. }
  47. }
  48. }
  49. void mbed_error_printf(const char *format, ...)
  50. {
  51. va_list arg;
  52. va_start(arg, format);
  53. mbed_error_vfprintf(format, arg);
  54. va_end(arg);
  55. }
  56. void mbed_error_vfprintf(const char *format, va_list arg)
  57. {
  58. #if DEVICE_SERIAL
  59. #define ERROR_BUF_SIZE (128)
  60. core_util_critical_section_enter();
  61. char buffer[ERROR_BUF_SIZE];
  62. int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg);
  63. if (size > 0) {
  64. if (!stdio_uart_inited) {
  65. serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
  66. }
  67. #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
  68. char stdio_out_prev = '\0';
  69. for (int i = 0; i < size; i++) {
  70. if (buffer[i] == '\n' && stdio_out_prev != '\r') {
  71. serial_putc(&stdio_uart, '\r');
  72. }
  73. serial_putc(&stdio_uart, buffer[i]);
  74. stdio_out_prev = buffer[i];
  75. }
  76. #else
  77. for (int i = 0; i < size; i++) {
  78. serial_putc(&stdio_uart, buffer[i]);
  79. }
  80. #endif
  81. }
  82. core_util_critical_section_exit();
  83. #endif
  84. }