1 /* 2 * uart.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 UART module. 30 * 31 * 2005 06 19 R. Krten created 32 */ 33 34 #ifndef __UART_H__ 35 #define __UART_H__ 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 typedef void (*bytehandler_func_t) (void *, int); 42 typedef void (*bithandler_func_t) (void *, int); 43 44 45 typedef struct dsp_uart_attr_s 46 { 47 bytehandler_func_t bytehandler; /* byte handler */ 48 void *bytehandler_arg; /* arbitrary ID passed to bytehandler as first argument */ 49 } dsp_uart_attr_t; 50 51 typedef struct 52 { 53 dsp_uart_attr_t attr; 54 int have_start; /* wait for start bit to show up */ 55 int data; /* data buffer */ 56 int nbits; /* number of bits accumulated so far */ 57 } dsp_uart_handle_t; 58 59 /* 60 * Function prototypes 61 * 62 * General calling order is: 63 * a) create the attributes structure (dsp_uart_attr_init) 64 * b) initialize fields in the attributes structure (dsp_uart_attr_set_*) 65 * c) create a Bell-202 handle (dsp_uart_create) 66 * d) feed bits through dsp_uart_bit_handler 67 */ 68 69 void dsp_uart_attr_init(dsp_uart_attr_t *attributes); 70 71 bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attributes, void **bytehandler_arg); 72 void dsp_uart_attr_set_bytehandler(dsp_uart_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); 73 74 dsp_uart_handle_t * dsp_uart_create(dsp_uart_attr_t *attributes); 75 void dsp_uart_destroy(dsp_uart_handle_t **handle); 76 77 void dsp_uart_bit_handler(void *handle, int bit); 78 79 #ifdef __cplusplus 80 } 81 #endif 82 #endif 83