mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by Umar Naeem

Committer:
ranaumarnaeem
Date:
Tue May 23 12:54:50 2017 +0000
Revision:
165:2dd56e6daeec
Parent:
163:74e0ce7f98e8
jhjg

Who changed what in which revision?

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