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/third_party/allwpilib/hal/src/main/native/athena/SPI.cpp b/third_party/allwpilib/hal/src/main/native/athena/SPI.cpp
index 37c5f0e..977d447 100644
--- a/third_party/allwpilib/hal/src/main/native/athena/SPI.cpp
+++ b/third_party/allwpilib/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;
}
diff --git a/third_party/allwpilib/wpilibc/src/main/native/include/frc/SPI.h b/third_party/allwpilib/wpilibc/src/main/native/include/frc/SPI.h
index 8e721bc..9bc9564 100644
--- a/third_party/allwpilib/wpilibc/src/main/native/include/frc/SPI.h
+++ b/third_party/allwpilib/wpilibc/src/main/native/include/frc/SPI.h
@@ -166,10 +166,10 @@
/**
* Set the data to be transmitted by the engine.
*
- * Up to 16 bytes are configurable, and may be followed by up to 127 zero
+ * Up to 23 bytes are configurable, and may be followed by up to 127 zero
* bytes.
*
- * @param dataToSend data to send (maximum 16 bytes)
+ * @param dataToSend data to send (maximum 23 bytes)
* @param zeroSize number of zeros to send after the data
*/
void SetAutoTransmitData(wpi::ArrayRef<uint8_t> dataToSend, int zeroSize);