Home | History | Annotate | Download | only in include
      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 
     19 // This module manages the serial port over which HCI commands
     20 // and data are sent/received.
     21 
     22 #pragma once
     23 
     24 #include <stdbool.h>
     25 #include <stdint.h>
     26 
     27 typedef enum {
     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 
     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.
     50 bool userial_init(void);
     51 
     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.
     59 bool userial_open(userial_port_t port);
     60 void userial_close(void);
     61 void userial_close_reader(void);
     62 
     63 // 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.
     66 uint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len);
     67 
     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.
     71 uint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len);
     72