1 /** 2 * \file 3 * 4 * \brief USART related functionality declaration. 5 * 6 * Copyright (C) 2014 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 _HPL_SYNC_USART_H_INCLUDED 45 #define _HPL_SYNC_USART_H_INCLUDED 46 47 /** 48 * \addtogroup HPL USART SYNC 49 * 50 * \section hpl_usart_sync_rev Revision History 51 * - v1.0.0 Initial Release 52 * 53 *@{ 54 */ 55 56 #include <hpl_usart.h> 57 58 #ifdef __cplusplus 59 extern "C" { 60 #endif 61 62 /** 63 * \brief USART descriptor device structure 64 */ 65 struct _usart_sync_device { 66 void *hw; 67 }; 68 69 /** 70 * \name HPL functions 71 */ 72 //@{ 73 /** 74 * \brief Initialize synchronous USART 75 * 76 * This function does low level USART configuration. 77 * 78 * \param[in] device The pointer to USART device instance 79 * \param[in] hw The pointer to hardware instance 80 * 81 * \return Initialization status 82 */ 83 int32_t _usart_sync_init(struct _usart_sync_device *const device, void *const hw); 84 85 /** 86 * \brief Deinitialize USART 87 * 88 * This function closes the given USART by disabling its clock. 89 * 90 * \param[in] device The pointer to USART device instance 91 */ 92 void _usart_sync_deinit(struct _usart_sync_device *const device); 93 94 /** 95 * \brief Enable usart module 96 * 97 * This function will enable the usart module 98 * 99 * \param[in] device The pointer to USART device instance 100 */ 101 void _usart_sync_enable(struct _usart_sync_device *const device); 102 103 /** 104 * \brief Disable usart module 105 * 106 * This function will disable the usart module 107 * 108 * \param[in] device The pointer to USART device instance 109 */ 110 void _usart_sync_disable(struct _usart_sync_device *const device); 111 112 /** 113 * \brief Calculate baud rate register value 114 * 115 * \param[in] baud Required baud rate 116 * \param[in] clock_rate clock frequency 117 * \param[in] samples The number of samples 118 * \param[in] mode USART mode 119 * \param[in] fraction A fraction value 120 * 121 * \return Calculated baud rate register value 122 */ 123 uint16_t _usart_sync_calculate_baud_rate(const uint32_t baud, const uint32_t clock_rate, const uint8_t samples, 124 const enum usart_baud_rate_mode mode, const uint8_t fraction); 125 126 /** 127 * \brief Set baud rate 128 * 129 * \param[in] device The pointer to USART device instance 130 * \param[in] baud_rate A baud rate to set 131 */ 132 void _usart_sync_set_baud_rate(struct _usart_sync_device *const device, const uint32_t baud_rate); 133 134 /** 135 * \brief Set data order 136 * 137 * \param[in] device The pointer to USART device instance 138 * \param[in] order A data order to set 139 */ 140 void _usart_sync_set_data_order(struct _usart_sync_device *const device, const enum usart_data_order order); 141 142 /** 143 * \brief Set mode 144 * 145 * \param[in] device The pointer to USART device instance 146 * \param[in] mode A mode to set 147 */ 148 void _usart_sync_set_mode(struct _usart_sync_device *const device, const enum usart_mode mode); 149 150 /** 151 * \brief Set parity 152 * 153 * \param[in] device The pointer to USART device instance 154 * \param[in] parity A parity to set 155 */ 156 void _usart_sync_set_parity(struct _usart_sync_device *const device, const enum usart_parity parity); 157 158 /** 159 * \brief Set stop bits mode 160 * 161 * \param[in] device The pointer to USART device instance 162 * \param[in] stop_bits A stop bits mode to set 163 */ 164 void _usart_sync_set_stop_bits(struct _usart_sync_device *const device, const enum usart_stop_bits stop_bits); 165 166 /** 167 * \brief Set character size 168 * 169 * \param[in] device The pointer to USART device instance 170 * \param[in] size A character size to set 171 */ 172 void _usart_sync_set_character_size(struct _usart_sync_device *const device, const enum usart_character_size size); 173 174 /** 175 * \brief Retrieve usart status 176 * 177 * \param[in] device The pointer to USART device instance 178 */ 179 uint32_t _usart_sync_get_status(const struct _usart_sync_device *const device); 180 181 /** 182 * \brief Write a byte to the given USART instance 183 * 184 * \param[in] device The pointer to USART device instance 185 * \param[in] data Data to write 186 */ 187 void _usart_sync_write_byte(struct _usart_sync_device *const device, uint8_t data); 188 189 /** 190 * \brief Read a byte from the given USART instance 191 * 192 * \param[in] device The pointer to USART device instance 193 * \param[in] data Data to write 194 * 195 * \return Data received via USART interface. 196 */ 197 uint8_t _usart_sync_read_byte(const struct _usart_sync_device *const device); 198 199 /** 200 * \brief Check if USART is ready to send next byte 201 * 202 * \param[in] device The pointer to USART device instance 203 * 204 * \return Status of the ready check. 205 * \retval true if the USART is ready to send next byte 206 * \retval false if the USART is not ready to send next byte 207 */ 208 bool _usart_sync_is_byte_sent(const struct _usart_sync_device *const device); 209 210 /** 211 * \brief Check if there is data received by USART 212 * 213 * \param[in] device The pointer to USART device instance 214 * 215 * \return Status of the data received check. 216 * \retval true if the USART has received a byte 217 * \retval false if the USART has not received a byte 218 */ 219 bool _usart_sync_is_byte_received(const struct _usart_sync_device *const device); 220 221 /** 222 * \brief Set the state of flow control pins 223 * 224 * \param[in] device The pointer to USART device instance 225 * \param[in] state - A state of flow control pins to set 226 */ 227 void _usart_sync_set_flow_control_state(struct _usart_sync_device *const device, 228 const union usart_flow_control_state state); 229 230 /** 231 * \brief Retrieve the state of flow control pins 232 * 233 * This function retrieves the of flow control pins. 234 * 235 * \return USART_FLOW_CONTROL_STATE_UNAVAILABLE. 236 */ 237 union usart_flow_control_state _usart_sync_get_flow_control_state(const struct _usart_sync_device *const device); 238 239 /** 240 * \brief Retrieve ordinal number of the given USART hardware instance 241 * 242 * \param[in] device The pointer to USART device instance 243 * 244 * \return The ordinal number of the given USART hardware instance 245 */ 246 uint8_t _usart_sync_get_hardware_index(const struct _usart_sync_device *const device); 247 //@} 248 249 #ifdef __cplusplus 250 } 251 #endif 252 /**@}*/ 253 #endif /* _HPL_SYNC_USART_H_INCLUDED */ 254