#ifndef MYRADIO_PHY_RECEIVER_H_ #define MYRADIO_PHY_RECEIVER_H_ /* Lowlevel receiver definitions. * These functions do poke with the actual RX hardware. */ #include "util.h" #include /* Our receiver is based on the AnalogToDigital-converter 0. * We basically get a binary signal from the radio. The radio * hardware did already demodulate the HF signal and filter * out any HF. * Our tunable is the threshold value for the logical HIGH. * The ADC is in freerunning mode and continuously scans the * input pin. The current status can be fetched by calling the * receiver_get_current_signal() function. * Note that the current signal is delayed by the ADC delay, which * is defined by the ADC prescaler. However, as our prescaler is 64 * we run the ADC at a frequency of 250kHz (16Mhz crystal). That means * our delay is as low as 4 microseconds. */ //FIXME tune this to the correct value for our radio #define RECEIVER_THRESHOLD 50 /* in ADC LSBs */ static inline bool receiver_get_current_signal(void) { return (ADC > RECEIVER_THRESHOLD); } static inline void receiver_initialize(void) { /* Multiplexer = ADC0; Reference = AVcc */ ADMUX = (1 << REFS0); /* Enable ADC; Prescaler = 64 */ ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS2); /* Poke the ADC once to initialize it */ ADCSRA |= (1 << ADSC); while (ADCSRA & (1 << ADSC)) mb(); /* Now enable free-running mode. */ ADCSRA |= (1 << ADSC) | (1 << ADFR); } #endif /* MYRADIO_PHY_RECEIVER_H_ */