Implemented KISS flow control
This commit is contained in:
parent
9b4105c585
commit
2c80adbda4
|
@ -84,6 +84,7 @@ static void AFSK_txStart(Afsk *afsk) {
|
||||||
afsk->phaseAcc = 0;
|
afsk->phaseAcc = 0;
|
||||||
afsk->bitstuffCount = 0;
|
afsk->bitstuffCount = 0;
|
||||||
afsk->sending = true;
|
afsk->sending = true;
|
||||||
|
afsk->sending_data = true;
|
||||||
LED_TX_ON();
|
LED_TX_ON();
|
||||||
afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
|
afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
|
||||||
AFSK_DAC_IRQ_START();
|
AFSK_DAC_IRQ_START();
|
||||||
|
@ -121,6 +122,7 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
|
||||||
if (fifo_isempty(&afsk->txFifo) && afsk->tailLength == 0) {
|
if (fifo_isempty(&afsk->txFifo) && afsk->tailLength == 0) {
|
||||||
AFSK_DAC_IRQ_STOP();
|
AFSK_DAC_IRQ_STOP();
|
||||||
afsk->sending = false;
|
afsk->sending = false;
|
||||||
|
afsk->sending_data = false;
|
||||||
LED_TX_OFF();
|
LED_TX_OFF();
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,6 +130,7 @@ uint8_t AFSK_dac_isr(Afsk *afsk) {
|
||||||
afsk->bitStuff = true;
|
afsk->bitStuff = true;
|
||||||
if (afsk->preambleLength == 0) {
|
if (afsk->preambleLength == 0) {
|
||||||
if (fifo_isempty(&afsk->txFifo)) {
|
if (fifo_isempty(&afsk->txFifo)) {
|
||||||
|
afsk->sending_data = false;
|
||||||
afsk->tailLength--;
|
afsk->tailLength--;
|
||||||
afsk->currentOutputByte = HDLC_FLAG;
|
afsk->currentOutputByte = HDLC_FLAG;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -104,9 +104,10 @@ typedef struct Afsk
|
||||||
uint16_t phaseInc; // Phase increment per sample
|
uint16_t phaseInc; // Phase increment per sample
|
||||||
|
|
||||||
FIFOBuffer txFifo; // FIFO for transmit data
|
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; // Set when modem is sending
|
||||||
|
volatile bool sending_data; // Set when modem is sending data
|
||||||
|
|
||||||
// Demodulation values
|
// Demodulation values
|
||||||
FIFOBuffer delayFifo; // Delayed FIFO for frequency discrimination
|
FIFOBuffer delayFifo; // Delayed FIFO for frequency discrimination
|
||||||
|
|
|
@ -114,6 +114,7 @@ void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {
|
||||||
ax25_putchar(ctx, crch);
|
ax25_putchar(ctx, crch);
|
||||||
|
|
||||||
fputc(HDLC_FLAG, ctx->ch);
|
fputc(HDLC_FLAG, ctx->ch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||||
|
|
|
@ -11,6 +11,7 @@ Serial *serial;
|
||||||
size_t frame_len;
|
size_t frame_len;
|
||||||
bool IN_FRAME;
|
bool IN_FRAME;
|
||||||
bool ESCAPE;
|
bool ESCAPE;
|
||||||
|
bool FLOWCONTROL;
|
||||||
|
|
||||||
uint8_t command = CMD_UNKNOWN;
|
uint8_t command = CMD_UNKNOWN;
|
||||||
unsigned long custom_preamble = CONFIG_AFSK_PREAMBLE_LEN;
|
unsigned long custom_preamble = CONFIG_AFSK_PREAMBLE_LEN;
|
||||||
|
@ -23,6 +24,7 @@ void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) {
|
||||||
ax25ctx = ax25;
|
ax25ctx = ax25;
|
||||||
serial = ser;
|
serial = ser;
|
||||||
channel = afsk;
|
channel = afsk;
|
||||||
|
FLOWCONTROL = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kiss_messageCallback(AX25Ctx *ctx) {
|
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) {
|
void kiss_serialCallback(uint8_t sbyte) {
|
||||||
|
@ -114,6 +123,12 @@ void kiss_serialCallback(uint8_t sbyte) {
|
||||||
slotTime = sbyte * 10;
|
slotTime = sbyte * 10;
|
||||||
} else if (command == CMD_P) {
|
} else if (command == CMD_P) {
|
||||||
p = sbyte;
|
p = sbyte;
|
||||||
|
} else if (command == CMD_READY) {
|
||||||
|
if (sbyte == 0x00) {
|
||||||
|
FLOWCONTROL = false;
|
||||||
|
} else {
|
||||||
|
FLOWCONTROL = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#define CMD_TXTAIL 0x04
|
#define CMD_TXTAIL 0x04
|
||||||
#define CMD_FULLDUPLEX 0x05
|
#define CMD_FULLDUPLEX 0x05
|
||||||
#define CMD_SETHARDWARE 0x06
|
#define CMD_SETHARDWARE 0x06
|
||||||
|
#define CMD_READY 0x0F
|
||||||
#define CMD_RETURN 0xFF
|
#define CMD_RETURN 0xFF
|
||||||
|
|
||||||
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser);
|
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser);
|
||||||
|
|
Loading…
Reference in New Issue