mirror of https://github.com/markqvist/MMDVM.git
parent
6161d298f7
commit
99ac6146d9
1
Debug.h
1
Debug.h
|
@ -27,7 +27,6 @@
|
||||||
#define DEBUG3(a,b,c) serial.writeDebug((a),(b),(c))
|
#define DEBUG3(a,b,c) serial.writeDebug((a),(b),(c))
|
||||||
#define DEBUG4(a,b,c,d) serial.writeDebug((a),(b),(c),(d))
|
#define DEBUG4(a,b,c,d) serial.writeDebug((a),(b),(c),(d))
|
||||||
#define DEBUG5(a,b,c,d,e) serial.writeDebug((a),(b),(c),(d),(e))
|
#define DEBUG5(a,b,c,d,e) serial.writeDebug((a),(b),(c),(d),(e))
|
||||||
#define ASSERT(a) serial.writeAssert((a),#a,__FILE__,__LINE__)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -54,6 +54,20 @@ int CSerialPort::availableInt(uint8_t n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSerialPort::availableForWriteInt(uint8_t n)
|
||||||
|
{
|
||||||
|
switch (n) {
|
||||||
|
case 1U:
|
||||||
|
return Serial.availableForWrite();
|
||||||
|
case 2U:
|
||||||
|
return Serial2.availableForWrite();
|
||||||
|
case 3U:
|
||||||
|
return Serial3.availableForWrite();
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t CSerialPort::readInt(uint8_t n)
|
uint8_t CSerialPort::readInt(uint8_t n)
|
||||||
{
|
{
|
||||||
switch (n) {
|
switch (n) {
|
||||||
|
|
|
@ -93,7 +93,8 @@ CSerialPort::CSerialPort() :
|
||||||
m_buffer(),
|
m_buffer(),
|
||||||
m_ptr(0U),
|
m_ptr(0U),
|
||||||
m_len(0U),
|
m_len(0U),
|
||||||
m_debug(false)
|
m_debug(false),
|
||||||
|
m_repeat()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,8 +644,10 @@ void CSerialPort::process()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if defined(SERIAL_REPEATER)
|
#if defined(SERIAL_REPEATER)
|
||||||
case MMDVM_SERIAL:
|
case MMDVM_SERIAL: {
|
||||||
writeInt(3U, m_buffer + 3U, m_len - 3U);
|
for (uint8_t i = 3U; i < m_len; i++)
|
||||||
|
m_repeat.put(m_buffer[i]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -661,9 +664,22 @@ void CSerialPort::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SERIAL_REPEATER)
|
#if defined(SERIAL_REPEATER)
|
||||||
// Drain any incoming serial data
|
// Write any outgoing serial data
|
||||||
while (availableInt(3U))
|
uint16_t space = m_repeat.getData();
|
||||||
readInt(3U);
|
if (space > 0U) {
|
||||||
|
int avail = availableForWriteInt(3U);
|
||||||
|
if (avail < space)
|
||||||
|
space = avail;
|
||||||
|
|
||||||
|
for (uint16_t i = 0U; i < space; i++) {
|
||||||
|
uint8_t c = m_repeat.get();
|
||||||
|
writeInt(3U, &c, 1U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read any incoming serial data
|
||||||
|
while (availableInt(3U))
|
||||||
|
readInt(3U);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1058,32 +1074,3 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n
|
||||||
|
|
||||||
writeInt(1U, reply, count, true);
|
writeInt(1U, reply, count, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSerialPort::writeAssert(bool cond, const char* text, const char* file, long line)
|
|
||||||
{
|
|
||||||
if (cond)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint8_t reply[200U];
|
|
||||||
|
|
||||||
reply[0U] = MMDVM_FRAME_START;
|
|
||||||
reply[1U] = 0U;
|
|
||||||
reply[2U] = MMDVM_DEBUG2;
|
|
||||||
|
|
||||||
uint8_t count = 3U;
|
|
||||||
for (uint8_t i = 0U; text[i] != '\0'; i++, count++)
|
|
||||||
reply[count] = text[i];
|
|
||||||
|
|
||||||
reply[count++] = ' ';
|
|
||||||
|
|
||||||
for (uint8_t i = 0U; file[i] != '\0'; i++, count++)
|
|
||||||
reply[count] = file[i];
|
|
||||||
|
|
||||||
reply[count++] = (line >> 8) & 0xFF;
|
|
||||||
reply[count++] = (line >> 0) & 0xFF;
|
|
||||||
|
|
||||||
reply[1U] = count;
|
|
||||||
|
|
||||||
writeInt(1U, reply, count, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
14
SerialPort.h
14
SerialPort.h
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
#include "SerialRB.h"
|
||||||
|
|
||||||
|
|
||||||
class CSerialPort {
|
class CSerialPort {
|
||||||
|
@ -55,13 +56,12 @@ public:
|
||||||
void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3);
|
void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3);
|
||||||
void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4);
|
void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4);
|
||||||
|
|
||||||
void writeAssert(bool cond, const char* text, const char* file, long line);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t m_buffer[256U];
|
uint8_t m_buffer[256U];
|
||||||
uint8_t m_ptr;
|
uint8_t m_ptr;
|
||||||
uint8_t m_len;
|
uint8_t m_len;
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
|
CSerialRB m_repeat;
|
||||||
|
|
||||||
void sendACK();
|
void sendACK();
|
||||||
void sendNAK(uint8_t err);
|
void sendNAK(uint8_t err);
|
||||||
|
@ -74,9 +74,9 @@ private:
|
||||||
// Hardware versions
|
// Hardware versions
|
||||||
void beginInt(uint8_t n, int speed);
|
void beginInt(uint8_t n, int speed);
|
||||||
int availableInt(uint8_t n);
|
int availableInt(uint8_t n);
|
||||||
|
int availableForWriteInt(uint8_t n);
|
||||||
uint8_t readInt(uint8_t n);
|
uint8_t readInt(uint8_t n);
|
||||||
void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false);
|
void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
|
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
|
||||||
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
|
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
|
||||||
|
* Copyright (c) 2017 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -207,7 +208,7 @@ void InitUSART1(int speed)
|
||||||
RXSerialfifoinit1();
|
RXSerialfifoinit1();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AvailUSART1(void)
|
uint8_t AvailUSART1()
|
||||||
{
|
{
|
||||||
if (RXSerialfifolevel1() > 0U)
|
if (RXSerialfifolevel1() > 0U)
|
||||||
return 1U;
|
return 1U;
|
||||||
|
@ -215,7 +216,12 @@ uint8_t AvailUSART1(void)
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ReadUSART1(void)
|
int AvailForWriteUSART1()
|
||||||
|
{
|
||||||
|
return TXSerialfifolevel1();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ReadUSART1()
|
||||||
{
|
{
|
||||||
uint8_t data_c = RXSerialfifo1[RXSerialfifotail1];
|
uint8_t data_c = RXSerialfifo1[RXSerialfifotail1];
|
||||||
|
|
||||||
|
@ -395,7 +401,7 @@ void InitUSART2(int speed)
|
||||||
RXSerialfifoinit2();
|
RXSerialfifoinit2();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AvailUSART2(void)
|
uint8_t AvailUSART2()
|
||||||
{
|
{
|
||||||
if (RXSerialfifolevel2() > 0U)
|
if (RXSerialfifolevel2() > 0U)
|
||||||
return 1U;
|
return 1U;
|
||||||
|
@ -403,7 +409,12 @@ uint8_t AvailUSART2(void)
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ReadUSART2(void)
|
int AvailForWriteUSART2()
|
||||||
|
{
|
||||||
|
return TXSerialfifolevel2();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ReadUSART2()
|
||||||
{
|
{
|
||||||
uint8_t data_c = RXSerialfifo2[RXSerialfifotail2];
|
uint8_t data_c = RXSerialfifo2[RXSerialfifotail2];
|
||||||
|
|
||||||
|
@ -583,7 +594,7 @@ void InitUSART3(int speed)
|
||||||
RXSerialfifoinit3();
|
RXSerialfifoinit3();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AvailUSART3(void)
|
uint8_t AvailUSART3()
|
||||||
{
|
{
|
||||||
if (RXSerialfifolevel3() > 0U)
|
if (RXSerialfifolevel3() > 0U)
|
||||||
return 1U;
|
return 1U;
|
||||||
|
@ -591,7 +602,12 @@ uint8_t AvailUSART3(void)
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ReadUSART3(void)
|
int AvailForWriteUSART3()
|
||||||
|
{
|
||||||
|
return TXSerialfifolevel3();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ReadUSART3()
|
||||||
{
|
{
|
||||||
uint8_t data_c = RXSerialfifo3[RXSerialfifotail3];
|
uint8_t data_c = RXSerialfifo3[RXSerialfifotail3];
|
||||||
|
|
||||||
|
@ -775,7 +791,7 @@ void InitUART5(int speed)
|
||||||
RXSerialfifoinit5();
|
RXSerialfifoinit5();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AvailUART5(void)
|
uint8_t AvailUART5()
|
||||||
{
|
{
|
||||||
if (RXSerialfifolevel5() > 0U)
|
if (RXSerialfifolevel5() > 0U)
|
||||||
return 1U;
|
return 1U;
|
||||||
|
@ -783,7 +799,12 @@ uint8_t AvailUART5(void)
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ReadUART5(void)
|
int AvailForWriteUSART5()
|
||||||
|
{
|
||||||
|
return TXSerialfifolevel5();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ReadUART5()
|
||||||
{
|
{
|
||||||
uint8_t data_c = RXSerialfifo5[RXSerialfifotail5];
|
uint8_t data_c = RXSerialfifo5[RXSerialfifotail5];
|
||||||
|
|
||||||
|
@ -847,7 +868,29 @@ int CSerialPort::availableInt(uint8_t n)
|
||||||
return AvailUART5();
|
return AvailUART5();
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return false;
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSerialPort::availableForWriteInt(uint8_t n)
|
||||||
|
{
|
||||||
|
switch (n) {
|
||||||
|
case 1U:
|
||||||
|
#if defined(STM32F4_DISCOVERY)
|
||||||
|
return AvailForWriteUSART3();
|
||||||
|
#elif defined(STM32F4_PI)
|
||||||
|
return AvailForWriteUSART1();
|
||||||
|
#elif defined(STM32F4_NUCLEO)
|
||||||
|
return AvailForWriteUSART2();
|
||||||
|
#endif
|
||||||
|
case 3U:
|
||||||
|
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||||
|
return AvailForWriteUSART1();
|
||||||
|
#else
|
||||||
|
return AvailForWriteUART5();
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue