pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


jncg-ecu_control-TLE82353_C11_workaround20181018
Posted by Anonymous on Thu 18th Oct 2018 16:10
raw | new post

  1. diff --git a/ptxdist/local_src/common/hw/tle82353sa.cpp b/ptxdist/local_src/common/hw/tle82353sa.cpp
  2. index 35720a9..44ba8d9 100644
  3. --- a/ptxdist/local_src/common/hw/tle82353sa.cpp
  4. +++ b/ptxdist/local_src/common/hw/tle82353sa.cpp
  5. @@ -151,6 +151,19 @@ bool TLE82353SA::readRegister(int hdl, unsigned char adr, unsigned long &value)
  6.     return bRet;
  7.  }
  8.  
  9. +bool TLE82353SA::readICVersion(int hdl, unsigned long &value)
  10. +{
  11. +       bool            bRet;
  12. +       unsigned long   regvalue;
  13. +
  14. +       bRet = readRegister(hdl, REGISTER_ICVID, regvalue);
  15. +       if (bRet)
  16. +       {
  17. +               value = TLE82353SA_GET_IC_VERSION(regvalue);
  18. +       }
  19. +       return bRet;
  20. +}
  21. +
  22.  bool TLE82353SA::initTLE( int hdl, unsigned long clkDividervalue, bool includeClkDivider, bool resetDiagRegister )
  23.  {
  24.  
  25. diff --git a/ptxdist/local_src/common/hw/tle82353sa.h b/ptxdist/local_src/common/hw/tle82353sa.h
  26. index 4b0ea77..1da9929 100644
  27. --- a/ptxdist/local_src/common/hw/tle82353sa.h
  28. +++ b/ptxdist/local_src/common/hw/tle82353sa.h
  29. @@ -59,6 +59,10 @@ TLE82353SA
  30.   */
  31.  #define TLE82353SA_MASKED_RESET_VALUE  0x00C10000
  32.  #define TLE82353SA_IC_VERSION_MASK     0x0000FF00
  33. +#define TLE82353SA_IC_VERSION_SHIFT    (8)
  34. +
  35. +#define TLE82353SA_GET_IC_VERSION(regval) \
  36. +       (((regval) & TLE82353SA_IC_VERSION_MASK) >> TLE82353SA_IC_VERSION_SHIFT)
  37.  #define TLE82353SA_RESET_VALUE_OK(regval) \
  38.         (((regval) & ~TLE82353SA_IC_VERSION_MASK) == TLE82353SA_MASKED_RESET_VALUE)
  39.  
  40. @@ -123,6 +127,14 @@ public:
  41.     static bool readRegister( int hdl, unsigned char adr, unsigned long &value );
  42.  
  43.     /**
  44. +    * @brief readICVersion get IC version (see TLE82453 Data Sheet (Rev 1.0, 2015-03-27), page 53) from hardware
  45. +    * @param hdl ready opened filehandle to SPIDEV file
  46. +    * @param value Reference to where the result should be stored
  47. +    * @return true on sucess
  48. +    */
  49. +   static bool readICVersion( int hdl, unsigned long &value );
  50. +
  51. +   /**
  52.      * @brief initTLE initialize the tle
  53.      * @param hdl ready opened filehandle to SPIDEV file
  54.      * @return true on success
  55. diff --git a/ptxdist/local_src/ecu-control/ecutle.cpp b/ptxdist/local_src/ecu-control/ecutle.cpp
  56. index 814af70..c8d192e 100644
  57. --- a/ptxdist/local_src/ecu-control/ecutle.cpp
  58. +++ b/ptxdist/local_src/ecu-control/ecutle.cpp
  59. @@ -43,6 +43,121 @@
  60.  /*    here: Defines                                                          */
  61.  /*****************************************************************************/
  62.  
  63. +#define WORKAROUND_TLE82353SA_C11_FUNCTION_CHANGE 1
  64. +
  65. +/*****************************************************************************/
  66. +/*    here: Utility functions                                                */
  67. +/*****************************************************************************/
  68. +
  69. +static
  70. +bool fixUpTLEReg(int tle_fd, unsigned long adr, unsigned long& value)
  71. +{
  72. +#if WORKAROUND_TLE82353SA_C11_FUNCTION_CHANGE
  73. +/*
  74. + * Workaround for a functional change in the TLE82353SA between chip version
  75. + * B13 and chip version C11.
  76. + *
  77. + * In version C11 the "Current FB" value (bits 23:12) of registers 0x40, 0x41
  78. + * and 0x41 needs to be multiplied by factor 2 compared to the older chip
  79. + * version B13.
  80. + *
  81. + * Fortunately the chip version can be extracted (at the cost of extra SPI bus
  82. + * traffic, if not cached "somewhere") and used to distinguish between both
  83. + * versions.
  84. + *
  85. + * ** Test sequence:
  86. + * -- snip --
  87. + * # activate hardware safety (must run (="toggle") in the background
  88. + * # during the whole test!)
  89. + * ecu-control --safety wdt 800000 &
  90. + * # enable TLE
  91. + * ecu-control --io wdo 46 0
  92. + * # enable power
  93. + * ecu-control --io wao 1 800
  94. + *
  95. + * # after that it should be possible to read the power value back via
  96. + * ecu-control --tle read 0x40
  97. + * -- snip --
  98. + *
  99. + * Expected value should be around "0x0018c0f8".
  100. + *
  101. + */
  102. +       bool            retval = false;
  103. +       unsigned long   tle_version = 0xDEADBEEF;
  104. +
  105. +       switch(adr)
  106. +       {
  107. +               case 0x40:
  108. +               case 0x41:
  109. +               case 0x42:
  110. +                       if (!TLE82353SA::readICVersion(tle_fd, tle_version))
  111. +                       {
  112. +                               (void)fprintf(stderr, "WARNING: EcuTle::readRegister: could not read TLE version, ucAdr=%x\n", (int)adr);
  113. +                               return false;
  114. +                       }
  115. +
  116. +                       switch(tle_version)
  117. +                       {
  118. +                               case 4: /* B13 step = 00000100 */
  119. +                                       retval = true;
  120. +                                       break;
  121. +                               case 6: /* C11 step = 00000110 */
  122. +                               {
  123. +#define TLE_CURRENT_FB_MASK    (0x00FFF000UL)
  124. +#define TLE_CURRENT_FB_SHIFT   (12)
  125. +                                       unsigned long tmpval;
  126. +                                       /*
  127. +                                        * fetch bits 12-23 (counting from 0) for "Current FB" and
  128. +                                        * move them to the lower bits...
  129. +                                        */
  130. +                                       tmpval = (value & TLE_CURRENT_FB_MASK) >> TLE_CURRENT_FB_SHIFT;
  131. +
  132. +                                       /*
  133. +                                        * ... then multiply the value by 2 (and complain if
  134. +                                        * the result gets too large to fit into 12 bits;
  135. +                                        * pow(2,12)-1==0xFFF) ...
  136. +                                        */
  137. +                                       tmpval *= 2;
  138. +                                       if (tmpval > 0xFFF)
  139. +                                       {
  140. +                                               (void)fprintf(stderr, "fixUpTLEReg: value cutoff at 0xFFF %lx\n", tmpval);
  141. +                                               tmpval = 0xFFF;
  142. +                                               retval = false;
  143. +                                       }
  144. +                                       else
  145. +                                       {
  146. +                                               retval = true;
  147. +                                       }
  148. +
  149. +                                       /*
  150. +                                        * ... and then shift the bits back into their place and into
  151. +                                        * the value we wish to return.
  152. +                                        */
  153. +                                       value &= ~TLE_CURRENT_FB_MASK;
  154. +                                       value |= (tmpval << TLE_CURRENT_FB_SHIFT) & TLE_CURRENT_FB_MASK;
  155. +                               }
  156. +                                       break;
  157. +                               default:
  158. +                                       (void)fprintf(stderr, "EcuTle::readRegister: unknown TLE version %lx, no fixup done, ucAdr=%x, value=%lx\n",
  159. +                                               tle_version,
  160. +                                               (int)adr,
  161. +                                               (unsigned long)value);
  162. +                                       retval = false;
  163. +                                       break;
  164. +                       }
  165. +                       break;
  166. +               default:
  167. +                       retval = true;
  168. +                       break;
  169. +       }
  170. +
  171. +       return retval;
  172. +#else
  173. +       return true;
  174. +#endif /* WORKAROUND_TLE82353SA_C11_FUNCTION_CHANGE */
  175. +}
  176. +
  177. +
  178.  /*****************************************************************************/
  179.  /*    here: Classes                                                          */
  180.  /*****************************************************************************/
  181. @@ -97,7 +212,10 @@ int EcuTle::execute_special(int iChannel, unsigned long& ulValue)
  182.         /* initialized before */
  183.         ok = TLE82353SA::readRegister( fd, ucCmd, ulValue);
  184.         if( ok ){
  185. -          iRet = RETCODE_OK;
  186. +           if (fixUpTLEReg(fd, ucCmd, ulValue))
  187. +                iRet = RETCODE_OK;
  188. +           else
  189. +                iRet = RETCODE_FAIL;
  190.         }
  191.         else{
  192.            iRet = RETCODE_FAIL;
  193. @@ -223,7 +341,10 @@ int EcuTle::readRegister(const ECuParameter &parameters, unsigned long& value)
  194.           unsigned char ucAdr = (unsigned char)adr;
  195.           ok = TLE82353SA::readRegister( fd, ucAdr, value);
  196.           if( ok ){
  197. -            iRet = RETCODE_OK;
  198. +           if (fixUpTLEReg(fd, ucAdr, value))
  199. +                iRet = RETCODE_OK;
  200. +           else
  201. +                iRet = RETCODE_FAIL;
  202.           }
  203.           else{
  204.              iRet = RETCODE_FAIL;

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