forked from EmbeddedRPC/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
erpc_usb_cdc_transport.hpp
128 lines (110 loc) · 3.82 KB
/
erpc_usb_cdc_transport.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright 2020 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_
#define _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_
#include "erpc_config_internal.h"
#include <cstdio>
#if !ERPC_THREADS_IS(NONE)
#include "erpc_threading.h"
#endif
#include "erpc_framed_transport.hpp"
extern "C" {
#include "fsl_component_serial_manager.h"
}
/*!
* @addtogroup USB_CDC_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Very basic transport to send/receive messages via virtual USB CDC port.
*
* @ingroup USB_CDC_transport
*/
class UsbCdcTransport : public FramedTransport
{
public:
/*!
* @brief Constructor.
*
* @param[in] serialHandle Pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE allocated by the
* caller, see serial manager header file.
* @param[in] serialConfig Pointer to user-defined configuration structure allocated by the caller, see serial
* manager header file.
* @param[in] usbCdcConfig Pointer to serial port usb config structure allocated by the caller, see serial manager
* header file.
* @param[in] usbRingBuffer Pointer to point serial manager ring buffer allocated by the caller, see serial manager
* header file.
* @param[in] usbRingBufferLength Serial manager ring buffer size.
*/
UsbCdcTransport(serial_handle_t serialHandle, serial_manager_config_t *serialConfig,
serial_port_usb_cdc_config_t *usbCdcConfig, uint8_t *usbRingBuffer, uint32_t usbRingBufferLength);
/*!
* @brief Destructor.
*/
virtual ~UsbCdcTransport(void);
/*!
* @brief Initialize USB CDC peripheral configuration structure with values specified in UsbCdcTransport
* constructor.
*
* @retval kErpcStatus_InitFailed When USB CDC init function failed.
* @retval kErpcStatus_Success When USB CDC init function was executed successfully.
*/
virtual erpc_status_t init(void);
/*!
* @brief Function called from Serial Manager Rx Callback to unblock the receive function
*
* Unblocks the receive function.
*/
void rx_cb(void);
/*!
* @brief Function called from Serial Manager Tx Callback to unblock the send function
*
* Unblocks the send function.
*/
void tx_cb(void);
protected:
#if !ERPC_THREADS_IS(NONE)
Semaphore m_rxSemaphore; /*!< Semaphore used by RTOS to block task until the receiving is not complete */
Semaphore m_txSemaphore; /*!< Semaphore used by RTOS to block task until the sending is not complete */
#endif
private:
serial_handle_t m_serialHandle;
serial_manager_config_t *m_serialConfig;
serial_port_usb_cdc_config_t *m_usbCdcConfig;
uint8_t *m_usbRingBuffer;
uint32_t m_usbRingBufferLength;
using FramedTransport::underlyingReceive;
using FramedTransport::underlyingSend;
/*!
* @brief Receive data from USB CDC peripheral.
*
* @param[inout] data Preallocated buffer for receiving data.
* @param[in] size Size of data to read.
*
* @retval kErpcStatus_ReceiveFailed USB CDC failed to receive data.
* @retval kErpcStatus_Success Successfully received all data.
*/
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
/*!
* @brief Write data to USB CDC peripheral.
*
* @param[in] data Buffer to send.
* @param[in] size Size of data to send.
*
* @retval kErpcStatus_Success Always returns success status.
*/
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;
};
} // namespace erpc
/*! @} */
#endif /* _EMBEDDED_RPC__USB_CDC_TRANSPORT_H_ */