1.1 diff -r 000000000000 -r 11aef665a5d8 drivers/device/MicoDMA.h 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/drivers/device/MicoDMA.h Fri Aug 13 10:43:05 2010 +0100 1.4 @@ -0,0 +1,218 @@ 1.5 +/**************************************************************************** 1.6 +** 1.7 +** Name: MicoDMA.h 1.8 +** 1.9 +** Description: 1.10 +** Declares prototypes of functions for manipulating LatticeMico32 DMA 1.11 +** 1.12 +** Revision: 3.0 1.13 +** 1.14 +** Disclaimer: 1.15 +** 1.16 +** This source code is intended as a design reference which 1.17 +** illustrates how these types of functions can be implemented. It 1.18 +** is the user's responsibility to verify their design for 1.19 +** consistency and functionality through the use of formal 1.20 +** verification methods. Lattice Semiconductor provides no warranty 1.21 +** regarding the use or functionality of this code. 1.22 +** 1.23 +** -------------------------------------------------------------------- 1.24 +** 1.25 +** Lattice Semiconductor Corporation 1.26 +** 5555 NE Moore Court 1.27 +** Hillsboro, OR 97214 1.28 +** U.S.A 1.29 +** 1.30 +** TEL: 1-800-Lattice (USA and Canada) 1.31 +** (503)268-8001 (other locations) 1.32 +** 1.33 +** web: http://www.latticesemi.com 1.34 +** email: techsupport@latticesemi.com 1.35 +** 1.36 +** -------------------------------------------------------------------------- 1.37 +** 1.38 +** Change History (Latest changes on top) 1.39 +** 1.40 +** Ver Date Description 1.41 +** -------------------------------------------------------------------------- 1.42 +** 1.43 +** 3.0 Mar-25-2008 Added Header 1.44 +** 1.45 +**--------------------------------------------------------------------------- 1.46 +*****************************************************************************/ 1.47 + 1.48 +#ifndef MICODMA_H_ 1.49 +#define MICODMA_H_ 1.50 + 1.51 +#include "DDStructs.h" 1.52 + 1.53 +#ifdef __cplusplus 1.54 +extern "C" { 1.55 +#endif 1.56 + 1.57 +/*************************************************************** 1.58 + *************************************************************** 1.59 + * * 1.60 + * DMA PHYSICAL DEVICE SPECIFIC INFORMATION * 1.61 + * * 1.62 + *************************************************************** 1.63 + ***************************************************************/ 1.64 + 1.65 + /* 1.66 + ------------------------------------------------------ 1.67 + - DMA registers specific bit definitions used - 1.68 + - in the driver implementation - 1.69 + ------------------------------------------------------ 1.70 + */ 1.71 + /* CONTROL-REGISTER BIT-MASKS */ 1.72 + #define MICODMA_CONTROL_SADDR_CONSTANT (0x01) 1.73 + #define MICODMA_CONTROL_DADDR_CONSTANT (0x02) 1.74 + #define MICODMA_CONTROL_USHORT_TRANSFER (0x04) 1.75 + #define MICODMA_CONTROL_UINT_TRANSFER (0x08) 1.76 + #define MICODMA_CONTROL_BURST_SIZE (0x30) 1.77 + #define MICODMA_CONTROL_BURST_ENABLE (0x40) 1.78 + 1.79 + /* STATUS-REGISTER BIT-MASKS */ 1.80 + #define MICODMA_STATUS_BUSY (0x01) 1.81 + #define MICODMA_STATUS_IE (0x02) 1.82 + #define MICODMA_STATUS_SUCCESS (0x04) 1.83 + #define MICODMA_STATUS_START (0x08) 1.84 + 1.85 + 1.86 + /* DMA OPERATIONAL CODES (USED INTERNALLY) */ 1.87 + #define MICODMA_STATE_SUCCESS (0x00) 1.88 + #define MICODMA_STATE_PENDING (0x01) 1.89 + #define MICODMA_STATE_ACTIVE (0x02) 1.90 + #define MICODMA_STATE_ERROR (0x03) 1.91 + #define MICODMA_STATE_ABORTED (0x04) 1.92 + 1.93 + 1.94 + /* 1.95 + ------------------------------------------------------ 1.96 + - - 1.97 + - DMA Device Register-map - 1.98 + - - 1.99 + ------------------------------------------------------ 1.100 + */ 1.101 + typedef struct st_MicoDMA{ 1.102 + /* address to read data from */ 1.103 + volatile unsigned int sAddr; 1.104 + 1.105 + /* address to write data to */ 1.106 + volatile unsigned int dAddr; 1.107 + 1.108 + /* dma-length */ 1.109 + volatile unsigned int len; 1.110 + 1.111 + /* control register */ 1.112 + volatile unsigned int control; 1.113 + 1.114 + /* status register */ 1.115 + volatile unsigned int status; 1.116 + }MicoDMA_t; 1.117 + 1.118 + 1.119 + 1.120 +/*************************************************************** 1.121 + *************************************************************** 1.122 + * * 1.123 + * DMA SOFTWARE DRIVER SPECIFIC INFORMATION * 1.124 + * * 1.125 + *************************************************************** 1.126 + ***************************************************************/ 1.127 + 1.128 + /* DMA-TYPE QUALIFIERS */ 1.129 + /* DMA-type enumerator */ 1.130 + typedef enum e_DMAType_t{ 1.131 + DMA_CONSTANT_SRC_ADDR = 0x01, 1.132 + DMA_CONSTANT_DST_ADDR = 0x02, 1.133 + DMA_16BIT_TRANSFER = 0x04, 1.134 + DMA_32BIT_TRANSFER = 0x08, 1.135 + DMA_BURST_SIZE_4 = 0x40, 1.136 + DMA_BURST_SIZE_8 = 0x50, 1.137 + DMA_BURST_SIZE_16 = 0x60, 1.138 + DMA_BURST_SIZE_32 = 0x70, 1.139 + DMA_BURST_SIZE = DMA_BURST_SIZE_8, /* Legacy: replaced by BURST_SIZE_X above */ 1.140 + DMA_BURST_ENABLE = 0x40 /* Legacy: replaced by BURST_SIZE_X above */ 1.141 + 1.142 + }DMAType_t; 1.143 + 1.144 + 1.145 + typedef struct st_DMADesc_t DMADesc_t; 1.146 + 1.147 + /* DMA Completion callback type */ 1.148 + typedef void(*DMACallback_t)(DMADesc_t *desc, unsigned int status); 1.149 + 1.150 + 1.151 + /* DMA Descriptor that defines a DMA operation */ 1.152 + struct st_DMADesc_t{ 1.153 + /* address to read data from */ 1.154 + unsigned int sAddr; 1.155 + 1.156 + /* address to write data to */ 1.157 + unsigned int dAddr; 1.158 + 1.159 + /* length of transfer */ 1.160 + unsigned int length; 1.161 + 1.162 + /* DMA transfer-qualifier */ 1.163 + unsigned int type; 1.164 + 1.165 + /* User-provided private data */ 1.166 + void *priv; 1.167 + 1.168 + /* descriptor state */ 1.169 + unsigned int state; 1.170 + 1.171 + /* used internally by the driver: Stores byte-length */ 1.172 + unsigned int reserved; 1.173 + 1.174 + /* used internally for chaining descriptors */ 1.175 + DMACallback_t onCompletion; 1.176 + DMADesc_t *prev; 1.177 + DMADesc_t *next; 1.178 + }; 1.179 + 1.180 + 1.181 + 1.182 + /* 1.183 + ------------------------------------------------------ 1.184 + - - 1.185 + - FUNCTIONS - 1.186 + - - 1.187 + ------------------------------------------------------ 1.188 + */ 1.189 + 1.190 + 1.191 + /* well-known DMA specific return values */ 1.192 + #define MICODMA_ERR_INVALID_POINTERS (1) 1.193 + #define MICODMA_ERR_DESCRIPTOR_NOT_PENDING (2) 1.194 + #define MICODMA_ERR_DESC_LEN_ERR (3) 1.195 + 1.196 + 1.197 + /* initialization routine */ 1.198 + void MicoDMAInit(MicoDMACtx_t *ctx); 1.199 + 1.200 + /* queue a new descriptor */ 1.201 + unsigned int MicoDMAQueueRequest(MicoDMACtx_t *ctx, DMADesc_t *desc, DMACallback_t callback); 1.202 + 1.203 + /* dequeue an existing queued descriptor */ 1.204 + unsigned int MicoDMADequeueRequest(MicoDMACtx_t *ctx, DMADesc_t *desc, unsigned int callback); 1.205 + 1.206 + /* query status of a descriptor */ 1.207 + unsigned int MicoDMAGetState(DMADesc_t *desc); 1.208 + 1.209 + /* pause DMA operations (after completion of the currently active descr.) */ 1.210 + unsigned int MicoDMAPause(MicoDMACtx_t *ctx); 1.211 + 1.212 + /* resume DMA operations */ 1.213 + unsigned int MicoDMAResume(MicoDMACtx_t *ctx); 1.214 + 1.215 + 1.216 +#ifdef __cplusplus 1.217 +} 1.218 +#endif 1.219 + 1.220 + 1.221 +#endif /*MICODMA_H_*/ 1.222 +