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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [comport/] [comport.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 comport class declaration.
6
 */
7
 
8
#ifndef __DEBUGGER_COMPORT_H__
9
#define __DEBUGGER_COMPORT_H__
10
 
11
#include "iclass.h"
12
#include "iservice.h"
13
#include "coreservices/ithread.h"
14
#include "coreservices/iserial.h"
15
#include "coreservices/irawlistener.h"
16
#include <string>
17
//#define DBG_ZEPHYR
18
 
19
 
20
namespace debugger {
21
 
22
class ComPortService : public IService,
23
                       public IThread,
24
                       public ISerial,
25
                       public IRawListener {
26
public:
27
    explicit ComPortService(const char *name);
28
    virtual ~ComPortService();
29
 
30
    /** IService interface */
31
    virtual void postinitService();
32
 
33
    /** ISerial */
34
    virtual int writeData(const char *buf, int sz);
35
    virtual void registerRawListener(IFace *listener);
36
    virtual void unregisterRawListener(IFace *listener);
37
 
38
    /** IRawListener */
39
    virtual void updateData(const char *buf, int buflen);
40
 
41
protected:
42
    /** IThread interface */
43
    virtual void busyLoop();
44
 
45
private:
46
    void getSerialPortList(AttributeType *list);
47
    int openSerialPort(const char *port, int baud, void *hdl);
48
    void closeSerialPort(void *hdl);
49
    int readSerialPort(void *hdl, char *buf, int bufsz);
50
    int writeSerialPort(void *hdl, char *buf, int bufsz);
51
    void cleanSerialPort(void *hdl);
52
 
53
private:
54
    AttributeType isEnable_;
55
    AttributeType uartSim_;
56
    AttributeType logFile_;
57
    AttributeType comPortName_;
58
    AttributeType comPortSpeed_;
59
    AttributeType portListeners_;
60
 
61
    FILE *logfile_;
62
#if defined(_WIN32) || defined(__CYGWIN__)
63
    HANDLE hPort_;
64
#else
65
    int hPort_;
66
#endif
67
 
68
    bool isSimulation_;
69
    bool portOpened_;
70
    ISerial *iuartSim_;
71
 
72
    class SimpleFifoType {
73
    public:
74
        SimpleFifoType() {
75
            wr_ = &arr_[1];
76
            rd_ = &arr_[0];
77
        }
78
        bool isEmpty() {
79
            return ((wr_ - rd_) == 1)
80
                || (wr_ == arr_ && rd_ == &arr_[FIFO_SZ - 1]);
81
        }
82
        bool isFull() {
83
            return wr_ == rd_;
84
        }
85
        void put(char v) {
86
            if (isFull()) {
87
                return;
88
            }
89
            *wr_ = v;
90
            if ((++wr_) == &arr_[FIFO_SZ]) {
91
                wr_ = arr_;
92
            }
93
        }
94
        char get() {
95
            if (isEmpty()) {
96
                return 0;
97
            }
98
            if ((++rd_) == &arr_[FIFO_SZ]) {
99
                rd_ = arr_;
100
            }
101
            return *rd_;
102
        }
103
    private:
104
        static const int FIFO_SZ = 4096;
105
        char arr_[FIFO_SZ];
106
        char *rd_, *wr_;
107
    };
108
    SimpleFifoType txFifo_;
109
    SimpleFifoType rxFifo_;
110
    mutex_def mutexListeners_;
111
};
112
 
113
DECLARE_CLASS(ComPortService)
114
 
115
}  // namespace debugger
116
 
117
#endif  // __DEBUGGER_COMPORT_H__

powered by: WebSVN 2.1.0

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