afsk.h
Go to the documentation of this file.
00001
00043 #ifndef NET_AFSK_H
00044 #define NET_AFSK_H
00045 
00046 #include "cfg/cfg_afsk.h"
00047 #include "hw/hw_afsk.h"
00048
00049 #include <cfg/compiler.h>
00050
00051 #include <io/kfile.h>
00052
00053 #include <struct/fifobuf.h>
00054
00055
00056
00062 #define SAMPLERATE 9600
00063 
00069 #define BITRATE    1200
00070 
00071 #define SAMPLEPERBIT (SAMPLERATE / BITRATE)
00072 
00077 typedef struct Hdlc
00078 {
00079     uint8_t demod_bits;
00080     uint8_t bit_idx;
00081     uint8_t currchar;
00082     bool rxstart;
00083 } Hdlc;
00084
00088 #define AFSK_RXFIFO_OVERRUN BV(0)
00089 
00093 typedef struct Afsk
00094 {
00096     KFile fd;
00097
00099     int adc_ch;
00100
00102     int dac_ch;
00103
00105     uint8_t sample_count;
00106
00108     uint8_t curr_out;
00109
00111     uint8_t tx_bit;
00112
00114     bool bit_stuff;
00115
00117     uint8_t stuff_cnt;
00121     uint16_t phase_acc;
00122
00124     uint16_t phase_inc;
00125
00127     FIFOBuffer delay_fifo;
00128
00134     int8_t delay_buf[SAMPLEPERBIT / 2 + 1];
00135
00137     FIFOBuffer rx_fifo;
00138
00140     uint8_t rx_buf[CONFIG_AFSK_RX_BUFLEN];
00141
00143     FIFOBuffer tx_fifo;
00144
00146     uint8_t tx_buf[CONFIG_AFSK_TX_BUFLEN];
00147
00149     int16_t iir_x[2];
00150
00152     int16_t iir_y[2];
00153
00159     uint8_t sampled_bits;
00160
00165     int8_t curr_phase;
00166
00168     uint8_t found_bits;
00169
00171     volatile bool sending;
00172
00177     volatile int status;
00178
00180     Hdlc hdlc;
00181
00188     uint16_t preamble_len;
00189
00196     uint16_t trailer_len;
00197 } Afsk;
00198
00199 #define KFT_AFSK MAKE_ID('A', 'F', 'S', 'K')
00200 
00201 INLINE Afsk *AFSK_CAST(KFile *fd)
00202 {
00203   ASSERT(fd->_type == KFT_AFSK);
00204   return (Afsk *)fd;
00205 }
00206
00207
00208 void afsk_adc_isr(Afsk *af, int8_t sample);
00209 uint8_t afsk_dac_isr(Afsk *af);
00210 void afsk_init(Afsk *af, int adc_ch, int dac_ch);
00211
00212
00218 #define AFSK_BUTTERWORTH  0
00219 #define AFSK_CHEBYSHEV    1
00220 /* \} */
00221
00222 int afsk_testSetup(void);
00223 int afsk_testRun(void);
00224 int afsk_testTearDown(void);
00225
00226 #endif /* NET_AFSK_H */