Skip to content

Fix long writes/reads stack overflowing #8802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TESTS/nfc/eeprom/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef enum {
TERMINATE = 0xFF00
} TestCommand_t;

/* We group the command based on their fist byte to simplify step checking.
/* We group the command based on their first byte to simplify step checking.
* Individual conditions of a step are checked in the event so this doesn't
* sacrifice any correctness checking */
const size_t TEST_COMMAND_GROUP_MASK = 0xFF00;
Expand Down Expand Up @@ -359,7 +359,7 @@ class DriverTest : public NFCEEPROMDriver::Delegate {
_driver->write_bytes(_address, _operation_data, _operation_size);
break;
case ERASE_BYTES:
_driver->erase_bytes(_address, 4);
_driver->erase_bytes(_address, _operation_size);
break;
case READ_SIZE:
_driver->read_size();
Expand Down
1 change: 1 addition & 0 deletions features/nfc/nfc/NFCEEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class NFCEEPROM : public NFCTarget, public NFCEEPROMDriver::Delegate {

Delegate *_delegate;
NFCEEPROMDriver *_driver;
events::EventQueue *_event_queue;
bool _initialized;

nfc_eeprom_operation_t _current_op;
Expand Down
14 changes: 6 additions & 8 deletions features/nfc/source/nfc/NFCEEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace mbed;
using namespace mbed::nfc;

NFCEEPROM::NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span<uint8_t> &ndef_buffer) : NFCTarget(ndef_buffer),
_delegate(NULL), _driver(driver), _initialized(false), _current_op(nfc_eeprom_idle), _ndef_buffer_read_sz(0), _eeprom_address(0), _operation_result(NFC_ERR_UNKNOWN)
_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)
{
_driver->set_delegate(this);
_driver->set_event_queue(queue);
Expand Down Expand Up @@ -68,7 +68,6 @@ void NFCEEPROM::write_ndef_message()

// Reset EEPROM address
_eeprom_address = 0;

// Go through the steps!
_driver->start_session();

Expand All @@ -87,7 +86,6 @@ void NFCEEPROM::read_ndef_message()
}
return;
}

_current_op = nfc_eeprom_read_start_session;

// Reset EEPROM address
Expand All @@ -114,7 +112,6 @@ void NFCEEPROM::erase_ndef_message()
}
return;
}

_current_op = nfc_eeprom_erase_start_session;

// Reset EEPROM address
Expand Down Expand Up @@ -230,7 +227,7 @@ void NFCEEPROM::on_bytes_read(size_t count)
ac_buffer_builder_write_n_skip(buffer_builder, count);

// Continue reading
continue_read();
_event_queue->call(this, &NFCEEPROM::continue_read);
break;
}
default:
Expand All @@ -254,7 +251,7 @@ void NFCEEPROM::on_bytes_written(size_t count)
ac_buffer_read_n_skip(&_ndef_buffer_reader, count);

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

// Start reading bytes
_current_op = nfc_eeprom_read_read_bytes;
continue_read();
_event_queue->call(this, &NFCEEPROM::continue_read);
break;
}
default:
Expand All @@ -343,6 +340,7 @@ void NFCEEPROM::on_size_read(bool success, size_t size)

void NFCEEPROM::on_bytes_erased(size_t count)
{

switch (_current_op) {
case nfc_eeprom_erase_erase_bytes:
if (count == 0) {
Expand All @@ -354,7 +352,7 @@ void NFCEEPROM::on_bytes_erased(size_t count)
_eeprom_address += count;

// Continue erasing
continue_erase();
_event_queue->call(this, &NFCEEPROM::continue_erase);
break;
default:
// Should not happen, state machine is broken or driver is doing something wrong
Expand Down