1 /***************************************************************************//**
2  * @file
3  * @brief DMADRV API definition.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef __SILICON_LABS_DMADRV_H__
32 #define __SILICON_LABS_DMADRV_H__
33 
34 #include "em_device.h"
35 
36 #include "ecode.h"
37 
38 #include "dmadrv_signals.h"
39 
40 #if defined(LDMA_PRESENT) && (LDMA_COUNT == 1)
41 #if (_SILICON_LABS_32B_SERIES > 2)
42 #define EMDRV_DMADRV_LDMA_S3
43 #else
44 #define EMDRV_DMADRV_DMA_PRESENT
45 #define EMDRV_DMADRV_LDMA
46 #endif
47 #else
48 #error "No valid DMA engine defined."
49 #endif
50 
51 #include "dmadrv_config.h"
52 #include "sl_code_classification.h"
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /***************************************************************************//**
59  * @addtogroup dmadrv
60  * @{
61  ******************************************************************************/
62 
63 /***************************************************************************//**
64  * @addtogroup dmadrv_error_codes Error Codes
65  * @{
66  ******************************************************************************/
67 
68 #define ECODE_EMDRV_DMADRV_OK                  (ECODE_OK)                               ///< A successful return value.
69 #define ECODE_EMDRV_DMADRV_PARAM_ERROR         (ECODE_EMDRV_DMADRV_BASE | 0x00000001)   ///< An illegal input parameter.
70 #define ECODE_EMDRV_DMADRV_NOT_INITIALIZED     (ECODE_EMDRV_DMADRV_BASE | 0x00000002)   ///< DMA is not initialized.
71 #define ECODE_EMDRV_DMADRV_ALREADY_INITIALIZED (ECODE_EMDRV_DMADRV_BASE | 0x00000003)   ///< DMA has already been initialized.
72 #define ECODE_EMDRV_DMADRV_CHANNELS_EXHAUSTED  (ECODE_EMDRV_DMADRV_BASE | 0x00000004)   ///< No DMA channels available.
73 #define ECODE_EMDRV_DMADRV_IN_USE              (ECODE_EMDRV_DMADRV_BASE | 0x00000005)   ///< DMA is in use.
74 #define ECODE_EMDRV_DMADRV_ALREADY_FREED       (ECODE_EMDRV_DMADRV_BASE | 0x00000006)   ///< A DMA channel was free.
75 #define ECODE_EMDRV_DMADRV_CH_NOT_ALLOCATED    (ECODE_EMDRV_DMADRV_BASE | 0x00000007)   ///< A channel is not reserved.
76 
77 /** @} (end addtogroup error codes) */
78 /***************************************************************************//**
79  * @brief
80  *  DMADRV transfer completion callback function.
81  *
82  * @details
83  *  The callback function is called when a transfer is complete.
84  *
85  * @param[in] channel
86  *  The DMA channel number.
87  *
88  * @param[in] sequenceNo
89  *  The number of times the callback was called. Useful on long chains of
90  *  linked transfers or on endless ping-pong type transfers.
91  *
92  * @param[in] userParam
93  *  Optional user parameter supplied on DMA invocation.
94  *
95  * @return
96  *   When doing ping-pong transfers, return true to continue or false to
97  *   stop transfers.
98  ******************************************************************************/
99 typedef bool (*DMADRV_Callback_t)(unsigned int channel,
100                                   unsigned int sequenceNo,
101                                   void *userParam);
102 
103 Ecode_t DMADRV_AllocateChannel(unsigned int *channelId,
104                                void         *capabilities);
105 Ecode_t DMADRV_AllocateChannelById(unsigned int channelId,
106                                    void         *capabilities);
107 Ecode_t DMADRV_DeInit(void);
108 Ecode_t DMADRV_FreeChannel(unsigned int channelId);
109 Ecode_t DMADRV_Init(void);
110 
111 Ecode_t DMADRV_MemoryPeripheral(unsigned int              channelId,
112                                 DMADRV_PeripheralSignal_t peripheralSignal,
113                                 void                      *dst,
114                                 void                      *src,
115                                 bool                      srcInc,
116                                 int                       len,
117                                 DMADRV_DataSize_t         size,
118                                 DMADRV_Callback_t         callback,
119                                 void                      *cbUserParam);
120 Ecode_t DMADRV_PeripheralMemory(unsigned int              channelId,
121                                 DMADRV_PeripheralSignal_t peripheralSignal,
122                                 void                      *dst,
123                                 void                      *src,
124                                 bool                      dstInc,
125                                 int                       len,
126                                 DMADRV_DataSize_t         size,
127                                 DMADRV_Callback_t         callback,
128                                 void                      *cbUserParam);
129 Ecode_t DMADRV_MemoryPeripheralPingPong(unsigned int              channelId,
130                                         DMADRV_PeripheralSignal_t peripheralSignal,
131                                         void                      *dst,
132                                         void                      *src0,
133                                         void                      *src1,
134                                         bool                      srcInc,
135                                         int                       len,
136                                         DMADRV_DataSize_t         size,
137                                         DMADRV_Callback_t         callback,
138                                         void                      *cbUserParam);
139 Ecode_t DMADRV_PeripheralMemoryPingPong(unsigned int              channelId,
140                                         DMADRV_PeripheralSignal_t peripheralSignal,
141                                         void                      *dst0,
142                                         void                      *dst1,
143                                         void                      *src,
144                                         bool                      dstInc,
145                                         int                       len,
146                                         DMADRV_DataSize_t         size,
147                                         DMADRV_Callback_t         callback,
148                                         void                      *cbUserParam);
149 
150 #if defined(EMDRV_DMADRV_LDMA)
151 Ecode_t DMADRV_LdmaStartTransfer(int                channelId,
152                                  LDMA_TransferCfg_t *transfer,
153                                  LDMA_Descriptor_t  *descriptor,
154                                  DMADRV_Callback_t  callback,
155                                  void               *cbUserParam);
156 #elif defined(EMDRV_DMADRV_LDMA_S3)
157 Ecode_t DMADRV_LdmaStartTransfer(int                            channelId,
158                                  sl_hal_ldma_transfer_config_t  *transfer,
159                                  sl_hal_ldma_descriptor_t       *descriptor,
160                                  DMADRV_Callback_t              callback,
161                                  void                           *cbUserParam);
162 #endif
163 
164 Ecode_t DMADRV_PauseTransfer(unsigned int channelId);
165 Ecode_t DMADRV_ResumeTransfer(unsigned int channelId);
166 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL)
167 Ecode_t DMADRV_StopTransfer(unsigned int channelId);
168 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL)
169 Ecode_t DMADRV_TransferActive(unsigned int channelId,
170                               bool         *active);
171 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL)
172 Ecode_t DMADRV_TransferCompletePending(unsigned int channelId,
173                                        bool         *pending);
174 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL)
175 Ecode_t DMADRV_TransferDone(unsigned int channelId,
176                             bool         *done);
177 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL)
178 Ecode_t DMADRV_TransferRemainingCount(unsigned int channelId,
179                                       int          *remaining);
180 
181 /** @} (end addtogroup dmadrv) */
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* __SILICON_LABS_DMADRV_H__ */
188