Fix long writes/reads stack overflowing (#8802)

* writes and reads queue, not overflow stack IOTPAN-295
pull/9101/head
Conrad Braam 2018-12-14 00:18:01 +00:00 committed by Cruz Monrreal
parent ecd1133baf
commit 3b138fba02
3 changed files with 9 additions and 10 deletions

View File

@ -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;
@ -359,7 +359,7 @@ public:
_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();

View File

@ -144,6 +144,7 @@ private:
Delegate *_delegate;
NFCEEPROMDriver *_driver;
events::EventQueue *_event_queue;
bool _initialized;
nfc_eeprom_operation_t _current_op;

View File

@ -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);
@ -68,7 +68,6 @@ void NFCEEPROM::write_ndef_message()
// Reset EEPROM address
_eeprom_address = 0;
// Go through the steps!
_driver->start_session();
@ -87,7 +86,6 @@ void NFCEEPROM::read_ndef_message()
}
return;
}
_current_op = nfc_eeprom_read_start_session;
// Reset EEPROM address
@ -114,7 +112,6 @@ void NFCEEPROM::erase_ndef_message()
}
return;
}
_current_op = nfc_eeprom_erase_start_session;
// Reset EEPROM address
@ -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:
@ -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
@ -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:
@ -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) {
@ -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