This source file includes following definitions.
- dsp_uart_attr_init
- dsp_uart_attr_get_bytehandler
- dsp_uart_attr_set_bytehandler
- dsp_uart_create
- dsp_uart_destroy
- dsp_uart_bit_handler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <private/ftdm_core.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <errno.h>
40
41 #include "uart.h"
42
43
44
45
46
47
48
49
50 void dsp_uart_attr_init (dsp_uart_attr_t *attr)
51 {
52 memset (attr, 0, sizeof (*attr));
53 }
54
55
56
57
58
59
60
61
62
63
64 bytehandler_func_t dsp_uart_attr_get_bytehandler(dsp_uart_attr_t *attr, void **bytehandler_arg)
65 {
66 *bytehandler_arg = attr->bytehandler_arg;
67 return attr->bytehandler;
68 }
69
70 void dsp_uart_attr_set_bytehandler(dsp_uart_attr_t *attr, bytehandler_func_t bytehandler, void *bytehandler_arg)
71 {
72 attr->bytehandler = bytehandler;
73 attr->bytehandler_arg = bytehandler_arg;
74 }
75
76 dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr)
77 {
78 dsp_uart_handle_t *handle;
79
80 handle = ftdm_malloc(sizeof (*handle));
81 if (handle) {
82 memset(handle, 0, sizeof (*handle));
83
84
85 memcpy(&handle->attr, attr, sizeof (*attr));
86 }
87 return handle;
88 }
89
90 void dsp_uart_destroy(dsp_uart_handle_t **handle)
91 {
92 if (*handle) {
93 ftdm_safe_free(*handle);
94 *handle = NULL;
95 }
96 }
97
98
99 void dsp_uart_bit_handler(void *x, int bit)
100 {
101 dsp_uart_handle_t *handle = (dsp_uart_handle_t *) x;
102
103 if (!handle->have_start) {
104 if (bit) {
105 return;
106 }
107 handle->have_start = 1;
108 handle->data = 0;
109 handle->nbits = 0;
110 return;
111 }
112
113 handle->data >>= 1;
114 handle->data |= 0x80 * !!bit;
115 handle->nbits++;
116
117 if (handle->nbits == 8) {
118 handle->attr.bytehandler(handle->attr.bytehandler_arg, handle->data);
119 handle->nbits = 0;
120 handle->data = 0;
121 handle->have_start = 0;
122 }
123
124 }
125