pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


ecu-control debug patch
Posted by Anonymous on Tue 2nd Oct 2018 15:11
raw | new post

  1. diff --git a/ptxdist/local_src/ecu-control/ecuioanalog.cpp b/ptxdist/local_src/ecu-control/ecuioanalog.cpp
  2. index e3841ef..80c00e8 100644
  3. --- a/ptxdist/local_src/ecu-control/ecuioanalog.cpp
  4. +++ b/ptxdist/local_src/ecu-control/ecuioanalog.cpp
  5. @@ -30,6 +30,7 @@
  6.  
  7.  #include <stdio.h>
  8.  #include <unistd.h>
  9. +#include <errno.h>
  10.  #include <stdlib.h>
  11.  #include <fcntl.h>
  12.  #include <string.h>
  13. @@ -274,6 +275,7 @@ int EcuIOAnalog::writeOutChannel(const ECuParameter &parameters)
  14.  
  15.  int EcuIOAnalog::readChannelFromADS7953(int channel, unsigned long &ulValue)
  16.  {
  17. +ulValue = 0xDEADBEEF;
  18.     int iRet (RETCODE_OK);
  19.     int fd = -1;
  20.     char usChannel=0;
  21. @@ -282,6 +284,8 @@ int EcuIOAnalog::readChannelFromADS7953(int channel, unsigned long &ulValue)
  22.     unsigned char rd_buf[64];
  23.     unsigned short readChannel;
  24.     struct spi_ioc_transfer     xfer;
  25. +   int retSpiNum;
  26. +
  27.     memset(&xfer, 0, sizeof xfer);
  28.     memset(&wr_buf[0], 0, sizeof wr_buf);
  29.     memset(&rd_buf[0], 0, sizeof rd_buf);
  30. @@ -299,14 +303,30 @@ int EcuIOAnalog::readChannelFromADS7953(int channel, unsigned long &ulValue)
  31.        iRet =RETCODE_FILE_ACCESS_ERROR;
  32.     }
  33.     else{
  34. +#if 0 /* horrible debug code follows... */
  35. +uint8_t spimode = 0xDE;
  36. +retSpiNum = ioctl(fd, SPI_IOC_RD_MODE, &spimode);
  37. +if (retSpiNum != -1)
  38. +       (void)fprintf(stderr, "spi_mode=%d\n", (int)spimode);
  39. +else
  40. +       (void)fprintf(stderr, "SPI_IOC_RD_MODE failed, errno=%s\n", strerror(errno));
  41. +
  42. +spimode = SPI_MODE_3;
  43. +retSpiNum = ioctl(fd, SPI_IOC_WR_MODE, &spimode);
  44. +if (retSpiNum == -1)
  45. +       (void)fprintf(stderr, "SPI_IOC_WR_MODE failed, errno=%s\n", strerror(errno));
  46. +#endif
  47.  
  48.        xfer.tx_buf = (__u64)&wr_buf[0];
  49.        xfer.rx_buf = (__u64)&rd_buf[0];
  50.        xfer.len = 6;
  51.        xfer.cs_change = 0;
  52.        xfer.bits_per_word = 16;
  53. +#if 1
  54.        xfer.delay_usecs = 10;
  55. -
  56. +#else
  57. +      xfer.speed_hz = 20000000;
  58. +#endif
  59.        /* Mode control register
  60.         * D15-12 : 0001 selects manual mode
  61.         * D11    : 1    enable programming of bits D6-D0
  62. @@ -325,16 +345,40 @@ int EcuIOAnalog::readChannelFromADS7953(int channel, unsigned long &ulValue)
  63.        pUS = (unsigned short*)&wr_buf[0];
  64.        xfer.len = 6;
  65.        *pUS = 0x1800 | ( usChannel << 7 );
  66. +      
  67. +(void)fprintf(stderr, "wr_buf='");
  68. +for (unsigned int cn=0 ; cn < (xfer.len*2) ; cn++)
  69. +{
  70. +       (void)fprintf(stderr, "%2.2x ", (int)wr_buf[cn]);
  71. +}
  72. +(void)fprintf(stderr, "'\n");
  73.  
  74. -      ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
  75. +      errno=0;
  76. +      retSpiNum = ioctl(fd, SPI_IOC_MESSAGE(1), &xfer);
  77. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): retSpiNum=%d, should be 2!, strerror=%s\n",
  78. +       (int)retSpiNum,
  79. +       strerror(errno));
  80.  
  81. -      pUS = (unsigned short*)&rd_buf[4];
  82. +      pUS = (unsigned short*)&rd_buf[4]; // fixme: endian ?
  83.        readChannel = ( rd_buf[5] >> 4 );
  84. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): readChannel=%d\n, usChannel=%d\n",
  85. +       (int)readChannel,
  86. +       (int)usChannel);
  87. +
  88. +(void)fprintf(stderr, "rd_buf='");
  89. +for (int cn=0 ; cn < (retSpiNum*(16/8)) ; cn++)
  90. +{
  91. +       (void)fprintf(stderr, "%2.2x ", (int)rd_buf[cn]);
  92. +}
  93. +(void)fprintf(stderr, "'\n");
  94. +
  95.        if( readChannel == usChannel ){
  96. -         ulValue = (rd_buf[5] & 0x0f) << 8 | rd_buf[4];
  97. +         ulValue = ((long)(rd_buf[5] & 0x0f)) << 8L | ((long)rd_buf[4]);
  98.           iRet = RETCODE_OK;
  99. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): OK\n");
  100.        }
  101.        else{
  102. +(void)fprintf(stderr, "EcuIOAnalog::readChannelFromADS7953(): readChannel == usChannel failed\n");
  103.           iRet = RETCODE_GENERAL_ERROR;
  104.        }
  105.        close(fd);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at