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