Rewrite buffer related stuff to avoid weird stack overflow(?) issues

This commit is contained in:
Lexi / Zoe 2021-04-17 17:40:56 +02:00
parent d898f6e518
commit b5c5fd4ede
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
6 changed files with 33 additions and 44 deletions

View file

@ -103,14 +103,12 @@ void commandRead(char* arg) {
uartPutLine("OK");
uint8_t byteBuffer[DATA_BLOCK_SIZE];
DataBuffer buffer = {
.data = byteBuffer,
.maxSize = DATA_BLOCK_SIZE,
.bytes = 0
};
// Create data buffer
DataBuffer buffer;
do {
buffer.bytes = 0;
// Read a single block with up to DATA_BLOCK_SIZE bytes
Address nextAddress = eepromReadBlock(range, &buffer);
range.isValid = nextAddress.isValid;
@ -121,16 +119,16 @@ void commandRead(char* arg) {
// First the size of the package (1 byte) followed by the data bytes
uartPutChar(buffer.bytes);
for (int i = 0; i < buffer.bytes; i++) {
for (uint8_t i = 0; i < buffer.bytes; i++) {
uartPutChar(buffer.data[i]);
}
} else {
// Fancy ASCII output
uartPutChar('<');
uartPutInteger(buffer.bytes);
uartPutString("<0x");
uartPutHexByte(buffer.bytes);
uartPutChar('>');
for (int i = 0; i < buffer.bytes; i++) {
for (uint8_t i = 0; i < buffer.bytes; i++) {
uartPutChar(' ');
uartPutHexByte(buffer.data[i]);
}
@ -159,17 +157,12 @@ void commandWrite(char* arg) {
return;
}
// Create data buffer
uint8_t byteBuffer[DATA_BLOCK_SIZE];
DataBuffer buffer = {
.data = byteBuffer,
.maxSize = DATA_BLOCK_SIZE,
.bytes = 0
};
// "OK" indicates that data can be sent now.
uartPutLine("OK START");
// Create data buffer
DataBuffer buffer;
Address currentAddress = startAddress;
uint8_t block_length = 0;
@ -180,10 +173,8 @@ void commandWrite(char* arg) {
// Read and check block length
block_length = uartGetChar();
if (block_length > buffer.maxSize) {
uartPutString("ERROR maximal block size is: ");
uartPutInteger(buffer.maxSize);
uartPutLine(NULL);
if (block_length > DATA_BLOCK_SIZE) {
uartPutLine("ERROR maximal block size is: " STR(DATA_BLOCK_SIZE));
return;
}
@ -196,9 +187,6 @@ void commandWrite(char* arg) {
if (buffer.bytes > 0) {
currentAddress = eepromWriteBlock(currentAddress, buffer);
// TODO wait necessary?
//_delay_ms(100);
if (!currentAddress.isValid) {
uartPutLine("ERROR reached end of EEPROM while writing block");
return;