Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • e-24/public/ahoi/firmware
1 result
Show changes
......@@ -201,7 +201,7 @@ HAL_UART_MspInit(UART_HandleTypeDef *huart)
HAL_GPIO_Init(CFG_USART_RX_GPIO_PORT, &GPIO_InitStruct);
HAL_NVIC_SetPriority(CFG_USART_IRQn, 0, 0);
HAL_NVIC_SetPriority(CFG_USART_IRQn, CFG_USART_IRQn_PRIO);
HAL_NVIC_EnableIRQ(CFG_USART_IRQn);
__HAL_UART_ENABLE_IT(huart,UART_IT_RXNE);
}
......
/**
* Copyright 2016-2018
* Copyright 2016-2023
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
......@@ -62,7 +62,8 @@ bool txEnabled = false;
static sample_time_t s = 0;
sample_time_t adda_getSampleTime() {
sample_time_t
adda_getRxSampleLagTicks() {
return s;
}
......@@ -90,7 +91,7 @@ adda_getSample( fp16_t *sample )
}
// timer
timerTicks += TX_FACTOR;
timerTicks += RX_DOWNSAMPLE;
// read next sample
if (feof(sample_file) || fscanf(sample_file, "%lf", &srcSample) == EOF) {
......@@ -140,22 +141,6 @@ void
adda_activateSampling()
{
if (txEnabled) {
// bring down DAC
/*
uint16_t i, j;
//sample_time_t start = adda_getTimerTicks();
for (i = SAMPLES_DAC_ENABLE-1; i != 0; i--) {
// signal only has time-resolution of timer sampling rate
for (j = 0; j < TX_FACTOR; j++) {
adda_setSample(( j * DAC_TURNON_SIGNAL[i-1] + (TX_FACTOR - j) * DAC_TURNON_SIGNAL[i]) / TX_FACTOR);
}
}
for (j = 0; j < TX_FACTOR; j++) {
adda_setSample(DAC_TURNON_SIGNAL[0]);
}
*/
txEnabled = false;
}
......@@ -173,22 +158,6 @@ adda_activateSampling()
void
adda_activateTransmission()
{
/*
uint16_t i, j;
// bring up DAC
//sample_time_t start = adda_getTimerTicks();
for (i = 0; i < SAMPLES_DAC_ENABLE-1; i++) {
// signal only has time-resolution of timer sampling rate
for (j = 0; j < TX_FACTOR; j++) {
adda_setSample(( (TX_FACTOR - j) * DAC_TURNON_SIGNAL[i] + j * DAC_TURNON_SIGNAL[i+1]) / TX_FACTOR);
}
}
for (j = 0; j < TX_FACTOR; j++) {
adda_setSample(DAC_TURNON_SIGNAL[SAMPLES_DAC_ENABLE-1]);
}
*/
// TODO insert neutral samples here for remaining time!
txEnabled = true;
......@@ -234,7 +203,7 @@ adda_getTimerTicks(void)
void
adda_wait(sample_time_t dt)
adda_waitTimerTicks(sample_time_t dt)
{
// FIXME skip samples?
return;
......
#
# Copyright 2016-2020
# Copyright 2016-2023
#
# Timo Kortbrae,
# Jan Heitmann,
......@@ -67,19 +67,3 @@ aci/csrc
OPTIMIZATION= -funroll-loops -finline-functions -O2
CFLAGS= -std=gnu99 -Wall
#CFLAGS+=-DSPREADER_DESPREAD_MAJORITY
CFLAGS+= -DSPREADER_DESPREAD_BESTBIT
#CFLAGS+=-DSPREADER_DESPREAD_MAGSUM
CFLAGS += -DSAMPLING_FREQ=200000 -DTX_FACTOR=1
#CFLAGS+= -DTXGAIN_COMP
CFLAGS+= -DSYNC_AUTO_NOISE
# use short symbols
#CFLAGS += -DHIGHSPEED
# use wide band
#CFLAGS += -DWIDEBAND
Subproject commit 737f467cc78a7c518bc280a4801bc071d42c99d3
Subproject commit eed5f0e3cdb14f4c8d2321b72bd78e1e3d92de6c
/**
* Copyright 2016-2021
* Copyright 2016-2023
*
* Bernd-Christian Renner
* Jan Heitmann, and
......@@ -112,6 +112,8 @@
#include "batvoltage.h"
#include "error.h"
#include "aci.h"
#include "aci_sample.h"
#include "aci_sniffmode.h"
......@@ -183,7 +185,7 @@ processRxPacket(void)
// FIXME work-around to attach footer to packet sent via serial line
*((mm_footer_t *)(pkt->payload + pkt->header.len)) = pkt->footer;
while (! host_sendPacket((uint8_t*)pkt, MM_HEADER_LEN + pkt->header.len + MM_FOOTER_LEN)) { ; }
WAIT_TIMED(! host_sendPacket((uint8_t*)pkt, MM_HEADER_LEN + pkt->header.len + MM_FOOTER_LEN));
packetpool_put(pkt);
// TODO where /exactly/ should we do this (before or after packet transmission?
......@@ -212,11 +214,11 @@ processTxPacket(void)
// i.e., it has finished tx->rx when we start sending
// FIXME make sure we count in the time that has already elapsed!
if (TXRX_TURNAROUND_TICKS > RXTX_TURNAROUND_TICKS) {
adda_wait(TXRX_TURNAROUND_TICKS - RXTX_TURNAROUND_TICKS);
adda_waitTimerTicks(TXRX_TURNAROUND_TICKS - RXTX_TURNAROUND_TICKS);
}
// wait ranging delay
adda_wait(ranging_getDelay());
adda_waitTimerTicks(ranging_getDelayTicks());
send_sendPacket(pkt);
pin_debug_set(DEBUG_PIN_7);
......
/**
* Copyright 2016-2019
* Copyright 2016-2023
*
* Bernd-Christian Renner,
* Jan Heitmann, and
......@@ -163,7 +163,7 @@ ranging_processPong(mm_packet_t * const pong)
void
ranging_setDelay(sample_time_t d)
ranging_setDelayTicks(sample_time_t d)
{
rangingDelay = d;
}
......@@ -171,7 +171,7 @@ ranging_setDelay(sample_time_t d)
sample_time_t
ranging_getDelay(void)
ranging_getDelayTicks(void)
{
return rangingDelay;
}
......@@ -179,7 +179,7 @@ ranging_getDelay(void)
void
ranging_trackTxTime(sample_time_t t)
ranging_trackTxTicks(sample_time_t t)
{
rangingTx = t;
}
......
/**
* Copyright 2016-2019
* Copyright 2016-2023
*
* Bernd-Christian Renner,
* Jan Heitmann, and
......@@ -56,15 +56,15 @@ ranging_processPong(mm_packet_t * const pong);
void
ranging_setDelay(sample_time_t d);
ranging_setDelayTicks(sample_time_t d);
sample_time_t
ranging_getDelay(void);
ranging_getDelayTicks(void);
void
ranging_trackTxTime(sample_time_t t);
ranging_trackTxTicks(sample_time_t t);
......
/**
* Copyright 2016-2020
* Copyright 2016-2023
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
......@@ -89,7 +89,7 @@ static uint8_t curFreqCarrierIdx;
// effective voltage to derive an power estimate
static fp32_t Ueff;
static fp32_t Umean;
static sample_time_t rxStartTime;
static rx_sample_cnt_t rxStartCnt;
// receive level
static fp64_t rxLevel;
......@@ -261,7 +261,7 @@ receive_readChip(void)
// 2. read ADC values of current chip
// and calculate integral values
for (i = 0; i < SAMPLES_PER_SYMBOL; i++) {
for (i = 0; i < RX_SAMPLES_PER_SYMBOL; i++) {
// get new sample (once available)
while (! adda_getSample(&sample)) { /* wait */
......@@ -499,7 +499,7 @@ receive_reset()
rxpBuf = rxBuf;
rxBufBitCnt = 0;
rxStartTime = adda_getSampleTime();
rxStartCnt = adda_getSampleCnt();
// effective voltage / rssi
Ueff = 0;
......@@ -532,12 +532,12 @@ receive_reset()
void
receive_finish()
{
uint32_t UeffCnt;
rx_sample_cnt_t UeffCnt;
// we should not count in the last symbol, as it may be lacking
// bits (the last symbol may have less than the max. number of bits)
// calc number of symbols (one bit after despreading), where numBands are sent in parallel
UeffCnt = adda_getSampleTime() - rxStartTime;
UeffCnt = adda_getSampleCnt() - rxStartCnt;
rxPkt->footer.power = channelquality_calcPowerLevel(Ueff, Umean, UeffCnt, numBands);
dbg("POWER %u (%u, %d, %u)\n", rxPkt->footer.power, Ueff, Umean, UeffCnt);
......@@ -556,9 +556,10 @@ receive_finish()
// get start time by subtracting preamble length
// TODO implement preamble length in some more appropriate place
// FIXME FIXME FIXME FIXME FIXME
rxPkt->meta.startTime = rxPkt->meta.syncTime - (freq_getNumSyncTxSymbols() + FREQ_SFD_LEN) * SAMPLES_PER_SYMBOL;
// HACK TX_SAMPLES_PER_SYMBOL is correct here, b/c time ticks correspond to higher TX frequency
rxPkt->meta.startTime = rxPkt->meta.syncTime - (freq_getNumSyncTxSymbols() + FREQ_SFD_LEN) * TX_SAMPLES_PER_SYMBOL;
// get end time by adding header+payload length
rxPkt->meta.endTime = rxPkt->meta.syncTime + (((HEADER_ENC_BITS + PAYLOAD_ENC_BITS(rxPkt->header.len)) * numChips + numBands - 1) / numBands) * SAMPLES_PER_SYMBOL;
rxPkt->meta.endTime = rxPkt->meta.syncTime + (((HEADER_ENC_BITS + PAYLOAD_ENC_BITS(rxPkt->header.len)) * numChips + numBands - 1) / numBands) * TX_SAMPLES_PER_SYMBOL;
// deliver packet to the outside world
if (rxCbHandler) {
......
/**
* Copyright 2016-2020
* Copyright 2016-2023
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
......@@ -207,7 +207,7 @@ __attribute__((__always_inline__))
static inline void
send_sendPreambleBit(uint8_t symb, uint8_t hop)
{
uint8_t k, l;
uint8_t k;
uint16_t j;
const fp16_t * pWaveform[FREQ_SYNC_NUM_MAX];
fp32_t txGain[FREQ_SYNC_NUM_MAX];
......@@ -230,39 +230,32 @@ send_sendPreambleBit(uint8_t symb, uint8_t hop)
txGain[k] = fp32_div(txGain[k], txGainSum);
}
// send waveforms only have sine values
for (l = 0; l < SYNC_MOD_INDEX; l++) {
for (k = 0; k < FREQ_SYNC_NUM_MAX; k++) {
pWaveform[k] = freq_getSyncTxFreq(symb, k, hop);
}
// send LUTs are pure sine waveforms
for (k = 0; k < FREQ_SYNC_NUM_MAX; k++) {
pWaveform[k] = freq_getSyncTxFreq(symb, k, hop);
}
for (j = 0; j < TX_FACTOR*SAMPLES_PER_SYMBOL; j++) {
fp32_t sample = 0;
// NOTE divide each time to prevent overflows
// another solution would be to use a larger type and divide in the end
for (k = 0; k < FREQ_SYNC_NUM_MAX; k++) {
for (j = 0; j < TX_SAMPLES_PER_SYMBOL; j++) {
fp32_t sample = 0;
// NOTE divide each time to prevent overflows
// another solution would be to use a larger type and divide in the end
for (k = 0; k < FREQ_SYNC_NUM_MAX; k++) {
#ifdef TXGAIN_COMP
// FIXME Speed hack
sample += txGain[k] * pWaveform[k][j];
//sample += fp32_mul16(txGain[k], pWaveform[k][j]);
// FIXME Speed hack
sample += txGain[k] * pWaveform[k][j];
//sample += fp32_mul16(txGain[k], pWaveform[k][j]);
#else
sample += pWaveform[k][j];
sample += pWaveform[k][j];
#endif
}
// scale sample
// FIXME too slow?
//sample = (fp16_t)((sample * FREQ_SYNC_NUM_MAX) / numBands);
// sample = sample / numBands;
}
// send it
// send it
#ifdef TXGAIN_COMP
adda_setSample((fp16_t)(sample >> FP_Q)); // FIXME hack
//adda_setSample( (fp16_t)( (sample / FREQ_SYNC_NUM_MAX) >> FP_Q) );
adda_setSample((fp16_t)(sample >> FP_Q)); // FIXME hack
//adda_setSample( (fp16_t)( (sample / FREQ_SYNC_NUM_MAX) >> FP_Q) );
#else
adda_setSample(sample / FREQ_SYNC_NUM_MAX); // FIXME hack
adda_setSample(sample / FREQ_SYNC_NUM_MAX); // FIXME hack
#endif
}
}
}
......@@ -389,7 +382,7 @@ send_sendData()
}
// 3. prepare DAC values for this chip with parallel bits
for (i = 0; i < TX_FACTOR*SAMPLES_PER_SYMBOL; i++) {
for (i = 0; i < TX_SAMPLES_PER_SYMBOL; i++) {
fp32_t sample = 0;
// TODO may be use constant here and add up zeros to save some time ... ?
// (the loop can be unrolled, if we use a constant)
......@@ -492,7 +485,7 @@ send_sendPacket(mm_packet_t * const pkt)
send_sendSFD();
send_sendData();
send_finish();
ranging_trackTxTime(adda_getTimerTicks()); // TODO only, if not an ack
ranging_trackTxTicks(adda_getTimerTicks()); // TODO only, if not an ack
led_off(LED_MODEM_TX);
......
/**
* Copyright 2016-2019
* Copyright 2016-2023
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
......@@ -60,9 +60,9 @@
typedef struct {
freq_magnitude_t mag; /* magnitude val */
uint8_t freq; /* index of signal found */
sample_time_t dist;
sample_time_t tMax;
sample_time_t tFirst;
rx_sample_cnt_t dist;
rx_sample_cnt_t tMax;
rx_sample_cnt_t tFirst;
} peak_t;
......@@ -83,7 +83,7 @@ typedef enum {
// sync state
static sync_state_t state = SYNC_RESET;
static freq_product_t ringbuffer[SAMPLES_PER_SYMBOL][NUM_SYMBOLS][FREQ_SYNC_NUM_MAX];
static freq_product_t ringbuffer[RX_SAMPLES_PER_SYMBOL][NUM_SYMBOLS][FREQ_SYNC_NUM_MAX];
// integral windowing
static freq_integral_t integral[NUM_SYMBOLS][FREQ_SYNC_NUM_MAX];
......@@ -108,7 +108,7 @@ static peak_t peaks[SYNC_SYMBOLS_NUM_MAX + 1 + NUM_PEAK_LOOKAHEAD] =
static uint8_t peakNum = 0;
// expected end-of-preamble time (as sample count) and real end-of-preamble time
static sample_time_t endOfPreambleTime;
static rx_sample_cnt_t endOfPreambleCnt;
static sample_time_t syncTime;
// pointers to preamble waveform look-up tables
......@@ -120,7 +120,7 @@ static const fp16_t * pWaveform[NUM_SYMBOLS][FREQ_SYNC_NUM_MAX] = {{ NULL }};
//static sample_time_t syncStartTime;
// detect preamble and sync/sfd noise
static fp32_t noiseLP[SAMPLES_PER_SYMBOL] = { 0 };
static fp32_t noiseLP[RX_SAMPLES_PER_SYMBOL] = { 0 };
static fp32_t noiseSum = 0;
......@@ -132,7 +132,15 @@ static fp32_t noiseSum = 0;
static void
sync_reset(void);
// HACK
// compiler optimization makes sync_peakReset() inline upon
// certain changes (PIN_DEBUG calls). This in turn is braking
// something, so that modem cannot receive any longer.
// this needs to be sorted out at some point (Q: what happens?), but for now
// we simply introduce this hack
// it may have other side effects, though ...
static void
__attribute__((noinline))
sync_peakReset(uint16_t bufPos);
static void
......@@ -141,7 +149,7 @@ sync_detect(void);
static bool
sync_wait(void);
static sample_time_t
static rx_sample_cnt_t
sync_calcEndOfPreamble(const peak_t * peaks, uint8_t numPeaks);
......@@ -197,9 +205,13 @@ sync_peakReset(uint16_t bufPos)
for (j = 0; j < FREQ_SYNC_NUM_MAX; j++) {
const fp16_t * np;
dbg("SYNCFREQ idx %u %u @ %u\n", i, j, adda_getSampleTime());
np = 2*(bufPos) + freq_getSyncFreq(i, j, hop[i]);
tainted |= pWaveform[i][j] != np;
dbg("SYNCFREQ idx %u %u @ %u\n", i, j, adda_getSampleCnt());
np = 2 * bufPos + freq_getSyncFreq(i, j, hop[i]);
// NOTE rewrote
// tainted |= pWaveform[i][j] != np;
if (pWaveform[i][j] != np) {
tainted = true;
}
dbg("SYNCFREQ ptr %u %ld %p %p\n",
pWaveform[i][j] != np, np - pWaveform[i][j], np, pWaveform[i][j]);
pWaveform[i][j] = np;
......@@ -213,7 +225,7 @@ sync_peakReset(uint16_t bufPos)
// bufPos is always used to setup frequencies)
if (tainted) {
memset(integral[i], 0, sizeof(integral[0]));
for (uint16_t k = 0; k < SAMPLES_PER_SYMBOL; k++) {
for (uint16_t k = 0; k < RX_SAMPLES_PER_SYMBOL; k++) {
memset(ringbuffer[k][i], 0, sizeof(ringbuffer[0][0]));
}
}
......@@ -247,13 +259,13 @@ sync_detect()
// current sample and time
fp16_t sample;
fp32_t sqSample; // squared sample for noise calculation
sample_time_t stime;
rx_sample_cnt_t stime;
// set up signal threshold and preamble length
const uint8_t numSyncSymb = freq_getNumSyncRxSymbols();
// peak detection window
const uint16_t peakWinSize = freq_getSignalWindowSize();
const rx_sample_cnt_t peakWinSize = freq_getSignalWindowSize();
#ifdef SYNC_AUTO_NOISE
// NOTE this is a work-around, because fpDiv for calculating SNR is simply to slow as it is!
......@@ -267,7 +279,7 @@ sync_detect()
// get new sample (if available) and time
while (adda_getSample(&sample)) {
stime = adda_getSampleTime();
stime = adda_getSampleCnt();
// integrate signal level
// TODO Ueff += fp16_square(sample);
......@@ -279,7 +291,7 @@ sync_detect()
// use peaks[peakNum].dist
// then re-enable tFirst usage
if ((peakNum > 0) && /*peaks[peakNum-1].mag < rxThresh && */
(stime - peaks[peakNum-1].tMax > 2*SAMPLES_PER_SYMBOL))
(stime - peaks[peakNum-1].tMax > 2*RX_SAMPLES_PER_SYMBOL))
{
dbg("%u.%u LOST SYNC %u Mag %u / %u\n", stime, bufPos, peakNum, peaks[peakNum].mag, rxThresh);
sync_peakReset(bufPos);
......@@ -369,7 +381,7 @@ sync_detect()
//uint32_t magTmp = magTot;
// FIXME we do not really add one here
// -> if we sum up the freq components (squares), the max. value changes,
magTot /= SAMPLES_PER_SYMBOL / 2 + noiseSum;
magTot /= RX_SAMPLES_PER_SYMBOL / 2 + noiseSum;
// FIXME the main problem with this one is that we do not scale! (a relative measure would be nicer!)
/*magTot = 0;
......@@ -449,11 +461,11 @@ sync_detect()
// HACK accept symbol, if peakWinSize too late
// we should have two parameters here, because peakWinSize is used in two contexts ...
//if (peaks[peakNum].dist >= peakWinSize ||
// (peakNum > 0 && stime - peaks[0].tMax > peakNum * SAMPLES_PER_SYMBOL + SIGNAL_WINDOW_MAX_DELAY))
// (peakNum > 0 && stime - peaks[0].tMax > peakNum * RX_SAMPLES_PER_SYMBOL + SIGNAL_WINDOW_MAX_DELAY))
if (peaks[peakNum].dist >= peakWinSize ||
// FIXME requires that tFirst is properly reset for peakNum==0
/*(stime - peaks[peakNum].tFirst > SAMPLES_PER_SYMBOL + SIGNAL_WINDOW_MAX_DELAY) ||*/
(peakNum > 0 && stime - peaks[0].tMax > peakNum * SAMPLES_PER_SYMBOL + SIGNAL_WINDOW_MAX_DELAY))
(peakNum > 0 && stime - peaks[0].tMax > peakNum * RX_SAMPLES_PER_SYMBOL + SIGNAL_WINDOW_MAX_DELAY))
{
dbg("%u.%u FOUND PEAK %u (%u) Symb %u:%u Mag %u/%u @ %u %u %u (%u)\n", stime, bufPos, peakNum+1, peakNum % NUM_SYMBOLS, peaks[peakNum].freq, hop[peakNum % NUM_SYMBOLS], peaks[peakNum].mag, rxThresh, peaks[peakNum].tMax, peaks[peakNum].tMax-peaks[peakNum].tFirst, peaks[peakNum].dist, peakWinSize);
......@@ -491,7 +503,7 @@ sync_detect()
// handled/resolved when bufPos is finally incremented
// NOTE please refer to sync_peakReset()
dbg("SYNCFREQ idx %u %u\n", symb, j);
pWaveform[symb][j] = 2*((bufPos+1) & SAMPLES_PER_SYMBOL_MASK) + freq_getSyncFreq(symb, j, hop[symb]);
pWaveform[symb][j] = 2*((bufPos+1) & RX_SAMPLES_PER_SYMBOL_MASK) + freq_getSyncFreq(symb, j, hop[symb]);
// DEBUG dbg("w[%u][%u] = (%u,%u,%u) [peak]\n", symb, i, symb, i, hop[symb]);
// NOTE integral vaues are cleared below (outside of loop)
......@@ -503,7 +515,7 @@ sync_detect()
// clear ringbuffer and integral after waveform change
// TODO check if we're only resetting on a waveform change
// no need (and it's actually harmful) when only resetting
for (i = 0; i < SAMPLES_PER_SYMBOL; i++) {
for (i = 0; i < RX_SAMPLES_PER_SYMBOL; i++) {
for (j = 0; j < FREQ_SYNC_NUM_MAX; j++) {
ringbuffer[i][symb][j].sin = 0;
ringbuffer[i][symb][j].cos = 0;
......@@ -529,7 +541,7 @@ sync_detect()
if (peakNum >= numSyncSymb) {
// FIXME is there a guarantee this will never be before the current time
// => no! see sync_wait()
endOfPreambleTime = sync_calcEndOfPreamble(peaks, peakNum);
endOfPreambleCnt = sync_calcEndOfPreamble(peaks, peakNum);
state = SYNC_WAIT;
break;
}
......@@ -542,7 +554,7 @@ sync_detect()
// NOTE buffer and waveforms must have same length and resetting
// *should* be done after all uses of both in the loop
// bufPos *must* be initialized with 0 before first use
bufPos = (bufPos + 1) & SAMPLES_PER_SYMBOL_MASK;
bufPos = (bufPos + 1) & RX_SAMPLES_PER_SYMBOL_MASK;
if (bufPos == 0) {
for (i = 0; i < NUM_SYMBOLS; i++) {
for (j = 0; j < FREQ_SYNC_NUM_MAX; j++) {
......@@ -562,8 +574,8 @@ sync_detect()
bool
sync_wait()
{
sample_timediff_t dt;
fp16_t sample;
rx_sample_diffcnt_t ds;
fp16_t sample;
// eat up samples (till end of preamble)
// TODO off by one?
......@@ -572,13 +584,12 @@ sync_wait()
// - do not compare directly, since time will wrap around at some point!
// - if this is negative, we've already run into the payload?
// => should we really continue then?
/*if ((sample_timediff_t)(endOfPreambleTime - adda_getSampleTime()) < 0) {
/*if ((sample_timediff_t)(endOfPreambleCnt - adda_getSampleCnt()) < 0) {
dbg("UUUUUUUUUUUUUUUUUUUUUUUUPPPPPPPPPPPPPPPPPPPPPPPPPSSSS\n");
}
else*/
dt = endOfPreambleTime - adda_getSampleTime();
if (dt <= 0) {
//syncTime = adda_getTimerTicks() + dt;
ds = endOfPreambleCnt - adda_getSampleCnt();
if (ds <= 0) {
aci_packetstat_incSync();
state = SYNC_RESET;
return true;
......@@ -592,12 +603,12 @@ sync_wait()
// expected, this is equivalent to the expected end of the preamble
// get center of gravity for all calculated preamble symbol starting points
// and add half the time of the total preamble
sample_time_t
rx_sample_cnt_t
sync_calcEndOfPreamble(const peak_t * peaks, uint8_t numPeaks)
{
uint8_t i;
//sample_longtime_t peakTimesAvg;
sample_time_t peakTimesAvg;
//rx_sample_longcnt_t peakCntAvg;
rx_sample_cnt_t peakCntAvg;
// shift by SYNC_SYMBOLS_NUM_RX_LEAD_IGNORE
peaks += SYNC_SYMBOLS_NUM_RX_LEAD_IGNORE;
......@@ -609,20 +620,20 @@ sync_calcEndOfPreamble(const peak_t * peaks, uint8_t numPeaks)
// = 1/N * sum{i=0..N-1} (peak[i].time - peak[0].time + peak[0].time)
// = peak[0].time + 1/N * sum{i=0..N-1} (peak[i].time - peak[0].time)
// = peak[0].time + 1/N * sum{i=1..N-1} (peak[i].time - peak[0].time)
peakTimesAvg = 0;
peakCntAvg = 0;
for (i = 1; i < numPeaks; i++) {
peakTimesAvg += peaks[i].tMax - peaks[0].tMax;
peakCntAvg += peaks[i].tMax - peaks[0].tMax;
}
peakTimesAvg /= numPeaks;
peakCntAvg /= numPeaks;
// add the expected time from (ideal) center of gravity to (ideal) payload begin
// NOTE we always omit the last SYNC_SYMBOLS_NUM_RX_TRAIL_IGNORE symbols
// add SYNC_SYMBOLS_NUM_RX_TRAIL_IGNORE for the symbols we do not touch ...
peakTimesAvg += ((sample_longtime_t)(numPeaks + SYNC_SYMBOLS_NUM_RX_TRAIL_IGNORE) * SAMPLES_PER_SYMBOL) / 2;
peakCntAvg += ((rx_sample_cnt_t)(numPeaks + SYNC_SYMBOLS_NUM_RX_TRAIL_IGNORE) * RX_SAMPLES_PER_SYMBOL) / 2;
//dbg("end of preamble @ %lu\n", peakTimesAvg);
// undo relative times during summing / averaging
return (sample_time_t)(peaks[0].tMax + peakTimesAvg);
return (rx_sample_cnt_t)(peaks[0].tMax + peakCntAvg);
}
......@@ -693,7 +704,7 @@ sync_waitSfd()
// TODO debug output
for (curTry = 0; curTry < numTries; curTry++) {
dbg("SFDTRY %u of %u @ %u ================================\n", curTry+1, numTries, adda_getSampleTime());
dbg("SFDTRY %u of %u @ %u ================================\n", curTry+1, numTries, adda_getSampleCnt());
// reset symb, hop, status before each try
symb = 0;
......@@ -711,7 +722,7 @@ sync_waitSfd()
// correlate
noiseSum = 0;
memset(integral, 0, sizeof(integral));
for (n = 0; n < SAMPLES_PER_SYMBOL; n++) {
for (n = 0; n < RX_SAMPLES_PER_SYMBOL; n++) {
// obtain sample
while (! adda_getSample(&sample)) { /* wait */
board_enterPowerSaveMode();
......@@ -735,7 +746,7 @@ sync_waitSfd()
// get SNR: signal / (noise + signal)
// NOTE please see note in sync_detect()
magTot /= SAMPLES_PER_SYMBOL / 2 + noiseSum;
magTot /= RX_SAMPLES_PER_SYMBOL / 2 + noiseSum;
if (magTot < rxThresh) {
dbg("SFDSYMB FAIL %u of %u Mag %d/%d\n", i+1, FREQ_SFD_LEN, magTot, rxThresh);
......@@ -760,7 +771,7 @@ sync_waitSfd()
// eat out remaining symbols of current try
for (i++; i < FREQ_SFD_LEN; i++) {
for (n = 0; n < SAMPLES_PER_SYMBOL; n++) {
for (n = 0; n < RX_SAMPLES_PER_SYMBOL; n++) {
// obtain sample
while (! adda_getSample(&sample)) { /* wait */
board_enterPowerSaveMode();
......@@ -770,18 +781,18 @@ sync_waitSfd()
// final check (if ok still true, we found all FREQ_SFD_LEN symbols
if (ok) {
dbg("SFD FOUND @ %u ================================\n", adda_getSampleTime());
dbg("SFD FOUND @ %u ================================\n", adda_getSampleCnt());
aci_packetstat_incSfd();
aci_sfdstat_inc(curTry);
// syncTime /must/ be the time of the sample at which we identified the sync,
// so we take the current time and subtract the number of samples we're lagging behind
// (time is only the number samples since we booted)
syncTime = adda_getTimerTicks() - adda_getSampleLag();
syncTime = adda_getTimerTicks() - adda_getRxSampleLagTicks();
return true;
}
}
dbg("SFD MISSED @ %u ================================\n", adda_getSampleTime());
dbg("SFD MISSED @ %u ================================\n", adda_getSampleCnt());
return false;
}
......
/**
* Copyright 2016-2020
* Copyright 2016-2023
*
* Bernd-Christian Renner and
* Hamburg University of Technology (TUHH).
......@@ -61,10 +61,14 @@ typedef uint8_t rssi_t;
// TIME
///////////////////////////////////////////////////////////////////////////
typedef uint64_t sample_longtime_t;
//typedef uint64_t sample_longtime_t;
typedef uint32_t sample_time_t;
typedef int32_t sample_timediff_t;
//typedef uint64_t rx_sample_longcnt_t;
typedef uint32_t rx_sample_cnt_t;
typedef uint32_t rx_sample_diffcnt_t;
///////////////////////////////////////////////////////////////////////////
......