blob: f50401d7a6b3910931c7118ec0d979baef11c8df [file] [log] [blame]
Kévin Redon69b92d92019-01-24 16:39:20 +01001/**
2 * \file
3 *
4 * \brief I/O related functionality declaration.
5 *
6 * Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
7 *
8 * \asf_license_start
9 *
10 * \page License
11 *
12 * Subject to your compliance with these terms, you may use Microchip
13 * software and any derivatives exclusively with Microchip products.
14 * It is your responsibility to comply with third party license terms applicable
15 * to your use of third party software (including open source software) that
16 * may accompany Microchip software.
17 *
18 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
26 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29 *
30 * \asf_license_stop
31 *
32 */
33
34#ifndef _HAL_IO_INCLUDED
35#define _HAL_IO_INCLUDED
36
37/**
38 * \addtogroup doc_driver_hal_helper_io I/O Driver
39 *
40 *@{
41 */
42
43#include <compiler.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * \brief I/O descriptor
51 *
52 * The I/O descriptor forward declaration.
53 */
54struct io_descriptor;
55
56/**
57 * \brief I/O write function pointer type
58 */
59typedef int32_t (*io_write_t)(struct io_descriptor *const io_descr, const uint8_t *const buf, const uint16_t length);
60
61/**
62 * \brief I/O read function pointer type
63 */
64typedef int32_t (*io_read_t)(struct io_descriptor *const io_descr, uint8_t *const buf, const uint16_t length);
65
66/**
67 * \brief I/O descriptor
68 */
69struct io_descriptor {
70 io_write_t write; /*! The write function pointer. */
71 io_read_t read; /*! The read function pointer. */
72};
73
74/**
75 * \brief I/O write interface
76 *
77 * This function writes up to \p length of bytes to a given I/O descriptor.
78 * It returns the number of bytes actually write.
79 *
80 * \param[in] descr An I/O descriptor to write
81 * \param[in] buf The buffer pointer to story the write data
82 * \param[in] length The number of bytes to write
83 *
84 * \return The number of bytes written
85 */
86int32_t io_write(struct io_descriptor *const io_descr, const uint8_t *const buf, const uint16_t length);
87
88/**
89 * \brief I/O read interface
90 *
91 * This function reads up to \p length bytes from a given I/O descriptor, and
92 * stores it in the buffer pointed to by \p buf. It returns the number of bytes
93 * actually read.
94 *
95 * \param[in] descr An I/O descriptor to read
96 * \param[in] buf The buffer pointer to story the read data
97 * \param[in] length The number of bytes to read
98 *
99 * \return The number of bytes actually read. This number can be less than the
100 * requested length. E.g., in a driver that uses ring buffer for
101 * reception, it may depend on the availability of data in the
102 * ring buffer.
103 */
104int32_t io_read(struct io_descriptor *const io_descr, uint8_t *const buf, const uint16_t length);
105
106#ifdef __cplusplus
107}
108#endif
109/**@}*/
110#endif /* _HAL_IO_INCLUDED */