Skip to content

Commit 4e4638a

Browse files
committed
Fix BLE regression (receiving >64b data) after recent tweak to the input buffer
1 parent fa554c2 commit 4e4638a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/jsdevices.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,12 @@ void CALLED_FROM_INTERRUPT jshIOEventOverflowed() {
439439
/// Push an IO event (max IOEVENT_MAX_LEN) into the ioBuffer (designed to be called from IRQ), returns true on success, Calls jshHadEvent();
440440
bool CALLED_FROM_INTERRUPT jshPushEvent(IOEventFlags evt, uint8_t *data, unsigned int length) {
441441
assert(length<IOEVENT_MAX_LEN);
442-
if (length>IOEVENT_MAX_LEN) length=IOEVENT_MAX_LEN;
442+
if (length>IOEVENT_MAX_LEN) {
443+
#ifndef RELEASE
444+
jsiConsolePrintf("%d>IOEVENT_MAX_LEN\n", length);
445+
#endif
446+
length=IOEVENT_MAX_LEN;
447+
}
443448
/* We're disabling IRQs for this bit because it's actually quite likely for
444449
* USB and USART data to be coming in at the same time, and it can trip
445450
* things up if one IRQ interrupts another. */
@@ -496,8 +501,13 @@ void jshPushIOCharEvents(IOEventFlags channel, char *data, unsigned int count) {
496501
ioHead = (ioHead+1) & IOBUFFERMASK;
497502
}
498503
} else {
499-
// Push the event
500-
jshPushEvent(channel, (uint8_t*)data, count);
504+
// Push the event (split into IOEVENT_MAX_LEN chunks just in case)
505+
while (count) {
506+
unsigned int c = (count > IOEVENT_MAX_LEN) ? IOEVENT_MAX_LEN : count;
507+
jshPushEvent(channel, (uint8_t*)data, c);
508+
count -= c;
509+
data += c;
510+
}
501511
}
502512
// Set flow control (as we've just filled the buffer up more)
503513
if (DEVICE_HAS_DEVICE_STATE(channel) && jshGetEventsUsed() > IOBUFFER_XOFF)

src/jsdevices.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ typedef enum {
175175
#define IOEVENTFLAGS_GETTYPE(X) ((X)&EV_TYPE_MASK)
176176

177177
// maximum length for an event. BLE is the biggest event we have so deal with that if we need to
178-
#if NRF_BLE_MAX_MTU_SIZE>61
179-
#define IOEVENT_MAX_LEN (NRF_BLE_MAX_MTU_SIZE+3)
180-
#else
181178
#define IOEVENT_MAX_LEN 64
179+
#if defined(NRF_SDH_BLE_GATT_MAX_MTU_SIZE) && NRF_SDH_BLE_GATT_MAX_MTU_SIZE+3>IOEVENT_MAX_LEN
180+
#undef IOEVENT_MAX_LEN
181+
#define IOEVENT_MAX_LEN (NRF_SDH_BLE_GATT_MAX_MTU_SIZE+3)
182182
#endif
183183

184184
#include "jspin.h"

0 commit comments

Comments
 (0)