blob: 2d1424fd135c463fb5ee4b641fe0476db1c30403 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2009-2012 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
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
Sharvil Nanavatic4e0e042014-04-26 10:40:30 -070019// This module manages the serial port over which HCI commands
20// and data are sent/received.
The Android Open Source Project5738f832012-12-12 16:00:35 -080021
Sharvil Nanavati16715982014-04-26 00:58:15 -070022#pragma once
The Android Open Source Project5738f832012-12-12 16:00:35 -080023
Sharvil Nanavati16715982014-04-26 00:58:15 -070024#include <stdbool.h>
25#include <stdint.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080026
27typedef enum {
Sharvil Nanavati16715982014-04-26 00:58:15 -070028 USERIAL_PORT_1,
29 USERIAL_PORT_2,
30 USERIAL_PORT_3,
31 USERIAL_PORT_4,
32 USERIAL_PORT_5,
33 USERIAL_PORT_6,
34 USERIAL_PORT_7,
35 USERIAL_PORT_8,
36 USERIAL_PORT_9,
37 USERIAL_PORT_10,
38 USERIAL_PORT_11,
39 USERIAL_PORT_12,
40 USERIAL_PORT_13,
41 USERIAL_PORT_14,
42 USERIAL_PORT_15,
43 USERIAL_PORT_16,
44 USERIAL_PORT_17,
45 USERIAL_PORT_18,
46} userial_port_t;
47
Myles Watson29483132016-10-31 13:50:51 -070048// Initializes the userial module. This function should only be called once.
49// It returns true if the module was initialized, false if there was an error.
Sharvil Nanavati16715982014-04-26 00:58:15 -070050bool userial_init(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -080051
Sharvil Nanavatic4e0e042014-04-26 10:40:30 -070052// Opens the given serial port. Returns true if successful, false otherwise.
53// Once this function is called, the userial module will begin producing
54// buffers from data read off the serial port. If you wish to pause the
55// production of buffers, call |userial_pause_reading|. You can then resume
56// by calling |userial_resume_reading|. This function returns true if the
57// serial port was successfully opened and buffer production has started. It
58// returns false if there was an error.
Sharvil Nanavati16715982014-04-26 00:58:15 -070059bool userial_open(userial_port_t port);
The Android Open Source Project5738f832012-12-12 16:00:35 -080060void userial_close(void);
Chris Manton11aa94d2014-08-15 09:04:00 -070061void userial_close_reader(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -080062
Sharvil Nanavatic4e0e042014-04-26 10:40:30 -070063// Reads a maximum of |len| bytes from the serial port into |p_buffer|.
64// This function returns the number of bytes actually read, which may be
65// less than |len|. This function will not block.
Myles Watson5ff20a22016-10-31 10:53:52 -070066uint16_t userial_read(uint16_t msg_id, uint8_t* p_buffer, uint16_t len);
Sharvil Nanavatic4e0e042014-04-26 10:40:30 -070067
68// Writes a maximum of |len| bytes from |p_data| to the serial port.
69// This function returns the number of bytes actually written, which may be
70// less than |len|. This function may block.
Myles Watson5ff20a22016-10-31 10:53:52 -070071uint16_t userial_write(uint16_t msg_id, const uint8_t* p_data, uint16_t len);