• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2018 Realtek Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  Filename:      userial_vendor.h
22  *
23  *  Description:   Contains vendor-specific definitions used in serial port
24  *                 controls
25  *
26  ******************************************************************************/
27 
28 #ifndef USERIAL_VENDOR_H
29 #define USERIAL_VENDOR_H
30 
31 #include <assert.h>
32 #include "bt_vendor_rtk.h"
33 #include "userial.h"
34 #include "hci_h5_int.h"
35 #include "rtk_parse.h"
36 #include "bt_skbuff.h"
37 
38 /******************************************************************************
39 **  Constants & Macros
40 ******************************************************************************/
41 #define RTK_NO_INTR(fn)                                                                                                \
42     do {                                                                                                               \
43     } while ((fn) == -1 && errno == EINTR)
44 
45 /**** baud rates ****/
46 #define USERIAL_BAUD_300 0
47 #define USERIAL_BAUD_600 1
48 #define USERIAL_BAUD_1200 2
49 #define USERIAL_BAUD_2400 3
50 #define USERIAL_BAUD_9600 4
51 #define USERIAL_BAUD_19200 5
52 #define USERIAL_BAUD_57600 6
53 #define USERIAL_BAUD_115200 7
54 #define USERIAL_BAUD_230400 8
55 #define USERIAL_BAUD_460800 9
56 #define USERIAL_BAUD_921600 10
57 #define USERIAL_BAUD_1M 11
58 #define USERIAL_BAUD_1_5M 12
59 #define USERIAL_BAUD_2M 13
60 #define USERIAL_BAUD_3M 14
61 #define USERIAL_BAUD_4M 15
62 #define USERIAL_BAUD_AUTO 16
63 
64 /**** Data Format ****/
65 /* Stop Bits */
66 #define USERIAL_STOPBITS_1 1
67 #define USERIAL_STOPBITS_1_5 (1 << 1)
68 #define USERIAL_STOPBITS_2 (1 << 2)
69 
70 /* Parity Bits */
71 #define USERIAL_PARITY_NONE (1 << 3)
72 #define USERIAL_PARITY_EVEN (1 << 4)
73 #define USERIAL_PARITY_ODD (1 << 5)
74 
75 /* Data Bits */
76 #define USERIAL_DATABITS_5 (1 << 6)
77 #define USERIAL_DATABITS_6 (1 << 7)
78 #define USERIAL_DATABITS_7 (1 << 8)
79 #define USERIAL_DATABITS_8 (1 << 9)
80 
81 #define USERIAL_HW_FLOW_CTRL_OFF 0
82 #define USERIAL_HW_FLOW_CTRL_ON 1
83 
84 #if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE)
85 /* These are the ioctl values used for bt_wake ioctl via UART driver. you may
86  * need to redefine them on you platform!
87  * Logically they need to be unique and not colide with existing uart ioctl's.
88  */
89 #ifndef USERIAL_IOCTL_BT_WAKE_ASSERT
90 #define USERIAL_IOCTL_BT_WAKE_ASSERT 0x8003
91 #endif
92 #ifndef USERIAL_IOCTL_BT_WAKE_DEASSERT
93 #define USERIAL_IOCTL_BT_WAKE_DEASSERT 0x8004
94 #endif
95 #ifndef USERIAL_IOCTL_BT_WAKE_GET_ST
96 #define USERIAL_IOCTL_BT_WAKE_GET_ST 0x8005
97 #endif
98 #endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
99 
100 /******************************************************************************
101 **  Type definitions
102 ******************************************************************************/
103 /* Structure used to configure serial port during open */
104 typedef struct {
105     uint16_t fmt;     /* Data format */
106     uint8_t baud;     /* Baud rate */
107     uint8_t hw_fctrl; /* hardware flowcontrol */
108 } tUSERIAL_CFG;
109 
110 typedef enum {
111 #if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE)
112     USERIAL_OP_ASSERT_BT_WAKE,
113     USERIAL_OP_DEASSERT_BT_WAKE,
114     USERIAL_OP_GET_BT_WAKE_STATE,
115 #endif
116     USERIAL_OP_NOP,
117 } userial_vendor_ioctl_op_t;
118 
119 enum { RTKBT_PACKET_IDLE, RTKBT_PACKET_TYPE, RTKBT_PACKET_HEADER, RTKBT_PACKET_CONTENT, RTKBT_PACKET_END };
120 
121 /******************************************************************************
122 **  Extern variables and functions
123 ******************************************************************************/
124 
125 /******************************************************************************
126 **  Functions
127 ******************************************************************************/
128 
129 /*******************************************************************************
130 **
131 ** Function        userial_vendor_init
132 **
133 ** Description     Initialize userial vendor-specific control block
134 **
135 ** Returns         None
136 **
137 *******************************************************************************/
138 void userial_vendor_init(char *bt_device_node);
139 
140 /*******************************************************************************
141 **
142 ** Function        userial_vendor_open
143 **
144 ** Description     Open the serial port with the given configuration
145 **
146 ** Returns         device fd
147 **
148 *******************************************************************************/
149 int userial_vendor_open(tUSERIAL_CFG *p_cfg);
150 
151 /*******************************************************************************
152 **
153 ** Function        userial_vendor_close
154 **
155 ** Description     Conduct vendor-specific close work
156 **
157 ** Returns         None
158 **
159 *******************************************************************************/
160 void userial_vendor_close(void);
161 
162 /*******************************************************************************
163 **
164 ** Function        userial_vendor_set_baud
165 **
166 ** Description     Set new baud rate
167 **
168 ** Returns         None
169 **
170 *******************************************************************************/
171 void userial_vendor_set_baud(uint8_t userial_baud);
172 
173 /*******************************************************************************
174 **
175 ** Function        userial_vendor_ioctl
176 **
177 ** Description     ioctl interface
178 **
179 ** Returns         None
180 **
181 *******************************************************************************/
182 void userial_vendor_ioctl(userial_vendor_ioctl_op_t op, void *p_data);
183 
184 void userial_vendor_set_hw_fctrl(uint8_t hw_fctrl);
185 
186 int userial_socket_open(void);
187 
188 int userial_vendor_usb_ioctl(int operation, void *param);
189 
190 int userial_vendor_usb_open(void);
191 
192 void userial_recv_rawdata_hook(unsigned char *buffer, unsigned int total_length);
193 
194 #define RTK_HANDLE_EVENT
195 #define RTK_HANDLE_CMD
196 #endif /* USERIAL_VENDOR_H */
197