1 /** 2 * \file 3 * 4 * \brief I/O related functionality declaration. 5 * 6 * Copyright (C) 2014 - 2016 Atmel Corporation. All rights reserved. 7 * 8 * \asf_license_start 9 * 10 * \page License 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions are met: 14 * 15 * 1. Redistributions of source code must retain the above copyright notice, 16 * this list of conditions and the following disclaimer. 17 * 18 * 2. Redistributions in binary form must reproduce the above copyright notice, 19 * this list of conditions and the following disclaimer in the documentation 20 * and/or other materials provided with the distribution. 21 * 22 * 3. The name of Atmel may not be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * 4. This software may only be redistributed and used in connection with an 26 * Atmel microcontroller product. 27 * 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 * 40 * \asf_license_stop 41 * 42 */ 43 44 #ifndef _HAL_IO_INCLUDED 45 #define _HAL_IO_INCLUDED 46 47 /** 48 * \addtogroup doc_driver_hal_helper_io I/O Driver 49 * 50 *@{ 51 */ 52 53 #include <compiler.h> 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 /** 60 * \brief I/O descriptor 61 * 62 * The I/O descriptor forward declaration. 63 */ 64 struct io_descriptor; 65 66 /** 67 * \brief I/O write function pointer type 68 */ 69 typedef int32_t (*io_write_t)(struct io_descriptor *const io_descr, const uint8_t *const buf, const uint16_t length); 70 71 /** 72 * \brief I/O read function pointer type 73 */ 74 typedef int32_t (*io_read_t)(struct io_descriptor *const io_descr, uint8_t *const buf, const uint16_t length); 75 76 /** 77 * \brief I/O descriptor 78 */ 79 struct io_descriptor { 80 io_write_t write; /*! The write function pointer. */ 81 io_read_t read; /*! The read function pointer. */ 82 }; 83 84 /** 85 * \brief I/O write interface 86 * 87 * This function writes up to \p length of bytes to a given I/O descriptor. 88 * It returns the number of bytes actually write. 89 * 90 * \param[in] descr An I/O descriptor to write 91 * \param[in] buf The buffer pointer to story the write data 92 * \param[in] length The number of bytes to write 93 * 94 * \return The number of bytes written 95 */ 96 int32_t io_write(struct io_descriptor *const io_descr, const uint8_t *const buf, const uint16_t length); 97 98 /** 99 * \brief I/O read interface 100 * 101 * This function reads up to \p length bytes from a given I/O descriptor, and 102 * stores it in the buffer pointed to by \p buf. It returns the number of bytes 103 * actually read. 104 * 105 * \param[in] descr An I/O descriptor to read 106 * \param[in] buf The buffer pointer to story the read data 107 * \param[in] length The number of bytes to read 108 * 109 * \return The number of bytes actually read. This number can be less than the 110 * requested length. E.g., in a driver that uses ring buffer for 111 * reception, it may depend on the availability of data in the 112 * ring buffer. 113 */ 114 int32_t io_read(struct io_descriptor *const io_descr, uint8_t *const buf, const uint16_t length); 115 116 #ifdef __cplusplus 117 } 118 #endif 119 /**@}*/ 120 #endif /* _HAL_IO_INCLUDED */ 121