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