dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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