Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
mbed_board.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include <stdio.h> 00017 #include "hal/gpio_api.h" 00018 #include "platform/mbed_wait_api.h" 00019 #include "platform/mbed_toolchain.h" 00020 #include "platform/mbed_interface.h" 00021 #include "platform/mbed_critical.h" 00022 #include "hal/serial_api.h" 00023 00024 #if DEVICE_SERIAL 00025 extern int stdio_uart_inited; 00026 extern serial_t stdio_uart; 00027 #endif 00028 00029 WEAK void mbed_die(void) { 00030 #if !defined (NRF51_H) && !defined(TARGET_EFM32) 00031 core_util_critical_section_enter(); 00032 #endif 00033 gpio_t led_err; gpio_init_out(&led_err, LED1); 00034 00035 while (1) { 00036 for (int i = 0; i < 4; ++i) { 00037 gpio_write(&led_err, 1); 00038 wait_ms(150); 00039 gpio_write(&led_err, 0); 00040 wait_ms(150); 00041 } 00042 00043 for (int i = 0; i < 4; ++i) { 00044 gpio_write(&led_err, 1); 00045 wait_ms(400); 00046 gpio_write(&led_err, 0); 00047 wait_ms(400); 00048 } 00049 } 00050 } 00051 00052 void mbed_error_printf(const char* format, ...) { 00053 va_list arg; 00054 va_start(arg, format); 00055 mbed_error_vfprintf(format, arg); 00056 va_end(arg); 00057 } 00058 00059 void mbed_error_vfprintf(const char * format, va_list arg) { 00060 #if DEVICE_SERIAL 00061 #define ERROR_BUF_SIZE (128) 00062 core_util_critical_section_enter(); 00063 char buffer[ERROR_BUF_SIZE]; 00064 int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg); 00065 if (size > 0) { 00066 if (!stdio_uart_inited) { 00067 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX); 00068 } 00069 #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES 00070 char stdio_out_prev = '\0'; 00071 for (int i = 0; i < size; i++) { 00072 if (buffer[i] == '\n' && stdio_out_prev != '\r') { 00073 serial_putc(&stdio_uart, '\r'); 00074 } 00075 serial_putc(&stdio_uart, buffer[i]); 00076 stdio_out_prev = buffer[i]; 00077 } 00078 #else 00079 for (int i = 0; i < size; i++) { 00080 serial_putc(&stdio_uart, buffer[i]); 00081 } 00082 #endif 00083 } 00084 core_util_critical_section_exit(); 00085 #endif 00086 }
Generated on Sun Jul 17 2022 08:25:27 by 1.7.2