The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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