8b/10b tx/rx works
This commit is contained in:
parent
ee1d1bd0c2
commit
67e30fa91e
4 changed files with 126 additions and 10 deletions
File diff suppressed because one or more lines are too long
|
|
@ -124,7 +124,7 @@ void TIM1_CC_IRQHandler(void) {
|
|||
}
|
||||
*/
|
||||
static size_t received_symbols = 0;
|
||||
static int symbol_buf[32];
|
||||
static int symbol_buf[64];
|
||||
static size_t received_bits = 0;
|
||||
static int16_t bit_buf[256];
|
||||
size_t adc_reduced_pos = 0;
|
||||
|
|
@ -145,16 +145,13 @@ void DMA1_Channel1_IRQHandler(void) {
|
|||
int sample = buf[i];
|
||||
|
||||
adc_reduced[adc_reduced_pos] = (sample & 0xffff)>>9;
|
||||
if (adc_reduced_pos == 0) {
|
||||
asm volatile ("bkpt");
|
||||
}
|
||||
|
||||
if ((last_sample <= threshold_adc_counts && sample >= threshold_adc_counts) ||
|
||||
(last_sample >= threshold_adc_counts && sample <= threshold_adc_counts)){
|
||||
sampling_phase = sample_per_baud / 4; /* /2 for half baud sampling point, /2 for sinusoidal edge shape */
|
||||
|
||||
} else if (sampling_phase == 0) {
|
||||
int bit = sample < threshold_adc_counts;
|
||||
int bit = sample > threshold_adc_counts;
|
||||
adc_reduced[adc_reduced_pos] |= 0x80;
|
||||
|
||||
bit_buf[received_bits] = bit;
|
||||
|
|
@ -171,7 +168,10 @@ void DMA1_Channel1_IRQHandler(void) {
|
|||
sampling_phase--;
|
||||
}
|
||||
|
||||
adc_reduced_pos = (adc_reduced_pos+1) % COUNT_OF(adc_reduced);
|
||||
adc_reduced_pos++;
|
||||
if (adc_reduced_pos == COUNT_OF(adc_reduced)) {
|
||||
adc_reduced_pos =0;
|
||||
}
|
||||
last_sample = sample;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def parse_size(s):
|
||||
if s is None:
|
||||
return s
|
||||
|
||||
s = s.lower()
|
||||
SUFFIXES = {'k': 1e3, 'm': 1e6, 'g': 1e9}
|
||||
if s[-1] in SUFFIXES:
|
||||
|
|
|
|||
|
|
@ -202,6 +202,9 @@ void dma_tx_constant(size_t table_size, uint16_t constant) {
|
|||
DMA1_Channel1->CCR |= DMA_CCR_EN;
|
||||
}
|
||||
|
||||
int8_t bit_arr[4096];
|
||||
size_t bit_pos = 0;
|
||||
|
||||
void DMA1_Channel1_IRQHandler() {
|
||||
static int transfer_errors = 0;
|
||||
static int current_symbol = 0x2aa;
|
||||
|
|
@ -213,6 +216,10 @@ void DMA1_Channel1_IRQHandler() {
|
|||
DMA1->IFCR = DMA_IFCR_CGIF1;
|
||||
|
||||
int bit = !!(current_symbol & (1<<tx_bitpos));
|
||||
bit_arr[bit_pos++] = bit;
|
||||
if (bit_pos == COUNT_OF(bit_arr)) {
|
||||
bit_pos = 0;
|
||||
}
|
||||
|
||||
if (tx_last_bit == bit) {
|
||||
dma_tx_constant(COUNT_OF(waveform_zero_one), bit ? WAVEFORM_CONST_ONE : WAVEFORM_CONST_ZERO);
|
||||
|
|
@ -224,14 +231,15 @@ void DMA1_Channel1_IRQHandler() {
|
|||
|
||||
tx_last_bit = bit;
|
||||
|
||||
tx_bitpos ++;
|
||||
if (tx_bitpos >= 10) {
|
||||
tx_bitpos = 0;
|
||||
tx_sympos ++;
|
||||
if (tx_bitpos == 0) {
|
||||
tx_bitpos = 9;
|
||||
current_symbol = xfr_8b10b_encode(&encoder_state_8b10b, tx_datagram[tx_sympos]);
|
||||
tx_sympos ++;
|
||||
if (tx_sympos >= COUNT_OF(tx_datagram)) {
|
||||
tx_sympos = 0;
|
||||
}
|
||||
} else {
|
||||
tx_bitpos --;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue