| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** | 
 | 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 Nanavati | d9fd65e | 2014-04-26 10:40:30 -0700 | [diff] [blame] | 19 | // This module manages the serial port over which HCI commands | 
 | 20 | // and data are sent/received. | 
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 21 |  | 
| Sharvil Nanavati | bbe0c30 | 2014-04-26 00:58:15 -0700 | [diff] [blame] | 22 | #pragma once | 
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 23 |  | 
| Sharvil Nanavati | bbe0c30 | 2014-04-26 00:58:15 -0700 | [diff] [blame] | 24 | #include <stdbool.h> | 
 | 25 | #include <stdint.h> | 
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 |  | 
 | 27 | typedef enum { | 
| Sharvil Nanavati | bbe0c30 | 2014-04-26 00:58:15 -0700 | [diff] [blame] | 28 |   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 Nanavati | d9fd65e | 2014-04-26 10:40:30 -0700 | [diff] [blame] | 48 | // 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 Nanavati | bbe0c30 | 2014-04-26 00:58:15 -0700 | [diff] [blame] | 50 | bool userial_init(void); | 
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 51 |  | 
| Sharvil Nanavati | d9fd65e | 2014-04-26 10:40:30 -0700 | [diff] [blame] | 52 | // 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 Nanavati | bbe0c30 | 2014-04-26 00:58:15 -0700 | [diff] [blame] | 59 | bool userial_open(userial_port_t port); | 
| The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 60 | void userial_close(void); | 
 | 61 |  | 
| Sharvil Nanavati | d9fd65e | 2014-04-26 10:40:30 -0700 | [diff] [blame] | 62 | // 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. | 
 | 65 | uint16_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. | 
 | 70 | uint16_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. | 
 | 74 | void userial_pause_reading(void); | 
 | 75 |  | 
 | 76 | // Resumes reading data from the serial port if reads were previously paused. | 
 | 77 | // This function is idempotent. | 
 | 78 | void userial_resume_reading(void); |