Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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