/** * Digital Voice Modem - DSP Firmware (Hotspot) * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * @package DVM / DSP Firmware (Hotspot) * */ // // Based on code from the MMDVM_HS project. (https://github.com/juribeparada/MMDVM_HS) // Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) // /* * Copyright (c) 2020 by Jonathan Naylor G4KLX * Copyright (c) 2020 by Geoffrey Merck F4FXL - KC3FRA * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #if defined(STM32F10X_MD) || defined(STM32F4XX) #if !defined(__STM_UART_H__) #define __STM_UART_H__ #include "Defines.h" #if defined(STM32F10X_MD) #include #elif defined(STM32F4XX) #include "stm32f4xx.h" #endif const uint16_t BUFFER_SIZE = 2048U; //needs to be a power of 2 ! const uint16_t BUFFER_MASK = BUFFER_SIZE - 1; // --------------------------------------------------------------------------- // Class Declaration // This class represents a FIFO buffer on a STM32 UART. // --------------------------------------------------------------------------- class DSP_FW_API STM_UARTFIFO { public: /// Initializes a new instance of the STM_UARTFIFO class. STM_UARTFIFO() : m_head(0U), m_tail(0U) { /* stub */ } /// uint8_t get() { return m_buffer[BUFFER_MASK & (m_tail++)]; } /// void put(uint8_t data) { m_buffer[BUFFER_MASK & (m_head++)] = data; } /// Helper to reset data values to defaults. void reset() { m_tail = 0U; m_head = 0U; } /// bool isEmpty() { return m_tail == m_head; } /// bool isFull() { return ((m_head + 1U) & BUFFER_MASK) == (m_tail & BUFFER_MASK); } private: volatile uint8_t m_buffer[BUFFER_SIZE]; volatile uint16_t m_head; volatile uint16_t m_tail; }; // --------------------------------------------------------------------------- // Class Declaration // This class represents an STM32 UART. // --------------------------------------------------------------------------- class STM_UART { public: /// Initializes a new instance of the STM_UART class. STM_UART(); /// void init(USART_TypeDef* usart); /// uint8_t read(); /// void write(const uint8_t* data, uint16_t length); /// void handleIRQ(); /// Flushes the transmit shift register. void flush(); /// uint16_t available(); /// uint16_t availableForWrite(); private: USART_TypeDef* m_usart; STM_UARTFIFO m_rxFifo; STM_UARTFIFO m_txFifo; }; #endif // __SERIAL_PORT_H__ #endif