/* * The MIT License (MIT) * * Copyright (c) 2015 Johan Kanflo (github.com/kanflo) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include #include #include #if (configUSE_COUNTING_SEMAPHORES == 0) #error "You need to define configUSE_COUNTING_SEMAPHORES in a local FreeRTOSConfig.h, see examples/terminal/FreeRTOSConfig.h" #endif // IRQ driven UART RX driver for ESP8266 written for use with esp-open-rtos // TODO: Handle UART1 #ifndef UART0 #define UART0 (0) #endif #define UART0_RX_SIZE (128) // ESP8266 UART HW FIFO size static xSemaphoreHandle uart0_sem = NULL; static bool inited = false; static void uart0_rx_init(void); IRAM void uart0_rx_handler(void) { // TODO: Handle UART1, see reg 0x3ff20020, bit2, bit0 represents uart1 and uart0 respectively if (!UART(UART0).INT_STATUS & UART_INT_STATUS_RXFIFO_FULL) { return; } // printf(" [%08x (%d)]\n", READ_PERI_REG(UART_INT_ST(UART0)), READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)); if (UART(UART0).INT_STATUS & UART_INT_STATUS_RXFIFO_FULL) { UART(UART0).INT_CLEAR = UART_INT_CLEAR_RXFIFO_FULL; if (UART(UART0).STATUS & (UART_STATUS_RXFIFO_COUNT_M << UART_STATUS_RXFIFO_COUNT_S)) { long int xHigherPriorityTaskWoken; _xt_isr_mask(1 << INUM_UART); _xt_clear_ints(1<