38 #include <boost/static_assert.hpp> 39 #include <boost/thread/mutex.hpp> 40 #include <boost/thread.hpp> 63 this->page_ = page & 0xffff;
69 this->page_ = page & 0xffff;
75 this->page_ = (length-1) & 0xffff;
130 if (!readSpiEepromCmd(com, mbx, cmd))
132 ROS_ERROR(
"Error reading SPI Eeprom Cmd busy bit");
142 }
while (tries <= 10);
144 ROS_ERROR(
"Timed out waiting for SPI state machine to be idle (%d)", tries);
160 if (!waitForSpiEepromReady(com, mbx))
168 ROS_ERROR(
"Error writing SPI EEPROM command");
179 if (!readSpiEepromCmd(com, mbx, stat))
195 ROS_WARN(
"Eeprom state machine took %d cycles", tries);
200 fprintf(stderr,
"eeprom busy reading again, waiting...\n");
202 }
while (++tries < 10);
204 ROS_ERROR(
"Eeprom SPI state machine busy after %d cycles", tries);
225 boost::lock_guard<boost::mutex> lock(mutex_);
227 if (length > MAX_EEPROM_PAGE_SIZE)
229 ROS_ERROR(
"Eeprom read length %d > %d", length, MAX_EEPROM_PAGE_SIZE);
233 if (page >= NUM_EEPROM_PAGES)
235 ROS_ERROR(
"Eeprom read page %d > %d", page, NUM_EEPROM_PAGES-1);
242 memset(data,0,length);
245 ROS_ERROR(
"Error zeroing eeprom data buffer");
253 memset(&cmd,0,
sizeof(cmd));
255 if (!sendSpiEepromCmd(com, mbx, cmd))
257 ROS_ERROR(
"Error sending SPI read command");
267 ROS_ERROR(
"Error reading eeprom data from buffer");
291 boost::lock_guard<boost::mutex> lock(mutex_);
295 ROS_ERROR(
"Eeprom write length %d > %d", length, MAX_EEPROM_PAGE_SIZE);
299 if (page >= NUM_EEPROM_PAGES)
301 ROS_ERROR(
"Eeprom write page %d > %d", page, NUM_EEPROM_PAGES-1);
306 if (!waitForSpiEepromReady(com, mbx))
311 const void *write_buf = data;
314 uint8_t buf[MAX_EEPROM_PAGE_SIZE];
315 if (length < MAX_EEPROM_PAGE_SIZE)
317 memcpy(buf, data, length);
318 memset(buf+length, 0xFF, MAX_EEPROM_PAGE_SIZE-length);
325 ROS_ERROR(
"Write of SPI EEPROM buffer failed");
332 if (!sendSpiEepromCmd(com, mbx, cmd))
334 ROS_ERROR(
"Error giving SPI EEPROM write command");
339 if (!waitForEepromReady(com, mbx))
365 if (!readEepromStatusReg(com, mbx, status_reg))
374 }
while (++tries < 20);
378 ROS_ERROR(
"Eeprom still busy after %d cycles", tries);
384 ROS_WARN(
"EEPROM took %d cycles to be ready", tries);
410 unsigned char data[2] = {0xD7, 0x00};
411 BOOST_STATIC_ASSERT(
sizeof(data) == 2);
421 if (!sendSpiEepromCmd(com, mbx, cmd))
423 ROS_ERROR(
"Sending SPI abitrary command");
431 ROS_ERROR(
"Reading status register data from SPI buffer");
461 ROS_ERROR(
"Reading SPI command register with mailbox");
bool waitForEepromReady(EthercatCom *com, WGMailbox *mbx)
Waits for EEPROM to become ready.
bool sendSpiEepromCmd(EthercatCom *com, WGMailbox *mbx, const WG0XSpiEepromCmd &cmd)
Sends command to SPI EEPROM state machine.
static const unsigned SPI_WRITE_OP
bool readSpiEepromCmd(EthercatCom *com, WGMailbox *mbx, WG0XSpiEepromCmd &cmd)
Reads SPI state machine command register.
bool writeEepromPage(EthercatCom *com, WGMailbox *mbx, unsigned page, const void *data, unsigned length)
Write data to single eeprom page.
void build_arbitrary(unsigned length)
int writeMailbox(EthercatCom *com, unsigned address, void const *data, unsigned length)
Write data to WG0X local bus using mailbox communication.
bool readEepromPage(EthercatCom *com, WGMailbox *mbx, unsigned page, void *data, unsigned length)
Read data from single eeprom page.
void build_write(unsigned page)
void build_read(unsigned page)
static const unsigned SPI_ARBITRARY_OP
bool readEepromStatusReg(EthercatCom *com, WGMailbox *mbx, EepromStatusReg ®)
Reads EEPROM status register.
int readMailbox(EthercatCom *com, unsigned address, void *data, unsigned length)
Read data from WG0X local bus using mailbox communication.
union ethercat_hardware::WG0XSpiEepromCmd::@53 __attribute__
static const unsigned SPI_COMMAND_ADDR
bool waitForSpiEepromReady(EthercatCom *com, WGMailbox *mbx)
Waits for SPI eeprom state machine to be idle.
static const unsigned SPI_BUFFER_ADDR
static const unsigned SPI_READ_OP