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

powered by: WebSVN 2.1.0

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