Skip to content

Commit 13e54b0

Browse files
committed
Try to read and send the requested data in chunks
1 parent dbf0b19 commit 13e54b0

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

main.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,33 +196,30 @@ static void command_loop(void)
196196
uint32_t slen, rlen;
197197
readbytes_blocking(&slen, 3); // Read send length
198198
readbytes_blocking(&rlen, 3); // Read receive length
199-
slen &= 0x00FFFFFF; // Mask to use only the lower 24 bits
200-
rlen &= 0x00FFFFFF; // Mask to use only the lower 24 bits
199+
slen &= 0x00FFFFFF; // Ensure it's treated as 24-bit value
200+
rlen &= 0x00FFFFFF; // Ensure it's treated as 24-bit value
201201

202202
uint8_t tx_buffer[MAX_BUFFER_SIZE]; // Buffer for transmit data
203203
uint8_t rx_buffer[MAX_BUFFER_SIZE]; // Buffer for receive data
204204

205-
// Read data to be sent (if slen > 0)
205+
// Handling send operation
206206
if (slen > 0) {
207207
readbytes_blocking(tx_buffer, slen);
208208
cs_select(SPI_CS);
209209
spi_write_blocking(SPI_IF, tx_buffer, slen);
210210
cs_deselect(SPI_CS);
211211
}
212212

213-
// Send ACK after handling slen (before reading)
213+
// Send ACK after write operation
214214
sendbyte_blocking(S_ACK);
215215

216-
// Handle receive operation in chunks
217-
while (rlen > 0) {
218-
uint32_t chunk_size = (rlen < MAX_BUFFER_SIZE) ? rlen : MAX_BUFFER_SIZE;
219-
216+
// Handling receive operation
217+
if (rlen > 0) {
220218
cs_select(SPI_CS);
221-
spi_read_blocking(SPI_IF, 0, rx_buffer, chunk_size);
219+
spi_read_blocking(SPI_IF, 0, rx_buffer, rlen);
222220
cs_deselect(SPI_CS);
223221

224-
sendbytes_blocking(rx_buffer, chunk_size);
225-
rlen -= chunk_size;
222+
sendbytes_blocking(rx_buffer, rlen);
226223
}
227224

228225
break;

0 commit comments

Comments
 (0)