dma.cpp 2.47 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

#include "corundum.h"
#include "dma.h"
#include "mem.h"

void DMAReader::step()
{
    p.dma_ready = 1;
    if (p.dma_valid) {
        DMAOp *op = new DMAOp;
        op->engine = this;
        op->dma_addr = p.dma_addr;
        op->ram_sel = p.dma_ram_sel;
        op->ram_addr = p.dma_ram_addr;
        op->len = p.dma_len;
        op->tag = p.dma_tag;
        op->write = false;
        pending.insert(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
20
        /*std::cout << "dma[" << label << "] op " << op->dma_addr << " -> " <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
21
            op->ram_sel << ":" << op->ram_addr <<
Antoine Kaufmann's avatar
Antoine Kaufmann committed
22
            "   len=" << op->len << "   tag=" << (int) op->tag << std::endl;*/
Antoine Kaufmann's avatar
Antoine Kaufmann committed
23
24
25
26
27
28
29
30
31

        pci_dma_issue(op);
    }

    p.dma_status_valid = 0;
    if (!completed.empty()) {
        DMAOp *op = completed.front();
        completed.pop_front();

Antoine Kaufmann's avatar
Antoine Kaufmann committed
32
        //std::cout << "dma[" << label << "] status complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

        p.dma_status_valid = 1;
        p.dma_status_tag = op->tag;
        pending.erase(op);
        delete op;
    }
}

void DMAReader::pci_op_complete(DMAOp *op)
{
    mw.op_issue(op);
}

void DMAReader::mem_op_complete(DMAOp *op)
{
    completed.push_back(op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
49
    //std::cout << "dma[" << label << "] mem complete " << op->dma_addr << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
50
}
Antoine Kaufmann's avatar
Antoine Kaufmann committed
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
93
94
95
96
97
98



void DMAWriter::step()
{
    p.dma_ready = 1;
    if (p.dma_valid) {
        DMAOp *op = new DMAOp;
        op->engine = this;
        op->dma_addr = p.dma_addr;
        op->ram_sel = p.dma_ram_sel;
        op->ram_addr = p.dma_ram_addr;
        op->len = p.dma_len;
        op->tag = p.dma_tag;
        op->write = true;
        pending.insert(op);
        std::cout << "dma write [" << label << "] op " << op->dma_addr << " -> " <<
            op->ram_sel << ":" << op->ram_addr <<
            "   len=" << op->len << "   tag=" << (int) op->tag << std::endl;

        mr.op_issue(op);
    }

    p.dma_status_valid = 0;
    if (!completed.empty()) {
        DMAOp *op = completed.front();
        completed.pop_front();

        std::cout << "dma write [" << label << "] status complete " << op->dma_addr << std::endl;

        p.dma_status_valid = 1;
        p.dma_status_tag = op->tag;
        pending.erase(op);
        delete op;
    }
}

void DMAWriter::pci_op_complete(DMAOp *op)
{
    std::cout << "dma write [" << label << "] pci complete " << op->dma_addr << std::endl;
    completed.push_back(op);
}

void DMAWriter::mem_op_complete(DMAOp *op)
{
    std::cout << "dma write [" << label << "] mem complete " << op->dma_addr << std::endl;
    pci_dma_issue(op);
}