Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief USART 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_SYNC_USART_H_INCLUDED |
| 35 | #define _HAL_SYNC_USART_H_INCLUDED |
| 36 | |
| 37 | #include "hal_io.h" |
| 38 | #include <hpl_usart_sync.h> |
| 39 | |
| 40 | /** |
| 41 | * \addtogroup doc_driver_hal_usart_sync |
| 42 | * |
| 43 | * @{ |
| 44 | */ |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
| 50 | /** |
| 51 | * \brief Synchronous USART descriptor |
| 52 | */ |
| 53 | struct usart_sync_descriptor { |
| 54 | struct io_descriptor io; |
| 55 | struct _usart_sync_device device; |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * \brief Initialize USART interface |
| 60 | * |
| 61 | * This function initializes the given I/O descriptor to be used |
| 62 | * as USART interface descriptor. |
| 63 | * It checks if the given hardware is not initialized and |
| 64 | * if the given hardware is permitted to be initialized. |
| 65 | * |
| 66 | * \param[out] descr A USART descriptor which is used to communicate via USART |
| 67 | * \param[in] hw The pointer to hardware instance |
| 68 | * \param[in] func The pointer to as set of functions pointers |
| 69 | * |
| 70 | * \return Initialization status. |
| 71 | */ |
| 72 | int32_t usart_sync_init(struct usart_sync_descriptor *const descr, void *const hw, void *const func); |
| 73 | |
| 74 | /** |
| 75 | * \brief Deinitialize USART interface |
| 76 | * |
| 77 | * This function deinitializes the given I/O descriptor. |
| 78 | * It checks if the given hardware is initialized and |
| 79 | * if the given hardware is permitted to be deinitialized. |
| 80 | * |
| 81 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 82 | * |
| 83 | * \return De-initialization status. |
| 84 | */ |
| 85 | int32_t usart_sync_deinit(struct usart_sync_descriptor *const descr); |
| 86 | |
| 87 | /** |
| 88 | * \brief Enable USART interface |
| 89 | * |
| 90 | * Enables the USART interface |
| 91 | * |
| 92 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 93 | * |
| 94 | * \return Enabling status. |
| 95 | */ |
| 96 | int32_t usart_sync_enable(struct usart_sync_descriptor *const descr); |
| 97 | |
| 98 | /** |
| 99 | * \brief Disable USART interface |
| 100 | * |
| 101 | * Disables the USART interface |
| 102 | * |
| 103 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 104 | * |
| 105 | * \return Disabling status. |
| 106 | */ |
| 107 | int32_t usart_sync_disable(struct usart_sync_descriptor *const descr); |
| 108 | |
| 109 | /** |
| 110 | * \brief Retrieve I/O descriptor |
| 111 | * |
| 112 | * This function retrieves the I/O descriptor of the given USART descriptor. |
| 113 | * |
| 114 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 115 | * \param[out] io An I/O descriptor to retrieve |
| 116 | * |
| 117 | * \return The status of the I/O descriptor retrieving. |
| 118 | */ |
| 119 | int32_t usart_sync_get_io_descriptor(struct usart_sync_descriptor *const descr, struct io_descriptor **io); |
| 120 | |
| 121 | /** |
| 122 | * \brief Specify action for flow control pins |
| 123 | * |
| 124 | * This function sets the action (or state) for the flow control pins |
| 125 | * if the flow control is enabled. |
| 126 | * It sets the state of flow control pins only if the automatic support of |
| 127 | * the flow control is not supported by the hardware. |
| 128 | * |
| 129 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 130 | * \param[in] state A state to set the flow control pins |
| 131 | * |
| 132 | * \return The status of flow control action setup. |
| 133 | */ |
| 134 | int32_t usart_sync_set_flow_control(struct usart_sync_descriptor *const descr, |
| 135 | const union usart_flow_control_state state); |
| 136 | |
| 137 | /** |
| 138 | * \brief Set USART baud rate |
| 139 | * |
| 140 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 141 | * \param[in] baud_rate A baud rate to set |
| 142 | * |
| 143 | * \return The status of baud rate setting. |
| 144 | */ |
| 145 | int32_t usart_sync_set_baud_rate(struct usart_sync_descriptor *const descr, const uint32_t baud_rate); |
| 146 | |
| 147 | /** |
| 148 | * \brief Set USART data order |
| 149 | * |
| 150 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 151 | * \param[in] data_order A data order to set |
| 152 | * |
| 153 | * \return The status of data order setting. |
| 154 | */ |
| 155 | int32_t usart_sync_set_data_order(struct usart_sync_descriptor *const descr, const enum usart_data_order data_order); |
| 156 | |
| 157 | /** |
| 158 | * \brief Set USART mode |
| 159 | * |
| 160 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 161 | * \param[in] mode A mode to set |
| 162 | * |
| 163 | * \return The status of mode setting. |
| 164 | */ |
| 165 | int32_t usart_sync_set_mode(struct usart_sync_descriptor *const descr, const enum usart_mode mode); |
| 166 | |
| 167 | /** |
| 168 | * \brief Set USART parity |
| 169 | * |
| 170 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 171 | * \param[in] parity A parity to set |
| 172 | * |
| 173 | * \return The status of parity setting. |
| 174 | */ |
| 175 | int32_t usart_sync_set_parity(struct usart_sync_descriptor *const descr, const enum usart_parity parity); |
| 176 | |
| 177 | /** |
| 178 | * \brief Set USART stop bits |
| 179 | * |
| 180 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 181 | * \param[in] stop_bits Stop bits to set |
| 182 | * |
| 183 | * \return The status of stop bits setting. |
| 184 | */ |
| 185 | int32_t usart_sync_set_stopbits(struct usart_sync_descriptor *const descr, const enum usart_stop_bits stop_bits); |
| 186 | |
| 187 | /** |
| 188 | * \brief Set USART character size |
| 189 | * |
| 190 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 191 | * \param[in] size A character size to set |
| 192 | * |
| 193 | * \return The status of character size setting. |
| 194 | */ |
| 195 | int32_t usart_sync_set_character_size(struct usart_sync_descriptor *const descr, const enum usart_character_size size); |
| 196 | |
| 197 | /** |
| 198 | * \brief Retrieve the state of flow control pins |
| 199 | * |
| 200 | * This function retrieves the of flow control pins |
| 201 | * if the flow control is enabled. |
| 202 | * Function can return USART_FLOW_CONTROL_STATE_UNAVAILABLE in case |
| 203 | * if the flow control is done by the hardware |
| 204 | * and the pins state cannot be read out. |
| 205 | * |
| 206 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 207 | * \param[out] state The state of flow control pins |
| 208 | * |
| 209 | * \return The status of flow control state reading. |
| 210 | */ |
| 211 | int32_t usart_sync_flow_control_status(const struct usart_sync_descriptor *const descr, |
| 212 | union usart_flow_control_state *const state); |
| 213 | |
| 214 | /** |
| 215 | * \brief Check if the USART transmitter is empty |
| 216 | * |
| 217 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 218 | * |
| 219 | * \return The status of USART TX empty checking. |
| 220 | * \retval 0 The USART transmitter is not empty |
| 221 | * \retval 1 The USART transmitter is empty |
| 222 | */ |
| 223 | int32_t usart_sync_is_tx_empty(const struct usart_sync_descriptor *const descr); |
| 224 | |
| 225 | /** |
| 226 | * \brief Check if the USART receiver is not empty |
| 227 | * |
| 228 | * \param[in] descr A USART descriptor which is used to communicate via USART |
| 229 | * |
| 230 | * \return The status of USART RX empty checking. |
| 231 | * \retval 1 The USART receiver is not empty |
| 232 | * \retval 0 The USART receiver is empty |
| 233 | */ |
| 234 | int32_t usart_sync_is_rx_not_empty(const struct usart_sync_descriptor *const descr); |
| 235 | |
| 236 | /** |
| 237 | * \brief Retrieve the current driver version |
| 238 | * |
| 239 | * \return Current driver version. |
| 240 | */ |
| 241 | uint32_t usart_sync_get_version(void); |
| 242 | |
| 243 | #ifdef __cplusplus |
| 244 | } |
| 245 | #endif |
| 246 | /**@}*/ |
| 247 | #endif /* _HAL_SYNC_USART_H_INCLUDED */ |