@@ -36,6 +36,33 @@ extern void CDCSerial_Handler(void);
36
36
extern void serialEventRun1 (void ) __attribute__((weak));
37
37
extern void serialEvent1 (void ) __attribute__((weak));
38
38
39
+ static void cdc_mbox_isr (CurieMailboxMsg msg)
40
+ {
41
+ int new_head;
42
+ for (int i = 0 ; i < 4 ; i++)
43
+ {
44
+ uint32_t dword = msg.data [i];
45
+ for (int j = 0 ; j <4 ; j++)
46
+ {
47
+ if (((uint8_t )dword) != ' \0 ' )
48
+ {
49
+ new_head = (Serial._rx_buffer ->head +1 ) % CDCACM_BUFFER_SIZE;
50
+ if (new_head != Serial._rx_buffer ->tail )
51
+ {
52
+ Serial._rx_buffer ->data [Serial._rx_buffer ->head ] = (uint8_t )dword;
53
+ Serial._rx_buffer ->head = new_head;
54
+ }
55
+ }
56
+ else
57
+ {
58
+ i = 4 ;
59
+ break ;
60
+ }
61
+ dword = dword >> 8 ;
62
+ }
63
+ }
64
+ }
65
+
39
66
// Constructors ////////////////////////////////////////////////////////////////
40
67
41
68
CDCSerialClass::CDCSerialClass (uart_init_info *info)
@@ -47,9 +74,9 @@ CDCSerialClass::CDCSerialClass(uart_init_info *info)
47
74
48
75
void CDCSerialClass::setSharedData (struct cdc_acm_shared_data *cdc_acm_shared_data)
49
76
{
50
- this -> _shared_data = cdc_acm_shared_data;
51
- this -> _rx_buffer = cdc_acm_shared_data->rx_buffer ;
52
- this -> _tx_buffer = cdc_acm_shared_data->tx_buffer ;
77
+ _shared_data = cdc_acm_shared_data;
78
+ _rx_buffer = cdc_acm_shared_data->rx_buffer ;
79
+ _tx_buffer = cdc_acm_shared_data->tx_buffer ;
53
80
}
54
81
55
82
void CDCSerialClass::begin (const uint32_t dwBaudRate)
@@ -73,7 +100,9 @@ void CDCSerialClass::init(const uint32_t dwBaudRate, const uint8_t modeReg)
73
100
* Empty the Rx buffer but don't touch Tx buffer: it is drained by the
74
101
* LMT one way or another */
75
102
_rx_buffer->tail = _rx_buffer->head ;
76
-
103
+
104
+ mailbox_register (6 , cdc_mbox_isr);
105
+ mailbox_enable_receive (6 );
77
106
_shared_data->device_open = true ;
78
107
}
79
108
@@ -84,12 +113,10 @@ void CDCSerialClass::end( void )
84
113
85
114
int CDCSerialClass::available ( void )
86
115
{
87
- #define SBS CDCACM_BUFFER_SIZE
88
-
89
116
if (!_shared_data->device_open )
90
117
return (0 );
91
118
else
92
- return (int )(SBS + _rx_buffer->head - _rx_buffer->tail ) % SBS ;
119
+ return (int )(CDCACM_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail ) % CDCACM_BUFFER_SIZE ;
93
120
}
94
121
95
122
int CDCSerialClass::availableForWrite (void )
@@ -131,28 +158,16 @@ void CDCSerialClass::flush( void )
131
158
}
132
159
}
133
160
134
- size_t CDCSerialClass::write ( const uint8_t uc_data )
161
+ size_t CDCSerialClass::write (uint8_t uc_data )
135
162
{
136
- uint32_t retries = 2 ;
137
-
163
+ CurieMailboxMsg cdcacm_msg ;
164
+
138
165
if (!_shared_data->device_open || !_shared_data->host_open )
139
166
return (0 );
140
167
141
- do {
142
- int i = (uint32_t )(_tx_buffer->head + 1 ) % CDCACM_BUFFER_SIZE;
143
- // if we should be storing the received character into the location
144
- // just before the tail (meaning that the head would advance to the
145
- // current location of the tail), we're about to overflow the buffer
146
- // and so we don't write the character or advance the head.
147
- if (i != _tx_buffer->tail ) {
148
- _tx_buffer->data [_tx_buffer->head ] = uc_data;
149
- _tx_buffer->head = i;
150
-
151
- // Just use a fixed delay to make it compatible with the CODK-M based firmware
152
- delayMicroseconds (CDCACM_FIXED_DELAY);
153
- break ;
154
- }
155
- } while (retries--);
156
-
168
+ cdcacm_msg.channel = 7 ;
169
+ cdcacm_msg.data [0 ] = (uint32_t )uc_data;
170
+ mailbox_write (cdcacm_msg);
171
+ delayMicroseconds (_writeDelayUsec);
157
172
return 1 ;
158
173
}
0 commit comments