1 /* 2 * bell202.h 3 * 4 * Copyright (c) 2005 Robert Krten. All Rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * This module contains the manifest constants and declarations for 29 * the Bell-202 1200 baud FSK modem. 30 * 31 * 2005 03 20 R. Krten created 32 */ 33 34 #ifndef __FSK_H__ 35 #define __FSK_H__ 36 #include "uart.h" 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 typedef struct { 43 int freq_space; /* Frequency of the 0 bit */ 44 int freq_mark; /* Frequency of the 1 bit */ 45 int baud_rate; /* baud rate for the modem */ 46 } fsk_modem_definition_t; 47 48 /* Must be kept in sync with fsk_modem_definitions array in fsk.c */ 49 /* V.23 definitions: http://www.itu.int/rec/recommendation.asp?type=folders&lang=e&parent=T-REC-V.23 */ 50 typedef enum { 51 FSK_V23_FORWARD_MODE1 = 0, /* Maximum 600 bps for long haul */ 52 FSK_V23_FORWARD_MODE2, /* Standard 1200 bps V.23 */ 53 FSK_V23_BACKWARD, /* 75 bps return path for V.23 */ 54 FSK_BELL202 /* Bell 202 half-duplex 1200 bps */ 55 } fsk_modem_types_t; 56 57 typedef enum { 58 FSK_STATE_CHANSEIZE = 0, 59 FSK_STATE_CARRIERSIG, 60 FSK_STATE_DATA 61 } fsk_state_t; 62 63 typedef struct dsp_fsk_attr_s 64 { 65 int sample_rate; /* sample rate in HZ */ 66 bithandler_func_t bithandler; /* bit handler */ 67 void *bithandler_arg; /* arbitrary ID passed to bithandler as first argument */ 68 bytehandler_func_t bytehandler; /* byte handler */ 69 void *bytehandler_arg; /* arbitrary ID passed to bytehandler as first argument */ 70 } dsp_fsk_attr_t; 71 72 typedef struct 73 { 74 fsk_state_t state; 75 dsp_fsk_attr_t attr; /* attributes structure */ 76 double *correlates[4]; /* one for each of sin/cos for mark/space */ 77 int corrsize; /* correlate size (also number of samples in ring buffer) */ 78 double *buffer; /* sample ring buffer */ 79 int ringstart; /* ring buffer start offset */ 80 double cellpos; /* bit cell position */ 81 double celladj; /* bit cell adjustment for each sample */ 82 int previous_bit; /* previous bit (for detecting a transition to sync-up cell position) */ 83 int current_bit; /* current bit */ 84 int last_bit; 85 int downsampling_count; /* number of samples to skip */ 86 int current_downsample; /* current skip count */ 87 int conscutive_state_bits; /* number of bits in a row that matches the pattern for the current state */ 88 } dsp_fsk_handle_t; 89 90 /* 91 * Function prototypes 92 * 93 * General calling order is: 94 * a) create the attributes structure (dsp_fsk_attr_init) 95 * b) initialize fields in the attributes structure (dsp_fsk_attr_set_*) 96 * c) create a Bell-202 handle (dsp_fsk_create) 97 * d) feed samples through the handler (dsp_fsk_sample) 98 */ 99 100 void dsp_fsk_attr_init(dsp_fsk_attr_t *attributes); 101 102 bithandler_func_t dsp_fsk_attr_get_bithandler(dsp_fsk_attr_t *attributes, void **bithandler_arg); 103 void dsp_fsk_attr_set_bithandler(dsp_fsk_attr_t *attributes, bithandler_func_t bithandler, void *bithandler_arg); 104 bytehandler_func_t dsp_fsk_attr_get_bytehandler(dsp_fsk_attr_t *attributes, void **bytehandler_arg); 105 void dsp_fsk_attr_set_bytehandler(dsp_fsk_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); 106 int dsp_fsk_attr_get_samplerate(dsp_fsk_attr_t *attributes); 107 int dsp_fsk_attr_set_samplerate(dsp_fsk_attr_t *attributes, int samplerate); 108 109 dsp_fsk_handle_t * dsp_fsk_create(dsp_fsk_attr_t *attributes); 110 void dsp_fsk_destroy(dsp_fsk_handle_t **handle); 111 112 void dsp_fsk_sample(dsp_fsk_handle_t *handle, double normalized_sample); 113 114 extern fsk_modem_definition_t fsk_modem_definitions[]; 115 116 #ifdef __cplusplus 117 } /* extern C */ 118 #endif 119 120 #endif 121