From 5eed6650f8cd31b25fa7f417df272c194082be0b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 3 Jun 2007 03:07:08 +0000 Subject: [PATCH] make code style consistent with the rest of the lib. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@201 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/dsp/uart.c | 73 +++++++++++++++---------------------- libs/freetdm/src/dsp/uart.h | 12 +++--- 2 files changed, 36 insertions(+), 49 deletions(-) diff --git a/libs/freetdm/src/dsp/uart.c b/libs/freetdm/src/dsp/uart.c index c6e2105fcc..05a80753ec 100644 --- a/libs/freetdm/src/dsp/uart.c +++ b/libs/freetdm/src/dsp/uart.c @@ -60,35 +60,33 @@ void dsp_uart_attr_init (dsp_uart_attr_t *attr) * zero == ok, -1 == fail. */ -bytehandler_func_t dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg) +bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attr, void **bytehandler_arg) { - *bytehandler_arg = attr -> bytehandler_arg; - return (attr -> bytehandler); + *bytehandler_arg = attr->bytehandler_arg; + return attr->bytehandler; } -void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) +void dsp_uart_attr_set_bytehandler(dsp_uart_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg) { - attr -> bytehandler = bytehandler; - attr -> bytehandler_arg = bytehandler_arg; + attr->bytehandler = bytehandler; + attr->bytehandler_arg = bytehandler_arg; } -dsp_uart_handle_t *dsp_uart_create (dsp_uart_attr_t *attr) +dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) { - dsp_uart_handle_t *handle; + dsp_uart_handle_t *handle; - handle = malloc (sizeof (*handle)); - if (handle == NULL) { - return (handle); + handle = malloc(sizeof (*handle)); + if (handle) { + memset(handle, 0, sizeof (handle)); + + /* fill the attributes member */ + memcpy(&handle->attr, attr, sizeof (*attr)); } - memset (handle, 0, sizeof (handle)); - - /* fill the attributes member */ - memcpy (&handle -> attr, attr, sizeof (*attr)); - - return (handle); + return handle; } -void dsp_uart_destroy (dsp_uart_handle_t **handle) +void dsp_uart_destroy(dsp_uart_handle_t **handle) { if (*handle) { free(*handle); @@ -97,41 +95,30 @@ void dsp_uart_destroy (dsp_uart_handle_t **handle) } -void dsp_uart_bit_handler (void *x, int bit) +void dsp_uart_bit_handler(void *x, int bit) { dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x; - if (!handle -> have_start) { + if (!handle->have_start) { if (bit) { return; /* waiting for start bit (0) */ } - handle -> have_start = 1; - handle -> data = 0; - handle -> nbits = 0; + handle->have_start = 1; + handle->data = 0; + handle->nbits = 0; return; } - handle -> data >>= 1; - handle -> data |= 0x80 * !!bit; + handle->data >>= 1; + handle->data |= 0x80 * !!bit; - handle -> nbits++; - if (handle -> nbits == 8) { - (*handle -> attr.bytehandler) (handle -> attr.bytehandler_arg, handle -> data); - handle -> nbits = 0; - handle -> data = 0; - handle -> have_start = 0; - -/* might consider handling errors in the future... */ -#if 0 - } else if (handle -> nbits > 8) { - if (!bit) { - /* framing error; expected stop bit (mark, 1) */ - printf ("FRAME"); fflush (stdout); - } else { - handle -> have_start = 0; - handle -> nbits = 0; - } -#endif + handle->nbits++; + if (handle->nbits == 8) { + handle->attr.bytehandler(handle->attr.bytehandler_arg, handle->data); + handle->nbits = 0; + handle->data = 0; + handle->have_start = 0; } +/* might consider handling errors in the future... */ } diff --git a/libs/freetdm/src/dsp/uart.h b/libs/freetdm/src/dsp/uart.h index 9989ab935d..91b2bd0880 100644 --- a/libs/freetdm/src/dsp/uart.h +++ b/libs/freetdm/src/dsp/uart.h @@ -61,15 +61,15 @@ typedef struct * d) feed bits through dsp_uart_bit_handler */ -void dsp_uart_attr_init (dsp_uart_attr_t *attributes); +void dsp_uart_attr_init(dsp_uart_attr_t *attributes); -bytehandler_func_t dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg); -void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); +bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attributes, void **bytehandler_arg); +void dsp_uart_attr_set_bytehandler(dsp_uart_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg); -dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes); -void dsp_uart_destroy (dsp_uart_handle_t **handle); +dsp_uart_handle_t * dsp_uart_create(dsp_uart_attr_t *attributes); +void dsp_uart_destroy(dsp_uart_handle_t **handle); -void dsp_uart_bit_handler (void *handle, int bit); +void dsp_uart_bit_handler(void *handle, int bit); #endif // __UART_H__