OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [socsim_plugin/] [gnss_stub.cpp] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
* @brief      GNSS stub module functional model.
6
 */
7
 
8
#include "api_core.h"
9
#include "gnss_stub.h"
10
 
11
namespace debugger {
12
 
13
GNSSStub::GNSSStub(const char *name)  : IService(name) {
14
    registerInterface(static_cast<IMemoryOperation *>(this));
15
    registerInterface(static_cast<IClockListener *>(this));
16
    registerAttribute("IrqControl", &irqctrl_);
17
    registerAttribute("ClkSource", &clksrc_);
18
 
19
    memset(&regs_, 0, sizeof(regs_));
20
 
21
    regs_.misc.GenericChanCfg = 12;       // [4:0] gps
22
    regs_.misc.GenericChanCfg |= 12 << 5; // [8:5] glo
23
    regs_.misc.GenericChanCfg |= 2 << 9;  // [10:9] sbas
24
    regs_.misc.GenericChanCfg |= 6 << 11; // [14:11] gal
25
}
26
 
27
GNSSStub::~GNSSStub() {
28
}
29
 
30
void GNSSStub::postinitService() {
31
    iclk_ = static_cast<IClock *>(
32
        RISCV_get_service_iface(clksrc_.to_string(), IFACE_CLOCK));
33
    if (!iclk_) {
34
        RISCV_error("Can't find IClock interface %s", clksrc_.to_string());
35
    }
36
 
37
    iwire_ = static_cast<IWire *>(
38
        RISCV_get_service_port_iface(irqctrl_[0u].to_string(),
39
                                     irqctrl_[1].to_string(),
40
                                     IFACE_WIRE));
41
    if (!iwire_) {
42
        RISCV_error("Can't find IWire interface %s", irqctrl_[0u].to_string());
43
    }
44
}
45
 
46
ETransStatus GNSSStub::b_transport(Axi4TransactionType *trans) {
47
    uint64_t mask = (length_.to_uint64() - 1);
48
    uint64_t off = ((trans->addr - getBaseAddress()) & mask);
49
    trans->response = MemResp_Valid;
50
    if (trans->action == MemAction_Write) {
51
        for (uint64_t i = 0; i < trans->xsize/4; i++) {
52
            if (((trans->wstrb >> 4*i) & 0xf) == 0) {
53
                continue;
54
            }
55
            if (regs_.tmr.rw_MsLength == 0 && trans->wpayload.b32[i] != 0) {
56
                iclk_->registerStepCallback(
57
                    static_cast<IClockListener *>(this),
58
                    iclk_->getStepCounter() + trans->wpayload.b32[i]);
59
            }
60
            regs_.tmr.rw_MsLength = trans->wpayload.b32[i];
61
            if ((off + 4*i) == OFFSET(&regs_.tmr.rw_MsLength)) {
62
                RISCV_info("Set rw_MsLength = %d", regs_.tmr.rw_MsLength);
63
            }
64
        }
65
    } else {
66
        uint8_t *m = reinterpret_cast<uint8_t *>(&regs_);
67
        memcpy(trans->rpayload.b8, &m[off], trans->xsize);
68
    }
69
    return TRANS_OK;
70
}
71
 
72
void GNSSStub::stepCallback(uint64_t t) {
73
    iwire_->raiseLine();
74
    if (regs_.tmr.rw_MsLength) {
75
        regs_.tmr.rw_tow++;
76
        regs_.tmr.rw_tod++;
77
        iclk_->registerStepCallback(static_cast<IClockListener *>(this),
78
                                    t + regs_.tmr.rw_MsLength);
79
    }
80
}
81
 
82
}  // namespace debugger
83
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.