1 /** 2 * \file 3 * 4 * \brief USART related functionality declaration. 5 * 6 * Copyright (c) 2016-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 _HPL_USART_DMA_H_INCLUDED 35 #define _HPL_USART_DMA_H_INCLUDED 36 37 /** 38 * \addtogroup HPL USART 39 * 40 * \section hpl_usart_rev Revision History 41 * - v1.0.0 Initial Release 42 * 43 *@{ 44 */ 45 46 #include "hpl_usart.h" 47 #include "hpl_irq.h" 48 #include <hpl_dma.h> 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 /** 55 * \brief USART callback types 56 */ 57 enum usart_dma_callback_type { USART_DMA_RX_DONE, USART_DMA_TX_DONE, USART_DMA_ERROR }; 58 59 /** 60 * \brief USART device structure 61 * 62 * The USART device structure forward declaration. 63 */ 64 struct _usart_dma_device; 65 66 /** 67 * \brief The prototype for callback on USART DMA. 68 */ 69 typedef void (*usart_dma_cb_t)(struct _dma_resource *resource); 70 71 /** 72 * \brief USART interrupt callbacks 73 */ 74 struct _usart_dma_callbacks { 75 usart_dma_cb_t tx_done_cb; 76 usart_dma_cb_t rx_done_cb; 77 usart_dma_cb_t error_cb; 78 }; 79 80 /** 81 * \brief USART descriptor device structure 82 */ 83 struct _usart_dma_device { 84 struct _usart_dma_callbacks usart_cb; 85 void * hw; 86 struct _dma_resource * resource; 87 }; 88 /** 89 * \name HPL functions 90 */ 91 //@{ 92 /** 93 * \brief Initialize dmahronous USART 94 * 95 * This function does low level USART configuration. 96 * 97 * \param[in] device The pointer to USART device instance 98 * \param[in] hw The pointer to hardware instance 99 * 100 * \return Initialization status 101 */ 102 int32_t _usart_dma_init(struct _usart_dma_device *const device, void *const hw); 103 104 /** 105 * \brief Deinitialize USART 106 * 107 * This function closes the given USART by disabling its clock. 108 * 109 * \param[in] device The pointer to USART device instance 110 */ 111 void _usart_dma_deinit(struct _usart_dma_device *const device); 112 113 /** 114 * \brief Enable usart module 115 * 116 * This function will enable the usart module 117 * 118 * \param[in] device The pointer to USART device instance 119 */ 120 void _usart_dma_enable(struct _usart_dma_device *const device); 121 122 /** 123 * \brief Disable usart module 124 * 125 * This function will disable the usart module 126 * 127 * \param[in] device The pointer to USART device instance 128 */ 129 void _usart_dma_disable(struct _usart_dma_device *const device); 130 131 /** 132 * \brief Calculate baud rate register value 133 * 134 * \param[in] baud Required baud rate 135 * \param[in] clock_rate clock frequency 136 * \param[in] samples The number of samples 137 * \param[in] mode USART mode 138 * \param[in] fraction A fraction value 139 * 140 * \return Calculated baud rate register value 141 */ 142 uint16_t _usart_dma_calculate_baud_rate(const uint32_t baud, const uint32_t clock_rate, const uint8_t samples, 143 const enum usart_baud_rate_mode mode, const uint8_t fraction); 144 145 /** 146 * \brief Set baud rate 147 * 148 * \param[in] device The pointer to USART device instance 149 * \param[in] baud_rate A baud rate to set 150 */ 151 void _usart_dma_set_baud_rate(struct _usart_dma_device *const device, const uint32_t baud_rate); 152 153 /** 154 * \brief Set data order 155 * 156 * \param[in] device The pointer to USART device instance 157 * \param[in] order A data order to set 158 */ 159 void _usart_dma_set_data_order(struct _usart_dma_device *const device, const enum usart_data_order order); 160 161 /** 162 * \brief Set mode 163 * 164 * \param[in] device The pointer to USART device instance 165 * \param[in] mode A mode to set 166 */ 167 void _usart_dma_set_mode(struct _usart_dma_device *const device, const enum usart_mode mode); 168 169 /** 170 * \brief Set parity 171 * 172 * \param[in] device The pointer to USART device instance 173 * \param[in] parity A parity to set 174 */ 175 void _usart_dma_set_parity(struct _usart_dma_device *const device, const enum usart_parity parity); 176 177 /** 178 * \brief Set stop bits mode 179 * 180 * \param[in] device The pointer to USART device instance 181 * \param[in] stop_bits A stop bits mode to set 182 */ 183 void _usart_dma_set_stop_bits(struct _usart_dma_device *const device, const enum usart_stop_bits stop_bits); 184 185 /** 186 * \brief Set character size 187 * 188 * \param[in] device The pointer to USART device instance 189 * \param[in] size A character size to set 190 */ 191 void _usart_dma_set_character_size(struct _usart_dma_device *const device, const enum usart_character_size size); 192 193 /** 194 * \brief Set the state of flow control pins 195 * 196 * \param[in] device The pointer to USART device instance 197 * \param[in] state - A state of flow control pins to set 198 */ 199 void _usart_dma_set_flow_control_state(struct _usart_dma_device *const device, 200 const union usart_flow_control_state state); 201 202 /** 203 * \brief Eanble dma write 204 * 205 * \param[in] device The pointer to USART device instance 206 * \param[in] txbuf Pointer to the transfer information 207 * \param[in] length spi transfer data length 208 * 209 * \return Operation status 210 * \retval ERR_NONE Success 211 * \retval ERR_INVALID_DATA Invalid data 212 */ 213 int32_t _usart_dma_write(struct _usart_dma_device *const device, uint8_t const *txbuf, const uint16_t length); 214 215 /** 216 * \brief Eanble dma read 217 * 218 * \param[in] device The pointer to USART device instance 219 * \param[out] rxbuf Pointer to the receiver information 220 * \param[in] length spi receiver data length 221 * 222 * \return Operation status 223 * \retval ERR_NONE Success 224 * \retval ERR_INVALID_DATA Invalid data 225 */ 226 int32_t _usart_dma_read(struct _usart_dma_device *const device, uint8_t *const rxbuf, const uint16_t length); 227 228 /** 229 * \brief Enable/disable USART interrupt 230 * 231 * param[in] device The pointer to USART device instance 232 * param[in] type The type of interrupt to disable/enable if applicable 233 * param[in] state Enable or disable 234 */ 235 void _usart_dma_register_callback(struct _usart_dma_device *const device, const enum usart_dma_callback_type type, 236 usart_dma_cb_t cb); 237 //@} 238 239 #ifdef __cplusplus 240 } 241 #endif 242 /**@}*/ 243 #endif /* _HPL_USART_DMA_H_INCLUDED */ 244