This example shows, how frames are received and retransmitted if their CRC was correct. This example is esentially a combination from pgXmplTrxTx and pgXmplTrxRx. The retransmission of the frames is initiated within the transceiver interrupt routine without any CCA.
- Note
- Use this example with care !!! You can mess up your sensor network easily.
#include "board.h"
#include "transceiver.h"
#include "ioutil.h"
#include <util/crc16.h>
#include "xmpl.h"
static volatile uint8_t rxcnt;
static uint8_t state;
int main(void)
{
ERR_CHECK(TRX_OFF!=rval);
#if defined(TRX_IRQ_TRX_END)
#elif defined(TRX_IRQ_RX_END) && defined(TRX_IRQ_TX_END)
#else
# error "Unknown IRQ bits"
#endif
rxcnt = 0;
while(1);
}
#if defined(TRX_IF_RFA1)
ISR(TRX24_RX_END_vect)
{
uint8_t *pfrm, tmp, flen;
uint16_t crc;
pfrm = rxfrm;
tmp = flen;
crc = 0;
do
{
crc = _crc_ccitt_update(crc, *pfrm++);
}
while(tmp--);
if (crc == 0)
{
rxcnt ++;
rxfrm[2] ^=0xff;
}
}
ISR(TRX24_TX_END_vect)
{
}
#else
ISR(TRX_IRQ_vect)
{
uint8_t *pfrm, tmp, flen;
uint16_t crc;
if (irq_cause & TRX_IRQ_TRX_END)
{
{
}
else
{
pfrm = rxfrm;
tmp = flen;
crc = 0;
do
{
crc = _crc_ccitt_update(crc, *pfrm++);
}
while(tmp--);
if (crc == 0)
{
rxcnt ++;
rxfrm[2] ^=0xff;
}
}
}
}
#endif