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 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 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 4 sergeykhbr
    virtual void predeleteService();
33 3 sergeykhbr
 
34
    /** ISerial */
35
    virtual int writeData(const char *buf, int sz);
36
    virtual void registerRawListener(IFace *listener);
37
    virtual void unregisterRawListener(IFace *listener);
38 4 sergeykhbr
    virtual void getListOfPorts(AttributeType *list);
39
    virtual int openPort(const char *port, AttributeType settings);
40
    virtual void closePort();
41 3 sergeykhbr
 
42 4 sergeykhbr
    /** IRawListener (simulation only) */
43 3 sergeykhbr
    virtual void updateData(const char *buf, int buflen);
44
 
45
protected:
46
    /** IThread interface */
47
    virtual void busyLoop();
48
 
49
private:
50
    int readSerialPort(void *hdl, char *buf, int bufsz);
51
    int writeSerialPort(void *hdl, char *buf, int bufsz);
52
    void cleanSerialPort(void *hdl);
53
 
54
private:
55
    AttributeType isEnable_;
56
    AttributeType uartSim_;
57
    AttributeType logFile_;
58
    AttributeType comPortName_;
59
    AttributeType comPortSpeed_;
60
    AttributeType portListeners_;
61
 
62
    FILE *logfile_;
63
#if defined(_WIN32) || defined(__CYGWIN__)
64 4 sergeykhbr
    HANDLE prtHandler_;
65 3 sergeykhbr
#else
66 4 sergeykhbr
    int prtHandler_;
67 3 sergeykhbr
#endif
68
 
69
    bool isSimulation_;
70
    bool portOpened_;
71
    ISerial *iuartSim_;
72
 
73
    class SimpleFifoType {
74
    public:
75
        SimpleFifoType() {
76
            wr_ = &arr_[1];
77
            rd_ = &arr_[0];
78
        }
79
        bool isEmpty() {
80
            return ((wr_ - rd_) == 1)
81
                || (wr_ == arr_ && rd_ == &arr_[FIFO_SZ - 1]);
82
        }
83
        bool isFull() {
84
            return wr_ == rd_;
85
        }
86
        void put(char v) {
87
            if (isFull()) {
88
                return;
89
            }
90
            *wr_ = v;
91
            if ((++wr_) == &arr_[FIFO_SZ]) {
92
                wr_ = arr_;
93
            }
94
        }
95
        char get() {
96
            if (isEmpty()) {
97
                return 0;
98
            }
99
            if ((++rd_) == &arr_[FIFO_SZ]) {
100
                rd_ = arr_;
101
            }
102
            return *rd_;
103
        }
104
    private:
105
        static const int FIFO_SZ = 4096;
106
        char arr_[FIFO_SZ];
107
        char *rd_, *wr_;
108
    };
109
    SimpleFifoType txFifo_;
110
    SimpleFifoType rxFifo_;
111
    mutex_def mutexListeners_;
112
};
113
 
114
DECLARE_CLASS(ComPortService)
115
 
116
}  // namespace debugger
117
 
118
#endif  // __DEBUGGER_COMPORT_H__

powered by: WebSVN 2.1.0

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