/**
* 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) 2015,2016,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2016,2017,2018,2019,2020 by Andy Uribe CA6JAU
* Copyright (C) 2017 by Danilo DB4PLE
* Copyright (C) 2017-2021 Bryan Biedenkapp N2PLL
*
* 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(__IO_H__)
#define __IO_H__
#include "Defines.h"
#include "Globals.h"
#include "BitBuffer.h"
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
#if defined(DUPLEX)
#if defined(STM32_USB_HOST)
#define CAL_DLY_LOOP 98950U
#else
#define CAL_DLY_LOOP 96100U
#endif
#else
#if defined(STM32_USB_HOST)
#define CAL_DLY_LOOP 110850U
#else
#define CAL_DLY_LOOP 104600U
#endif
#endif
// ---------------------------------------------------------------------------
// Global Externs
// ---------------------------------------------------------------------------
extern uint32_t m_rxFrequency;
extern uint32_t m_txFrequency;
extern uint8_t m_rfPower;
// ---------------------------------------------------------------------------
// Class Declaration
// Implements the input/output data path with the radio air interface.
// ---------------------------------------------------------------------------
class DSP_FW_API IO {
public:
/// Initializes a new instance of the IO class.
IO();
/// Starts air interface sampler.
void start();
/// Process bits from air interface.
void process();
/// Write bits to air interface.
void write(uint8_t* data, uint16_t length, const uint8_t* control = NULL);
/// Helper to get how much space the transmit ring buffer has for samples.
uint16_t getSpace(void) const;
///
void setDecode(bool dcd);
/// Set modem mode.
void setMode(DVM_STATE modemState);
/// Hardware interrupt handler.
void interrupt1();
#if defined(DUPLEX)
/// Hardware interrupt handler.
void interrupt2();
#endif
/// Sets the ADF7021 RF configuration.
void rf1Conf(DVM_STATE modemState, bool reset);
#if defined(DUPLEX)
/// Sets the ADF7021 RF configuration.
void rf2Conf(DVM_STATE modemState);
#endif
///
void setDeviations(uint8_t dmrTXLevel, uint8_t p25TXLevel);
/// Sets the RF parameters.
uint8_t setRFParams(uint32_t rxFreq, uint32_t txFreq, uint8_t rfPower);
/// Sets the RF adjustment parameters.
void setRFAdjust(int8_t dmrDiscBWAdj, int8_t p25DiscBWAdj, int8_t dmrPostBWAdj, int8_t p25PostBWAdj);
/// Flag indicating the TX ring buffer has overflowed.
bool hasTXOverflow(void);
/// Flag indicating the RX ring buffer has overflowed.
bool hasRXOverflow(void);
///
void resetWatchdog(void);
///
uint32_t getWatchdog(void);
/// Gets the CPU type the firmware is running on.
uint8_t getCPU() const;
/// Gets the unique identifier for the air interface.
void getUDID(uint8_t* buffer);
///
void updateCal(DVM_STATE modemState);
///
void delayBit(void);
///
uint16_t readRSSI(void);
///
void selfTest();
///
void getIntCounter(uint16_t& int1, uint16_t& int2);
#if defined(ZUMSPOT_ADF7021) || defined(LONESTAR_USB) || defined(SKYBRIDGE_HS)
///
bool isDualBand();
#endif
///
void SCLK(bool on);
///
void SDATA(bool on);
///
bool SREAD();
///
void SLE1(bool on);
#if defined(DUPLEX)
///
void SLE2(bool on);
///
bool RXD2();
#endif
///
void CE(bool on);
///
bool RXD1();
///
bool CLK();
private:
bool m_started;
BitBuffer m_rxBuffer;
BitBuffer m_txBuffer;
uint32_t m_ledCount;
bool m_ledValue;
volatile uint32_t m_watchdog;
volatile uint16_t m_int1Counter;
volatile uint16_t m_int2Counter;
/// Helper to check the frequencies are within band ranges of the ADF7021.
void checkBand(uint32_t rxFreq, uint32_t txFreq);
#if defined(ZUMSPOT_ADF7021) || defined(LONESTAR_USB) || defined(SKYBRIDGE_HS)
///
void setBandVHF(bool enable);
///
bool hasSingleADF7021();
#endif
///
void configureBand();
///
void configureTxRx(DVM_STATE modemState);
///
void setTX();
///
void setRX(bool doSle = true);
///
void delayIfCal();
///
void delayReset();
///
void delayUS(uint32_t us);
// Hardware specific routines
/// Initializes hardware interrupts.
void initInt();
/// Starts hardware interrupts.
void startInt();
///
void setTXDInt(bool on);
#if defined(BIDIR_DATA_PIN)
///
void setDataDirOut(bool dir);
///
void setRXDInt(bool on);
#endif
///
void setLEDInt(bool on);
///
void setPTTInt(bool on);
///
void setCOSInt(bool on);
///
void setDMRInt(bool on);
///
void setP25Int(bool on);
};
#endif