-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
94 lines (49 loc) · 2.1 KB
/
main.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* DMA.cpp
*
* Created on: Apr 20, 2023
* Author: samso
*/
#include"dma.hpp"
#include<iostream>
// This code will initialize the DMA through the CPU and the DMA will do the reading and
// writing, and we see the work of the DMA while communicating with the hardware accelerator
int main() {
unsigned long int status;
DirectMemoryAccess* dma = new DirectMemoryAccess(0x40400000, 0x0e000000, 0x0f000000);
dma->reset();
dma->halt();
// In this section we store the data in the DRAM
dma->writeSourceByte(0);
dma->writeSourceByte(10);
dma->writeSourceByte(5);
dma->writeSourceByte(0);
dma->writeSourceString("hello");
dma->hexdumpSource(9); // the byte length: four numerical values plus five char ( 9 bytes)
// ------------------------------------------------
// In this section we set the interrupt where it will inform us IOC ( interrupt on complete)
// we disabled the error event and also the treshold is zero where there is no counting done
// by the internal counter.
dma->setInterrupt(true, false, 0);
dma->ready(); // ready the DMA
dma->setDestinationAddress(0x0f000000);
dma->setSourceAddress(0x0e000000);
dma->setDestinationLength(5); // as the output from the hw accelrator is rovvy( 5 bytes)
dma->setSourceLength(9);
// In this section we will wait the DMA till it is done with the task
printf("Waiting for MM2S...\n");
do {
status = dma->getMM2SStatus();
dma->dumpStatus(status);
} while((!(status & 1<<12) && !(status & 1 << 1))); // this is the byte counter where we
// will check the IOC value at the 13th bit ( count start from 0) is not done and print
// status values. The other one also check if the reserved bit is 1. Actually
// according to the DMA doc this value is always 1.
printf("Waiting for S2MM...\n");
do {
status = dma->getS2MMStatus();
dma->dumpStatus(status);
} while((!(status & 1<<12) && !(status & 1 << 1)));
dma->hexdumpDestination(5);
// Basically dumping is just printing the values of the memory content.
}