|
| 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_DeInit(void); |
| 106 | +Ecode_t DMADRV_FreeChannel(unsigned int channelId); |
| 107 | +Ecode_t DMADRV_Init(void); |
| 108 | + |
| 109 | +Ecode_t DMADRV_MemoryPeripheral(unsigned int channelId, |
| 110 | + DMADRV_PeripheralSignal_t peripheralSignal, |
| 111 | + void *dst, |
| 112 | + void *src, |
| 113 | + bool srcInc, |
| 114 | + int len, |
| 115 | + DMADRV_DataSize_t size, |
| 116 | + DMADRV_Callback_t callback, |
| 117 | + void *cbUserParam); |
| 118 | +Ecode_t DMADRV_PeripheralMemory(unsigned int channelId, |
| 119 | + DMADRV_PeripheralSignal_t peripheralSignal, |
| 120 | + void *dst, |
| 121 | + void *src, |
| 122 | + bool dstInc, |
| 123 | + int len, |
| 124 | + DMADRV_DataSize_t size, |
| 125 | + DMADRV_Callback_t callback, |
| 126 | + void *cbUserParam); |
| 127 | +Ecode_t DMADRV_MemoryPeripheralPingPong(unsigned int channelId, |
| 128 | + DMADRV_PeripheralSignal_t peripheralSignal, |
| 129 | + void *dst, |
| 130 | + void *src0, |
| 131 | + void *src1, |
| 132 | + bool srcInc, |
| 133 | + int len, |
| 134 | + DMADRV_DataSize_t size, |
| 135 | + DMADRV_Callback_t callback, |
| 136 | + void *cbUserParam); |
| 137 | +Ecode_t DMADRV_PeripheralMemoryPingPong(unsigned int channelId, |
| 138 | + DMADRV_PeripheralSignal_t peripheralSignal, |
| 139 | + void *dst0, |
| 140 | + void *dst1, |
| 141 | + void *src, |
| 142 | + bool dstInc, |
| 143 | + int len, |
| 144 | + DMADRV_DataSize_t size, |
| 145 | + DMADRV_Callback_t callback, |
| 146 | + void *cbUserParam); |
| 147 | + |
| 148 | +#if defined(EMDRV_DMADRV_LDMA) |
| 149 | +Ecode_t DMADRV_LdmaStartTransfer(int channelId, |
| 150 | + LDMA_TransferCfg_t *transfer, |
| 151 | + LDMA_Descriptor_t *descriptor, |
| 152 | + DMADRV_Callback_t callback, |
| 153 | + void *cbUserParam); |
| 154 | +#elif defined(EMDRV_DMADRV_LDMA_S3) |
| 155 | +Ecode_t DMADRV_LdmaStartTransfer(int channelId, |
| 156 | + sl_hal_ldma_transfer_config_t *transfer, |
| 157 | + sl_hal_ldma_descriptor_t *descriptor, |
| 158 | + DMADRV_Callback_t callback, |
| 159 | + void *cbUserParam); |
| 160 | +#endif |
| 161 | + |
| 162 | +Ecode_t DMADRV_PauseTransfer(unsigned int channelId); |
| 163 | +Ecode_t DMADRV_ResumeTransfer(unsigned int channelId); |
| 164 | +SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL) |
| 165 | +Ecode_t DMADRV_StopTransfer(unsigned int channelId); |
| 166 | +SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL) |
| 167 | +Ecode_t DMADRV_TransferActive(unsigned int channelId, |
| 168 | + bool *active); |
| 169 | +SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL) |
| 170 | +Ecode_t DMADRV_TransferCompletePending(unsigned int channelId, |
| 171 | + bool *pending); |
| 172 | +SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL) |
| 173 | +Ecode_t DMADRV_TransferDone(unsigned int channelId, |
| 174 | + bool *done); |
| 175 | +SL_CODE_CLASSIFY(SL_CODE_COMPONENT_DMADRV, SL_CODE_CLASS_TIME_CRITICAL) |
| 176 | +Ecode_t DMADRV_TransferRemainingCount(unsigned int channelId, |
| 177 | + int *remaining); |
| 178 | + |
| 179 | +/** @} (end addtogroup dmadrv) */ |
| 180 | + |
| 181 | +#ifdef __cplusplus |
| 182 | +} |
| 183 | +#endif |
| 184 | + |
| 185 | +#endif /* __SILICON_LABS_DMADRV_H__ */ |
0 commit comments