afsk.h

Go to the documentation of this file.
00001 
00044 #ifndef DRV_AFSK_H
00045 #define DRV_AFSK_H
00046 
00047 #include "cfg/cfg_afsk.h"
00048 #include "hw/hw_afsk.h"
00049 
00050 #include <kern/kfile.h>
00051 #include <cfg/compiler.h>
00052 #include <struct/fifobuf.h>
00053 
00054 
00055 
00061 #define SAMPLERATE 9600
00062 
00068 #define BITRATE    1200
00069 
00070 #define SAMPLEPERBIT (SAMPLERATE / BITRATE)
00071 
00076 typedef struct Hdlc
00077 {
00078     uint8_t demod_bits; 
00079     uint8_t bit_idx;    
00080     uint8_t currchar;   
00081     bool rxstart;       
00082 } Hdlc;
00083 
00087 #define AFSK_RXFIFO_OVERRUN BV(0)
00088 
00092 typedef struct Afsk
00093 {
00095     KFile fd;
00096 
00098     int adc_ch;
00099 
00101     int dac_ch;
00102 
00104     uint8_t sample_count;
00105 
00107     uint8_t curr_out;
00108 
00110     uint8_t tx_bit;
00111 
00113     bool bit_stuff;
00114 
00116     uint8_t stuff_cnt;
00120     uint16_t phase_acc;
00121 
00123     uint16_t phase_inc;
00124 
00126     FIFOBuffer delay_fifo;
00127 
00133     int8_t delay_buf[SAMPLEPERBIT / 2 + 1];
00134 
00136     FIFOBuffer rx_fifo;
00137 
00139     uint8_t rx_buf[CONFIG_AFSK_RX_BUFLEN];
00140 
00142     FIFOBuffer tx_fifo;
00143 
00145     uint8_t tx_buf[CONFIG_AFSK_TX_BUFLEN];
00146 
00148     int16_t iir_x[2];
00149 
00151     int16_t iir_y[2];
00152 
00158     uint8_t sampled_bits;
00159 
00164     int8_t curr_phase;
00165 
00167     uint8_t found_bits;
00168 
00170     volatile bool sending;
00171 
00176     volatile int status;
00177 
00179     Hdlc hdlc;
00180 
00187     uint16_t preamble_len;
00188 
00195     uint16_t trailer_len;
00196 } Afsk;
00197 
00198 #define KFT_AFSK MAKE_ID('A', 'F', 'S', 'K')
00199 
00200 INLINE Afsk *AFSK_CAST(KFile *fd)
00201 {
00202   ASSERT(fd->_type == KFT_AFSK);
00203   return (Afsk *)fd;
00204 }
00205 
00206 
00207 void afsk_adc_isr(Afsk *af, int8_t sample);
00208 uint8_t afsk_dac_isr(Afsk *af);
00209 void afsk_init(Afsk *af, int adc_ch, int dac_ch);
00210 
00211 
00217 #define AFSK_BUTTERWORTH  0
00218 #define AFSK_CHEBYSHEV    1
00219 /* \} */
00220 
00221 int afsk_testSetup(void);
00222 int afsk_testRun(void);
00223 int afsk_testTearDown(void);
00224 
00225 #endif