I am having trouble getting the SPI program I'm working on to behave correctly, and it seems to be a problem with the SPI_IOC_MESSAGE (N) macro.
Here's an example of code that DOES NOT work (ioctl returns EINVAL (22)):
std::vector<spi_ioc_transfer> tr;
<code that fills tr with 1+ transfers>
if (tr.size() > 0)
{
int ret = ioctl(fd, SPI_IOC_MESSAGE(tr.size()), tr.data());
if (ret < 1)
{
int err = errno;
}
}
My test code is now creating a vector of length 1. If I explicitly changed the code to:
int ret = ioctl(fd, SPI_IOC_MESSAGE( 1 ), tr.data());
... then ioctl (...) succeeds, and my bits go through the pipe. If you look at the macro extension SPI_IOC_MESSAGE in Eclipse, I don’t understand why this is not good.
Suggestions?
I cross-compile for Linux / ARM (Beaglebone Black) from a 64-bit Linux virtual machine, but I don’t see that this affects the macro.
EDIT: Here are two macro extensions from the C preprocessor
int ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((tr.size())*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((tr.size())*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), tr.data());
and the letter:
int ret = ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), tr.data());
, , tr.size() .
, ,
#ifdef __cplusplus
extern "C" {
#endif
#include <linux/spi/spidev.h>
#ifdef __cplusplus
}
#endif
linux SPI include "extern C" C, , , SPI_IOC_MESSAGE( tr.size() ) SPI_IOC_MESSAGE( an_int ) ( GDB ).