10b966c5eSopenharmony_ci/******************************************************************************
20b966c5eSopenharmony_ci *
30b966c5eSopenharmony_ci *  Copyright 2009-2012 Broadcom Corporation
40b966c5eSopenharmony_ci *
50b966c5eSopenharmony_ci *  Licensed under the Apache License, Version 2.0 (the "License");
60b966c5eSopenharmony_ci *  you may not use this file except in compliance with the License.
70b966c5eSopenharmony_ci *  You may obtain a copy of the License at:
80b966c5eSopenharmony_ci *
90b966c5eSopenharmony_ci *  http://www.apache.org/licenses/LICENSE-2.0
100b966c5eSopenharmony_ci *
110b966c5eSopenharmony_ci *  Unless required by applicable law or agreed to in writing, software
120b966c5eSopenharmony_ci *  distributed under the License is distributed on an "AS IS" BASIS,
130b966c5eSopenharmony_ci *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140b966c5eSopenharmony_ci *  See the License for the specific language governing permissions and
150b966c5eSopenharmony_ci *  limitations under the License.
160b966c5eSopenharmony_ci *
170b966c5eSopenharmony_ci ******************************************************************************/
180b966c5eSopenharmony_ci
190b966c5eSopenharmony_ci// This module manages the serial port over which HCI commands
200b966c5eSopenharmony_ci// and data are sent/received.
210b966c5eSopenharmony_ci
220b966c5eSopenharmony_ci#ifndef BT_VENDOR_USERIAL_H
230b966c5eSopenharmony_ci#define BT_VENDOR_USERIAL_H
240b966c5eSopenharmony_ci
250b966c5eSopenharmony_ci#include <stdbool.h>
260b966c5eSopenharmony_ci#include <stdint.h>
270b966c5eSopenharmony_ci
280b966c5eSopenharmony_citypedef enum {
290b966c5eSopenharmony_ci    USERIAL_PORT_1,
300b966c5eSopenharmony_ci    USERIAL_PORT_2,
310b966c5eSopenharmony_ci    USERIAL_PORT_3,
320b966c5eSopenharmony_ci    USERIAL_PORT_4,
330b966c5eSopenharmony_ci    USERIAL_PORT_5,
340b966c5eSopenharmony_ci    USERIAL_PORT_6,
350b966c5eSopenharmony_ci    USERIAL_PORT_7,
360b966c5eSopenharmony_ci    USERIAL_PORT_8,
370b966c5eSopenharmony_ci    USERIAL_PORT_9,
380b966c5eSopenharmony_ci    USERIAL_PORT_10,
390b966c5eSopenharmony_ci    USERIAL_PORT_11,
400b966c5eSopenharmony_ci    USERIAL_PORT_12,
410b966c5eSopenharmony_ci    USERIAL_PORT_13,
420b966c5eSopenharmony_ci    USERIAL_PORT_14,
430b966c5eSopenharmony_ci    USERIAL_PORT_15,
440b966c5eSopenharmony_ci    USERIAL_PORT_16,
450b966c5eSopenharmony_ci    USERIAL_PORT_17,
460b966c5eSopenharmony_ci    USERIAL_PORT_18,
470b966c5eSopenharmony_ci} userial_port_t;
480b966c5eSopenharmony_ci
490b966c5eSopenharmony_ci// Initializes the userial module. This function should only be called once.
500b966c5eSopenharmony_ci// It returns true if the module was initialized, false if there was an error.
510b966c5eSopenharmony_cibool userial_init(void);
520b966c5eSopenharmony_ci
530b966c5eSopenharmony_ci// Opens the given serial port. Returns true if successful, false otherwise.
540b966c5eSopenharmony_ci// Once this function is called, the userial module will begin producing
550b966c5eSopenharmony_ci// buffers from data read off the serial port. If you wish to pause the
560b966c5eSopenharmony_ci// production of buffers, call |userial_pause_reading|. You can then resume
570b966c5eSopenharmony_ci// by calling |userial_resume_reading|. This function returns true if the
580b966c5eSopenharmony_ci// serial port was successfully opened and buffer production has started. It
590b966c5eSopenharmony_ci// returns false if there was an error.
600b966c5eSopenharmony_cibool userial_open(userial_port_t port);
610b966c5eSopenharmony_civoid userial_close(void);
620b966c5eSopenharmony_civoid userial_close_reader(void);
630b966c5eSopenharmony_ci
640b966c5eSopenharmony_ci// Reads a maximum of |len| bytes from the serial port into |p_buffer|.
650b966c5eSopenharmony_ci// This function returns the number of bytes actually read, which may be
660b966c5eSopenharmony_ci// less than |len|. This function will not block.
670b966c5eSopenharmony_ciuint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len);
680b966c5eSopenharmony_ci
690b966c5eSopenharmony_ci// Writes a maximum of |len| bytes from |p_data| to the serial port.
700b966c5eSopenharmony_ci// This function returns the number of bytes actually written, which may be
710b966c5eSopenharmony_ci// less than |len|. This function may block.
720b966c5eSopenharmony_ciuint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len);
730b966c5eSopenharmony_ci#endif