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