Implemented P-persistent CSMA in KISS mode

This commit is contained in:
Mark Qvist 2014-11-19 10:27:42 +01:00
parent e0aa5f2f65
commit b9200f1d6e
7 changed files with 970 additions and 1815 deletions

View File

@ -6,9 +6,13 @@
#define PROTOCOL_SIMPLE_SERIAL 0x01
#define PROTOCOL_KISS 0x02
// Which serial protocol we want the modem to use
#define SERIAL_PROTOCOL PROTOCOL_SIMPLE_SERIAL
//#define SERIAL_PROTOCOL PROTOCOL_KISS
// Enable P-persistent CSMA
#define CSMA_ENABLE true
// Debug & test options
#define SERIAL_DEBUG false
#define PASSALL true

View File

@ -103,7 +103,7 @@ static void init(void)
#if SERIAL_PROTOCOL == PROTOCOL_KISS
// Init KISS
kiss_init(&ax25, &ser);
kiss_init(&ax25, &afsk, &ser);
#endif
// That's all!

View File

@ -8,6 +8,7 @@
static uint8_t serialBuffer[CONFIG_AX25_FRAME_BUF_LEN+1]; // Buffer for holding incoming serial data
AX25Ctx *ax25ctx;
Afsk *channel;
Serial *serial;
size_t frame_len;
bool IN_FRAME;
@ -16,9 +17,13 @@ uint8_t command = CMD_UNKNOWN;
unsigned long custom_preamble = CONFIG_AFSK_PREAMBLE_LEN;
unsigned long custom_tail = CONFIG_AFSK_TRAILER_LEN;
void kiss_init(AX25Ctx *ax25, Serial *ser) {
unsigned long slotTime = 200;
uint8_t p = 63;
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) {
ax25ctx = ax25;
serial = ser;
channel = afsk;
}
void kiss_messageCallback(AX25Ctx *ctx) {
@ -44,11 +49,39 @@ void fon(void) {
while (ts--) PORTB |= BV(2);
}
void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len) {
bool sent = false;
while (!sent) {
if(!channel->hdlc.receiving) {
uint8_t tp = rand() & 0xFF;
if (tp < p) {
ax25_sendRaw(ctx, buf, len);
sent = true;
} else {
ticks_t start = timer_clock();
while (timer_clock() - start < ms_to_ticks(slotTime)) {
cpu_relax();
}
}
} else {
while (channel->hdlc.receiving) {
cpu_relax();
}
}
}
}
void kiss_serialCallback(uint8_t sbyte) {
if (IN_FRAME && sbyte == FEND && command == CMD_DATA) {
IN_FRAME = false;
#if CSMA_ENABLE
kiss_csma(ax25ctx, serialBuffer, frame_len);
#else
ax25_sendRaw(ax25ctx, serialBuffer, frame_len);
#endif
} else if (sbyte == FEND) {
IN_FRAME = true;
command = CMD_UNKNOWN;
@ -75,6 +108,10 @@ void kiss_serialCallback(uint8_t sbyte) {
custom_preamble = sbyte * 10UL;
} else if (command == CMD_TXTAIL) {
custom_tail = sbyte * 10;
} else if (command == CMD_SLOTTIME) {
slotTime = sbyte * 10;
} else if (command == CMD_P) {
p = sbyte;
}
}

View File

@ -18,9 +18,10 @@
#include <net/ax25.h>
#include <drv/ser.h>
#include "afsk.h"
void kiss_init(AX25Ctx *ax25, Serial *ser);
void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser);
void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len);
void kiss_messageCallback(AX25Ctx *ctx);
void kiss_serialCallback(uint8_t sbyte);
void fon(void);

View File

@ -1,2 +1,2 @@
#define VERS_BUILD 2367
#define VERS_BUILD 2400
#define VERS_HOST "shard"

Binary file not shown.

File diff suppressed because it is too large Load Diff