Fix bounds of SPI AutoRead sizes
The comment matches the code now.
Also, the previous max-allowed size would result in writing to invalid
locations in the FPGA and then telling it a size of 0.
Change-Id: Ic97f5f6713a6cc253dc4ba6df39570b324cbd99c
diff --git a/hal/src/main/native/athena/SPI.cpp b/hal/src/main/native/athena/SPI.cpp
index 37c5f0e..977d447 100644
--- a/hal/src/main/native/athena/SPI.cpp
+++ b/hal/src/main/native/athena/SPI.cpp
@@ -565,12 +565,18 @@
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
int32_t dataSize, int32_t zeroSize,
int32_t* status) {
- if (dataSize < 0 || dataSize > 32) {
+ static_assert(tSPI::kNumAutoTxRegisters >= 6,
+ "FPGA does not have enough tx registers");
+ static_assert(tSPI::kNumAutoTxElements == 4,
+ "FPGA has the wrong number of tx elements");
+ // 24 = 6 * 4, but the documentation needs updating if it ever changes, so
+ // just hard-code it here.
+ if (dataSize < 0 || dataSize > 23) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}
- if (zeroSize < 0 || zeroSize > 127) {
+ if (zeroSize < 0 || zeroSize >= 128) {
*status = PARAMETER_OUT_OF_RANGE;
return;
}