Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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