mirror of
https://github.com/juribeparada/MMDVM_HS.git
synced 2026-04-07 23:33:40 +00:00
All tested compilers & make build now have proper timing for tx switching (gcc 4.9.3, O0, Os, O3, gcc 6.3. O0, O3)
This commit is contained in:
parent
02ee23b684
commit
70457f269e
6 changed files with 104 additions and 66 deletions
83
IO.cpp
83
IO.cpp
|
|
@ -29,9 +29,11 @@ uint32_t m_frequency_rx;
|
|||
uint32_t m_frequency_tx;
|
||||
uint8_t m_power;
|
||||
|
||||
extern volatile bool sle_request;
|
||||
// TODO: move to IO class as members
|
||||
volatile bool totx_request = false;
|
||||
volatile bool torx_request = false;
|
||||
bool volatile even = true;
|
||||
volatile bool even = true;
|
||||
static uint32_t last_clk = 2;
|
||||
|
||||
CIO::CIO():
|
||||
m_started(false),
|
||||
|
|
@ -101,8 +103,7 @@ void CIO::process()
|
|||
|
||||
// Switch off the transmitter if needed
|
||||
if (m_txBuffer.getData() == 0U && m_tx) {
|
||||
//while(CLK_pin()==0) { asm volatile ("nop"); }
|
||||
//while(CLK_pin()) { asm volatile ("nop"); }
|
||||
setRX(false);
|
||||
torx_request = true;
|
||||
while(torx_request) { asm volatile ("nop"); }
|
||||
}
|
||||
|
|
@ -158,13 +159,33 @@ void CIO::interrupt()
|
|||
if (!m_started)
|
||||
return;
|
||||
|
||||
uint8_t clk = CLK_pin();
|
||||
uint8_t clk = CLK_pin();
|
||||
|
||||
// this is to prevent activation by spurious interrupts
|
||||
// which seem to happen if you send out an control word
|
||||
// needs investigation
|
||||
// this workaround will fail if only rising or falling edge
|
||||
// is used to trigger the interrupt !!!!
|
||||
// TODO: figure out why sending the control word seems to issue interrupts
|
||||
// possibly this is a design problem of the RF7021 board or too long wires
|
||||
// on the breadboard build
|
||||
// but normally this will not hurt too much
|
||||
if (clk == last_clk) {
|
||||
return;
|
||||
} else {
|
||||
last_clk = clk;
|
||||
}
|
||||
|
||||
|
||||
// we set the TX bit at TXD low, sampling of ADF7021 happens at rising clock
|
||||
if (m_tx && clk == 0) {
|
||||
|
||||
m_txBuffer.get(bit);
|
||||
even = !even;
|
||||
|
||||
// use this for tracking issues
|
||||
// P25_pin(even);
|
||||
|
||||
#if defined(BIDIR_DATA_PIN)
|
||||
if(bit)
|
||||
RXD_pin_write(HIGH);
|
||||
|
|
@ -177,21 +198,26 @@ void CIO::interrupt()
|
|||
TXD_pin(LOW);
|
||||
#endif
|
||||
// wait a brief period before raising SLE
|
||||
if (sle_request == true) {
|
||||
#if 1
|
||||
asm volatile("mov r8, r8 \n\t"
|
||||
"mov r8, r8 \n\t"
|
||||
"mov r8, r8 \n\t"
|
||||
);
|
||||
#endif
|
||||
if (totx_request == true) {
|
||||
asm volatile("nop \n\t"
|
||||
"nop \n\t"
|
||||
"nop \n\t"
|
||||
);
|
||||
|
||||
// SLE Pulse, should be moved out of here into class method
|
||||
// according to datasheet in 4FSK we have to deliver this before 1/4 tbit == 26uS
|
||||
SLE_pin(HIGH);
|
||||
asm volatile("mov r8, r8 \n\t"
|
||||
"mov r8, r8 \n\t"
|
||||
"mov r8, r8 \n\t"
|
||||
);
|
||||
asm volatile("nop \n\t"
|
||||
"nop \n\t"
|
||||
"nop \n\t"
|
||||
);
|
||||
SLE_pin(LOW);
|
||||
SDATA_pin(LOW);
|
||||
sle_request = false;
|
||||
|
||||
// now do housekeeping
|
||||
totx_request = false;
|
||||
// first tranmittted bit is always the odd bit
|
||||
even = false;
|
||||
}
|
||||
}
|
||||
// we sample the RX bit at rising TXD clock edge, so TXD must be 1 and we are not in tx mode
|
||||
|
|
@ -203,10 +229,26 @@ void CIO::interrupt()
|
|||
|
||||
m_rxBuffer.put(bit);
|
||||
}
|
||||
if (torx_request == true && even == true && m_tx && clk == 0) {
|
||||
setRX();
|
||||
if (torx_request == true && even == false && m_tx && clk == 0) {
|
||||
// that is absolutely crucial in 4FSK, see datasheet:
|
||||
// enable sle after 1/4 tBit == 26uS when sending MSB (even == false) and clock is low
|
||||
delay_us(26);
|
||||
|
||||
// SLE Pulse, should be moved out of here into class method
|
||||
SLE_pin(HIGH);
|
||||
asm volatile("nop \n\t"
|
||||
"nop \n\t"
|
||||
"nop \n\t"
|
||||
);
|
||||
SLE_pin(LOW);
|
||||
SDATA_pin(LOW);
|
||||
|
||||
// now do housekeeping
|
||||
m_tx = false;
|
||||
torx_request = false;
|
||||
//last tranmittted bit is always the even bit
|
||||
// since the current bit is a transitional "don't care" bit, never transmitted
|
||||
even = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -274,6 +316,9 @@ void CIO::write(uint8_t* data, uint16_t length)
|
|||
// Switch the transmitter on if needed
|
||||
if (!m_tx) {
|
||||
setTX();
|
||||
totx_request = true;
|
||||
// not sure if needed, would be better if handled in interrupt (like torx_request)
|
||||
// or move into setTX()
|
||||
while(CLK_pin());
|
||||
m_tx = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue