o Numerous changes
o New commands
o Bug fixes
o Temperature measurement support
Dev1
DigitalConfections 2020-05-25 22:52:05 -04:00
rodzic 559b4a3a3f
commit d5210b08b3
4 zmienionych plików z 1601 dodań i 1571 usunięć

13
defs.h
Wyświetl plik

@ -36,7 +36,7 @@
//#define TRANQUILIZE_WATCHDOG
#define PRODUCT_NAME_SHORT "ARDF Tx"
#define PRODUCT_NAME_LONG "ARDF Dual-Band Transmitter"
#define PRODUCT_NAME_LONG "WB8WFK ARDF Transmitter"
/*******************************************************/
@ -65,6 +65,14 @@ typedef unsigned char uint8_t;
#define BIAS_DAC DAC081C_I2C_SLAVE_ADDR_A2
#endif
typedef enum {
// TX1 = 0xA4,
// TX2 = 0xA3,
// TX3 = 0xA2,
// TX4 = 0xA1,
TX5 = 0xA0
} Tx_t;
/*******************************************************/
/* Error Codes */
/*******************************************************/
@ -157,7 +165,7 @@ typedef uint16_t BatteryLevel; /* in milliVolts */
/******************************************************
* EEPROM definitions */
#define EEPROM_INITIALIZED_FLAG 0xAC
#define EEPROM_INITIALIZED_FLAG 0xAD
#define EEPROM_UNINITIALIZED 0x00
#define EEPROM_STATION_ID_DEFAULT "FOXBOX"
@ -175,6 +183,7 @@ typedef uint16_t BatteryLevel; /* in milliVolts */
#define EEPROM_CLOCK_CALIBRATION_DEFAULT 15629
#define EEPROM_OVERRIDE_DIP_SW_DEFAULT 0
#define EEPROM_ENABLE_LEDS_DEFAULT 1
#define EEPROM_ENABLE_SYNC_DEFAULT 1
#define EEPROM_SI5351_CALIBRATION_DEFAULT 0x00
#define EEPROM_CLK0_OUT_DEFAULT 133000000

Wyświetl plik

@ -25,7 +25,6 @@
#include "linkbus.h"
#include "defs.h"
//#include "util.h"
//#include <string.h>
//#include <stdio.h>
@ -35,7 +34,18 @@
static volatile BOOL g_bus_disabled = TRUE;
static const char crlf[] = "\n";
static char lineTerm[8] = "\n";
static const char textPrompt[] = "TX> ";
static const char textPrompt[] = "> ";
static const char textHelp[][LINKBUS_MAX_TX_MSG_LENGTH] = { "\nCommands:\n",
" CAL - Calibrate\n",
" DIP - Override DIP\n",
" FAC - Factory reset\n",
" GO - Sync clock\n",
" ID - Set callsign\n",
" LED - LED on/off\n",
" RST - Reset\n",
" SYN - Sync on/off\n",
" VER - S/W version\n" };
static char g_tempMsgBuff[LINKBUS_MAX_MSG_LENGTH];
@ -43,124 +53,124 @@ static char g_tempMsgBuff[LINKBUS_MAX_MSG_LENGTH];
BOOL linkbus_start_tx(void);
/* Module global variables */
static volatile BOOL linkbus_tx_active = FALSE; // volatile is required to ensure optimizer handles this properly
static volatile BOOL linkbus_tx_active = FALSE; /* volatile is required to ensure optimizer handles this properly */
static LinkbusTxBuffer tx_buffer[LINKBUS_NUMBER_OF_TX_MSG_BUFFERS];
static LinkbusRxBuffer rx_buffer[LINKBUS_NUMBER_OF_RX_MSG_BUFFERS];
LinkbusTxBuffer* nextFullTxBuffer(void)
{
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
while(tx_buffer[bufferIndex][0] == '\0')
{
if(++count >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
found = FALSE;
break;
}
while(tx_buffer[bufferIndex][0] == '\0')
{
if(++count >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
found = FALSE;
break;
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
if(found)
{
return( &tx_buffer[bufferIndex]);
}
if(found)
{
return( &tx_buffer[bufferIndex]);
}
return(null);
return(null);
}
LinkbusTxBuffer* nextEmptyTxBuffer(void)
{
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
while(tx_buffer[bufferIndex][0] != '\0')
{
if(++count >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
found = FALSE;
break;
}
while(tx_buffer[bufferIndex][0] != '\0')
{
if(++count >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
found = FALSE;
break;
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_TX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
if(found)
{
return( &tx_buffer[bufferIndex]);
}
if(found)
{
return( &tx_buffer[bufferIndex]);
}
return(null);
return(null);
}
LinkbusRxBuffer* nextEmptyRxBuffer(void)
{
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
while(rx_buffer[bufferIndex].id != MESSAGE_EMPTY)
{
if(++count >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
found = FALSE;
break;
}
while(rx_buffer[bufferIndex].id != MESSAGE_EMPTY)
{
if(++count >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
found = FALSE;
break;
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
if(found)
{
return( &rx_buffer[bufferIndex]);
}
if(found)
{
return( &rx_buffer[bufferIndex]);
}
return(null);
return(null);
}
LinkbusRxBuffer* nextFullRxBuffer(void)
{
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
BOOL found = TRUE;
static uint8_t bufferIndex = 0;
uint8_t count = 0;
while(rx_buffer[bufferIndex].id == MESSAGE_EMPTY)
{
if(++count >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
found = FALSE;
break;
}
while(rx_buffer[bufferIndex].id == MESSAGE_EMPTY)
{
if(++count >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
found = FALSE;
break;
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
bufferIndex++;
if(bufferIndex >= LINKBUS_NUMBER_OF_RX_MSG_BUFFERS)
{
bufferIndex = 0;
}
}
if(found)
{
return( &rx_buffer[bufferIndex]);
}
if(found)
{
return( &rx_buffer[bufferIndex]);
}
return(null);
return(null);
}
@ -169,125 +179,131 @@ LinkbusRxBuffer* nextFullRxBuffer(void)
************************************************************************/
BOOL linkbusTxInProgress(void)
{
return(linkbus_tx_active);
return(linkbus_tx_active);
}
BOOL linkbus_start_tx(void)
{
BOOL success = !linkbus_tx_active;
BOOL success = !linkbus_tx_active;
if(success) /* message will be lost if transmit is busy */
{
linkbus_tx_active = TRUE;
UCSR0B |= (1 << UDRIE0);
}
if(success) /* message will be lost if transmit is busy */
{
linkbus_tx_active = TRUE;
UCSR0B |= (1 << UDRIE0);
}
return(success);
return(success);
}
void linkbus_end_tx(void)
{
if(linkbus_tx_active)
{
UCSR0B &= ~(1 << UDRIE0);
linkbus_tx_active = FALSE;
}
if(linkbus_tx_active)
{
UCSR0B &= ~(1 << UDRIE0);
linkbus_tx_active = FALSE;
}
}
void linkbus_reset_rx(void)
{
if(UCSR0B & (1 << RXEN0)) /* perform only if rx is currently enabled */
{
UCSR0B &= ~(1 << RXEN0);
if(UCSR0B & (1 << RXEN0)) /* perform only if rx is currently enabled */
{
UCSR0B &= ~(1 << RXEN0);
/* uint16_t s = sizeof(rx_buffer); // test */
memset(rx_buffer, 0, sizeof(rx_buffer));
memset(rx_buffer, 0, sizeof(rx_buffer));
/* if(s) s = 0; // test */
UCSR0B |= (1 << RXEN0);
}
UCSR0B |= (1 << RXEN0);
}
}
void linkbus_init(uint32_t baud)
{
memset(rx_buffer, 0, sizeof(rx_buffer));
memset(rx_buffer, 0, sizeof(rx_buffer));
for(int bufferIndex=0; bufferIndex<LINKBUS_NUMBER_OF_TX_MSG_BUFFERS; bufferIndex++)
{
tx_buffer[bufferIndex][0] = '\0';
}
for(int bufferIndex = 0; bufferIndex < LINKBUS_NUMBER_OF_TX_MSG_BUFFERS; bufferIndex++)
{
tx_buffer[bufferIndex][0] = '\0';
}
/*Set baud rate */
uint16_t myubrr = MYUBRR(baud);
UBRR0H = (uint8_t)(myubrr >> 8);
UBRR0L = (uint8_t)myubrr;
/* Enable receiver and transmitter and related interrupts */
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
/* UCSR0B = (1<<RXEN0) | (1<<TXEN0); */
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1 << USBS0) | (3 << UCSZ00);
g_bus_disabled = FALSE;
/*Set baud rate */
uint16_t myubrr = MYUBRR(baud);
UBRR0H = (uint8_t)(myubrr >> 8);
UBRR0L = (uint8_t)myubrr;
/* Enable receiver and transmitter and related interrupts */
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
/* UCSR0B = (1<<RXEN0) | (1<<TXEN0);
* Set frame format: 8data, 2stop bit */
UCSR0C = (1 << USBS0) | (3 << UCSZ00);
g_bus_disabled = FALSE;
}
void linkbus_disable(void)
{
uint8_t bufferIndex;
uint8_t bufferIndex;
g_bus_disabled = TRUE;
UCSR0B = 0;
linkbus_end_tx();
memset(rx_buffer, 0, sizeof(rx_buffer));
g_bus_disabled = TRUE;
UCSR0B = 0;
linkbus_end_tx();
memset(rx_buffer, 0, sizeof(rx_buffer));
for(bufferIndex=0; bufferIndex<LINKBUS_NUMBER_OF_TX_MSG_BUFFERS; bufferIndex++)
{
tx_buffer[bufferIndex][0] = '\0';
}
for(bufferIndex = 0; bufferIndex < LINKBUS_NUMBER_OF_TX_MSG_BUFFERS; bufferIndex++)
{
tx_buffer[bufferIndex][0] = '\0';
}
}
void linkbus_enable(void)
{
uint8_t bufferIndex;
uint8_t bufferIndex;
g_bus_disabled = FALSE;
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
g_bus_disabled = FALSE;
UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
memset(rx_buffer, 0, sizeof(rx_buffer));
memset(rx_buffer, 0, sizeof(rx_buffer));
for(bufferIndex=0; bufferIndex<LINKBUS_NUMBER_OF_TX_MSG_BUFFERS; bufferIndex++)
{
tx_buffer[bufferIndex][0] = '\0';
}
for(bufferIndex = 0; bufferIndex < LINKBUS_NUMBER_OF_TX_MSG_BUFFERS; bufferIndex++)
{
tx_buffer[bufferIndex][0] = '\0';
}
}
BOOL linkbus_send_text(char* text)
{
BOOL err = TRUE;
uint16_t tries = 200;
BOOL err = TRUE;
uint16_t tries = 200;
if(g_bus_disabled) return err;
if(g_bus_disabled)
{
return( err);
}
if(text)
{
LinkbusTxBuffer* buff = nextEmptyTxBuffer();
if(text)
{
LinkbusTxBuffer* buff = nextEmptyTxBuffer();
while(!buff && tries)
{
while(linkbusTxInProgress() && tries)
{
if(tries) tries--; /* wait until transmit finishes */
}
buff = nextEmptyTxBuffer();
}
while(!buff && tries)
{
while(linkbusTxInProgress() && tries)
{
if(tries)
{
tries--; /* wait until transmit finishes */
}
}
buff = nextEmptyTxBuffer();
}
if(buff)
{
sprintf(*buff, text);
if(buff)
{
sprintf(*buff, text);
linkbus_start_tx();
err = FALSE;
}
}
linkbus_start_tx();
err = FALSE;
}
}
return(err);
return(err);
}
@ -297,44 +313,47 @@ BOOL linkbus_send_text(char* text)
void lb_send_msg(LBMessageType msgType, char* msgLabel, char* msgStr)
{
char prefix = '$';
char terminus = ';';
char prefix = '$';
char terminus = ';';
if(msgType == LINKBUS_MSG_REPLY)
{
prefix = '!';
}
else if(msgType == LINKBUS_MSG_QUERY)
{
terminus = '?';
}
if(msgType == LINKBUS_MSG_REPLY)
{
prefix = '!';
}
else if(msgType == LINKBUS_MSG_QUERY)
{
terminus = '?';
}
sprintf(g_tempMsgBuff, "%c%s,%s%c", prefix, msgLabel, msgStr, terminus);
sprintf(g_tempMsgBuff, "%c%s,%s%c", prefix, msgLabel, msgStr, terminus);
linkbus_send_text(g_tempMsgBuff);
linkbus_send_text(g_tempMsgBuff);
}
void lb_send_sync(void)
{
sprintf(g_tempMsgBuff, ".....");
linkbus_send_text(g_tempMsgBuff);
sprintf(g_tempMsgBuff, ".....");
linkbus_send_text(g_tempMsgBuff);
}
void lb_broadcast_num(uint16_t data, char* str)
{
char t[6] = "\0";
char t[6] = "\0";
sprintf(t, "%u", data);
g_tempMsgBuff[0] = '\0';
sprintf(t, "%u", data);
g_tempMsgBuff[0] = '\0';
if(str)
{
sprintf(g_tempMsgBuff, "%s,%s;", str, t);
}
if(str)
{
sprintf(g_tempMsgBuff, "%s,%s;", str, t);
}
if(g_tempMsgBuff[0]) linkbus_send_text(g_tempMsgBuff);
if(g_tempMsgBuff[0])
{
linkbus_send_text(g_tempMsgBuff);
}
}
/***********************************************************************************
@ -343,7 +362,7 @@ void lb_broadcast_num(uint16_t data, char* str)
void lb_send_NewPrompt(void)
{
linkbus_send_text((char*)crlf);
linkbus_send_text((char*)textPrompt);
}
void lb_send_NewLine(void)
@ -365,11 +384,17 @@ void lb_echo_char(uint8_t c)
BOOL lb_send_string(char* str)
{
if(str == NULL) return TRUE;
if(strlen(str) > LINKBUS_MAX_MSG_LENGTH) return TRUE;
if(str == NULL)
{
return( TRUE);
}
if(strlen(str) > LINKBUS_MAX_MSG_LENGTH)
{
return( TRUE);
}
strncpy(g_tempMsgBuff, str, LINKBUS_MAX_MSG_LENGTH);
linkbus_send_text(g_tempMsgBuff);
return FALSE;
return( FALSE);
}
void lb_send_value(uint16_t value, char* label)
@ -377,3 +402,41 @@ void lb_send_value(uint16_t value, char* label)
sprintf(g_tempMsgBuff, "> %s=%d%s", label, value, lineTerm);
linkbus_send_text(g_tempMsgBuff);
}
/***********************************************************************
* lb_send_Help(void)
************************************************************************/
void lb_send_Help(void)
{
if(g_bus_disabled)
{
return;
}
sprintf(g_tempMsgBuff, "\n*** %s Ver. %s ***", PRODUCT_NAME_LONG, SW_REVISION);
while(linkbus_send_text(g_tempMsgBuff))
{
;
}
while(linkbusTxInProgress())
{
;
}
size_t n = sizeof(textHelp) / sizeof(textHelp[0]);
for(uint8_t i = 0; i < n; i++)
{
while(linkbus_send_text((char*)textHelp[i]))
{
;
}
while(linkbusTxInProgress())
{
;
}
}
lb_send_NewLine();
}

Wyświetl plik

@ -35,7 +35,8 @@
#define LINKBUS_MAX_MSG_FIELD_LENGTH 21
#define LINKBUS_MAX_MSG_NUMBER_OF_FIELDS 3
#define LINKBUS_NUMBER_OF_RX_MSG_BUFFERS 2
#define LINKBUS_NUMBER_OF_TX_MSG_BUFFERS 8
#define LINKBUS_MAX_TX_MSG_LENGTH 40
#define LINKBUS_NUMBER_OF_TX_MSG_BUFFERS 10
#define LINKBUS_POWERUP_DELAY_SECONDS 6
@ -97,21 +98,10 @@ typedef enum
MESSAGE_FACTORY_RESET = 'F' * 100 + 'A' * 10 + 'C', /* Sets EEPROM back to defaults */
MESSAGE_OVERRIDE_DIP = 'D' *100 + 'I' * 10 + 'P', /* Override DIP switch settings using this value */
MESSAGE_LEDS = 'L' * 100 + 'E' * 10 + 'D', /* Turn on or off LEDs - accepts 1 or 0 or ON or OFF */
MESSAGE_CLOCK = 'T' * 100 + 'I' * 10 + 'M', /* Sets/reads the real-time clock */
MESSAGE_STARTFINISH = 'S' * 10 + 'F', /* Sets the start and finish times */
MESSAGE_BAT = 'B' * 100 + 'A' * 10 + 'T', /* Battery charge data */
MESSAGE_SYNC_ENABLE = 'S' * 100 + 'Y' * 10 + 'N', /* Enable or disable transmitter syncing */
MESSAGE_TEMP = 'T' * 100 + 'E' * 10 + 'M', /* Temperature data */
MESSAGE_PERM = 'P' * 100 + 'R' * 10 + 'M', /* Saves most settings to EEPROM "perm" */
MESSAGE_TX_POWER = 'P' * 100 + 'O' * 10 + 'W', /* Sets transmit power level */
MESSAGE_TX_MOD = 'M' * 100 + 'O' * 10 + 'D', /* Sets 2m modulation format to AM or CW */
#ifdef DONOTUSE
MESSAGE_DRIVE_LEVEL = 'D' * 100 + 'R' * 10 + 'I', /* Adjust 2m drive level */
#endif // DONOTUSE
MESSAGE_SET_STATION_ID = 'I' * 10 + 'D', /* Sets amateur radio callsign text */
MESSAGE_SET_PATTERN = 'P' * 10 + 'A', /* Sets unique transmit pattern */
MESSAGE_CODE_SPEED = 'S' * 100 + 'P' * 10 + 'D', /* Sets id and pattern code speeds */
MESSAGE_ESP_COMM = 'E' * 100 + 'S' * 10 + 'P', /* Communications with ESP8266 controller */
MESSAGE_GO = 'G' * 10 + 'O', /* Start transmitting now without delay */
MESSAGE_GO = 'G' * 10 + 'O', /* Synchronizes clock */
/* UTILITY MESSAGES */
MESSAGE_RESET = 'R' * 100 + 'S' * 10 + 'T', /* Processor reset */
@ -120,14 +110,6 @@ typedef enum
INVALID_MESSAGE = UINT16_MAX /* This value must never overlap a valid message ID */
} LBMessageID;
#define MESSAGE_CLOCK_LABEL "TIM"
#define MESSAGE_ESP_LABEL "ESP"
#define MESSAGE_ERRORCODE_LABEL "EC"
#define MESSAGE_STATUSCODE_LABEL "SC"
#define MESSAGE_BAND_LABEL "BND"
#define MESSAGE_TX_POWER_LABEL "POW"
#define MESSAGE_ACK "!ACK;"
typedef enum
{
LINKBUS_MSG_UNKNOWN = 0,
@ -161,7 +143,7 @@ typedef enum
TRANSMITTER_ID = 3
} DeviceID;
typedef char LinkbusTxBuffer[LINKBUS_MAX_MSG_LENGTH];
typedef char LinkbusTxBuffer[LINKBUS_MAX_TX_MSG_LENGTH];
typedef struct
{
@ -263,4 +245,8 @@ BOOL lb_send_string(char* str);
*/
void lb_send_value(uint16_t value, char* label);
/**
*/
void lb_send_Help(void);
#endif /* LINKBUS_H_ */