Skip to content

Commit 3b138fb

Browse files
ConradBraamCruz Monrreal
authored andcommitted
Fix long writes/reads stack overflowing (ARMmbed#8802)
* writes and reads queue, not overflow stack IOTPAN-295
1 parent ecd1133 commit 3b138fb

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

TESTS/nfc/eeprom/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef enum {
6666
TERMINATE = 0xFF00
6767
} TestCommand_t;
6868

69-
/* We group the command based on their fist byte to simplify step checking.
69+
/* We group the command based on their first byte to simplify step checking.
7070
* Individual conditions of a step are checked in the event so this doesn't
7171
* sacrifice any correctness checking */
7272
const size_t TEST_COMMAND_GROUP_MASK = 0xFF00;
@@ -359,7 +359,7 @@ class DriverTest : public NFCEEPROMDriver::Delegate {
359359
_driver->write_bytes(_address, _operation_data, _operation_size);
360360
break;
361361
case ERASE_BYTES:
362-
_driver->erase_bytes(_address, 4);
362+
_driver->erase_bytes(_address, _operation_size);
363363
break;
364364
case READ_SIZE:
365365
_driver->read_size();

features/nfc/nfc/NFCEEPROM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class NFCEEPROM : public NFCTarget, public NFCEEPROMDriver::Delegate {
144144

145145
Delegate *_delegate;
146146
NFCEEPROMDriver *_driver;
147+
events::EventQueue *_event_queue;
147148
bool _initialized;
148149

149150
nfc_eeprom_operation_t _current_op;

features/nfc/source/nfc/NFCEEPROM.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace mbed;
2121
using namespace mbed::nfc;
2222

2323
NFCEEPROM::NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span<uint8_t> &ndef_buffer) : NFCTarget(ndef_buffer),
24-
_delegate(NULL), _driver(driver), _initialized(false), _current_op(nfc_eeprom_idle), _ndef_buffer_read_sz(0), _eeprom_address(0), _operation_result(NFC_ERR_UNKNOWN)
24+
_delegate(NULL), _driver(driver), _event_queue(queue), _initialized(false), _current_op(nfc_eeprom_idle), _ndef_buffer_read_sz(0), _eeprom_address(0), _operation_result(NFC_ERR_UNKNOWN)
2525
{
2626
_driver->set_delegate(this);
2727
_driver->set_event_queue(queue);
@@ -68,7 +68,6 @@ void NFCEEPROM::write_ndef_message()
6868

6969
// Reset EEPROM address
7070
_eeprom_address = 0;
71-
7271
// Go through the steps!
7372
_driver->start_session();
7473

@@ -87,7 +86,6 @@ void NFCEEPROM::read_ndef_message()
8786
}
8887
return;
8988
}
90-
9189
_current_op = nfc_eeprom_read_start_session;
9290

9391
// Reset EEPROM address
@@ -114,7 +112,6 @@ void NFCEEPROM::erase_ndef_message()
114112
}
115113
return;
116114
}
117-
118115
_current_op = nfc_eeprom_erase_start_session;
119116

120117
// Reset EEPROM address
@@ -230,7 +227,7 @@ void NFCEEPROM::on_bytes_read(size_t count)
230227
ac_buffer_builder_write_n_skip(buffer_builder, count);
231228

232229
// Continue reading
233-
continue_read();
230+
_event_queue->call(this, &NFCEEPROM::continue_read);
234231
break;
235232
}
236233
default:
@@ -254,7 +251,7 @@ void NFCEEPROM::on_bytes_written(size_t count)
254251
ac_buffer_read_n_skip(&_ndef_buffer_reader, count);
255252

256253
// Continue writing
257-
continue_write();
254+
_event_queue->call(this, &NFCEEPROM::continue_write);
258255
break;
259256
default:
260257
// Should not happen, state machine is broken or driver is doing something wrong
@@ -331,7 +328,7 @@ void NFCEEPROM::on_size_read(bool success, size_t size)
331328

332329
// Start reading bytes
333330
_current_op = nfc_eeprom_read_read_bytes;
334-
continue_read();
331+
_event_queue->call(this, &NFCEEPROM::continue_read);
335332
break;
336333
}
337334
default:
@@ -343,6 +340,7 @@ void NFCEEPROM::on_size_read(bool success, size_t size)
343340

344341
void NFCEEPROM::on_bytes_erased(size_t count)
345342
{
343+
346344
switch (_current_op) {
347345
case nfc_eeprom_erase_erase_bytes:
348346
if (count == 0) {
@@ -354,7 +352,7 @@ void NFCEEPROM::on_bytes_erased(size_t count)
354352
_eeprom_address += count;
355353

356354
// Continue erasing
357-
continue_erase();
355+
_event_queue->call(this, &NFCEEPROM::continue_erase);
358356
break;
359357
default:
360358
// Should not happen, state machine is broken or driver is doing something wrong

0 commit comments

Comments
 (0)