X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fafsk.h;h=4ab20c5053391c2777c967316e7782033fb14618;hb=5254bfa9aa0e9dd3bca2a54ecbba23d2bb999300;hp=371597122a30059c2686b53dc1afa5208b096214;hpb=d6af05ba9e8ba0c4f6b503c9eda0b8d532973d87;p=bertos.git diff --git a/bertos/net/afsk.h b/bertos/net/afsk.h index 37159712..4ab20c50 100644 --- a/bertos/net/afsk.h +++ b/bertos/net/afsk.h @@ -44,13 +44,84 @@ #ifndef DRV_AFSK_H #define DRV_AFSK_H +#include "cfg/cfg_afsk.h" +#include "hw/hw_afsk.h" + #include #include -#include "hw/hw_afsk.h" +#include + + +// Demodulator constants +#define SAMPLERATE 9600 +#define BITRATE 1200 + +#define SAMPLEPERBIT (SAMPLERATE / BITRATE) + typedef struct Afsk { - KFile fd; + KFile fd; + + int adc_ch; + int dac_ch; + + /** Current sample of bit for output data. */ + uint8_t sample_count; + + /** Current character to be modulated */ + uint8_t curr_out; + + /** Mask of current modulated bit */ + uint8_t tx_bit; + + /** True if bit stuff is allowed, false otherwise */ + bool bit_stuff; + + /** Counter for bit stuffing */ + uint8_t stuff_cnt; + /** + * DDS phase accumulator for generating modulated data. + */ + uint16_t phase_acc; + + /** Current phase increment for current modulated bit */ + uint16_t phase_inc; + + /** Delay line used to delay samples by (SAMPLEPERBIT / 2) */ + FIFOBuffer delay_fifo; + + /** + * Buffer for delay FIFO. + * The 1 is added because the FIFO macros need + * 1 byte more to handle a buffer (SAMPLEPERBIT / 2) bytes long. + */ + int8_t delay_buf[SAMPLEPERBIT / 2 + 1]; + + FIFOBuffer rx_fifo; + uint8_t rx_buf[CONFIG_AFSK_RX_BUFLEN]; + + FIFOBuffer tx_fifo; + uint8_t tx_buf[CONFIG_AFSK_TX_BUFLEN]; + + int16_t iir_x[2]; + int16_t iir_y[2]; + + uint8_t sampled_bits; + uint8_t found_bits; + int8_t curr_phase; + + /* True while modem sends data */ + volatile bool sending; + + + bool hdlc_rxstart; + uint8_t hdlc_currchar; + uint8_t hdlc_bit_idx; + uint8_t hdlc_demod_bits; + + uint16_t preamble_len; + uint16_t trailer_len; } Afsk; #define KFT_AFSK MAKE_ID('A', 'F', 'S', 'K') @@ -61,7 +132,10 @@ INLINE Afsk *AFSK_CAST(KFile *fd) return (Afsk *)fd; } -void afsk_init(Afsk *af); +void afsk_adc_isr(Afsk *af, int8_t curr_sample); +void afsk_dac_isr(Afsk *af); +void afsk_init(Afsk *af, int adc_ch, int dac_ch); + /** * \name afsk filter type @@ -72,5 +146,8 @@ void afsk_init(Afsk *af); #define AFSK_CHEBYSHEV 1 /* \} */ +int afsk_testSetup(void); +int afsk_testRun(void); +int afsk_testTearDown(void); #endif