JM9 XRCU Board 0.1.3a
Libraries API Reference
Loading...
Searching...
No Matches
VirtIOSerial.h
1
23
24#ifndef _VIRTIOSERIAL_H_
25#define _VIRTIOSERIAL_H_
26
27#if defined (VIRTIOCON)
28#include "Stream.h"
29#include "openamp.h"
30#include "wiring.h"
31#include "virtio_buffer.h"
32
33//================================================================================
34// Serial over OpenAMP
35
36// This structure is used to be able to get VirtIOSerial instance (C++ class)
37// from handler (C structure) specially for rpmsg message management
38typedef struct {
39 // Those 2 first fields must remain in this order at the beginning of the structure
40 void *__this;
41 VIRT_UART_HandleTypeDef handle;
42 bool initialized;
43 bool first_message_discarded;
44 virtio_buffer_t ring;
45} VirtIOSerialObj_t;
46
47
48class VirtIOSerial : public Stream {
49 public:
50 void begin(void);
51 void begin(uint32_t);
52 void begin(uint32_t, uint8_t);
53 void end(void);
54
55 virtual int available(void);
56 virtual int availableForWrite(void);
57 virtual int peek(void);
58 virtual int read(void);
59 virtual size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer
60 virtual size_t write(uint8_t);
61 virtual size_t write(const uint8_t *buffer, size_t size);
62 virtual void flush(void);
63
64 static void rxGenericCallback(VIRT_UART_HandleTypeDef *huart);
65 void rxCallback(VIRT_UART_HandleTypeDef *huart);
66
67 using Print::write; // pull in write(str) from Print
68 operator bool(void)
69 {
70 return true;
71 }
72
73 private:
74 static uint32_t VirtIOSerial_index;
75 VirtIOSerialObj_t _VirtIOSerialObj;
76 void checkMessageFromISR(void);
77};
78
79extern VirtIOSerial SerialVirtIO;
80
81#endif /* VIRTIOCON */
82#endif /* _VIRTIOSERIAL_H_ */
Definition Stream.h:49