blob: 86984f6f8667033fcdededbb97585b1c84167ce4 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 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
Sharvil Nanavatid9fd65e2014-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 Nanavatibbe0c302014-04-26 00:58:15 -070022#pragma once
The Android Open Source Project5738f832012-12-12 16:00:35 -080023
Sharvil Nanavatibbe0c302014-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 Nanavatibbe0c302014-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
Sharvil Nanavatid9fd65e2014-04-26 10:40:30 -070048// Initializes the userial module. This function should only ever be called once.
49// It returns true if the module could be initialized, false if there was an error.
Sharvil Nanavatibbe0c302014-04-26 00:58:15 -070050bool userial_init(void);
The Android Open Source Project5738f832012-12-12 16:00:35 -080051
Sharvil Nanavatid9fd65e2014-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 Nanavatibbe0c302014-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);
61
Sharvil Nanavatid9fd65e2014-04-26 10:40:30 -070062// Reads a maximum of |len| bytes from the serial port into |p_buffer|.
63// This function returns the number of bytes actually read, which may be
64// less than |len|. This function will not block.
65uint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len);
66
67// Writes a maximum of |len| bytes from |p_data| to the serial port.
68// This function returns the number of bytes actually written, which may be
69// less than |len|. This function may block.
70uint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len);
71
72// Pauses reading data from the serial port. No new buffers will be produced
73// until |userial_resume_reading| is called. This function is idempotent.
74void userial_pause_reading(void);
75
76// Resumes reading data from the serial port if reads were previously paused.
77// This function is idempotent.
78void userial_resume_reading(void);