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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [appdbg64g/] [main.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      Test application to verify UDP/EDCL transport library.
6
 */
7
 
8
#include "api_core.h"
9
#include "iservice.h"
10
#include "coreservices/iudp.h"
11
#include "coreservices/ithread.h"
12
#include "coreservices/icpuriscv.h"
13
/** Plugin verification */
14
#include "simple_plugin/isimple_plugin.h"
15
#include <stdio.h>
16
#include <string>
17
 
18
using namespace debugger;
19
 
20
static AttributeType Config;
21
 
22
const AttributeType *getConfigOfService(const AttributeType &cfg,
23
                                        const char *name) {
24
    const AttributeType &serv = cfg["Services"];
25
    for (unsigned i = 0; i < serv.size(); i++) {
26
        const AttributeType &inst = serv[i]["Instances"];
27
        for (unsigned n = 0; n < inst.size(); n++) {
28
            if (strcmp(inst[n]["Name"].to_string(), name) == 0) {
29
                return &inst[n];
30
            }
31
        }
32
    }
33
    return 0;
34
}
35
 
36
int main(int argc, char* argv[]) {
37
    AttributeType scriptFile("");
38
    AttributeType databuf;
39
 
40
    RISCV_init();
41
    RISCV_set_current_dir();
42
 
43
    // Parse arguments:
44
    if (argc > 1) {
45
        for (int i = 1; i < argc; i++) {
46
            if (strcmp(argv[i], "-c") == 0) {
47
                i++;
48
                RISCV_read_json_file(argv[i], &databuf);
49
            } else if (strcmp(argv[i], "-script") == 0) {
50
                i++;
51
                scriptFile.make_string(argv[i]);
52
            }
53
        }
54
    }
55
 
56
    if (databuf.size() == 0) {
57
        printf("Error: Platform script file not defined\n");
58
        printf("       Use -c key to specify configuration file location:\n");
59
        printf("Example: appdbg64.exe -c ../../targets/default.json\n");
60
        return 0;
61
    }
62
 
63
    Config.from_config(databuf.to_string());
64
    Config["GlobalSettings"]["ScriptFile"] = scriptFile;
65
 
66
    if (RISCV_set_configuration(&Config)) {
67
        printf("Error: can't instantiate configuration\n");
68
        return 0;
69
    }
70
 
71
    // Connect simulator to the EDCL debugger if enabled:
72
    if (Config["GlobalSettings"]["SimEnable"].to_bool()) {
73
        IUdp *iudp1 = static_cast<IUdp *>
74
                (RISCV_get_service_iface("udpboard", IFACE_UDP));
75
        IUdp *iudp2 = static_cast<IUdp *>
76
                (RISCV_get_service_iface("udpedcl", IFACE_UDP));
77
 
78
        AttributeType t1 = iudp1->getConnectionSettings();
79
        iudp2->setTargetSettings(&t1);
80
        t1 = iudp2->getConnectionSettings();
81
        iudp1->setTargetSettings(&t1);
82
    }
83
 
84
    IService *itst = static_cast<IService *>(RISCV_get_service("example0"));
85
    if (itst == NULL) {
86
        /**
87
         * @brief Create instance of the example plugin class.
88
         */
89
        IFace *simple = RISCV_get_class("SimplePluginClass");
90
        if (simple) {
91
                itst = static_cast<IService *>(RISCV_create_service(
92
                          simple, "example0", NULL));
93
        }
94
    }
95
 
96
    /**
97
     * Unreset all CPUs
98
     */
99
    AttributeType cpu_list;
100
    RISCV_get_services_with_iface(IFACE_CPU_RISCV, &cpu_list);
101
    for (unsigned i = 0; i < cpu_list.size(); i++) {
102
        IService *iserv = static_cast<IService *>(cpu_list[i].to_iface());
103
        ICpuRiscV *icpu = static_cast<ICpuRiscV *>(
104
                    iserv->getInterface(IFACE_CPU_RISCV));
105
        icpu->lowerSignal(CPU_SIGNAL_RESET);  // Active HIGH. Unreset CPU model.
106
    }
107
 
108
    if (itst != NULL) {
109
        /** Get plugin specific interface. */
110
        ISimplePlugin * itst_access = static_cast<ISimplePlugin *>(
111
                                itst->getInterface(IFACE_SIMPLE_PLUGIN));
112
        /** Call example method */
113
        itst_access->exampleAction(0xcafe);
114
    }
115
 
116 3 sergeykhbr
    RISCV_dispatcher_start();
117 2 sergeykhbr
 
118
    //const char *t1 = RISCV_get_configuration();
119
    //RISCV_write_json_file(configFile.to_string(), t1);
120
    RISCV_cleanup();
121
        return 0;
122
}

powered by: WebSVN 2.1.0

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