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 <kern/kfile.h>
00050 #include <cfg/compiler.h>
00051 #include <struct/fifobuf.h>
00052 
00053 
00054 
00060 #define SAMPLERATE 9600
00061 
00067 #define BITRATE    1200
00068 
00069 #define SAMPLEPERBIT (SAMPLERATE / BITRATE)
00070 
00075 typedef struct Hdlc
00076 {
00077     uint8_t demod_bits; 
00078     uint8_t bit_idx;    
00079     uint8_t currchar;   
00080     bool rxstart;       
00081 } Hdlc;
00082 
00086 #define AFSK_RXFIFO_OVERRUN BV(0)
00087 
00091 typedef struct Afsk
00092 {
00094     KFile fd;
00095 
00097     int adc_ch;
00098 
00100     int dac_ch;
00101 
00103     uint8_t sample_count;
00104 
00106     uint8_t curr_out;
00107 
00109     uint8_t tx_bit;
00110 
00112     bool bit_stuff;
00113 
00115     uint8_t stuff_cnt;
00119     uint16_t phase_acc;
00120 
00122     uint16_t phase_inc;
00123 
00125     FIFOBuffer delay_fifo;
00126 
00132     int8_t delay_buf[SAMPLEPERBIT / 2 + 1];
00133 
00135     FIFOBuffer rx_fifo;
00136 
00138     uint8_t rx_buf[CONFIG_AFSK_RX_BUFLEN];
00139 
00141     FIFOBuffer tx_fifo;
00142 
00144     uint8_t tx_buf[CONFIG_AFSK_TX_BUFLEN];
00145 
00147     int16_t iir_x[2];
00148 
00150     int16_t iir_y[2];
00151 
00157     uint8_t sampled_bits;
00158 
00163     int8_t curr_phase;
00164 
00166     uint8_t found_bits;
00167 
00169     volatile bool sending;
00170 
00175     volatile int status;
00176 
00178     Hdlc hdlc;
00179 
00186     uint16_t preamble_len;
00187 
00194     uint16_t trailer_len;
00195 } Afsk;
00196 
00197 #define KFT_AFSK MAKE_ID('A', 'F', 'S', 'K')
00198 
00199 INLINE Afsk *AFSK_CAST(KFile *fd)
00200 {
00201   ASSERT(fd->_type == KFT_AFSK);
00202   return (Afsk *)fd;
00203 }
00204 
00205 
00206 void afsk_adc_isr(Afsk *af, int8_t sample);
00207 uint8_t afsk_dac_isr(Afsk *af);
00208 void afsk_init(Afsk *af, int adc_ch, int dac_ch);
00209 
00210 
00216 #define AFSK_BUTTERWORTH  0
00217 #define AFSK_CHEBYSHEV    1
00218 /* \} */
00219 
00220 int afsk_testSetup(void);
00221 int afsk_testRun(void);
00222 int afsk_testTearDown(void);
00223 
00224 #endif /* NET_AFSK_H */