]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libchip_samv7/include/dac_dma.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libchip_samv7 / include / dac_dma.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2014, 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  *  \file\r
31  *\r
32  *  \section Purpose\r
33  *\r
34  *  Interface for configuration the Analog-to-Digital Converter (DACC) peripheral.\r
35  *\r
36  *  \section Usage\r
37  *\r
38  *  -# Configurate the pins for DACC\r
39  *  -# Initialize the DACC with DACC_Initialize().\r
40  *  -# Select the active channel using DACC_EnableChannel()\r
41  *  -# Start the conversion with DACC_StartConversion()\r
42  *  -# Wait the end of the conversion by polling status with DACC_GetStatus()\r
43  *  -# Finally, get the converted data using DACC_GetConvertedData()\r
44  *\r
45 */\r
46 #ifndef _DAC_DMA_\r
47 #define _DAC_DMA_\r
48 \r
49 /*----------------------------------------------------------------------------\r
50  *        Headers\r
51  *----------------------------------------------------------------------------*/\r
52 #include "chip.h"\r
53 \r
54 #include <stdint.h>\r
55 #include <assert.h>\r
56 \r
57 \r
58 #ifdef __cplusplus\r
59  extern "C" {\r
60 #endif\r
61 \r
62 \r
63 /*----------------------------------------------------------------------------\r
64  *        Types\r
65  *----------------------------------------------------------------------------*/\r
66 \r
67 /** DAC transfer complete callback. */\r
68 typedef void (*DacCallback)( uint8_t, void* ) ;\r
69 \r
70 /** \brief Dac Transfer Request prepared by the application upper layer.\r
71  *\r
72  * This structure is sent to the DAC_SendCommand function to start the transfer.\r
73  * At the end of the transfer, the callback is invoked by the interrupt handler.\r
74  */\r
75 typedef struct\r
76 {\r
77     /** Pointer to the Tx data. */\r
78     uint8_t *pTxBuff;\r
79     /** Tx size in bytes. */\r
80     uint16_t TxSize;\r
81     /** Tx loop back. */\r
82     uint16_t loopback;\r
83     /** DACC channel*/\r
84     uint8_t dacChannel; \r
85     /** Callback function invoked at the end of transfer. */\r
86     DacCallback callback;\r
87     /** Callback arguments. */\r
88     void *pArgument;\r
89 } DacCmd ;\r
90 \r
91 \r
92 /** Constant structure associated with DAC port. This structure prevents\r
93     client applications to have access in the same time. */\r
94 typedef struct \r
95 {\r
96     /** Pointer to DAC Hardware registers */\r
97     Dacc* pDacHw ;\r
98     /** Current SpiCommand being processed */\r
99     DacCmd *pCurrentCommand ;\r
100     /** Pointer to DMA driver */\r
101     sXdmad* pXdmad ;\r
102     /** DACC Id as defined in the product datasheet */\r
103     uint8_t dacId ;\r
104     /** Mutual exclusion semaphore. */\r
105     volatile int8_t semaphore ;\r
106 } DacDma;\r
107 \r
108 \r
109 /*------------------------------------------------------------------------------\r
110  *         Definitions\r
111  *------------------------------------------------------------------------------*/\r
112 #define DAC_OK          0\r
113 #define DAC_ERROR       1\r
114 #define DAC_ERROR_LOCK  2\r
115 \r
116 #define DACC_CHANNEL_0 0\r
117 #define DACC_CHANNEL_1 1\r
118 \r
119 /*------------------------------------------------------------------------------\r
120  *         Exported functions\r
121  *------------------------------------------------------------------------------*/\r
122 extern uint32_t Dac_ConfigureDma( DacDma *pDacd ,\r
123                            Dacc *pDacHw ,\r
124                            uint8_t DacId,\r
125                            sXdmad *pXdmad );\r
126 extern uint32_t Dac_SendData( DacDma *pDacd, DacCmd *pCommand);\r
127 \r
128 \r
129 /*------------------------------------------------------------------------------\r
130  *         Macros function of register access\r
131  *------------------------------------------------------------------------------*/\r
132 #define DACC_SoftReset(pDACC)                 ((pDACC)->DACC_CR = DACC_CR_SWRST)\r
133 #define DACC_CfgModeReg(pDACC, mode)          { (pDACC)->DACC_MR = (mode); }\r
134 #define DACC_GetModeReg(pDACC)                ((pDACC)->DACC_MR)\r
135 #define DACC_CfgTrigger(pDACC, mode)          { (pDACC)->DACC_TRIGR = (mode); }\r
136 \r
137 #define DACC_EnableChannel(pDACC, channel)    {(pDACC)->DACC_CHER = (1 << (channel));}\r
138 #define DACC_DisableChannel(pDACC, channel)   {(pDACC)->DACC_CHDR = (1 << (channel));}\r
139 \r
140 #define DACC_EnableIt(pDACC, mode)            {(pDACC)->DACC_IER = (mode);}\r
141 #define DACC_DisableIt(pDACC, mode)           {(pDACC)->DACC_IDR = (mode);}\r
142 #define DACC_GetStatus(pDACC)                 ((pDACC)->DACC_ISR)\r
143 #define DACC_GetChannelStatus(pDACC)          ((pDACC)->DACC_CHSR)\r
144 #define DACC_GetInterruptMaskStatus(pDACC)    ((pDACC)->DACC_IMR)\r
145 \r
146 \r
147 #ifdef __cplusplus\r
148 }\r
149 #endif\r
150 \r
151 #endif /* #ifndef _DAC_DMA_ */\r