mbed library sources. Supersedes mbed-src.
Dependents: SPIne CH_Communicatuin_Test CH_Communicatuin_Test2 MCP_SPIne ... more
Fork of mbed-dev-f303 by
platform/mbed_board.c@160:d5399cc887bb, 2017-03-14 (annotated)
- Committer:
- <>
- Date:
- Tue Mar 14 16:40:56 2017 +0000
- Revision:
- 160:d5399cc887bb
- Parent:
- 149:156823d33999
- Child:
- 163:74e0ce7f98e8
This updates the lib to the mbed lib v138
Who changed what in which revision?
User | Revision | Line number | New 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 |
<> | 160:d5399cc887bb | 78 | |
<> | 160:d5399cc887bb | 79 | #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES |
<> | 160:d5399cc887bb | 80 | char stdio_out_prev; |
<> | 160:d5399cc887bb | 81 | #endif |
<> | 160:d5399cc887bb | 82 | |
<> | 149:156823d33999 | 83 | core_util_critical_section_enter(); |
<> | 149:156823d33999 | 84 | char buffer[128]; |
<> | 149:156823d33999 | 85 | int size = vsprintf(buffer, format, arg); |
<> | 149:156823d33999 | 86 | if (size > 0) { |
<> | 149:156823d33999 | 87 | if (!stdio_uart_inited) { |
<> | 160:d5399cc887bb | 88 | serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX); |
<> | 149:156823d33999 | 89 | } |
<> | 160:d5399cc887bb | 90 | #if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES |
<> | 160:d5399cc887bb | 91 | for (unsigned int i = 0; i < size; i++) { |
<> | 160:d5399cc887bb | 92 | if (buffer[i] == '\n' && stdio_out_prev != '\r') { |
<> | 160:d5399cc887bb | 93 | serial_putc(&stdio_uart, '\r'); |
<> | 160:d5399cc887bb | 94 | } |
<> | 160:d5399cc887bb | 95 | serial_putc(&stdio_uart, buffer[i]); |
<> | 160:d5399cc887bb | 96 | stdio_out_prev = buffer[i]; |
<> | 160:d5399cc887bb | 97 | } |
<> | 160:d5399cc887bb | 98 | #else |
<> | 160:d5399cc887bb | 99 | for (unsigned int i = 0; i < size; i++) { |
<> | 149:156823d33999 | 100 | serial_putc(&stdio_uart, buffer[i]); |
<> | 149:156823d33999 | 101 | } |
<> | 160:d5399cc887bb | 102 | #endif |
<> | 149:156823d33999 | 103 | } |
<> | 149:156823d33999 | 104 | core_util_critical_section_exit(); |
<> | 149:156823d33999 | 105 | #endif |
<> | 149:156823d33999 | 106 | } |