Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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