Remove unused prototypes.
Add function pointer typedef. Switch to use /* */ comments to survive pickier compile flags. Add dsp_uart_destroy function (takes ** pointer so it can set the pointer back to NULL) git-svn-id: http://svn.openzap.org/svn/openzap/trunk@200 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
98cdabe0c1
commit
34d002aaa4
|
@ -46,8 +46,7 @@
|
||||||
* attributes structure is used.
|
* attributes structure is used.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void dsp_uart_attr_init (dsp_uart_attr_t *attr)
|
||||||
dsp_uart_attr_init (dsp_uart_attr_t *attr)
|
|
||||||
{
|
{
|
||||||
memset (attr, 0, sizeof (*attr));
|
memset (attr, 0, sizeof (*attr));
|
||||||
}
|
}
|
||||||
|
@ -61,22 +60,19 @@ dsp_uart_attr_init (dsp_uart_attr_t *attr)
|
||||||
* zero == ok, -1 == fail.
|
* zero == ok, -1 == fail.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void (*
|
bytehandler_func_t dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg)
|
||||||
dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attr, void **bytehandler_arg)) (void *, int)
|
|
||||||
{
|
{
|
||||||
*bytehandler_arg = attr -> bytehandler_arg;
|
*bytehandler_arg = attr -> bytehandler_arg;
|
||||||
return (attr -> bytehandler);
|
return (attr -> bytehandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg)
|
||||||
dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attr, void (*bytehandler) (void *, int ), 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_handle_t *dsp_uart_create (dsp_uart_attr_t *attr)
|
||||||
dsp_uart_create (dsp_uart_attr_t *attr)
|
|
||||||
{
|
{
|
||||||
dsp_uart_handle_t *handle;
|
dsp_uart_handle_t *handle;
|
||||||
|
|
||||||
|
@ -86,21 +82,28 @@ dsp_uart_create (dsp_uart_attr_t *attr)
|
||||||
}
|
}
|
||||||
memset (handle, 0, sizeof (handle));
|
memset (handle, 0, sizeof (handle));
|
||||||
|
|
||||||
// fill the attributes member
|
/* fill the attributes member */
|
||||||
memcpy (&handle -> attr, attr, sizeof (*attr));
|
memcpy (&handle -> attr, attr, sizeof (*attr));
|
||||||
|
|
||||||
return (handle);
|
return (handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void dsp_uart_destroy (dsp_uart_handle_t **handle)
|
||||||
dsp_uart_bit_handler (void *x, int bit)
|
{
|
||||||
|
if (*handle) {
|
||||||
|
free(*handle);
|
||||||
|
*handle = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
// printf ("bit %d handle -> have_start %d handle -> data %02X handle -> nbits %d\n", bit, handle -> have_start, handle -> data, handle -> nbits);
|
|
||||||
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;
|
||||||
|
@ -118,11 +121,11 @@ dsp_uart_bit_handler (void *x, int bit)
|
||||||
handle -> data = 0;
|
handle -> data = 0;
|
||||||
handle -> have_start = 0;
|
handle -> have_start = 0;
|
||||||
|
|
||||||
// might consider handling errors in the future...
|
/* might consider handling errors in the future... */
|
||||||
#if 0
|
#if 0
|
||||||
} else if (handle -> nbits > 8) {
|
} else if (handle -> nbits > 8) {
|
||||||
if (!bit) {
|
if (!bit) {
|
||||||
// framing error; expected stop bit (mark, 1)
|
/* framing error; expected stop bit (mark, 1) */
|
||||||
printf ("FRAME"); fflush (stdout);
|
printf ("FRAME"); fflush (stdout);
|
||||||
} else {
|
} else {
|
||||||
handle -> have_start = 0;
|
handle -> have_start = 0;
|
||||||
|
|
|
@ -35,18 +35,20 @@
|
||||||
#ifndef __UART_H__
|
#ifndef __UART_H__
|
||||||
#define __UART_H__
|
#define __UART_H__
|
||||||
|
|
||||||
|
typedef void (*bytehandler_func_t) (void *, int);
|
||||||
|
|
||||||
typedef struct dsp_uart_attr_s
|
typedef struct dsp_uart_attr_s
|
||||||
{
|
{
|
||||||
void (*bytehandler) (void *, int); // byte handler
|
bytehandler_func_t bytehandler; /* byte handler */
|
||||||
void *bytehandler_arg; // arbitrary ID passed to bytehandler as first argument
|
void *bytehandler_arg; /* arbitrary ID passed to bytehandler as first argument */
|
||||||
} dsp_uart_attr_t;
|
} dsp_uart_attr_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
dsp_uart_attr_t attr;
|
dsp_uart_attr_t attr;
|
||||||
int have_start; // wait for start bit to show up
|
int have_start; /* wait for start bit to show up */
|
||||||
int data; // data buffer
|
int data; /* data buffer */
|
||||||
int nbits; // number of bits accumulated so far
|
int nbits; /* number of bits accumulated so far */
|
||||||
} dsp_uart_handle_t;
|
} dsp_uart_handle_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -56,24 +58,18 @@ typedef struct
|
||||||
* a) create the attributes structure (dsp_uart_attr_init)
|
* a) create the attributes structure (dsp_uart_attr_init)
|
||||||
* b) initialize fields in the attributes structure (dsp_uart_attr_set_*)
|
* b) initialize fields in the attributes structure (dsp_uart_attr_set_*)
|
||||||
* c) create a Bell-202 handle (dsp_uart_create)
|
* c) create a Bell-202 handle (dsp_uart_create)
|
||||||
* d) feed samples through the handler (dsp_uart_sample)
|
* d) feed bits through dsp_uart_bit_handler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern void dsp_uart_attr_init (dsp_uart_attr_t *attributes);
|
void dsp_uart_attr_init (dsp_uart_attr_t *attributes);
|
||||||
|
|
||||||
extern void (*dsp_uart_attr_get_bithandler (dsp_uart_attr_t *attributes, void **bithandler_arg)) (void *, int);
|
bytehandler_func_t dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg);
|
||||||
extern void dsp_uart_attr_set_bithandler (dsp_uart_attr_t *attributes, void (*bithandler) (void *, int ), void *bithandler_arg);
|
void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, bytehandler_func_t bytehandler, void *bytehandler_arg);
|
||||||
extern void (*dsp_uart_attr_get_bytehandler (dsp_uart_attr_t *attributes, void **bytehandler_arg)) (void *, int);
|
|
||||||
extern void dsp_uart_attr_set_bytehandler (dsp_uart_attr_t *attributes, void (*bytehandler) (void *, int ), void *bytehandler_arg);
|
|
||||||
extern int dsp_uart_attr_get_samplerate (dsp_uart_attr_t *attributes);
|
|
||||||
extern int dsp_uart_attr_set_samplerate (dsp_uart_attr_t *attributes, int samplerate);
|
|
||||||
|
|
||||||
extern dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes);
|
dsp_uart_handle_t * dsp_uart_create (dsp_uart_attr_t *attributes);
|
||||||
extern void dsp_uart_destroy (dsp_uart_handle_t *handle);
|
void dsp_uart_destroy (dsp_uart_handle_t **handle);
|
||||||
|
|
||||||
extern void dsp_uart_sample (dsp_uart_handle_t *handle, double normalized_sample);
|
void dsp_uart_bit_handler (void *handle, int bit);
|
||||||
|
|
||||||
extern void dsp_uart_bit_handler (void *handle, int bit);
|
|
||||||
|
|
||||||
#endif // __UART_H__
|
#endif // __UART_H__
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue