TUKS MCU Introductory course / TUKS-COURSE-2-LED
Committer:
elmot
Date:
Sat Feb 25 08:59:21 2017 +0000
Revision:
6:0018763974d3
Parent:
1:d0dfbce63a89
No comment

Who changed what in which revision?

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