Software APIs
usbdev_serial.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 #ifndef OPENTITAN_SW_HOST_TESTS_USBDEV_USBDEV_STREAM_USBDEV_SERIAL_H_
5 #define OPENTITAN_SW_HOST_TESTS_USBDEV_USBDEV_STREAM_USBDEV_SERIAL_H_
6 #include "usbdev_stream.h"
7 
8 /**
9  * Bulk Transfer Stream over ttyUSBn serial connection using File Descriptors.
10  */
11 class USBDevSerial : public USBDevStream {
12  public:
13  USBDevSerial(unsigned id, uint32_t transfer_bytes, bool retrieve, bool check,
14  bool send, bool verbose)
15  : USBDevStream(id, transfer_bytes, retrieve, check, send, verbose) {}
16  ~USBDevSerial();
17 
18  /**
19  * Open the input and output ports to the board/device for this stream.
20  *
21  * @param in_name Device name of input serial port.
22  * @param out_name Device name of output serial port.
23  * @return true iff successful.
24  */
25  bool Open(const char *in_name, const char *out_name);
26  /**
27  * Finalize the stream, prior to shutting down.
28  */
29  virtual void Stop();
30  /**
31  * Pause the stream, prior to suspending the device.
32  */
33  virtual void Pause();
34  /**
35  * Resume stremaing.
36  */
37  virtual bool Resume();
38  /**
39  * Return a summary report of the stream settings or status.
40  *
41  * @param status Indicates whether settings or status requested.
42  * @param verbose true iff a more verbose report is required.
43  * @return Status report
44  */
45  virtual std::string Report(bool status = false, bool verbose = false) const;
46  /**
47  * Service this serial stream.
48  *
49  * @return true iff the stream is still operational.
50  */
51  virtual bool Service();
52 
53  private:
54  /**
55  * Retrieving of IN traffic from device.
56  *
57  * @return true iff the stream is still operational.
58  */
59  bool ServiceIN();
60  /**
61  * Sending of OUT traffic to device.
62  *
63  * @return true iff the stream is still operational.
64  */
65  bool ServiceOUT();
66  /**
67  * Open the input and output ports for this stream.
68  *
69  * @return true iff opened successfully.
70  */
71  bool OpenPorts();
72 
73  // Input port handle.
74  int in_;
75 
76  // Output port handle.
77  int out_;
78 
79  // Input port name.
80  std::string inPort_;
81 
82  // Output port name.
83  std::string outPort_;
84 
85  // Stream signature.
86  // Note: this is constructed piecemeal as the bytes are received from the
87  // device.
88  usbdev_stream_sig_t sig_;
89 };
90 
91 #endif // OPENTITAN_SW_HOST_TESTS_USBDEV_USBDEV_STREAM_USBDEV_SERIAL_H_