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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [gui_plugin/] [gui_plugin.cpp] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
/**
2
 * @file
3
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
4
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief      GUI for the RISC-V debugger.
6
 */
7
 
8
#include "api_core.h"
9
#include "gui_plugin.h"
10
#include "coreservices/iserial.h"
11
#include "coreservices/irawlistener.h"
12
#include <string>
13
 
14
namespace debugger {
15
 
16
GuiPlugin::GuiPlugin(const char *name)
17
    : IService(name), IHap(HAP_ConfigDone) {
18
    registerInterface(static_cast<IGui *>(this));
19
    registerInterface(static_cast<IThread *>(this));
20
    registerInterface(static_cast<IHap *>(this));
21
    registerAttribute("WidgetsConfig", &guiConfig_);
22
    registerAttribute("SocInfo", &socInfo_);
23
    registerAttribute("CommandExecutor", &cmdExecutor_);
24
 
25
    guiConfig_.make_dict();
26
    socInfo_.make_string("");
27
    cmdExecutor_.make_string("");
28
 
29
    char coredir[4096];
30
    RISCV_get_core_folder(coredir, sizeof(coredir));
31
    QString topDir(coredir);
32
    QResource::registerResource(
33
        topDir + "resources/gui.rcc");
34
 
35
    info_ = 0;
36
    ui_ = NULL;
37
    RISCV_event_create(&eventCommandAvailable_, "eventCommandAvailable_");
38
    RISCV_event_create(&config_done_, "eventGuiGonfigGone");
39
    RISCV_register_hap(static_cast<IHap *>(this));
40
    RISCV_mutex_init(&mutexCommand_);
41
 
42
    cmdQueueWrPos_ = 0;
43
    cmdQueueRdPos_ = 0;
44
    cmdQueueCntTotal_ = 0;
45
 
46
    // Adding path to platform libraries:
47
    char core_path[1024];
48
    RISCV_get_core_folder(core_path, sizeof(core_path));
49
    QStringList paths = QApplication::libraryPaths();
50
    std::string qt_path = std::string(core_path);
51
    std::string qt_lib_path = qt_path;
52
    paths.append(QString(qt_lib_path.c_str()));
53
    qt_lib_path += "qtlib/";
54
    paths.append(QString(qt_lib_path.c_str()));
55
    qt_lib_path += "platforms";
56
    paths.append(QString(qt_lib_path.c_str()));
57
 
58
    paths.append(QString("platforms"));
59
    QApplication::setLibraryPaths(paths);
60
 
61 3 sergeykhbr
    ui_ = new QtWrapper(static_cast<IGui *>(this));
62 2 sergeykhbr
}
63
 
64
GuiPlugin::~GuiPlugin() {
65
    RISCV_event_close(&config_done_);
66
    RISCV_event_close(&eventCommandAvailable_);
67
    RISCV_mutex_destroy(&mutexCommand_);
68
}
69
 
70
void GuiPlugin::postinitService() {
71
    iexec_ = static_cast<ICmdExecutor *>(
72
        RISCV_get_service_iface(cmdExecutor_.to_string(), IFACE_CMD_EXECUTOR));
73
    if (!iexec_) {
74
        RISCV_error("ICmdExecutor interface of %s not found.",
75
                    cmdExecutor_.to_string());
76
    }
77
 
78
    info_ = static_cast<ISocInfo *>(
79
        RISCV_get_service_iface(socInfo_.to_string(), IFACE_SOC_INFO));
80
    if (!iexec_) {
81
        RISCV_error("ISocInfo interface of %s not found.",
82
                    socInfo_.to_string());
83
    }
84
 
85 3 sergeykhbr
    ui_->postInit(&guiConfig_);
86 2 sergeykhbr
    run();
87
}
88
 
89
IFace *GuiPlugin::getSocInfo() {
90
    return info_;
91
}
92
 
93 3 sergeykhbr
const AttributeType *GuiPlugin::getpConfig() {
94
    return &guiConfig_;
95 2 sergeykhbr
}
96
 
97
void GuiPlugin::registerCommand(IGuiCmdHandler *src,
98
                                AttributeType *cmd,
99
                                bool silent) {
100
 
101
    if (cmdQueueCntTotal_ >= CMD_QUEUE_SIZE) {
102
        RISCV_error("Command queue size %d overflow. Target not responding",
103
                    cmdQueueCntTotal_);
104
        return;
105
    }
106
    //RISCV_info("CMD %s", cmd->to_string());
107
    if (cmdQueueWrPos_ == CMD_QUEUE_SIZE) {
108
        cmdQueueWrPos_ = 0;
109
    }
110
    RISCV_mutex_lock(&mutexCommand_);
111
    cmdQueue_[cmdQueueWrPos_].silent = silent;
112
    cmdQueue_[cmdQueueWrPos_].src = src;
113
    cmdQueue_[cmdQueueWrPos_++].cmd = *cmd;
114
    cmdQueueCntTotal_++;
115
    RISCV_mutex_unlock(&mutexCommand_);
116
    RISCV_event_set(&eventCommandAvailable_);
117
}
118
 
119
void GuiPlugin::removeFromQueue(IFace *iface) {
120
    RISCV_mutex_lock(&mutexCommand_);
121
    for (unsigned i = 0; i < CMD_QUEUE_SIZE; i++) {
122
        if (iface == cmdQueue_[i].src) {
123
            cmdQueue_[i].src = NULL;
124
        }
125
    }
126
    RISCV_mutex_unlock(&mutexCommand_);
127
}
128
 
129
void GuiPlugin::hapTriggered(IFace *isrc, EHapType type,
130
                                  const char *descr) {
131
    RISCV_event_set(&config_done_);
132
}
133
 
134
void GuiPlugin::busyLoop() {
135
    RISCV_event_wait(&config_done_);
136
 
137
    while (isEnabled()) {
138
        if (RISCV_event_wait_ms(&eventCommandAvailable_, 500)) {
139
            RISCV_event_clear(&eventCommandAvailable_);
140
            continue;
141
        }
142
 
143
        processCmdQueue();
144
    }
145 3 sergeykhbr
    ui_->gracefulClose();
146
    delete ui_;
147 2 sergeykhbr
}
148
 
149
bool GuiPlugin::processCmdQueue() {
150
    AttributeType resp;
151
    while (cmdQueueCntTotal_ > 0) {
152
        AttributeType &cmd = cmdQueue_[cmdQueueRdPos_].cmd;
153
 
154
        iexec_->exec(cmd.to_string(), &resp, cmdQueue_[cmdQueueRdPos_].silent);
155
 
156
        RISCV_mutex_lock(&mutexCommand_);
157
        if (cmdQueue_[cmdQueueRdPos_].src) {
158
            cmdQueue_[cmdQueueRdPos_].src->handleResponse(
159
                        const_cast<AttributeType *>(&cmd), &resp);
160
        }
161
        if ((++cmdQueueRdPos_) >= CMD_QUEUE_SIZE) {
162
            cmdQueueRdPos_ = 0;
163
        }
164
        cmdQueueCntTotal_--;
165
        RISCV_mutex_unlock(&mutexCommand_);
166
    }
167
    return false;
168
}
169
 
170
void GuiPlugin::stop() {
171
    IThread::stop();
172
}
173
 
174
extern "C" void plugin_init(void) {
175
    REGISTER_CLASS(GuiPlugin);
176
}
177
 
178
}  // namespace debugger

powered by: WebSVN 2.1.0

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