mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Fri Feb 16 16:09:33 2018 +0000
Revision:
181:57724642e740
Parent:
174:b96e65c34a4d
Child:
187:0387e8f68319
mbed-dev library. Release version 159.

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
AnnaBridge 174:b96e65c34a4d 33 gpio_t led_err; gpio_init_out(&led_err, LED1);
<> 149:156823d33999 34
<> 149:156823d33999 35 while (1) {
AnnaBridge 174:b96e65c34a4d 36 for (int i = 0; i < 4; ++i) {
AnnaBridge 174:b96e65c34a4d 37 gpio_write(&led_err, 1);
AnnaBridge 174:b96e65c34a4d 38 wait_ms(150);
AnnaBridge 174:b96e65c34a4d 39 gpio_write(&led_err, 0);
AnnaBridge 174:b96e65c34a4d 40 wait_ms(150);
AnnaBridge 174:b96e65c34a4d 41 }
<> 149:156823d33999 42
AnnaBridge 174:b96e65c34a4d 43 for (int i = 0; i < 4; ++i) {
AnnaBridge 174:b96e65c34a4d 44 gpio_write(&led_err, 1);
AnnaBridge 174:b96e65c34a4d 45 wait_ms(400);
AnnaBridge 174:b96e65c34a4d 46 gpio_write(&led_err, 0);
AnnaBridge 174:b96e65c34a4d 47 wait_ms(400);
AnnaBridge 174:b96e65c34a4d 48 }
<> 149:156823d33999 49 }
<> 149:156823d33999 50 }
<> 149:156823d33999 51
<> 149:156823d33999 52 void mbed_error_printf(const char* format, ...) {
<> 149:156823d33999 53 va_list arg;
<> 149:156823d33999 54 va_start(arg, format);
<> 149:156823d33999 55 mbed_error_vfprintf(format, arg);
<> 149:156823d33999 56 va_end(arg);
<> 149:156823d33999 57 }
<> 149:156823d33999 58
<> 149:156823d33999 59 void mbed_error_vfprintf(const char * format, va_list arg) {
<> 149:156823d33999 60 #if DEVICE_SERIAL
Anna Bridge 163:74e0ce7f98e8 61 #define ERROR_BUF_SIZE (128)
<> 149:156823d33999 62 core_util_critical_section_enter();
Anna Bridge 163:74e0ce7f98e8 63 char buffer[ERROR_BUF_SIZE];
Anna Bridge 163:74e0ce7f98e8 64 int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg);
<> 149:156823d33999 65 if (size > 0) {
<> 149:156823d33999 66 if (!stdio_uart_inited) {
<> 160:d5399cc887bb 67 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
<> 149:156823d33999 68 }
<> 160:d5399cc887bb 69 #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
Anna Bridge 163:74e0ce7f98e8 70 char stdio_out_prev = '\0';
Anna Bridge 163:74e0ce7f98e8 71 for (int i = 0; i < size; i++) {
<> 160:d5399cc887bb 72 if (buffer[i] == '\n' && stdio_out_prev != '\r') {
<> 160:d5399cc887bb 73 serial_putc(&stdio_uart, '\r');
<> 160:d5399cc887bb 74 }
<> 160:d5399cc887bb 75 serial_putc(&stdio_uart, buffer[i]);
<> 160:d5399cc887bb 76 stdio_out_prev = buffer[i];
<> 160:d5399cc887bb 77 }
<> 160:d5399cc887bb 78 #else
Anna Bridge 163:74e0ce7f98e8 79 for (int i = 0; i < size; i++) {
<> 149:156823d33999 80 serial_putc(&stdio_uart, buffer[i]);
<> 149:156823d33999 81 }
<> 160:d5399cc887bb 82 #endif
<> 149:156823d33999 83 }
<> 149:156823d33999 84 core_util_critical_section_exit();
<> 149:156823d33999 85 #endif
<> 149:156823d33999 86 }