| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#include <stdio.h> |
| 46 |
#include <stdlib.h> |
| 47 |
#include "xparameters.h" |
| 48 |
#include "Communication.h" |
| 49 |
#include "xaxidma.h" |
| 50 |
#include "xdma_config.h" |
| 51 |
#include "ad7091.h" |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#define NULL ((void *)0) |
| 58 |
#define SUCCESS 0 |
| 59 |
#define ERROR -1 |
| 60 |
|
| 61 |
|
| 62 |
#define ADC_BASEADDR XPAR_AXI_AD7091_0_BASEADDR |
| 63 |
|
| 64 |
|
| 65 |
#define DMA_DEV_ID XPAR_AXIDMA_0_DEVICE_ID |
| 66 |
#define DMA_BASEADDR XPAR_AXI_DMA_0_BASEADDR |
| 67 |
#define DDR_BASEADDR XPAR_DDR3_SDRAM_S_AXI_BASEADDR |
| 68 |
#define MEM_BASEADDR (DDR_BASEADDR + 0x1000000) |
| 69 |
|
| 70 |
#define RX_BD_SPACE_BASE (MEM_BASEADDR + 0x00001000) |
| 71 |
#define RX_BD_SPACE_HIGH (MEM_BASEADDR + 0x00001FFF) |
| 72 |
|
| 73 |
#define RX_BUFFER_BASE (MEM_BASEADDR + 0x00300000) |
| 74 |
#define RX_BUFFER_HIGH (MEM_BASEADDR + 0x004FFFFF) |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
#define SAMPLE_NO 16 * 1024 |
| 79 |
|
| 80 |
|
| 81 |
#define MAX_PKT_LEN 0x400 |
| 82 |
|
| 83 |
#define NUMBER_OF_PACKETS 0x20 |
| 84 |
|
| 85 |
#define BUS_WIDTH 4 |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
XAxiDma AxiDma; |
| 92 |
|
| 93 |
int startAcquisition = 0; |
| 94 |
u32 * prxData = NULL; |
| 95 |
u32 numberOfSample = 0; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
static int AxiDmaSetup(XAxiDma * AxiDmaInstPtr); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
int main(void) |
| 109 |
{ |
| 110 |
int Status; |
| 111 |
|
| 112 |
|
| 113 |
prxData = (u32*)RX_BUFFER_BASE; |
| 114 |
|
| 115 |
numberOfSample = SAMPLE_NO; |
| 116 |
|
| 117 |
|
| 118 |
UART_Init(115200); |
| 119 |
|
| 120 |
|
| 121 |
Status = AxiDmaSetup(&AxiDma); |
| 122 |
if(Status != SUCCESS) |
| 123 |
{ |
| 124 |
xil_printf("AXI DMA setup failed!\r\n"); |
| 125 |
return ERROR; |
| 126 |
} |
| 127 |
else |
| 128 |
{ |
| 129 |
xil_printf("AXI DMA setup complete.\r\n"); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
AD7091_Init(ADC_BASEADDR); |
| 134 |
|
| 135 |
|
| 136 |
while(!startAcquisition); |
| 137 |
|
| 138 |
|
| 139 |
Status = AD7091_GetData(numberOfSample); |
| 140 |
if(Status != SUCCESS) |
| 141 |
{ |
| 142 |
xil_printf("Overflow occurred\r\n"); |
| 143 |
} |
| 144 |
xil_printf("Data transaction was finished!\r\n"); |
| 145 |
|
| 146 |
|
| 147 |
while(startAcquisition); |
| 148 |
|
| 149 |
xil_printf("Data was saved to Acquisition.csv file!\r\n"); |
| 150 |
|
| 151 |
return SUCCESS; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
static int AxiDmaSetup(XAxiDma * AxiDmaInstPtr) |
| 164 |
{ |
| 165 |
XAxiDma_BdRing *RxRingPtr; |
| 166 |
XAxiDma_Config *Config; |
| 167 |
int Delay = 0; |
| 168 |
int Coalesce = 1; |
| 169 |
int Status; |
| 170 |
XAxiDma_Bd BdTemplate; |
| 171 |
XAxiDma_Bd *BdPtr; |
| 172 |
XAxiDma_Bd *BdCurPtr; |
| 173 |
u32 BdCount; |
| 174 |
u32 FreeBdCount; |
| 175 |
u32 RxBufferPtr; |
| 176 |
int Index; |
| 177 |
|
| 178 |
Config = XAxiDma_LookupConfig(DMA_DEV_ID); |
| 179 |
if (!Config) { |
| 180 |
xil_printf("No configuration found for %d\r\n", DMA_DEV_ID); |
| 181 |
return ERROR; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
Status = XAxiDma_CfgInitialize(AxiDmaInstPtr, Config); |
| 186 |
if (Status != SUCCESS) { |
| 187 |
xil_printf("Initialization failed %d\r\n", Status); |
| 188 |
return ERROR; |
| 189 |
} |
| 190 |
|
| 191 |
if(!XAxiDma_HasSg(AxiDmaInstPtr)) { |
| 192 |
xil_printf("Device configured as Simple mode \r\n"); |
| 193 |
return ERROR; |
| 194 |
} |
| 195 |
|
| 196 |
RxRingPtr = XAxiDma_GetRxRing(AxiDmaInstPtr); |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
XAxiDma_BdRingIntDisable(RxRingPtr, XAXIDMA_IRQ_ALL_MASK); |
| 201 |
|
| 202 |
|
| 203 |
XAxiDma_BdRingSetCoalesce(RxRingPtr, Coalesce, Delay); |
| 204 |
|
| 205 |
|
| 206 |
BdCount = XAxiDma_BdRingCntCalc(XAXIDMA_BD_MINIMUM_ALIGNMENT, |
| 207 |
RX_BD_SPACE_HIGH - RX_BD_SPACE_BASE + 1); |
| 208 |
|
| 209 |
Status = XAxiDma_BdRingCreate(RxRingPtr, RX_BD_SPACE_BASE, |
| 210 |
RX_BD_SPACE_BASE, |
| 211 |
XAXIDMA_BD_MINIMUM_ALIGNMENT, BdCount); |
| 212 |
|
| 213 |
if (Status != SUCCESS) { |
| 214 |
xil_printf("RX create BD ring failed %d\r\n", Status); |
| 215 |
return ERROR; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
XAxiDma_BdClear(&BdTemplate); |
| 222 |
|
| 223 |
Status = XAxiDma_BdRingClone(RxRingPtr, &BdTemplate); |
| 224 |
if (Status != SUCCESS) { |
| 225 |
xil_printf("RX clone BD failed %d\r\n", Status); |
| 226 |
return ERROR; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
FreeBdCount = XAxiDma_BdRingGetFreeCnt(RxRingPtr); |
| 232 |
|
| 233 |
Status = XAxiDma_BdRingAlloc(RxRingPtr, FreeBdCount, &BdPtr); |
| 234 |
if (Status != SUCCESS) { |
| 235 |
xil_printf("RX alloc BD failed %d\r\n", Status); |
| 236 |
return ERROR; |
| 237 |
} |
| 238 |
|
| 239 |
BdCurPtr = BdPtr; |
| 240 |
RxBufferPtr = RX_BUFFER_BASE; |
| 241 |
for (Index = 0; Index < FreeBdCount; Index++) { |
| 242 |
Status = XAxiDma_BdSetBufAddr(BdCurPtr, RxBufferPtr); |
| 243 |
|
| 244 |
if (Status != SUCCESS) { |
| 245 |
xil_printf("Set buffer addr %x on BD %x failed %d\r\n", |
| 246 |
(unsigned int)RxBufferPtr, |
| 247 |
(unsigned int)BdCurPtr, Status); |
| 248 |
return ERROR; |
| 249 |
} |
| 250 |
|
| 251 |
Status = XAxiDma_BdSetLength(BdCurPtr, MAX_PKT_LEN, |
| 252 |
RxRingPtr->MaxTransferLen); |
| 253 |
if (Status != SUCCESS) { |
| 254 |
xil_printf("Rx set length %d on BD %x failed %d\r\n", |
| 255 |
MAX_PKT_LEN, (unsigned int)BdCurPtr, Status); |
| 256 |
return ERROR; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
XAxiDma_BdSetCtrl(BdCurPtr, 0); |
| 263 |
XAxiDma_BdSetId(BdCurPtr, RxBufferPtr); |
| 264 |
|
| 265 |
RxBufferPtr += MAX_PKT_LEN; |
| 266 |
BdCurPtr = XAxiDma_BdRingNext(RxRingPtr, BdCurPtr); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
memset((void *)RX_BUFFER_BASE, 0, (MAX_PKT_LEN * NUMBER_OF_PACKETS * 4)); |
| 272 |
|
| 273 |
Status = XAxiDma_BdRingToHw(RxRingPtr, FreeBdCount, |
| 274 |
BdPtr); |
| 275 |
if (Status != SUCCESS) { |
| 276 |
xil_printf("RX submit hw failed %d\r\n", Status); |
| 277 |
return ERROR; |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
Status = XAxiDma_BdRingStart(RxRingPtr); |
| 282 |
if (Status != SUCCESS) { |
| 283 |
xil_printf("RX start hw failed %d\r\n", Status); |
| 284 |
return ERROR; |
| 285 |
} |
| 286 |
|
| 287 |
return SUCCESS; |
| 288 |
} |