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
This commit is contained in:
parent
ff448df407
commit
5eed6650f8
|
@ -60,35 +60,33 @@ void dsp_uart_attr_init (dsp_uart_attr_t *attr)
|
||||||
* zero == ok, -1 == fail.
|
* 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;
|
*bytehandler_arg = attr->bytehandler_arg;
|
||||||
return (attr -> bytehandler);
|
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 = bytehandler;
|
||||||
attr -> bytehandler_arg = bytehandler_arg;
|
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));
|
handle = malloc(sizeof (*handle));
|
||||||
if (handle == NULL) {
|
if (handle) {
|
||||||
return (handle);
|
memset(handle, 0, sizeof (handle));
|
||||||
|
|
||||||
|
/* fill the attributes member */
|
||||||
|
memcpy(&handle->attr, attr, sizeof (*attr));
|
||||||
}
|
}
|
||||||
memset (handle, 0, sizeof (handle));
|
return handle;
|
||||||
|
|
||||||
/* fill the attributes member */
|
|
||||||
memcpy (&handle -> attr, attr, sizeof (*attr));
|
|
||||||
|
|
||||||
return (handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dsp_uart_destroy (dsp_uart_handle_t **handle)
|
void dsp_uart_destroy(dsp_uart_handle_t **handle)
|
||||||
{
|
{
|
||||||
if (*handle) {
|
if (*handle) {
|
||||||
free(*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;
|
dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x;
|
||||||
|
|
||||||
if (!handle -> have_start) {
|
if (!handle->have_start) {
|
||||||
if (bit) {
|
if (bit) {
|
||||||
return; /* waiting for start bit (0) */
|
return; /* waiting for start bit (0) */
|
||||||
}
|
}
|
||||||
handle -> have_start = 1;
|
handle->have_start = 1;
|
||||||
handle -> data = 0;
|
handle->data = 0;
|
||||||
handle -> nbits = 0;
|
handle->nbits = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle -> data >>= 1;
|
handle->data >>= 1;
|
||||||
handle -> data |= 0x80 * !!bit;
|
handle->data |= 0x80 * !!bit;
|
||||||
|
|
||||||
handle -> nbits++;
|
handle->nbits++;
|
||||||
if (handle -> nbits == 8) {
|
if (handle->nbits == 8) {
|
||||||
(*handle -> attr.bytehandler) (handle -> attr.bytehandler_arg, handle -> data);
|
handle->attr.bytehandler(handle->attr.bytehandler_arg, handle->data);
|
||||||
handle -> nbits = 0;
|
handle->nbits = 0;
|
||||||
handle -> data = 0;
|
handle->data = 0;
|
||||||
handle -> have_start = 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
|
|
||||||
}
|
}
|
||||||
|
/* might consider handling errors in the future... */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,15 +61,15 @@ typedef struct
|
||||||
* d) feed bits through dsp_uart_bit_handler
|
* 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);
|
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);
|
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);
|
dsp_uart_handle_t * dsp_uart_create(dsp_uart_attr_t *attributes);
|
||||||
void dsp_uart_destroy (dsp_uart_handle_t **handle);
|
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__
|
#endif // __UART_H__
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue