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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [console/] [console.h] - Blame information for rev 2

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      Input console class declaration.
6
 */
7
 
8
#ifndef __DEBUGGER_CONSOLE_H__
9
#define __DEBUGGER_CONSOLE_H__
10
 
11
#include "iclass.h"
12
#include "iservice.h"
13
#include "ihap.h"
14
#include "coreservices/ithread.h"
15
#include "coreservices/iserial.h"
16
#include "coreservices/iclock.h"
17
#include "coreservices/iautocomplete.h"
18
#include "coreservices/icmdexec.h"
19
#include "coreservices/isrccode.h"
20
#include "coreservices/irawlistener.h"
21
#include "coreservices/isignallistener.h"
22
#include <string>
23
//#define DBG_ZEPHYR
24
 
25
namespace debugger {
26
 
27
class ConsoleService : public IService,
28
                       public IThread,
29
                       public IHap,
30
                       public IRawListener,
31
                       public ISignalListener,
32
                       public IClockListener {
33
public:
34
    explicit ConsoleService(const char *name);
35
    virtual ~ConsoleService();
36
 
37
    /** IService interface */
38
    virtual void postinitService();
39
    virtual void predeleteService();
40
 
41
    /** IHap */
42
    virtual void hapTriggered(IFace *isrc, EHapType type, const char *descr);
43
 
44
    /** IRawListener (default stream) */
45
    virtual void updateData(const char *buf, int buflen);
46
 
47
    /** IClockListener */
48
    virtual void stepCallback(uint64_t t);
49
 
50
    /** ISignalListener */
51
    virtual void updateSignal(int start, int width, uint64_t value);
52
 
53
protected:
54
    /** IThread interface */
55
    virtual void busyLoop();
56
 
57
private:
58
    friend class RawPortType;
59
    void writeBuffer(const char *buf);
60
    void processScriptFile();
61
    bool isData();
62
    uint32_t getData();
63
    void clearLine(int num);
64
    void processCommandLine();
65
 
66
    class RawPortType : public IRawListener {
67
    public:
68
        RawPortType(ConsoleService *parent, const char *name, bool wait_line = false) {
69
            parent_ = parent;
70
            waitLine_ = wait_line;
71
            if (name[0]) {
72
                name_ = "<" + std::string(name) + "> ";
73
            } else {
74
                name_ = "";
75
            }
76
            outdata_ = "";
77
        }
78
 
79
        // Fake IService method:
80
        virtual IFace *getInterface(const char *name) {
81
            if (strcmp(name, IFACE_RAW_LISTENER) == 0) {
82
                return static_cast<IRawListener *>(this);
83
            } else {
84
                return parent_->getInterface(name);
85
            }
86
        }
87
        // IRawListener
88
        virtual void updateData(const char *buf, int buflen) {
89
            if (!waitLine_) {
90
                outdata_ = name_ + std::string(buf);
91
                parent_->writeBuffer(outdata_.c_str());
92
                return;
93
            }
94
            for (int i = 0; i < buflen; i++) {
95
                if (buf[i] == '\r' || buf[i] == '\n') {
96
                    if (outdata_.size()) {
97
                            outdata_ = name_ + outdata_ + "\n";
98
                        parent_->writeBuffer(outdata_.c_str());
99
                    }
100
                    outdata_.clear();
101
                } else {
102
                    outdata_ += buf[i];
103
                }
104
            }
105
        }
106
 
107
    private:
108
        ConsoleService *parent_;
109
        std::string name_;
110
        std::string outdata_;
111
        bool waitLine_;
112
    };
113
 
114
private:
115
    AttributeType isEnable_;
116
    AttributeType stepQueue_;
117
    AttributeType autoComplete_;
118
    AttributeType commandExecutor_;
119
    AttributeType defaultLogFile_;
120
    AttributeType signals_;
121
    AttributeType inPort_;
122
 
123
    event_def config_done_;
124
    mutex_def mutexConsoleOutput_;
125
    IClock *iclk_;
126
    IAutoComplete *iautocmd_;
127
    ICmdExecutor *iexec_;
128
    ISourceCode *isrc_;
129
 
130
    RawPortType portSerial_;
131
 
132
    AttributeType cursor_;
133
    std::string cmdLine_;
134
    unsigned cmdSizePrev_;  // used to clear symbols if string shorter 
135
                            // than previous
136
 
137
#ifdef DBG_ZEPHYR
138
    int tst_cnt_;
139
#endif
140
#if defined(_WIN32) || defined(__CYGWIN__)
141
#else
142
    struct termios original_settings_;
143
    int term_fd_;
144
#endif
145
};
146
 
147
DECLARE_CLASS(ConsoleService)
148
 
149
}  // namespace debugger
150
 
151
#endif  // __DEBUGGER_CONSOLE_H__

powered by: WebSVN 2.1.0

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