Skip to content

Commit 1e77112

Browse files
committed
updated FW to handle full DVM protocol version 4
1 parent 9057c2a commit 1e77112

File tree

7 files changed

+191
-58
lines changed

7 files changed

+191
-58
lines changed

fw/v24/inc/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C" {
2828
//#define DEBUG_VCP
2929
//#define TRACE_VCP
3030

31-
#define VERSION_STRING "1.0"
31+
#define VERSION_STRING "2.0"
3232
#define DATE_STRING __DATE__ " " __TIME__
3333

3434
#define PERIODIC_STATUS

fw/v24/inc/fifo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ extern "C" {
1515

1616
#include <stdint.h>
1717

18+
#include "log.h"
19+
1820
typedef struct {
1921
uint8_t * const buffer;
22+
unsigned int size;
2023
int head;
2124
int tail;
2225
const int maxlen;

fw/v24/inc/sync.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern "C" {
3232
#define HDLC_ESCAPE_7E 0x5E // Follows the escape code to escape a 0x7E
3333
#define HDLC_ESCAPE_7D 0x5D // Follows the escape code to escape a 0x7D
3434

35+
#define P25_LDU_FRAME_LENGTH_BYTES 216U
36+
3537
// Pin Definitions (pin names are labelled in STM32CubeMX projet)
3638
#define GET_RXCLK(state) HAL_GPIO_ReadPin(DCE_RXCLK_GPIO_Port, DCE_RXCLK_Pin)
3739
#define GET_RXD() HAL_GPIO_ReadPin(DCE_RXD_GPIO_Port, DCE_RXD_Pin)
@@ -55,6 +57,7 @@ void SyncDrop();
5557
void SyncTimerCallback(void);
5658
bool SyncAddTxByte(const uint8_t byte);
5759
bool SyncAddTxBytes(const uint8_t *bytes, int len);
60+
uint8_t SyncGetTxFree();
5861
void RxMessageCallback();
5962
uint16_t StuffByte(uint8_t byte);
6063

fw/v24/inc/vcp.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
#include "stdint.h"
1818
#include "main.h"
1919
#include "log.h"
20+
#include "sync.h"
2021

2122
#define VCP_TX_BUF_LEN 512
2223
#define VCP_RX_BUF_LEN 512
@@ -25,20 +26,22 @@ extern "C" {
2526

2627
// DVM Serial Protocol Defines
2728
enum DVM_COMMANDS {
28-
CMD_GET_VERSION = 0x00,
29-
CMD_GET_STATUS = 0x01,
30-
CMD_P25_DATA = 0x31,
31-
CMD_P25_LOST = 0x32,
32-
CMD_P25_CLEAR = 0x33,
33-
CMD_ACK = 0x70,
34-
CMD_NAK = 0x7F,
35-
CMD_DEBUG1 = 0xF1,
36-
CMD_DEBUG2 = 0xF2,
37-
CMD_DEBUG3 = 0xF3,
38-
CMD_DEBUG4 = 0xF4,
39-
CMD_DEBUG5 = 0xF5,
40-
CMD_DEBUG_DUMP = 0xFA,
41-
DVM_FRAME_START = 0xFE,
29+
CMD_GET_VERSION = 0x00,
30+
CMD_GET_STATUS = 0x01,
31+
CMD_SET_MODE = 0x03,
32+
CMD_P25_DATA = 0x31,
33+
CMD_P25_LOST = 0x32,
34+
CMD_P25_CLEAR = 0x33,
35+
CMD_ACK = 0x70,
36+
CMD_NAK = 0x7F,
37+
CMD_DEBUG1 = 0xF1,
38+
CMD_DEBUG2 = 0xF2,
39+
CMD_DEBUG3 = 0xF3,
40+
CMD_DEBUG4 = 0xF4,
41+
CMD_DEBUG5 = 0xF5,
42+
CMD_DEBUG_DUMP = 0xFA,
43+
DVM_LONG_FRAME_START = 0xFD,
44+
DVM_SHORT_FRAME_START = 0xFE,
4245
};
4346

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

5053
void sendVersion();
54+
void sendStatus();
5155

5256
bool VCPWriteDebug1(const char *text);
5357
bool VCPWriteDebug2(const char *text, int16_t n1);

fw/v24/src/fifo.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ int FifoPush(FIFO_t *c, uint8_t data)
3333

3434
c->buffer[c->head] = data;
3535
c->head = next;
36+
37+
// Update our size
38+
if (c->size < c->maxlen) {
39+
c->size++;
40+
} else {
41+
log_warn("Somehow pushed to full fifo?");
42+
}
43+
3644
return 0;
3745
}
3846

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

6068
*data = c->buffer[c->tail];
6169
c->tail = next;
70+
71+
// Update our size
72+
if (c->size > 0) {
73+
c->size--;
74+
} else {
75+
log_warn("Somehow popped from 0-size fifo?");
76+
}
77+
6278
return 0;
6379
}
6480

6581
void FifoClear(FIFO_t *c)
6682
{
6783
uint8_t data = 0;
6884
while (FifoPop(c, &data) != -1) {}
85+
c->size = 0;
6986
return;
7087
}

fw/v24/src/sync.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,12 @@ void SyncTimerCallback(void)
441441
// Gate the TX & RX pins
442442
TXCLK_LOW();
443443
}
444+
}
445+
446+
/**
447+
* @brief Report the free space in the fifo, divided by the LDU frame size in bytes
448+
*/
449+
uint8_t SyncGetTxFree()
450+
{
451+
return (syncTxFifo.maxlen - syncTxFifo.size) / P25_LDU_FRAME_LENGTH_BYTES;
444452
}

0 commit comments

Comments
 (0)