Skip to content

Commit

Permalink
updated FW to handle full DVM protocol version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
W3AXL committed Jul 21, 2024
1 parent 9057c2a commit 1e77112
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 58 deletions.
2 changes: 1 addition & 1 deletion fw/v24/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
//#define DEBUG_VCP
//#define TRACE_VCP

#define VERSION_STRING "1.0"
#define VERSION_STRING "2.0"
#define DATE_STRING __DATE__ " " __TIME__

#define PERIODIC_STATUS
Expand Down
3 changes: 3 additions & 0 deletions fw/v24/inc/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ extern "C" {

#include <stdint.h>

#include "log.h"

typedef struct {
uint8_t * const buffer;
unsigned int size;
int head;
int tail;
const int maxlen;
Expand Down
3 changes: 3 additions & 0 deletions fw/v24/inc/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ extern "C" {
#define HDLC_ESCAPE_7E 0x5E // Follows the escape code to escape a 0x7E
#define HDLC_ESCAPE_7D 0x5D // Follows the escape code to escape a 0x7D

#define P25_LDU_FRAME_LENGTH_BYTES 216U

// Pin Definitions (pin names are labelled in STM32CubeMX projet)
#define GET_RXCLK(state) HAL_GPIO_ReadPin(DCE_RXCLK_GPIO_Port, DCE_RXCLK_Pin)
#define GET_RXD() HAL_GPIO_ReadPin(DCE_RXD_GPIO_Port, DCE_RXD_Pin)
Expand All @@ -55,6 +57,7 @@ void SyncDrop();
void SyncTimerCallback(void);
bool SyncAddTxByte(const uint8_t byte);
bool SyncAddTxBytes(const uint8_t *bytes, int len);
uint8_t SyncGetTxFree();
void RxMessageCallback();
uint16_t StuffByte(uint8_t byte);

Expand Down
32 changes: 18 additions & 14 deletions fw/v24/inc/vcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C" {
#include "stdint.h"
#include "main.h"
#include "log.h"
#include "sync.h"

#define VCP_TX_BUF_LEN 512
#define VCP_RX_BUF_LEN 512
Expand All @@ -25,20 +26,22 @@ extern "C" {

// DVM Serial Protocol Defines
enum DVM_COMMANDS {
CMD_GET_VERSION = 0x00,
CMD_GET_STATUS = 0x01,
CMD_P25_DATA = 0x31,
CMD_P25_LOST = 0x32,
CMD_P25_CLEAR = 0x33,
CMD_ACK = 0x70,
CMD_NAK = 0x7F,
CMD_DEBUG1 = 0xF1,
CMD_DEBUG2 = 0xF2,
CMD_DEBUG3 = 0xF3,
CMD_DEBUG4 = 0xF4,
CMD_DEBUG5 = 0xF5,
CMD_DEBUG_DUMP = 0xFA,
DVM_FRAME_START = 0xFE,
CMD_GET_VERSION = 0x00,
CMD_GET_STATUS = 0x01,
CMD_SET_MODE = 0x03,
CMD_P25_DATA = 0x31,
CMD_P25_LOST = 0x32,
CMD_P25_CLEAR = 0x33,
CMD_ACK = 0x70,
CMD_NAK = 0x7F,
CMD_DEBUG1 = 0xF1,
CMD_DEBUG2 = 0xF2,
CMD_DEBUG3 = 0xF3,
CMD_DEBUG4 = 0xF4,
CMD_DEBUG5 = 0xF5,
CMD_DEBUG_DUMP = 0xFA,
DVM_LONG_FRAME_START = 0xFD,
DVM_SHORT_FRAME_START = 0xFE,
};

void VCPRxITCallback(uint8_t* buf, uint32_t len);
Expand All @@ -48,6 +51,7 @@ bool VCPWrite(uint8_t *data, uint16_t len);
bool VCPWriteP25Frame(const uint8_t *data, uint16_t len);

void sendVersion();
void sendStatus();

bool VCPWriteDebug1(const char *text);
bool VCPWriteDebug2(const char *text, int16_t n1);
Expand Down
17 changes: 17 additions & 0 deletions fw/v24/src/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ int FifoPush(FIFO_t *c, uint8_t data)

c->buffer[c->head] = data;
c->head = next;

// Update our size
if (c->size < c->maxlen) {
c->size++;
} else {
log_warn("Somehow pushed to full fifo?");
}

return 0;
}

Expand All @@ -59,12 +67,21 @@ int FifoPop(FIFO_t *c, uint8_t *data)

*data = c->buffer[c->tail];
c->tail = next;

// Update our size
if (c->size > 0) {
c->size--;
} else {
log_warn("Somehow popped from 0-size fifo?");
}

return 0;
}

void FifoClear(FIFO_t *c)
{
uint8_t data = 0;
while (FifoPop(c, &data) != -1) {}
c->size = 0;
return;
}
8 changes: 8 additions & 0 deletions fw/v24/src/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,12 @@ void SyncTimerCallback(void)
// Gate the TX & RX pins
TXCLK_LOW();
}
}

/**
* @brief Report the free space in the fifo, divided by the LDU frame size in bytes
*/
uint8_t SyncGetTxFree()
{
return (syncTxFifo.maxlen - syncTxFifo.size) / P25_LDU_FRAME_LENGTH_BYTES;
}
Loading

0 comments on commit 1e77112

Please sign in to comment.