@@ -136,20 +136,24 @@ void HCIClass::poll(unsigned long timeout)
136136 HCITransport.wait (timeout);
137137 }
138138
139+ HCITransport.lockForRead ();
139140 while (HCITransport.available ()) {
140141 byte b = HCITransport.read ();
141142
142143 if (_recvIndex >= (int )sizeof (_recvBuffer)) {
143144 _recvIndex = 0 ;
144145 if (_debug) {
146+ HCITransport.unlockForRead ();
145147 _debug->println (" _recvBuffer overflow" );
148+ HCITransport.lockForRead ();
146149 }
147150 }
148151
149152 _recvBuffer[_recvIndex++] = b;
150153
151154 if (_recvBuffer[0 ] == HCI_ACLDATA_PKT) {
152155 if (_recvIndex > 5 && _recvIndex >= (5 + (_recvBuffer[3 ] + (_recvBuffer[4 ] << 8 )))) {
156+ HCITransport.unlockForRead ();
153157 if (_debug) {
154158 dumpPkt (" HCI ACLDATA RX <- " , _recvIndex, _recvBuffer);
155159 }
@@ -164,9 +168,11 @@ void HCIClass::poll(unsigned long timeout)
164168#ifdef ARDUINO_AVR_UNO_WIFI_REV2
165169 digitalWrite (NINA_RTS, LOW);
166170#endif
171+ HCITransport.lockForRead ();
167172 }
168173 } else if (_recvBuffer[0 ] == HCI_EVENT_PKT) {
169174 if (_recvIndex > 3 && _recvIndex >= (3 + _recvBuffer[2 ])) {
175+ HCITransport.unlockForRead ();
170176 if (_debug) {
171177 dumpPkt (" HCI EVENT RX <- " , _recvIndex, _recvBuffer);
172178 }
@@ -182,19 +188,23 @@ void HCIClass::poll(unsigned long timeout)
182188#ifdef ARDUINO_AVR_UNO_WIFI_REV2
183189 digitalWrite (NINA_RTS, LOW);
184190#endif
191+ HCITransport.lockForRead ();
185192 }
186193 } else {
187194 _recvIndex = 0 ;
188195
189196 if (_debug) {
197+ HCITransport.unlockForRead ();
190198 _debug->println (b, HEX);
199+ HCITransport.lockForRead ();
191200 }
192201 }
193202 }
194203
195204#ifdef ARDUINO_AVR_UNO_WIFI_REV2
196205 digitalWrite (NINA_RTS, HIGH);
197206#endif
207+ HCITransport.unlockForRead ();
198208}
199209
200210int HCIClass::reset ()
0 commit comments