Implemented CSMA
This commit is contained in:
parent
e80db61859
commit
8e60c1e52c
|
@ -123,6 +123,7 @@ static void AFSK_txStart(Afsk *afsk) {
|
||||||
afsk->bitstuffCount = 0;
|
afsk->bitstuffCount = 0;
|
||||||
afsk->sending = true;
|
afsk->sending = true;
|
||||||
afsk->sending_data = true;
|
afsk->sending_data = true;
|
||||||
|
LED_RX_OFF();
|
||||||
LED_TX_ON();
|
LED_TX_ON();
|
||||||
afsk->preambleLength = DIV_ROUND(config_preamble * BITRATE, 8000);
|
afsk->preambleLength = DIV_ROUND(config_preamble * BITRATE, 8000);
|
||||||
AFSK_DAC_IRQ_START();
|
AFSK_DAC_IRQ_START();
|
||||||
|
|
|
@ -30,6 +30,8 @@ Serial *serial;
|
||||||
volatile ticks_t last_serial_read = 0;
|
volatile ticks_t last_serial_read = 0;
|
||||||
extern volatile int8_t afsk_peak;
|
extern volatile int8_t afsk_peak;
|
||||||
|
|
||||||
|
ticks_t last_csma_check = 0;
|
||||||
|
|
||||||
size_t frame_len;
|
size_t frame_len;
|
||||||
bool IN_FRAME;
|
bool IN_FRAME;
|
||||||
bool ESCAPE;
|
bool ESCAPE;
|
||||||
|
@ -270,8 +272,15 @@ void kiss_csma(void) {
|
||||||
if (config_p == 255) {
|
if (config_p == 255) {
|
||||||
kiss_flushQueue();
|
kiss_flushQueue();
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement real CSMA
|
ticks_t csma_timeout = last_csma_check + ms_to_ticks(config_slottime);
|
||||||
|
if (timer_clock() > csma_timeout) {
|
||||||
|
uint8_t r = (uint8_t)random();
|
||||||
|
if (r < config_p) {
|
||||||
kiss_flushQueue();
|
kiss_flushQueue();
|
||||||
|
} else {
|
||||||
|
last_csma_check = timer_clock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,8 +289,15 @@ void kiss_csma(void) {
|
||||||
if (config_p == 255) {
|
if (config_p == 255) {
|
||||||
kiss_flushQueue();
|
kiss_flushQueue();
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement real CSMA
|
ticks_t csma_timeout = last_csma_check + ms_to_ticks(config_slottime);
|
||||||
|
if (timer_clock() > csma_timeout) {
|
||||||
|
uint8_t r = (uint8_t)random();
|
||||||
|
if (r < config_p) {
|
||||||
kiss_flushQueue();
|
kiss_flushQueue();
|
||||||
|
} else {
|
||||||
|
last_csma_check = timer_clock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -371,6 +387,9 @@ void kiss_flushQueue(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe remove this error state and fail
|
||||||
|
// silently, while reverting to operational state
|
||||||
|
// by resetting all buffers
|
||||||
if (processed < queue_height) {
|
if (processed < queue_height) {
|
||||||
while (true) {
|
while (true) {
|
||||||
LED_TX_ON();
|
LED_TX_ON();
|
||||||
|
|
Loading…
Reference in New Issue