1/******************************************************************************
2 *
3 *  Copyright 2009-2012 Broadcom 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// This module manages the serial port over which HCI commands
20// and data are sent/received.
21
22#ifndef BT_VENDOR_USERIAL_H
23#define BT_VENDOR_USERIAL_H
24
25#include <stdbool.h>
26#include <stdint.h>
27
28typedef enum {
29    USERIAL_PORT_1,
30    USERIAL_PORT_2,
31    USERIAL_PORT_3,
32    USERIAL_PORT_4,
33    USERIAL_PORT_5,
34    USERIAL_PORT_6,
35    USERIAL_PORT_7,
36    USERIAL_PORT_8,
37    USERIAL_PORT_9,
38    USERIAL_PORT_10,
39    USERIAL_PORT_11,
40    USERIAL_PORT_12,
41    USERIAL_PORT_13,
42    USERIAL_PORT_14,
43    USERIAL_PORT_15,
44    USERIAL_PORT_16,
45    USERIAL_PORT_17,
46    USERIAL_PORT_18,
47} userial_port_t;
48
49// Initializes the userial module. This function should only be called once.
50// It returns true if the module was initialized, false if there was an error.
51bool userial_init(void);
52
53// Opens the given serial port. Returns true if successful, false otherwise.
54// Once this function is called, the userial module will begin producing
55// buffers from data read off the serial port. If you wish to pause the
56// production of buffers, call |userial_pause_reading|. You can then resume
57// by calling |userial_resume_reading|. This function returns true if the
58// serial port was successfully opened and buffer production has started. It
59// returns false if there was an error.
60bool userial_open(userial_port_t port);
61void userial_close(void);
62void userial_close_reader(void);
63
64// Reads a maximum of |len| bytes from the serial port into |p_buffer|.
65// This function returns the number of bytes actually read, which may be
66// less than |len|. This function will not block.
67uint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len);
68
69// Writes a maximum of |len| bytes from |p_data| to the serial port.
70// This function returns the number of bytes actually written, which may be
71// less than |len|. This function may block.
72uint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len);
73#endif