Implemented KISS flow control

This commit is contained in:
Mark Qvist 2018-04-24 14:34:59 +02:00
parent 9b4105c585
commit 2c80adbda4
5 changed files with 25 additions and 4 deletions

View File

@ -84,6 +84,7 @@ static void AFSK_txStart(Afsk *afsk) {
afsk->phaseAcc = 0;
afsk->bitstuffCount = 0;
afsk->sending = true;
afsk->sending_data = true;
LED_TX_ON();
afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
AFSK_DAC_IRQ_START();
@ -121,6 +122,7 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
if (fifo_isempty(&afsk->txFifo) && afsk->tailLength == 0) {
AFSK_DAC_IRQ_STOP();
afsk->sending = false;
afsk->sending_data = false;
LED_TX_OFF();
return 0;
} else {
@ -128,6 +130,7 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
afsk->bitStuff = true;
if (afsk->preambleLength == 0) {
if (fifo_isempty(&afsk->txFifo)) {
afsk->sending_data = false;
afsk->tailLength--;
afsk->currentOutputByte = HDLC_FLAG;
} else {

View File

@ -104,9 +104,10 @@ typedef struct Afsk
uint16_t phaseInc; // Phase increment per sample
FIFOBuffer txFifo; // FIFO for transmit data
uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN]; // Actial data storage for said FIFO
uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN]; // Actual data storage for said FIFO
volatile bool sending; // Set when modem is sending
volatile bool sending_data; // Set when modem is sending data
// Demodulation values
FIFOBuffer delayFifo; // Delayed FIFO for frequency discrimination

View File

@ -114,6 +114,7 @@ void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {
ax25_putchar(ctx, crch);
fputc(HDLC_FLAG, ctx->ch);
}
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL

View File

@ -11,6 +11,7 @@ Serial *serial;
size_t frame_len;
bool IN_FRAME;
bool ESCAPE;
bool FLOWCONTROL;
uint8_t command = CMD_UNKNOWN;
unsigned long custom_preamble = CONFIG_AFSK_PREAMBLE_LEN;
@ -23,6 +24,7 @@ void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) {
ax25ctx = ax25;
serial = ser;
channel = afsk;
FLOWCONTROL = false;
}
void kiss_messageCallback(AX25Ctx *ctx) {
@ -75,9 +77,16 @@ void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len) {
}
}
}
}
if (FLOWCONTROL) {
while (channel->sending_data) { /* Wait */ }
fputc(FEND, &serial->uart0);
fputc(CMD_READY, &serial->uart0);
fputc(0x01, &serial->uart0);
fputc(FEND, &serial->uart0);
}
}
void kiss_serialCallback(uint8_t sbyte) {
@ -114,7 +123,13 @@ void kiss_serialCallback(uint8_t sbyte) {
slotTime = sbyte * 10;
} else if (command == CMD_P) {
p = sbyte;
}
} else if (command == CMD_READY) {
if (sbyte == 0x00) {
FLOWCONTROL = false;
} else {
FLOWCONTROL = true;
}
}
}
}

View File

@ -19,6 +19,7 @@
#define CMD_TXTAIL 0x04
#define CMD_FULLDUPLEX 0x05
#define CMD_SETHARDWARE 0x06
#define CMD_READY 0x0F
#define CMD_RETURN 0xFF
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser);