]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libchip_samv7/include/usart_dma.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libchip_samv7 / include / usart_dma.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2009, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Implementation of USART driver, transfer data through DMA.\r
34  *\r
35  */\r
36 \r
37 #ifndef _USART_DMA_H_\r
38 #define _USART_DMA_H_\r
39 \r
40 /*----------------------------------------------------------------------------\r
41  *        Headers\r
42  *----------------------------------------------------------------------------*/\r
43 \r
44 #include "chip.h"\r
45 \r
46 /*----------------------------------------------------------------------------\r
47  *        Definitions\r
48  *----------------------------------------------------------------------------*/\r
49 \r
50 /** An unspecified error has occured.*/\r
51 #define USARTD_ERROR          1\r
52 \r
53 /** USART driver is currently in use.*/\r
54 #define USARTD_ERROR_LOCK     2\r
55 \r
56 \r
57 #ifdef __cplusplus\r
58  extern "C" {\r
59 #endif\r
60 \r
61 /*----------------------------------------------------------------------------\r
62  *        Types\r
63  *----------------------------------------------------------------------------*/\r
64 \r
65 /** USART transfer complete callback. */\r
66 typedef void (*UsartdCallback)( uint8_t, void* ) ;\r
67 \r
68 /** \brief usart Transfer Request prepared by the application upper layer.\r
69  *\r
70  * This structure is sent to the USART_Send or USART_Rcv to start the transfer.\r
71  * At the end of the transfer, the callback is invoked by the interrupt handler.\r
72  */\r
73 typedef struct\r
74 {\r
75     /** Pointer to the Buffer. */\r
76     uint8_t *pBuff;\r
77     /** Buff size in bytes. */\r
78     uint8_t BuffSize;\r
79     /** Dma channel num. */\r
80     uint8_t ChNum;\r
81     /** Callback function invoked at the end of transfer. */\r
82     UsartdCallback callback;\r
83     /** Callback arguments. */\r
84     void *pArgument;\r
85     /** flag to indicate the current transfer. */\r
86     volatile uint8_t Done;\r
87 } UsartChannel ;\r
88 \r
89 /** Constant structure associated with USART port. This structure prevents\r
90     client applications to have access in the same time. */\r
91 typedef struct \r
92 {\r
93     /** Pointer to USART Hardware registers */\r
94     Usart* pUsartHw ;\r
95     /** Current Usart Rx channel */\r
96     UsartChannel *pRxChannel ;\r
97     /** Current Usart Tx channel */\r
98     UsartChannel *pTxChannel ;\r
99     /** Pointer to DMA driver */\r
100     sXdmad* pXdmad;\r
101     /** USART Id as defined in the product datasheet */\r
102     uint8_t usartId ;\r
103 } UsartDma;\r
104 \r
105 /*----------------------------------------------------------------------------\r
106  *        Exported functions\r
107  *----------------------------------------------------------------------------*/\r
108 \r
109 extern uint32_t USARTD_Configure( UsartDma *pUsartd ,\r
110                                  Usart *pUsartHw ,\r
111                                  uint8_t USARTId,\r
112                                  uint32_t UsartMode,\r
113                                  uint32_t UsartClk,\r
114                                  sXdmad *pXdmad );\r
115 \r
116 extern uint32_t USARTD_EnableTxChannels( UsartDma *pUsartd, UsartChannel *pTxCh);\r
117 \r
118 extern uint32_t USARTD_EnableRxChannels( UsartDma *pUsartd, UsartChannel *pRxCh);\r
119 \r
120 extern uint32_t USARTD_SendData( UsartDma* pUsartd ) ;\r
121 \r
122 extern uint32_t USARTD_RcvData( UsartDma *pUsartd);\r
123 \r
124 #ifdef __cplusplus\r
125 }\r
126 #endif\r
127 \r
128 #endif /* #ifndef _USART_DMA_ */\r