pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


quantron/ecu01 linbus update 20190313-002
Posted by Anonymous on Wed 13th Mar 2019 11:41
raw | new post
modification of post by Anonymous (view diff)

  1. diff --git a/ptxdist/local_src/ecu01-codesys/linbus/Linbus.c b/ptxdist/local_src/ecu01-codesys/linbus/Linbus.c
  2. index 822d132..96e2d73 100755
  3. --- a/ptxdist/local_src/ecu01-codesys/linbus/Linbus.c
  4. +++ b/ptxdist/local_src/ecu01-codesys/linbus/Linbus.c
  5. @@ -1,10 +1,13 @@
  6.  /******************************************************************************/
  7. -/*!
  8. -\brief             Library for Linbus Protocol
  9. +/*!
  10. +\file              $URL: https://subversion.eckelmann.local/svn/max/quantron_a/trunk/src/codesys/qa/QA.c $
  11. +
  12. +\brief             Schnittstellenmodul Quantron-A Funktionsbibliothek
  13.  
  14. -\author            $Author: Gudert
  15. +\author            $Author: HILTENKA $
  16. +\date              $Date: 2011-11-24 12:26:30 +0100 (Do, 24 Nov 2011) $
  17.  
  18. -\version           $Rev: $
  19. +\version           $Rev: 2090 $
  20.  
  21.  \b                 ECKELMANN INDUSTRIEAUTOMATION, WIESBADEN\n
  22.                     © Copyright 2009
  23. @@ -15,30 +18,150 @@
  24.  @Includes
  25.  *******************************************************************************/
  26.  
  27. +#include <string.h>
  28. +#include <sys/mount.h>
  29. +#include <linux/fs.h>
  30. +#include <stdio.h>
  31. +#include <stdlib.h>
  32. +
  33. +#include <time.h>
  34. +#include <fcntl.h>
  35. +#include <unistd.h>
  36. +#include <sys/time.h>
  37. +#include <sys/types.h>
  38. +#include <sys/stat.h>
  39. +#include <termios.h>
  40. +
  41. +/* Headerfiles Codesys-Componenten-Lib */
  42.  #include "CmpStd.h"
  43.  #include "CmpErrors.h"
  44.  #include "CmpItf.h"
  45. -#include "LinbusDep.h"
  46.  
  47. +/* Headerfile Dependend */
  48. +#include "LinbusDep.h"
  49.  #include "linbus_imp.h"
  50.  
  51.  
  52. +/*******************************************************************************
  53. +@Konstanten (modullokal)
  54. +*******************************************************************************/
  55. +
  56. +#define DEBUG_FUNC                 DEBUG_PRINT
  57. +#ifndef DEBUG_FUNC
  58. +   #define DEBUG_FUNC(a...)
  59. +#endif
  60. +#ifndef DEBUG_ITF_FUNC
  61. +   #define DEBUG_ITF_FUNC(a...)
  62. +#endif
  63. +#ifndef DEBUG_INTERLAL_FUNC
  64. +   #define DEBUG_INTERLAL_FUNC(a...)
  65. +#endif
  66. +
  67. +
  68. +
  69. +
  70. +/*******************************************************************************
  71. +@Typdefinitionen (modullokal)
  72. +*******************************************************************************/
  73. +
  74. +
  75. +typedef struct LIN_SLAVE_DATA_R {
  76. +    LIN_SLAVE_VERSION_TR tVers;                /* Version */
  77. +    LIN_SLAVE_VALUE_TR   tValue;               /* FaceValue */
  78. +    unsigned char  ucSlaveOnline;              /* Verbindungsstatus */
  79. +    unsigned char  ucSetNewValue;      /* Flag fuer neuen Sollwert */
  80. +    unsigned short usSetValue;         /* Sollwert */
  81. +    unsigned char  ucSetControl;       /* Steuerbits fuer Sollwert */
  82. +}  LIN_SLAVE_DATA_TR;
  83. +/*******************************************************************************
  84. +@Konstanten (modullokal)
  85. +*******************************************************************************/
  86. +
  87. +#define DEBUG_FUNC                 DEBUG_PRINT
  88. +#ifndef DEBUG_FUNC
  89. +   #define DEBUG_FUNC(a...)
  90. +#endif
  91. +#ifndef DEBUG_ITF_FUNC
  92. +   #define DEBUG_ITF_FUNC(a...)
  93. +#endif
  94. +#ifndef DEBUG_INTERLAL_FUNC
  95. +   #define DEBUG_INTERLAL_FUNC(a...)
  96. +#endif
  97. +
  98. +#define WORKING_DIR_LEN            100
  99. +#define STORAGE_NAME_LEN            40
  100. +#define MNT_POINT_NAME_LEN          40
  101. +#define MNT_DEV_CNT                  4
  102. +#define MNT_DEV_NAME_LEN            40
  103. +#define FILENAME_LEN                40
  104. +
  105. +#define QADRV_VERSION_LEN           20
  106. +
  107. +/*******************************************************************************
  108. +@Variablen (modullokal)
  109. +*******************************************************************************/
  110. +
  111. +
  112. +/*******************************************************************************
  113. +@Makros (modullokal)
  114. +*******************************************************************************/
  115. +
  116. +/*******************************************************************************
  117. +@Prototypen der lokalen Funktionen
  118. +*******************************************************************************/
  119. +static int lin_getslaveversion( void );
  120. +static int lin_getslavefacevalue( void );
  121. +static int lin_setslavevalue( void );
  122. +static int lin_clrslaveaddr( void );
  123. +static int lin_setslaveaddr( int iSlave );
  124. +static void lin_master_thread(SYS_TASK_PARAM *ptp);
  125. +static int lin_missing_slave( void );
  126. +static void lin_rx_thread(SYS_TASK_PARAM *ptp);
  127. +static int lin_recv( unsigned char *pucLinData, int iLinByteCnt, int iTimeout );
  128. +static int lin_recv_message( unsigned char *pucLinMsgData, int iLinMsgLen ) ;
  129. +static int lin_send( unsigned char *pucLinData, int iLinBytesCnt );
  130. +static int lin_send_breakbyte( void );
  131. +static int lin_send_message( unsigned char *pucLinMsgData, int iLinMsgLen );
  132. +static unsigned char lin_pidbyte( unsigned char ucVal );
  133. +static unsigned char lin_checksum( unsigned char *pucData, int iDataLen );
  134. +static int lin_master_alive( unsigned char ucNextFreeAdr, unsigned char ucSlaves, unsigned char ucAliveFlags );
  135. +static int lin_reset_all( void );
  136. +static int lin_set_value( unsigned char ucAdr, unsigned short usSollPos, unsigned char ucControlFlags );
  137. +static int lin_face_value( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData  );
  138. +static int lin_get_version( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData  );
  139.  static IBase* CDECL CreateInstance(CLASSID cid, RTS_RESULT *pResult);
  140.  static RTS_RESULT CDECL DeleteInstance(IBase *pIBase);
  141.  static int CDECL ExportFunctions(void);
  142.  static int CDECL ImportFunctions(void);
  143.  static RTS_UI32 CDECL CmpGetVersion(void);
  144.  static RTS_RESULT CDECL HookFunction(RTS_UI32 ulHook, RTS_UINTPTR ulParam1, RTS_UINTPTR ulParam2);
  145. -static void GetSettings( void );
  146. +static void GetQASettings( void );
  147.  
  148.  USE_STMT
  149.  
  150. +USE_SysSemCreate
  151. +USE_SysSemDelete
  152. +USE_SysSemEnter
  153. +USE_SysSemLeave
  154. +USE_SysTaskCreate
  155. +USE_SysTaskResume
  156. +USE_SysTaskSetExit
  157. +USE_SysTaskJoin
  158. +USE_SysTaskExit
  159. +USE_SysTaskWaitSleep
  160. +USE_SysTaskDestroy
  161. +USE_SysTaskEnter
  162. +USE_SysTaskLeave
  163. +USE_SysTaskEnd
  164. +
  165. +
  166. +
  167.  /******************************************************************************/
  168.  /*!
  169.  \fn            ComponentEntry
  170.  
  171.  \brief         Used to exchange function pointers between component manager and components.\n
  172. -               Called at startup for each component.
  173. +               Called at startup for each component.
  174.  
  175.  \return        Return  ERR_OK if library could be initialized, else error code
  176.  
  177. @@ -71,8 +194,7 @@ DLL_DECL int CDECL ComponentEntry(INIT_STRUCT *pInitStruct)
  178.  
  179.     return ERR_OK;
  180.  
  181. -}  /* eofn: ComponentEntry */
  182. -
  183. +}  /* eofn: ComponentEntry */
  184.  
  185.  /******************************************************************************/
  186.  /*!
  187. @@ -89,7 +211,7 @@ DLL_DECL int CDECL ComponentEntry(INIT_STRUCT *pInitStruct)
  188.  static IBase* CDECL CreateInstance(CLASSID cid, RTS_RESULT *pResult)
  189.  {
  190.     return NULL;
  191. -}  /* eofn: CreateInstance */
  192. +}  /* eofn: CreateInstance */  
  193.  
  194.  /******************************************************************************/
  195.  /*!
  196. @@ -99,20 +221,20 @@ static IBase* CDECL CreateInstance(CLASSID cid, RTS_RESULT *pResult)
  197.  
  198.  \return        ERR_NOTIMPLEMENTED
  199.  
  200. -\param         pIBase   -
  201. +\param         pIBase   -              
  202.  
  203.  *******************************************************************************/
  204.  static RTS_RESULT CDECL DeleteInstance(IBase *pIBase)
  205.  {
  206.     return ERR_NOTIMPLEMENTED;
  207.  
  208. -}  /* eofn: DeleteInstance */
  209. +}  /* eofn: DeleteInstance */  
  210.  
  211.  /******************************************************************************/
  212.  /*!
  213.  \fn            ExportFunctions
  214.  
  215. -\brief         Export function pointers as api
  216. +\brief         Export function pointers as api
  217.  
  218.  \return        ERR_OK = successfull
  219.  
  220. @@ -124,15 +246,15 @@ static int CDECL ExportFunctions(void)
  221.     /* Macro to export functions */
  222.     EXPORT_STMT;
  223.  
  224. -    return ERR_OK;
  225. +       return ERR_OK;
  226.  
  227. -}  /* eofn: ExportFunctions */
  228. +}  /* eofn: ExportFunctions */  
  229.  
  230.  /******************************************************************************/
  231.  /*!
  232.  \fn            ImportFunctions
  233.  
  234. -\brief         Get function pointers of other components
  235. +\brief         Get function pointers of other components
  236.  
  237.  \return        ERR_OK = successfull
  238.  
  239. @@ -146,13 +268,13 @@ static int CDECL ImportFunctions(void)
  240.  
  241.     return ERR_OK;
  242.  
  243. -}  /* eofn: ImportFunctions */
  244. +}  /* eofn: ImportFunctions */  
  245.  
  246.  /******************************************************************************/
  247.  /*!
  248.  \fn            CmpGetVersion
  249.  
  250. -\brief         Get Versionnumber
  251. +\brief         Get Versionnumber
  252.  
  253.  \return        Versionnumber
  254.  
  255. @@ -163,27 +285,7 @@ static RTS_UI32 CDECL CmpGetVersion(void)
  256.  {
  257.     return CMP_VERSION;
  258.  
  259. -}  /* eofn: CmpGetVersion */
  260. -
  261. -/******************************************************************************/
  262. -
  263. -/******************************************************************************/
  264. -/*!
  265. -\fn            GetSettings
  266. -
  267. -\brief         Einlesen der Konfigurationseintrage
  268. -
  269. -\return        keine
  270. -
  271. -\param         keine
  272. -
  273. -*******************************************************************************/
  274. -static void GetSettings( void )
  275. -{
  276. -
  277. -    return;
  278. -
  279. -}      /* eofn: GetQASettings */
  280. +}  /* eofn: CmpGetVersion */  
  281.  
  282.  /******************************************************************************/
  283.  /*!
  284. @@ -193,7 +295,7 @@ static void GetSettings( void )
  285.  
  286.  \return        0
  287.  
  288. -\param         ulHook   -\n
  289. +\param         ulHook   -\n    
  290.                 ulParam1 -\n
  291.                 ulParam2 -\n
  292.  
  293. @@ -205,16 +307,11 @@ static RTS_RESULT CDECL HookFunction(RTS_UI32 ulHook, RTS_UINTPTR ulParam1, RTS_
  294.        case CH_INIT_SYSTEM:
  295.           break;
  296.  
  297. -        case CH_INIT:
  298. -
  299. -       /********************************/
  300. -       /* Konfigurationsdaten einlesen */
  301. -       /********************************/
  302. -       GetSettings();
  303. +               case CH_INIT:
  304.  
  305.           break;
  306.  
  307. -       case CH_INIT2:
  308. +          case CH_INIT2:
  309.           break;
  310.  
  311.        case CH_INIT3:
  312. @@ -228,23 +325,17 @@ static RTS_RESULT CDECL HookFunction(RTS_UI32 ulHook, RTS_UINTPTR ulParam1, RTS_
  313.  
  314.        /* Cyclic */
  315.        case CH_COMM_CYCLE:
  316. -
  317.           break;
  318.  
  319.        case CH_EXIT_COMM:
  320.           break;
  321.        case CH_EXIT_TASKS:
  322.           break;
  323. -       case CH_EXIT3:
  324. -           break;
  325. +          case CH_EXIT3:
  326. +                  break;
  327.        case CH_EXIT2:
  328.           break;
  329. -        case CH_EXIT:
  330. -
  331. -       /*******************************************************/
  332. -       /* LIN-Schnittstelle schliessen falls geoeffnet wurde */
  333. -       /*******************************************************/
  334. -       LIN_Close();
  335. +               case CH_EXIT:
  336.  
  337.           break;
  338.        case CH_EXIT_SYSTEM:
  339. @@ -254,90 +345,89 @@ static RTS_RESULT CDECL HookFunction(RTS_UI32 ulHook, RTS_UINTPTR ulParam1, RTS_
  340.     }
  341.     return 0;
  342.  
  343. -}  /* eofn: HookFunction */
  344. +}  /* eofn: HookFunction */  
  345. +
  346. +
  347.  
  348. -/***********************************/
  349. -/*! Funktionsschnittstelle LIN-BUS */
  350. -/***********************************/
  351.  
  352.  void CDECL CDECL_EXT lin_open(lin_open_struct *p)
  353.  {
  354. -       p->Lin_Open = LIN_Open( p->iSlaveCount, p->iIntervall );
  355. +    p->Lin_Open = LIN_Open( p->iSlaveCount, p->iIntervall );
  356.  
  357.  }  /* eofn: lin_open */
  358.  
  359.  void CDECL CDECL_EXT lin_close(lin_close_struct *p)
  360.  {
  361. -       p->Lin_Close = LIN_Close();
  362. +    p->Lin_Close = LIN_Close();
  363.  
  364.  }  /* eofn: lin_close */
  365.  
  366.  void CDECL CDECL_EXT lin_getmasterstate(lin_getmasterstate_struct *p)
  367.  {
  368. -       p->Lin_GetMasterState = LIN_GetMasterState();
  369. +    p->Lin_GetMasterState = LIN_GetMasterState();
  370.  
  371.  }  /* eofn: lin_getmasterstate */
  372.  
  373.  void CDECL CDECL_EXT lin_getslavestate(lin_getslavestate_struct *p)
  374.  {
  375. -       p->Lin_GetSlaveState = LIN_GetSlaveState( p->iSlave );
  376. +    p->Lin_GetSlaveState = LIN_GetSlaveState( p->iSlave );
  377.  
  378.  }  /* eofn: lin_getslavestate */
  379.  
  380.  void CDECL CDECL_EXT lin_resetaddress(lin_resetaddress_struct *p)
  381.  {
  382. -       p->Lin_ResetAddress = LIN_ResetAddress();
  383. +    p->Lin_ResetAddress = LIN_ResetAddress();
  384.  
  385.  }  /* eofn: lin_resetaddress */
  386.  
  387.  void CDECL CDECL_EXT lin_setaddress(lin_setaddress_struct *p)
  388.  {
  389. -       p->Lin_SetAddress = LIN_SetAddress();
  390. +    p->Lin_SetAddress = LIN_SetAddress();
  391.  
  392.  }  /* eofn: lin_setaddress */
  393.  
  394.  void CDECL CDECL_EXT lin_getversion(lin_getversion_struct *p)
  395.  {
  396. -       LIN_SLAVE_VERSION_TR tLinSlaveVersion;
  397. +    LIN_SLAVE_VERSION_TR tLinSlaveVersion;
  398.  
  399. -       if (( p->Lin_GetVersion = LIN_GetVersion( p->iSlave,  &tLinSlaveVersion ) ) == 0 ) {
  400. +    if (( p->Lin_GetVersion = LIN_GetVersion( p->iSlave,  &tLinSlaveVersion ) ) == 0 ) {
  401.  
  402.                 /* Daten uebernehmen */
  403. -               p->ptVersion->bRelease   = tLinSlaveVersion.ucRelease;
  404. +        p->ptVersion->bRelease   = tLinSlaveVersion.ucRelease;
  405.                 p->ptVersion->bVersion   = tLinSlaveVersion.ucVersion;
  406.                 p->ptVersion->bVariant   = tLinSlaveVersion.ucVariant;
  407.                 p->ptVersion->bFormat    = tLinSlaveVersion.ucFormat;
  408.                 p->ptVersion->wManCode   = tLinSlaveVersion.usManCode;
  409.                 p->ptVersion->wFunction  = tLinSlaveVersion.usFunction;
  410. -       }
  411. +
  412. +    }
  413.  
  414.  }  /* eofn: lin_getversion */
  415.  
  416.  void CDECL CDECL_EXT lin_getfacevalue(lin_getfacevalue_struct *p)
  417.  {
  418. -       LIN_SLAVE_VALUE_TR tLinSlaveValue;
  419. +    LIN_SLAVE_VALUE_TR tLinSlaveValue;
  420.  
  421. -       if (( p->Lin_GetFaceValue = LIN_GetFaceValue( p->iSlave, &tLinSlaveValue ) ) == 0 ) {
  422. +    if (( p->Lin_GetFaceValue = LIN_GetFaceValue( p->iSlave, &tLinSlaveValue ) ) == 0 ) {
  423.  
  424.                 /* Daten uebernehmen */
  425. -               p->ptValue->bFormat   = tLinSlaveValue.ucFormat;
  426. +        p->ptValue->bFormat   = tLinSlaveValue.ucFormat;
  427.                 p->ptValue->wIstPos   = tLinSlaveValue.usIstPos;
  428.                 p->ptValue->bStatus   = tLinSlaveValue.ucStatus;
  429.                 p->ptValue->bErrorCnt = tLinSlaveValue.ucErrorCnt;
  430. -       }
  431. +
  432. +    }
  433.  
  434.  }  /* eofn: lin_getfacevalue */
  435.  
  436.  void CDECL CDECL_EXT lin_setvalue(lin_setvalue_struct *p)
  437.  {
  438. -       p->Lin_SetValue = LIN_SetValue( p->iSlave, p->wPosition, p->bPosFlags, p->bDeviceTyp );
  439. +   p->Lin_SetValue = LIN_SetValue( p->iSlave, p->wPosition, p->bPosFlags, p->bDeviceTyp );
  440.  
  441. -}  /* eofn: lin_setvalue */
  442. +}  /* eofn: lin_setvalue */
  443.  
  444.  void CDECL CDECL_EXT lin_mastersetvalue(lin_mastersetvalue_struct *p)
  445.  {
  446. -       p->Lin_MasterSetValue = LIN_MasterSetValue( p->wPosition, p->bPosFlags, p->bDeviceTyp );
  447. -
  448. -}  /* eofn: lin_mastersetvalue */
  449. +   p->Lin_MasterSetValue = LIN_MasterSetValue( p->wPosition, p->bPosFlags, p->bDeviceTyp );
  450.  
  451. -/*--- eof  ---*/
  452. +}  /* eofn: lin_mastersetvalue */
  453. diff --git a/ptxdist/local_src/ecu01-codesys/linbus/LinbusItf.m4 b/ptxdist/local_src/ecu01-codesys/linbus/LinbusItf.m4
  454. index b742b61..470b6af 100755
  455. --- a/ptxdist/local_src/ecu01-codesys/linbus/LinbusItf.m4
  456. +++ b/ptxdist/local_src/ecu01-codesys/linbus/LinbusItf.m4
  457. @@ -15,17 +15,6 @@ extern "C" {
  458.  #endif
  459.  
  460.  /**
  461. - * <description>T_LIN_SLAVE_VALUE</description>
  462. - */
  463. -typedef struct tagT_LIN_SLAVE_VALUE
  464. -{
  465. -       RTS_IEC_BYTE bFormat;          
  466. -       RTS_IEC_WORD wIstPos;          
  467. -       RTS_IEC_BYTE bStatus;          
  468. -       RTS_IEC_BYTE bErrorCnt;        
  469. -} T_LIN_SLAVE_VALUE;
  470. -
  471. -/**
  472.   * <description>T_LIN_SLAVE_VERSION</description>
  473.   */
  474.  typedef struct tagT_LIN_SLAVE_VERSION
  475. @@ -39,6 +28,17 @@ typedef struct tagT_LIN_SLAVE_VERSION
  476.  } T_LIN_SLAVE_VERSION;
  477.  
  478.  /**
  479. + * <description>T_LIN_SLAVE_VALUE</description>
  480. + */
  481. +typedef struct tagT_LIN_SLAVE_VALUE
  482. +{
  483. +       RTS_IEC_BYTE bFormat;          
  484. +       RTS_IEC_WORD wIstPos;          
  485. +       RTS_IEC_BYTE bStatus;          
  486. +       RTS_IEC_BYTE bErrorCnt;        
  487. +} T_LIN_SLAVE_VALUE;
  488. +
  489. +/**
  490.   * Close Lin-Bus device
  491.   */
  492.  typedef struct taglin_close_struct
  493. @@ -46,7 +46,7 @@ typedef struct taglin_close_struct
  494.         RTS_IEC_DINT Lin_Close;                         /* VAR_OUTPUT */       
  495.  } lin_close_struct;
  496.  
  497. -DEF_API(`void',`CDECL',`lin_close',`(lin_close_struct *p)',1,0x172A91EA,0x01000000)
  498. +DEF_API(`void',`CDECL',`lin_close',`(lin_close_struct *p)',1,RTSITF_GET_SIGNATURE(0x172A91EA, 0),0x01000000)
  499.  
  500.  /**
  501.   * Get face value for a slave
  502. @@ -58,7 +58,7 @@ typedef struct taglin_getfacevalue_struct
  503.         RTS_IEC_DINT Lin_GetFaceValue;          /* VAR_OUTPUT */       
  504.  } lin_getfacevalue_struct;
  505.  
  506. -DEF_API(`void',`CDECL',`lin_getfacevalue',`(lin_getfacevalue_struct *p)',1,0xF2C42FE1,0x01000000)
  507. +DEF_API(`void',`CDECL',`lin_getfacevalue',`(lin_getfacevalue_struct *p)',1,RTSITF_GET_SIGNATURE(0xF2C42FE1, 0),0x01000000)
  508.  
  509.  /**
  510.   * Get status of the master
  511. @@ -68,7 +68,7 @@ typedef struct taglin_getmasterstate_struct
  512.         RTS_IEC_DINT Lin_GetMasterState;        /* VAR_OUTPUT */       
  513.  } lin_getmasterstate_struct;
  514.  
  515. -DEF_API(`void',`CDECL',`lin_getmasterstate',`(lin_getmasterstate_struct *p)',1,0xD369816F,0x01000000)
  516. +DEF_API(`void',`CDECL',`lin_getmasterstate',`(lin_getmasterstate_struct *p)',1,RTSITF_GET_SIGNATURE(0xD369816F, 0),0x01000000)
  517.  
  518.  /**
  519.   * Get state of the slave
  520. @@ -79,7 +79,7 @@ typedef struct taglin_getslavestate_struct
  521.         RTS_IEC_DINT Lin_GetSlaveState;         /* VAR_OUTPUT */       
  522.  } lin_getslavestate_struct;
  523.  
  524. -DEF_API(`void',`CDECL',`lin_getslavestate',`(lin_getslavestate_struct *p)',1,0x5B508641,0x01000000)
  525. +DEF_API(`void',`CDECL',`lin_getslavestate',`(lin_getslavestate_struct *p)',1,RTSITF_GET_SIGNATURE(0x5B508641, 0),0x01000000)
  526.  
  527.  /**
  528.   * Get version of the slave
  529. @@ -91,7 +91,7 @@ typedef struct taglin_getversion_struct
  530.         RTS_IEC_DINT Lin_GetVersion;            /* VAR_OUTPUT */       
  531.  } lin_getversion_struct;
  532.  
  533. -DEF_API(`void',`CDECL',`lin_getversion',`(lin_getversion_struct *p)',1,0x8E7D4D48,0x01000000)
  534. +DEF_API(`void',`CDECL',`lin_getversion',`(lin_getversion_struct *p)',1,RTSITF_GET_SIGNATURE(0x8E7D4D48, 0),0x01000000)
  535.  
  536.  /**
  537.   * Set value for all clients
  538. @@ -100,11 +100,11 @@ typedef struct taglin_mastersetvalue_struct
  539.  {
  540.         RTS_IEC_WORD wPosition;                         /* VAR_INPUT */ /* new value */
  541.         RTS_IEC_BYTE bPosFlags;                         /* VAR_INPUT */ /* flags to set the new value */
  542. -       RTS_IEC_BYTE bDeviceTyp;                        /* VAR_INPUT */ /* flags to set the new value */
  543. +       RTS_IEC_BYTE bDeviceTyp;                        /* VAR_INPUT */ /* Device Type */
  544.         RTS_IEC_DINT Lin_MasterSetValue;        /* VAR_OUTPUT */       
  545.  } lin_mastersetvalue_struct;
  546.  
  547. -DEF_API(`void',`CDECL',`lin_mastersetvalue',`(lin_mastersetvalue_struct *p)',1,0xA5CE5514,0x01000000)
  548. +DEF_API(`void',`CDECL',`lin_mastersetvalue',`(lin_mastersetvalue_struct *p)',1,RTSITF_GET_SIGNATURE(0xA5CE5514, 0),0x01000000)
  549.  
  550.  /**
  551.   * Open Lin-Bus device
  552. @@ -116,7 +116,7 @@ typedef struct taglin_open_struct
  553.         RTS_IEC_DINT Lin_Open;                          /* VAR_OUTPUT */       
  554.  } lin_open_struct;
  555.  
  556. -DEF_API(`void',`CDECL',`lin_open',`(lin_open_struct *p)',1,0x97229571,0x01000000)
  557. +DEF_API(`void',`CDECL',`lin_open',`(lin_open_struct *p)',1,RTSITF_GET_SIGNATURE(0x97229571, 0),0x01000000)
  558.  
  559.  /**
  560.   * Reset slave adress
  561. @@ -126,7 +126,7 @@ typedef struct taglin_resetaddress_struct
  562.         RTS_IEC_DINT Lin_ResetAddress;          /* VAR_OUTPUT */       
  563.  } lin_resetaddress_struct;
  564.  
  565. -DEF_API(`void',`CDECL',`lin_resetaddress',`(lin_resetaddress_struct *p)',1,0x357557FD,0x01000000)
  566. +DEF_API(`void',`CDECL',`lin_resetaddress',`(lin_resetaddress_struct *p)',1,RTSITF_GET_SIGNATURE(0x357557FD, 0),0x01000000)
  567.  
  568.  /**
  569.   * Set slave adress
  570. @@ -136,7 +136,7 @@ typedef struct taglin_setaddress_struct
  571.         RTS_IEC_DINT Lin_SetAddress;            /* VAR_OUTPUT */       
  572.  } lin_setaddress_struct;
  573.  
  574. -DEF_API(`void',`CDECL',`lin_setaddress',`(lin_setaddress_struct *p)',1,0x2015BA0E,0x01000000)
  575. +DEF_API(`void',`CDECL',`lin_setaddress',`(lin_setaddress_struct *p)',1,RTSITF_GET_SIGNATURE(0x2015BA0E, 0),0x01000000)
  576.  
  577.  /**
  578.   * Set value for a slave
  579. @@ -146,11 +146,11 @@ typedef struct taglin_setvalue_struct
  580.         RTS_IEC_INT iSlave;                                     /* VAR_INPUT */ /* Slavenumber */
  581.         RTS_IEC_WORD wPosition;                         /* VAR_INPUT */ /* new value */
  582.         RTS_IEC_BYTE bPosFlags;                         /* VAR_INPUT */ /* flags to set the new value */
  583. -       RTS_IEC_BYTE bDeviceTyp;                        /* VAR_INPUT */ /* flags to set the new value */
  584. +       RTS_IEC_BYTE bDeviceTyp;                        /* VAR_INPUT */ /* Device Type */
  585.         RTS_IEC_DINT Lin_SetValue;                      /* VAR_OUTPUT */       
  586.  } lin_setvalue_struct;
  587.  
  588. -DEF_API(`void',`CDECL',`lin_setvalue',`(lin_setvalue_struct *p)',1,0xBEFBC8F0,0x01000000)
  589. +DEF_API(`void',`CDECL',`lin_setvalue',`(lin_setvalue_struct *p)',1,RTSITF_GET_SIGNATURE(0xBEFBC8F0, 0),0x01000000)
  590.  
  591.  #ifdef __cplusplus
  592.  }
  593. diff --git a/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.c b/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.c
  594. index a111c56..fe9d495 100755
  595. --- a/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.c
  596. +++ b/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.c
  597. @@ -1,1762 +1,1702 @@
  598. -/******************************************************************************/
  599.  
  600. -/*!
  601.  
  602. -\file              $URL: https://svn.eckelmann.group/svn/max/quantron_a/trunk/src/codesys/qa/linbus.c $
  603.  
  604. -
  605.  
  606. -\brief             Modul fuer die LIN-Bus-Kommunikation
  607.  
  608. -
  609.  
  610. -\author            $Author: Strunck $
  611.  
  612. -\date              $Date: 2016-10-20 10:31:12 +0200 (Do, 20 Okt 2016) $
  613.  
  614. -
  615.  
  616. -\version           $Rev: 3796 $
  617.  
  618. -
  619.  
  620. -\b                 ECKELMANN INDUSTRIEAUTOMATION, WIESBADEN\n
  621.  
  622. -                   © Copyright 2010
  623.  
  624. -
  625.  
  626. -*******************************************************************************/
  627.  
  628. -
  629.  
  630. -/*******************************************************************************
  631.  
  632. -@Includes
  633.  
  634. -*******************************************************************************/
  635.  
  636. -
  637.  
  638. -#include <time.h>
  639.  
  640. -#include <fcntl.h>
  641.  
  642. -#include <unistd.h>
  643.  
  644. -#include <sys/time.h>
  645.  
  646. -#include <sys/types.h>
  647.  
  648. -#include <sys/stat.h>
  649.  
  650. -#include <termios.h>
  651.  
  652. -
  653.  
  654. -/* Headerfiles Codesys-Componenten-Lib */
  655.  
  656. -#include "CmpStd.h"
  657.  
  658. -#include "CmpErrors.h"
  659.  
  660. -#include "CmpItf.h"
  661.  
  662. -
  663.  
  664. -/* Headerfile Dependend */
  665.  
  666. -#include "LinbusDep.h"
  667.  
  668. -
  669.  
  670. -/* Sonstige Headerfiles */
  671.  
  672. -#include "linbus_imp.h"
  673.  
  674. -#include "debug.h"
  675.  
  676. -#include "log.h"
  677.  
  678. -
  679.  
  680. -/*******************************************************************************
  681.  
  682. -@Konstanten (modullokal)
  683.  
  684. -*******************************************************************************/  
  685.  
  686. -
  687.  
  688. -#define DEBUG_FUNC                 DEBUG_PRINT
  689.  
  690. -#ifndef DEBUG_FUNC
  691.  
  692. -   #define DEBUG_FUNC(a...)
  693.  
  694. -#endif
  695.  
  696. -#ifndef DEBUG_ITF_FUNC
  697.  
  698. -   #define DEBUG_ITF_FUNC(a...)
  699.  
  700. -#endif
  701.  
  702. -#ifndef DEBUG_INTERLAL_FUNC
  703.  
  704. -   #define DEBUG_INTERLAL_FUNC(a...)
  705.  
  706. -#endif
  707.  
  708. -
  709.  
  710. -#define ISBITSET(val, bit)    ( ((val) & (1 << (bit)))? 1:0 )
  711.  
  712. -
  713.  
  714. -/**************************/
  715.  
  716. -/* LIN-Kommandos/Adressen */
  717.  
  718. -/**************************/
  719.  
  720. -#define  ADDR(x)                               (x << 2)
  721.  
  722. -#define  PID_PARITY(x)                         (x << 6)
  723.  
  724. -
  725.  
  726. -#define  LIN_SLAVE_1             0x0
  727.  
  728. -#define  LIN_SLAVE_2             0x1
  729.  
  730. -#define  LIN_SLAVE_3             0x2
  731.  
  732. -#define  LIN_SLAVE_4             0x3
  733.  
  734. -#define  LIN_SLAVE_5             0x4
  735.  
  736. -#define  LIN_SLAVE_6             0x5
  737.  
  738. -#define  LIN_SLAVE_7             0x6
  739.  
  740. -#define  LIN_SLAVE_8             0x7
  741.  
  742. -#define  LIN_SLAVE_9             0x8
  743.  
  744. -#define  LIN_SLAVE_10            0x9
  745.  
  746. -#define  LIN_SLAVE_11            0xA
  747.  
  748. -#define  LIN_SLAVE_12            0xB
  749.  
  750. -#define  LIN_SLAVE_13            0xC
  751.  
  752. -#define  LIN_SLAVE_14            0xD
  753.  
  754. -#define  LIN_MASTER                               0xE
  755.  
  756. -#define  CMD_FACEVALUE(adr)            (ADDR(adr) | 0x0 )
  757.  
  758. -#define  CMD_SETVALUE(adr)             (ADDR(adr) | 0x1 )
  759.  
  760. -#define  CMD_RESERVED(adr)             (ADDR(adr) | 0x2 )
  761.  
  762. -#define  CMD_VERSION(adr)              (ADDR(adr) | 0x3 )
  763.  
  764. -      
  765.  
  766. -#define  CMD_MASTER_ALIVE              (ADDR(LIN_MASTER) | 0x0 )
  767.  
  768. -#define  CMD_MASTER_SETVALUE           (ADDR(LIN_MASTER) | 0x1 )
  769.  
  770. -#define  CMD_RESET_ADDR                (ADDR(LIN_MASTER) | 0x3 )
  771.  
  772. -
  773.  
  774. -/**************************/
  775.  
  776. -/* LIN-Steuerflags Master */
  777.  
  778. -/**************************/
  779.  
  780. -#define  LIN_MASTER_INITFLAG     0x02
  781.  
  782. -
  783.  
  784. -/***********************************/
  785.  
  786. -/* LIN-Steuerflags Sollwert setzen */
  787.  
  788. -/***********************************/
  789.  
  790. -#define  LIN_SET_SOLL_POS        0x01
  791.  
  792. -#define  LIN_SET_SLOW            0x02
  793.  
  794. -#define  LIN_SET_MANUAL_OU       0x04
  795.  
  796. -#define  LIN_SET_MANUAL_IN       0x08
  797.  
  798. -#define  LIN_SET_SELFTEST        0x80
  799.  
  800. -
  801.  
  802. -/*******************/
  803.  
  804. -/* LIN-Fehlercodes */
  805.  
  806. -/*******************/
  807.  
  808. -#define  ERR_LIN_DEVICE          (-1)
  809.  
  810. -#define  ERR_LIN_PORTSETTING     (-2)
  811.  
  812. -#define  ERR_LIN_BAUDRATE        (-3)
  813.  
  814. -#define  ERR_LIN_TIMEOUT         (-4)
  815.  
  816. -#define  ERR_LIN_TIMEOUT_ECHO    (-5)
  817.  
  818. -#define  ERR_LIN_TIMEOUT_MSG     (-6)
  819.  
  820. -#define  ERR_LIN_SEND_MESSAGE    (-7)
  821.  
  822. -#define  ERR_LIN_CHECKSUM        (-8)
  823.  
  824. -
  825.  
  826. -/***************/
  827.  
  828. -/* LIN-Timeout */
  829.  
  830. -/***************/
  831.  
  832. -#define  LIN_TIMEOUT_ECHO                      50         /* 50 ms  Timeoutzeit fuer Echobytes */
  833.  
  834. -#define  LIN_TIMEOUT_MESSAGE     100        /* 100 ms Timeoutzeit fuer Clientantwort */
  835.  
  836. -
  837.  
  838. -/*************************/
  839.  
  840. -/* Sonstige Definitionen */
  841.  
  842. -/*************************/
  843.  
  844. -#define  LIN_BAUD_RATE                         B9600
  845.  
  846. -#define  MAX_LIN_FRAME_BUFFER          30
  847.  
  848. -#define  MAX_LIN_SLAVE           14
  849.  
  850. -#define  LIN_SYNCBYTE                  0x55
  851.  
  852. -#define  LIN_TYP_MOTOR                 0
  853.  
  854. -#define  LIN_PROTOKOLL_VERS      0
  855.  
  856. -#define  DRV_NAME_LEN                     20
  857.  
  858. -#define  LIN_MSG_RETRY           3
  859.  
  860. -
  861.  
  862. -#ifndef x86
  863.  
  864. -#define LINTHREAD_PRIO           38     /* RT-Linux; SCHED_FIFO */
  865.  
  866. -#else
  867.  
  868. -#define LINTHREAD_PRIO           54    /* kein RT-Linux; SCHED_OTHER */
  869.  
  870. -#endif
  871.  
  872. -#define LINTHREAD_ZYKLUS         10    /* 10ms Zykluszeit */
  873.  
  874. -
  875.  
  876. -#ifndef x86
  877.  
  878. -#define RXTHREAD_PRIO            38     /* RT-Linux; SCHED_FIFO */
  879.  
  880. -#else
  881.  
  882. -#define RXTHREAD_PRIO            54    /* kein RT-Linux; SCHED_OTHER */
  883.  
  884. -#endif
  885.  
  886. -
  887.  
  888. -/**************/
  889.  
  890. -/* Tracetypen */
  891.  
  892. -/**************/
  893.  
  894. -#define MSG_TX_TRACE_DATA          0
  895.  
  896. -#define MSG_RX_TRACE_DATA          1
  897.  
  898. -
  899.  
  900. -//#define _DEBUG
  901.  
  902. -
  903.  
  904. -/*******************************************************************************
  905.  
  906. -@Typdefinitionen (modullokal)
  907.  
  908. -*******************************************************************************/
  909.  
  910. -
  911.  
  912. -typedef struct LIN_SLAVE_DATA_R {
  913.  
  914. -       LIN_SLAVE_VERSION_TR tVers;             /* Version */
  915.  
  916. -       LIN_SLAVE_VALUE_TR   tValue;            /* FaceValue */
  917.  
  918. -       unsigned char  ucSlaveOnline;           /* Verbindungsstatus */
  919.  
  920. -       unsigned char  ucSetNewValue;           /* Flag fuer neuen Sollwert */
  921.  
  922. -       unsigned short usSetValue;              /* Sollwert */
  923.  
  924. -       unsigned char  ucSetControl;            /* Steuerbits fuer Sollwert */
  925.  
  926. -       unsigned char  ucDevice;
  927.  
  928. -
  929.  
  930. -}  LIN_SLAVE_DATA_TR;
  931.  
  932. -
  933.  
  934. -/*******************************************************************************
  935.  
  936. -@Konstanten (modullokal)
  937.  
  938. -*******************************************************************************/
  939.  
  940. -
  941.  
  942. -static const char cacDeviceName[DRV_NAME_LEN] = { "/dev/ttymxc1"};
  943.  
  944. -
  945.  
  946. -/*******************************************************************************
  947.  
  948. -@Variablen (modullokal)
  949.  
  950. -*******************************************************************************/
  951.  
  952. -
  953.  
  954. -/* Variablen Linbus-Schnittstellen */
  955.  
  956. -static int     iLinPort = -1;                                                     /* Porthandle */
  957.  
  958. -static struct  termios initial_settings, new_settings;   /* Portsettings */
  959.  
  960. -static speed_t BaudRate;                                 /* Baudrate */
  961.  
  962. -
  963.  
  964. -/* Variablen Masterthread */
  965.  
  966. -static RTS_HANDLE rtsMasterThreadHandle = RTS_INVALID_HANDLE; /* Handle MasterThread */
  967.  
  968. -static char acMasterThreadName[15] = { "LinMasterThread" };
  969.  
  970. -static int  iLinMasterState;                             /* Zustand Master */
  971.  
  972. -
  973.  
  974. -/* Variablen Empfangsthread */
  975.  
  976. -static RTS_HANDLE rtsRxThreadHandle = RTS_INVALID_HANDLE;     /* Handle RxThread */
  977.  
  978. -static char acRxThreadName[15] = { "LinRxThread" };
  979.  
  980. -
  981.  
  982. -/* Variablen Empfang/Sendefunktion */
  983.  
  984. -static unsigned char  acLinMsgBuffer[MAX_LIN_FRAME_BUFFER];     /* Nachrichtenpuffer */
  985.  
  986. -static unsigned char  acLinRxBuffer[MAX_LIN_FRAME_BUFFER];      /* Empfangspuffer */
  987.  
  988. -static int            iLinRxWrIndex;                     /* Schreibzeiger Empfangspuffer */
  989.  
  990. -static int            iLinRxRdIndex;                     /* Lesezeiger Empfangspuffer */
  991.  
  992. -
  993.  
  994. -/* Zustaende von Master und Slaves */
  995.  
  996. -static LIN_SLAVE_DATA_TR atLinSlaveData[MAX_LIN_SLAVE];  /* Slavezustaende */
  997.  
  998. -static int            iLinSlaveCnt;                      /* Anzahl der konfigurieren Slaves */
  999.  
  1000. -static int            iLinIntervall;                     /* Intervall fuer die Bearbeitung des Linbus */
  1001.  
  1002. -static int            iLinResetAddr;                     /* Flag fuer das Ruecksetzen der Adressen */
  1003.  
  1004. -static int            iLinSetAddr;                       /* Flag fuer das Setzen der Adressen */
  1005.  
  1006. -static unsigned char  ucLinMasterNewValue;               /* Flag fuer neuen Sollwert */
  1007.  
  1008. -static unsigned short usLinMasterValue;                  /* Neuer Sollwert fuer alle Slaves */
  1009.  
  1010. -static unsigned char  ucLinMasterControl;                /* Controlbyte fuer Sollwert aller Slaves */
  1011.  
  1012. -static unsigned char  ucLinMasterDevice;                               /* Device Type */
  1013.  
  1014. -static int            iLinAdrSlaveCnt;                   /* zu adressierender Lin-Slave */
  1015.  
  1016. -
  1017.  
  1018. -/*******************************************************************************
  1019.  
  1020. -@Prototypen der lokalen Funktionen
  1021.  
  1022. -*******************************************************************************/
  1023.  
  1024. -
  1025.  
  1026. -#ifdef _DEBUG
  1027.  
  1028. -static void lin_trace_message( int iTyp, unsigned char *pucMsg, int iLen );
  1029.  
  1030. -#endif
  1031.  
  1032. -static int lin_getslaveversion( void );
  1033.  
  1034. -static int lin_getslavefacevalue( void );
  1035.  
  1036. -static int lin_setslavevalue( void );
  1037.  
  1038. -static int lin_clrslaveaddr( void );
  1039.  
  1040. -static int lin_setslaveaddr( int iSlave );
  1041.  
  1042. -static void lin_master_thread(SYS_TASK_PARAM *ptp);
  1043.  
  1044. -static int lin_missing_slave( void );
  1045.  
  1046. -static void lin_rx_thread(SYS_TASK_PARAM *ptp);
  1047.  
  1048. -static int lin_recv( unsigned char *pucLinData, int iLinByteCnt, int iTimeout );
  1049.  
  1050. -static int lin_recv_message( unsigned char *pucLinMsgData, int iLinMsgLen ) ;
  1051.  
  1052. -static int lin_send( unsigned char *pucLinData, int iLinBytesCnt );
  1053.  
  1054. -static int lin_send_breakbyte( void );
  1055.  
  1056. -static int lin_send_message( unsigned char *pucLinMsgData, int iLinMsgLen );
  1057.  
  1058. -static unsigned char lin_pidbyte( unsigned char ucVal );
  1059.  
  1060. -static unsigned char lin_checksum( unsigned char *pucData, int iDataLen );
  1061.  
  1062. -static int lin_master_alive( unsigned char ucNextFreeAdr, unsigned char ucSlaves, unsigned char ucAliveFlags );
  1063.  
  1064. -static int lin_reset_all( void );
  1065.  
  1066. -static int lin_set_value( unsigned char ucAdr, unsigned short usSollPos, unsigned char ucControlFlags, unsigned char ucDeviceTyp  );
  1067.  
  1068. -static int lin_face_value( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData  );
  1069.  
  1070. -static int lin_get_version( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData  );
  1071.  
  1072. -
  1073.  
  1074. -USE_SysSemCreate  
  1075.  
  1076. -USE_SysSemDelete  
  1077.  
  1078. -USE_SysSemEnter    
  1079.  
  1080. -USE_SysSemLeave    
  1081.  
  1082. -USE_SysTaskCreate  
  1083.  
  1084. -USE_SysTaskResume  
  1085.  
  1086. -USE_SysTaskSetExit
  1087.  
  1088. -USE_SysTaskJoin    
  1089.  
  1090. -USE_SysTaskExit    
  1091.  
  1092. -USE_SysTaskWaitSleep
  1093.  
  1094. -USE_SysTaskDestroy
  1095.  
  1096. -USE_SysTaskEnter  
  1097.  
  1098. -USE_SysTaskLeave  
  1099.  
  1100. -USE_SysTaskEnd    
  1101.  
  1102. -
  1103.  
  1104. -#ifdef _DEBUG
  1105.  
  1106. -/******************************************************************************/
  1107.  
  1108. -/*!
  1109.  
  1110. -\fn        lin_trace_message
  1111.  
  1112. -
  1113.  
  1114. -\brief     Message ausgeben
  1115.  
  1116. -
  1117.  
  1118. -\return    keine
  1119.  
  1120. -
  1121.  
  1122. -\param     iTyp     - Typ Empfang- bzw. Sendenachricht
  1123.  
  1124. -           pucMsg   - Zeiger auf Nachricht
  1125.  
  1126. -           iMsgLen  - Nachrichtenlaenge
  1127.  
  1128. -                              
  1129.  
  1130. -*******************************************************************************/
  1131.  
  1132. -static void lin_trace_message( int iTyp, unsigned char *pucMsg, int iMsgLen )
  1133.  
  1134. -{
  1135.  
  1136. -
  1137.  
  1138. -   char acTraceMsg[100];
  1139.  
  1140. -   char acTraceByte[5];
  1141.  
  1142. -   int  iBytes;
  1143.  
  1144. -   int  iRet;
  1145.  
  1146. -   struct timeval tv_trace;
  1147.  
  1148. -
  1149.  
  1150. -   iRet = gettimeofday(&tv_trace, 0);
  1151.  
  1152. -   if ( iRet == 0 ) {
  1153.  
  1154. -
  1155.  
  1156. -      strcpy(acTraceMsg, "\0");
  1157.  
  1158. -      for ( iBytes = 0; iBytes < iMsgLen; iBytes++ ) {
  1159.  
  1160. -
  1161.  
  1162. -         sprintf(acTraceByte, "%02x", pucMsg[iBytes]);
  1163.  
  1164. -         strcat(acTraceMsg, acTraceByte);
  1165.  
  1166. -      }
  1167.  
  1168. -
  1169.  
  1170. -      if ( iTyp == MSG_TX_TRACE_DATA ) {
  1171.  
  1172. -
  1173.  
  1174. -         Log_Printf(COMPONENT_ID, "TxMsg: Daten: %s Time: %lu, %lu\n",
  1175.  
  1176. -                     acTraceMsg,
  1177.  
  1178. -                     (unsigned long)tv_trace.tv_sec,
  1179.  
  1180. -                     (unsigned long)tv_trace.tv_usec/1000);
  1181.  
  1182. -      }
  1183.  
  1184. -      else {
  1185.  
  1186. -
  1187.  
  1188. -                       Log_Printf(COMPONENT_ID, "RxMsg: Daten: %s Time: %lu, %lu\n",
  1189.  
  1190. -                     acTraceMsg,
  1191.  
  1192. -                     (unsigned long)tv_trace.tv_sec,
  1193.  
  1194. -                     (unsigned long)tv_trace.tv_usec/1000);
  1195.  
  1196. -      }
  1197.  
  1198. -   }
  1199.  
  1200. -   else{
  1201.  
  1202. -      Log_Warning(COMPONENT_ID, "TraceMsg: gettimeofday\n");
  1203.  
  1204. -   }
  1205.  
  1206. -
  1207.  
  1208. -   return;
  1209.  
  1210. -
  1211.  
  1212. -}  /* eofn: lin_trace_message */
  1213.  
  1214. -#endif
  1215.  
  1216. -
  1217.  
  1218. -/******************************************************************************/
  1219.  
  1220. -/*!
  1221.  
  1222. -\fn        lin_getslaveversion
  1223.  
  1224. -
  1225.  
  1226. -\brief     Version aller Slaves auslesen
  1227.  
  1228. -
  1229.  
  1230. -\return    Anzahl der nicht gefunden Slaves
  1231.  
  1232. -
  1233.  
  1234. -\param     keine
  1235.  
  1236. -
  1237.  
  1238. -*******************************************************************************/
  1239.  
  1240. -static int lin_getslaveversion( void )
  1241.  
  1242. -{
  1243.  
  1244. -       int iSlave;
  1245.  
  1246. -       int iRetry;
  1247.  
  1248. -       int iRet;
  1249.  
  1250. -
  1251.  
  1252. -       int iMissingSlaves = 0;
  1253.  
  1254. -
  1255.  
  1256. -       for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  1257.  
  1258. -
  1259.  
  1260. -               iRetry = 0;
  1261.  
  1262. -
  1263.  
  1264. -               do {
  1265.  
  1266. -                       /* Version der Slaves auslesen */
  1267.  
  1268. -                       iRet = lin_get_version( LIN_SLAVE_1 + iSlave, &atLinSlaveData[iSlave] );
  1269.  
  1270. -                       if ( iRet < 0 ) {
  1271.  
  1272. -                               /* Slave antwortet nicht; nochmal wiederholen */
  1273.  
  1274. -                               iRetry++;
  1275.  
  1276. -                       }
  1277.  
  1278. -               } while (( iRet < 0 ) && (iRetry <= LIN_MSG_RETRY ) );
  1279.  
  1280. -
  1281.  
  1282. -               if ( iRet < 0 ) {
  1283.  
  1284. -                       /* Slave antwortet nicht */
  1285.  
  1286. -                       atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  1287.  
  1288. -                       iMissingSlaves++;
  1289.  
  1290. -               }
  1291.  
  1292. -               else {
  1293.  
  1294. -                       atLinSlaveData[iSlave].ucSlaveOnline = TRUE;
  1295.  
  1296. -               }
  1297.  
  1298. -       }
  1299.  
  1300. -
  1301.  
  1302. -       return iMissingSlaves;
  1303.  
  1304. -
  1305.  
  1306. -}  /* eofn: lin_getslaveversion */
  1307.  
  1308. -
  1309.  
  1310. -/******************************************************************************/
  1311.  
  1312. -/*!
  1313.  
  1314. -\fn        lin_getslavefacevalue
  1315.  
  1316. -
  1317.  
  1318. -\brief     Istposition aller Slaves auslesen
  1319.  
  1320. -
  1321.  
  1322. -\return    0
  1323.  
  1324. -
  1325.  
  1326. -\param     keine
  1327.  
  1328. -
  1329.  
  1330. -*******************************************************************************/
  1331.  
  1332. -static int lin_getslavefacevalue( void )
  1333.  
  1334. -{
  1335.  
  1336. -       int iSlave;
  1337.  
  1338. -       int iRetry;
  1339.  
  1340. -       int iRet;
  1341.  
  1342. -
  1343.  
  1344. -       int iMissingSlaves = 0;
  1345.  
  1346. -
  1347.  
  1348. -       for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  1349.  
  1350. -
  1351.  
  1352. -               iRetry = 0;
  1353.  
  1354. -
  1355.  
  1356. -               do {
  1357.  
  1358. -                       /* Version der Slaves auslesen */
  1359.  
  1360. -                       iRet = lin_face_value( LIN_SLAVE_1 + iSlave, &atLinSlaveData[iSlave] );
  1361.  
  1362. -                       if ( iRet < 0 ) {
  1363.  
  1364. -                               /* Slave antwortet nicht; nochmal wiederholen */
  1365.  
  1366. -                               iRetry++;
  1367.  
  1368. -                       }
  1369.  
  1370. -               } while (( iRet < 0 ) && (iRetry <= LIN_MSG_RETRY ) );
  1371.  
  1372. -
  1373.  
  1374. -               if ( iRet < 0 ) {
  1375.  
  1376. -                       /* Slave antwortet nicht */
  1377.  
  1378. -                       atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  1379.  
  1380. -                       iMissingSlaves++;
  1381.  
  1382. -               }
  1383.  
  1384. -               else {
  1385.  
  1386. -                       atLinSlaveData[iSlave].ucSlaveOnline = TRUE;
  1387.  
  1388. -               }
  1389.  
  1390. -       }
  1391.  
  1392. -
  1393.  
  1394. -       return iMissingSlaves;
  1395.  
  1396. -
  1397.  
  1398. -}  /* eofn: lin_getslavefacevalue */
  1399.  
  1400. -
  1401.  
  1402. -/******************************************************************************/
  1403.  
  1404. -/*!
  1405.  
  1406. -\fn        lin_setslavevalue
  1407.  
  1408. -
  1409.  
  1410. -\brief     Sollposition fuer Slaves setzen
  1411.  
  1412. -
  1413.  
  1414. -\return    keine
  1415.  
  1416. -
  1417.  
  1418. -\param     keine
  1419.  
  1420. -
  1421.  
  1422. -*******************************************************************************/
  1423.  
  1424. -static int lin_setslavevalue( void )
  1425.  
  1426. -{
  1427.  
  1428. -       int iSlave;
  1429.  
  1430. -
  1431.  
  1432. -       /* Masterwert wurde geaendert */
  1433.  
  1434. -       if ( ucLinMasterNewValue == TRUE ) {
  1435.  
  1436. -               ucLinMasterNewValue = FALSE;
  1437.  
  1438. -
  1439.  
  1440. -               /* Neue Sollposition fuer alle uebernehmen senden */
  1441.  
  1442. -               lin_set_value(LIN_MASTER, usLinMasterValue, ucLinMasterControl, ucLinMasterDevice);
  1443.  
  1444. -       }
  1445.  
  1446. -       else {
  1447.  
  1448. -
  1449.  
  1450. -               for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  1451.  
  1452. -
  1453.  
  1454. -                       if ( atLinSlaveData[iSlave].ucSetNewValue == TRUE ) {
  1455.  
  1456. -                               atLinSlaveData[iSlave].ucSetNewValue = FALSE;
  1457.  
  1458. -
  1459.  
  1460. -                               /* Neue Sollposition fuer Slave uebernehmen senden */
  1461.  
  1462. -                               lin_set_value(LIN_SLAVE_1 + iSlave, atLinSlaveData[iSlave].usSetValue, atLinSlaveData[iSlave].ucSetControl, atLinSlaveData[iSlave].ucDevice);
  1463.  
  1464. -                       }
  1465.  
  1466. -               }
  1467.  
  1468. -       }
  1469.  
  1470. -
  1471.  
  1472. -       return 0;
  1473.  
  1474. -
  1475.  
  1476. -}  /* eofn: lin_setslavevalue */
  1477.  
  1478. -
  1479.  
  1480. -
  1481.  
  1482. -/******************************************************************************/
  1483.  
  1484. -/*!
  1485.  
  1486. -\fn        lin_clrslaveaddr
  1487.  
  1488. -
  1489.  
  1490. -\brief     Slaveadressen neu setzen
  1491.  
  1492. -
  1493.  
  1494. -\return    kein
  1495.  
  1496. -
  1497.  
  1498. -\param     keine
  1499.  
  1500. -
  1501.  
  1502. -*******************************************************************************/
  1503.  
  1504. -static int lin_clrslaveaddr( void )
  1505.  
  1506. -{
  1507.  
  1508. -       int iSlave;
  1509.  
  1510. -
  1511.  
  1512. -       /* Kommando Reset senden */
  1513.  
  1514. -       lin_reset_all();
  1515.  
  1516. -
  1517.  
  1518. -       /* Alle Slaves alle nicht erkannt markieren */
  1519.  
  1520. -       for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  1521.  
  1522. -
  1523.  
  1524. -               atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  1525.  
  1526. -       }
  1527.  
  1528. -
  1529.  
  1530. -       return 0;
  1531.  
  1532. -
  1533.  
  1534. -}  /* eofn: lin_clrlaveaddr */
  1535.  
  1536. -
  1537.  
  1538. -/******************************************************************************/
  1539.  
  1540. -/*!
  1541.  
  1542. -\fn        lin_setslaveaddr
  1543.  
  1544. -
  1545.  
  1546. -\brief     Slaveadressen neu setzen
  1547.  
  1548. -
  1549.  
  1550. -\return    Slavestatus
  1551.  
  1552. -            0 - Slave nicht vorhanden
  1553.  
  1554. -                         -1 - Slave vorhanden
  1555.  
  1556. -
  1557.  
  1558. -\param     iSlave    - Slave
  1559.  
  1560. -
  1561.  
  1562. -*******************************************************************************/
  1563.  
  1564. -static int lin_setslaveaddr( int iSlave )
  1565.  
  1566. -{
  1567.  
  1568. -       /* Kommando Alive an alle Slaves senden */
  1569.  
  1570. -       lin_master_alive( iSlave, iLinSlaveCnt, LIN_MASTER_INITFLAG );
  1571.  
  1572. -                  
  1573.  
  1574. -       /* Kommando FaceValue an Slave senden */
  1575.  
  1576. -       if ( lin_face_value( iSlave, &atLinSlaveData[iSlave] ) < 0 ) {
  1577.  
  1578. -
  1579.  
  1580. -               atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  1581.  
  1582. -               return -1;
  1583.  
  1584. -       }
  1585.  
  1586. -
  1587.  
  1588. -       /* Kommando FaceValue an Slave senden */
  1589.  
  1590. -       if ( lin_get_version( iSlave, &atLinSlaveData[iSlave] ) < 0 ) {
  1591.  
  1592. -
  1593.  
  1594. -               atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  1595.  
  1596. -               return -1;
  1597.  
  1598. -       }
  1599.  
  1600. -       atLinSlaveData[iSlave].ucSlaveOnline = TRUE;
  1601.  
  1602. -
  1603.  
  1604. -       return 0;
  1605.  
  1606. -
  1607.  
  1608. -}  /* eofn: lin_setslaveaddr */
  1609.  
  1610. -
  1611.  
  1612. -/******************************************************************************/
  1613.  
  1614. -/*!
  1615.  
  1616. -\fn        lin_missing_slave
  1617.  
  1618. -
  1619.  
  1620. -\brief     Fehlenden Slave suchen
  1621.  
  1622. -
  1623.  
  1624. -\return    Slavenummer
  1625.  
  1626. -
  1627.  
  1628. -\param     keine
  1629.  
  1630. -
  1631.  
  1632. -*******************************************************************************/
  1633.  
  1634. -static int lin_missing_slave( void )
  1635.  
  1636. -{
  1637.  
  1638. -       int iSlave = 0;
  1639.  
  1640. -
  1641.  
  1642. -       do {
  1643.  
  1644. -
  1645.  
  1646. -               if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  1647.  
  1648. -
  1649.  
  1650. -                       /* Slave ist nicht vorhanden */
  1651.  
  1652. -                       return iSlave;
  1653.  
  1654. -               }
  1655.  
  1656. -               iSlave++;
  1657.  
  1658. -       }       while ( iSlave < iLinSlaveCnt );
  1659.  
  1660. -
  1661.  
  1662. -       return -1;
  1663.  
  1664. -
  1665.  
  1666. -}  /* eofn: lin_missing_slave */
  1667.  
  1668. -
  1669.  
  1670. -/******************************************************************************/
  1671.  
  1672. -/*!
  1673.  
  1674. -\fn        lin_master_thread
  1675.  
  1676. -
  1677.  
  1678. -\brief     Protokollverarbeitung Linbus Master
  1679.  
  1680. -
  1681.  
  1682. -\return    keine
  1683.  
  1684. -
  1685.  
  1686. -\param     keine
  1687.  
  1688. -
  1689.  
  1690. -*******************************************************************************/
  1691.  
  1692. -static void lin_master_thread(SYS_TASK_PARAM *ptp)
  1693.  
  1694. -{
  1695.  
  1696. -       int iMissingSlaves;
  1697.  
  1698. -
  1699.  
  1700. -   CAL_SysTaskEnter(ptp->hTask);
  1701.  
  1702. -
  1703.  
  1704. -   while(!ptp->bExit) {
  1705.  
  1706. -
  1707.  
  1708. -               DEBUG_PRINT("Zustand Master : %i\n", iLinMasterState);
  1709.  
  1710. -               DEBUG_PRINT("\n");
  1711.  
  1712. -
  1713.  
  1714. -               switch ( iLinMasterState ) {
  1715.  
  1716. -      
  1717.  
  1718. -                       /*********************************************************************/
  1719.  
  1720. -                       case LIN_MASTER_CHECK : {
  1721.  
  1722. -                       /*********************************************************************/
  1723.  
  1724. -      
  1725.  
  1726. -                               /* Kommando Alive an alle Slaves senden */
  1727.  
  1728. -                               lin_master_alive( 0, iLinSlaveCnt, 0 );
  1729.  
  1730. -      
  1731.  
  1732. -                               /* Version der Slaves abfragen */
  1733.  
  1734. -                               iMissingSlaves = lin_getslaveversion();
  1735.  
  1736. -                               if ( iMissingSlaves == 1 ) {
  1737.  
  1738. -
  1739.  
  1740. -                                       /* fehlenden Slave setzen */
  1741.  
  1742. -                                       iLinAdrSlaveCnt = lin_missing_slave();
  1743.  
  1744. -
  1745.  
  1746. -                                       /* Timeout eines Slaves */
  1747.  
  1748. -                                       iLinMasterState = LIN_MASTER_INIT;
  1749.  
  1750. -                                       break;
  1751.  
  1752. -                               }
  1753.  
  1754. -                               else if ( iMissingSlaves > 1 ) {
  1755.  
  1756. -
  1757.  
  1758. -                                       /* Timeout mehrere Slaves */
  1759.  
  1760. -                                       iLinMasterState = LIN_MASTER_REPAIR;
  1761.  
  1762. -                                       break;
  1763.  
  1764. -                               }
  1765.  
  1766. -      
  1767.  
  1768. -                               /* Slave haben sich gemeldet */
  1769.  
  1770. -                               iLinMasterState = LIN_MASTER_ONLINE;
  1771.  
  1772. -                       }       break;
  1773.  
  1774. -      
  1775.  
  1776. -                       /*********************************************************************/
  1777.  
  1778. -                       case LIN_MASTER_INIT : {
  1779.  
  1780. -                       /*********************************************************************/
  1781.  
  1782. -      
  1783.  
  1784. -                               /* Adressen fuer Slaves setzen */
  1785.  
  1786. -                               lin_setslaveaddr( iLinAdrSlaveCnt );
  1787.  
  1788. -
  1789.  
  1790. -                               /* Version der Slaves abfragen */
  1791.  
  1792. -                               iMissingSlaves = lin_getslaveversion();
  1793.  
  1794. -                               if ( iMissingSlaves == 0 ) {
  1795.  
  1796. -
  1797.  
  1798. -                                       /* Alle Slave sind da */
  1799.  
  1800. -                                       iLinMasterState = LIN_MASTER_ONLINE;
  1801.  
  1802. -                                       break;
  1803.  
  1804. -                               }
  1805.  
  1806. -                               else if ( iMissingSlaves > 1 ) {
  1807.  
  1808. -
  1809.  
  1810. -                                       /* Timeout mehrerr Slaves */
  1811.  
  1812. -                                       iLinMasterState = LIN_MASTER_REPAIR;
  1813.  
  1814. -                                       break;
  1815.  
  1816. -                               }
  1817.  
  1818. -
  1819.  
  1820. -                               if ( iLinResetAddr == TRUE ) {
  1821.  
  1822. -                                       iLinResetAddr = FALSE;
  1823.  
  1824. -                                       iLinSetAddr = FALSE;
  1825.  
  1826. -      
  1827.  
  1828. -                                       /* Slaveadresse loeschen */
  1829.  
  1830. -                                       lin_clrslaveaddr();
  1831.  
  1832. -
  1833.  
  1834. -                                       /* Adressen loeschen */
  1835.  
  1836. -                                       iLinMasterState = LIN_MASTER_ADR_CLR;
  1837.  
  1838. -                                       break;
  1839.  
  1840. -                               }
  1841.  
  1842. -                       }       break;
  1843.  
  1844. -      
  1845.  
  1846. -                       /*********************************************************************/
  1847.  
  1848. -                       case LIN_MASTER_ONLINE : {
  1849.  
  1850. -                       /*********************************************************************/
  1851.  
  1852. -      
  1853.  
  1854. -                               /* Kommando Alive an alle Slaves senden */
  1855.  
  1856. -                               lin_master_alive( 0, iLinSlaveCnt, 0 );
  1857.  
  1858. -      
  1859.  
  1860. -                               /* Sollwert der Slaves senden */
  1861.  
  1862. -                               lin_setslavevalue();
  1863.  
  1864. -      
  1865.  
  1866. -                               /* Istwert der Slaves abfragen */
  1867.  
  1868. -                               iMissingSlaves = lin_getslavefacevalue();
  1869.  
  1870. -                               if ( iMissingSlaves == 1 ) {
  1871.  
  1872. -
  1873.  
  1874. -                                       /* fehlenden Slave setzen */
  1875.  
  1876. -                                       iLinAdrSlaveCnt = lin_missing_slave();
  1877.  
  1878. -
  1879.  
  1880. -                                       /* Timeout eines Slaves */
  1881.  
  1882. -                                       iLinMasterState = LIN_MASTER_INIT;
  1883.  
  1884. -                                       break;
  1885.  
  1886. -                               }
  1887.  
  1888. -                               else if ( iMissingSlaves > 1 ) {
  1889.  
  1890. -
  1891.  
  1892. -                                       /* Timeout eines Slaves */
  1893.  
  1894. -                                       iLinMasterState = LIN_MASTER_REPAIR;
  1895.  
  1896. -                                       break;
  1897.  
  1898. -                               }
  1899.  
  1900. -      
  1901.  
  1902. -                               if ( iLinResetAddr == TRUE ) {
  1903.  
  1904. -                                       iLinResetAddr = FALSE;
  1905.  
  1906. -                                       iLinSetAddr = FALSE;
  1907.  
  1908. -
  1909.  
  1910. -                                       /* Slaveadresse loeschen */
  1911.  
  1912. -                                       lin_clrslaveaddr();
  1913.  
  1914. -
  1915.  
  1916. -                                       /* Adressen loeschen */
  1917.  
  1918. -                                       iLinMasterState = LIN_MASTER_ADR_CLR;
  1919.  
  1920. -                                       break;
  1921.  
  1922. -                               }
  1923.  
  1924. -                       }       break;
  1925.  
  1926. -      
  1927.  
  1928. -                       /*********************************************************************/
  1929.  
  1930. -                       case LIN_MASTER_REPAIR : {
  1931.  
  1932. -                       /*********************************************************************/
  1933.  
  1934. -
  1935.  
  1936. -                               if ( iLinResetAddr == TRUE ) {
  1937.  
  1938. -                                       iLinResetAddr = FALSE;
  1939.  
  1940. -                                       iLinSetAddr = FALSE;
  1941.  
  1942. -
  1943.  
  1944. -                                       /* Slaveadresse loeschen */
  1945.  
  1946. -                                       lin_clrslaveaddr();
  1947.  
  1948. -
  1949.  
  1950. -                                       /* Adressen loeschen */
  1951.  
  1952. -                                       iLinMasterState = LIN_MASTER_ADR_CLR;
  1953.  
  1954. -                                       break;
  1955.  
  1956. -                               }
  1957.  
  1958. -                               /* Version der Slaves abfragen */
  1959.  
  1960. -                               iMissingSlaves = lin_getslaveversion();
  1961.  
  1962. -                               if ( iMissingSlaves == 1 ) {
  1963.  
  1964. -
  1965.  
  1966. -                                       /* fehlenden Slave setzen */
  1967.  
  1968. -                                       iLinAdrSlaveCnt = lin_missing_slave();
  1969.  
  1970. -
  1971.  
  1972. -                                       /* Timeout eines Slaves */
  1973.  
  1974. -                                       iLinMasterState = LIN_MASTER_INIT;
  1975.  
  1976. -                                       break;
  1977.  
  1978. -                               }
  1979.  
  1980. -              
  1981.  
  1982. -      
  1983.  
  1984. -                               /* Slave haben sich gemeldet */
  1985.  
  1986. -                               iLinMasterState = LIN_MASTER_ONLINE;
  1987.  
  1988. -                       }       break;
  1989.  
  1990. -
  1991.  
  1992. -                       /***************************************************************/
  1993.  
  1994. -                       case LIN_MASTER_ADR_CLR : {
  1995.  
  1996. -                       /***************************************************************/
  1997.  
  1998. -
  1999.  
  2000. -                               if ( iLinResetAddr == TRUE ) {
  2001.  
  2002. -                                       iLinResetAddr = FALSE;
  2003.  
  2004. -
  2005.  
  2006. -                                       /* Slaveadresse loeschen */
  2007.  
  2008. -                                       lin_clrslaveaddr();
  2009.  
  2010. -                                       break;
  2011.  
  2012. -                               }
  2013.  
  2014. -
  2015.  
  2016. -                               if ( iLinSetAddr == TRUE ) {
  2017.  
  2018. -                                       iLinSetAddr = FALSE;
  2019.  
  2020. -
  2021.  
  2022. -                                       /* Neuadressierung mit Adresse 0 */
  2023.  
  2024. -                                       iLinAdrSlaveCnt = 0;
  2025.  
  2026. -
  2027.  
  2028. -                                       /* Warte auf Slave */
  2029.  
  2030. -                                       iLinMasterState = LIN_MASTER_WAIT_FOR_SLAVE;
  2031.  
  2032. -                                       break;
  2033.  
  2034. -                               }
  2035.  
  2036. -                       }       break;
  2037.  
  2038. -
  2039.  
  2040. -                       /***************************************************************/
  2041.  
  2042. -                       case LIN_MASTER_WAIT_FOR_SLAVE : {
  2043.  
  2044. -                       /***************************************************************/
  2045.  
  2046. -
  2047.  
  2048. -                               /* Adressen fuer Slaves setzen */
  2049.  
  2050. -                               lin_setslaveaddr( iLinAdrSlaveCnt );
  2051.  
  2052. -
  2053.  
  2054. -                               /* pruefen ob Slave erkannt wurde */
  2055.  
  2056. -                               if ( atLinSlaveData[iLinAdrSlaveCnt].ucSlaveOnline == TRUE ) {
  2057.  
  2058. -
  2059.  
  2060. -                                       /* naechster Slave */
  2061.  
  2062. -                                       iLinAdrSlaveCnt++;
  2063.  
  2064. -
  2065.  
  2066. -                                       if ( iLinAdrSlaveCnt == iLinSlaveCnt ) {
  2067.  
  2068. -
  2069.  
  2070. -                                               /* alle Slaves adressiert */
  2071.  
  2072. -                                               iLinMasterState = LIN_MASTER_ONLINE;
  2073.  
  2074. -                                               break;
  2075.  
  2076. -                                       }
  2077.  
  2078. -                               }
  2079.  
  2080. -
  2081.  
  2082. -                               if ( iLinResetAddr == TRUE ) {
  2083.  
  2084. -                                       iLinResetAddr = FALSE;
  2085.  
  2086. -                                       iLinSetAddr = FALSE;
  2087.  
  2088. -
  2089.  
  2090. -                                       /* Slaveadresse loeschen */
  2091.  
  2092. -                                       lin_clrslaveaddr();
  2093.  
  2094. -
  2095.  
  2096. -                                       /* Adressen loeschen */
  2097.  
  2098. -                                       iLinMasterState = LIN_MASTER_ADR_CLR;
  2099.  
  2100. -                                       break;
  2101.  
  2102. -                               }
  2103.  
  2104. -                       }       break;
  2105.  
  2106. -
  2107.  
  2108. -                       /***************************************************************/
  2109.  
  2110. -                       default : {
  2111.  
  2112. -                       /***************************************************************/
  2113.  
  2114. -
  2115.  
  2116. -                       }       break;
  2117.  
  2118. -               }
  2119.  
  2120. -
  2121.  
  2122. -               CAL_SysTaskWaitSleep(ptp->hTask, iLinIntervall);
  2123.  
  2124. -       }
  2125.  
  2126. -
  2127.  
  2128. -   CAL_SysTaskLeave(ptp->hTask);
  2129.  
  2130. -   CAL_SysTaskEnd(ptp->hTask, 0);
  2131.  
  2132. -
  2133.  
  2134. -       return;
  2135.  
  2136. -
  2137.  
  2138. -}  /* eofn: lin_master_thread */
  2139.  
  2140. -
  2141.  
  2142. -/******************************************************************************/
  2143.  
  2144. -/*!
  2145.  
  2146. -\fn        lin_rx_thread
  2147.  
  2148. -
  2149.  
  2150. -\brief     Empfangsthread
  2151.  
  2152. -
  2153.  
  2154. -\return    keine
  2155.  
  2156. -
  2157.  
  2158. -\param     arg
  2159.  
  2160. -
  2161.  
  2162. -*******************************************************************************/
  2163.  
  2164. -static void lin_rx_thread(SYS_TASK_PARAM *ptp)
  2165.  
  2166. -{
  2167.  
  2168. -   CAL_SysTaskEnter(ptp->hTask);
  2169.  
  2170. -
  2171.  
  2172. -   while(!ptp->bExit) {
  2173.  
  2174. -
  2175.  
  2176. -               if ( read( iLinPort, &acLinRxBuffer[iLinRxWrIndex], 1 ) > 0 ) {
  2177.  
  2178. -
  2179.  
  2180. -                       iLinRxWrIndex++;
  2181.  
  2182. -                       if ( iLinRxWrIndex >= MAX_LIN_FRAME_BUFFER  ) {
  2183.  
  2184. -
  2185.  
  2186. -                               iLinRxWrIndex = 0;
  2187.  
  2188. -                       }
  2189.  
  2190. -               }
  2191.  
  2192. -       }
  2193.  
  2194. -
  2195.  
  2196. -   CAL_SysTaskLeave(ptp->hTask);
  2197.  
  2198. -   CAL_SysTaskEnd(ptp->hTask, 0);
  2199.  
  2200. -
  2201.  
  2202. -       return;
  2203.  
  2204. -
  2205.  
  2206. -}  /* eofn: lin_rx_thread */
  2207.  
  2208. -
  2209.  
  2210. -/******************************************************************************/
  2211.  
  2212. -/*!
  2213.  
  2214. -\fn        lin_recv
  2215.  
  2216. -
  2217.  
  2218. -\brief     Lin-Bytes empfangen
  2219.  
  2220. -
  2221.  
  2222. -\return    Ergebnis
  2223.  
  2224. -           = 0 - OK
  2225.  
  2226. -                         < 0 - Fehler
  2227.  
  2228. -
  2229.  
  2230. -\param     pucLinData  - Zeiger auf die Daten
  2231.  
  2232. -           iLinByteCnt - Anzahl an Bytes
  2233.  
  2234. -                         iTimeout    - Timeoutzeit fuer das Lesen
  2235.  
  2236. -                                                                                                        
  2237.  
  2238. -*******************************************************************************/
  2239.  
  2240. -static int lin_recv( unsigned char *pucLinData, int iLinByteCnt, int iTimeout )
  2241.  
  2242. -{
  2243.  
  2244. -       int iTimer = 0;
  2245.  
  2246. -       int iByteCnt = 0;
  2247.  
  2248. -
  2249.  
  2250. -       do {
  2251.  
  2252. -
  2253.  
  2254. -               if ( iLinRxRdIndex != iLinRxWrIndex ) {
  2255.  
  2256. -
  2257.  
  2258. -                       pucLinData[iByteCnt] = acLinRxBuffer[iLinRxRdIndex];
  2259.  
  2260. -                       iByteCnt++;
  2261.  
  2262. -
  2263.  
  2264. -                       iLinRxRdIndex++;
  2265.  
  2266. -                       if ( iLinRxRdIndex >= MAX_LIN_FRAME_BUFFER ) {
  2267.  
  2268. -
  2269.  
  2270. -                               iLinRxRdIndex = 0;
  2271.  
  2272. -                       }
  2273.  
  2274. -               }
  2275.  
  2276. -               else {
  2277.  
  2278. -
  2279.  
  2280. -                       /* Timeoutzeit abwarten */
  2281.  
  2282. -                       usleep(1000);
  2283.  
  2284. -                       iTimer++;
  2285.  
  2286. -               }
  2287.  
  2288. -
  2289.  
  2290. -       } while (( iByteCnt < iLinByteCnt ) && ( iTimer < iTimeout ));
  2291.  
  2292. -
  2293.  
  2294. -       /* pruefen ob alle Bytes gelesen wurden */
  2295.  
  2296. -       if ( iTimer >= iTimeout ) {
  2297.  
  2298. -
  2299.  
  2300. -               /* Fehler beim lesen; keine weiteren Bytes mehr lesen */
  2301.  
  2302. -               iLinRxRdIndex = 0;
  2303.  
  2304. -               iLinRxWrIndex = 0;
  2305.  
  2306. -               return ERR_LIN_TIMEOUT;
  2307.  
  2308. -       }
  2309.  
  2310. -
  2311.  
  2312. -       return 0;
  2313.  
  2314. -
  2315.  
  2316. -}  /* eofn: lin_recv */  
  2317.  
  2318. -
  2319.  
  2320. -/******************************************************************************/
  2321.  
  2322. -/*!
  2323.  
  2324. -\fn        lin_recv_message
  2325.  
  2326. -
  2327.  
  2328. -\brief     Lin-Message empfangen
  2329.  
  2330. -
  2331.  
  2332. -\return    Ergebnis
  2333.  
  2334. -           = 0 - OK
  2335.  
  2336. -                         < 0 - Fehler
  2337.  
  2338. -
  2339.  
  2340. -\param     pucLinData   - Zeiger auf die Daten
  2341.  
  2342. -           iLinBytesCnt - Anzahl an Bytes
  2343.  
  2344. -                                                                                                        
  2345.  
  2346. -*******************************************************************************/
  2347.  
  2348. -static int lin_recv_message( unsigned char *pucLinMsgData, int iLinMsgLen )
  2349.  
  2350. -{
  2351.  
  2352. -       unsigned char ucChecksum;
  2353.  
  2354. -
  2355.  
  2356. -       /************************************/
  2357.  
  2358. -       /* Response vom Client zuruecklesen */
  2359.  
  2360. -       /************************************/
  2361.  
  2362. -   if ( lin_recv( &pucLinMsgData[1], iLinMsgLen-1, LIN_TIMEOUT_MESSAGE ) < 0 ) {
  2363.  
  2364. -
  2365.  
  2366. -               /* Timeout/Fehler beim Empfang des Response */
  2367.  
  2368. -               return ERR_LIN_TIMEOUT_MSG;
  2369.  
  2370. -       }
  2371.  
  2372. -
  2373.  
  2374. -       /****************/
  2375.  
  2376. -       /* Traceausgabe */
  2377.  
  2378. -       /****************/
  2379.  
  2380. -       #ifdef _DEBUG
  2381.  
  2382. -       lin_trace_message( MSG_RX_TRACE_DATA,  pucLinMsgData, iLinMsgLen );
  2383.  
  2384. -       #endif
  2385.  
  2386. -
  2387.  
  2388. -       /*******************************/
  2389.  
  2390. -       /* Empfangsschecksumme pruefen */
  2391.  
  2392. -       /*******************************/
  2393.  
  2394. -       ucChecksum = lin_checksum(pucLinMsgData, iLinMsgLen -1);
  2395.  
  2396. -       if ( ucChecksum !=  pucLinMsgData[iLinMsgLen-1] ) {
  2397.  
  2398. -
  2399.  
  2400. -               /* Checksumme ist ungueltig */
  2401.  
  2402. -               Log_Warning(COMPONENT_ID, "Checksumme ist ungueltig\n");
  2403.  
  2404. -              
  2405.  
  2406. -               /* BUG 1898 - Clean Buffer */
  2407.  
  2408. -        // Kein Mutex benötigt
  2409.  
  2410. -        iLinRxWrIndex = 0;                     /* Schreibzeiger Empfangspuffer */
  2411.  
  2412. -        iLinRxRdIndex = 0;                     /* Lesezeiger Empfangspuffer */
  2413.  
  2414. -              
  2415.  
  2416. -               return ERR_LIN_CHECKSUM;
  2417.  
  2418. -       }
  2419.  
  2420. -
  2421.  
  2422. -       return 0;
  2423.  
  2424. -
  2425.  
  2426. -}  /* eofn: lin_recv_message */
  2427.  
  2428. -
  2429.  
  2430. -/******************************************************************************/
  2431.  
  2432. -/*!
  2433.  
  2434. -\fn        lin_send
  2435.  
  2436. -
  2437.  
  2438. -\brief     Lin-Bytes senden
  2439.  
  2440. -
  2441.  
  2442. -\return    Ergebnis
  2443.  
  2444. -           = 0 - OK
  2445.  
  2446. -                         < 0 - Fehler
  2447.  
  2448. -
  2449.  
  2450. -\param     pcLinData    - Zeiger auf die Daten
  2451.  
  2452. -           iLinBytesCnt - Anzahl an Bytes
  2453.  
  2454. -                                                                                                        
  2455.  
  2456. -*******************************************************************************/
  2457.  
  2458. -static int lin_send( unsigned char *pucLinData, int iLinBytesCnt )
  2459.  
  2460. -{
  2461.  
  2462. -   if ( write( iLinPort, pucLinData, iLinBytesCnt ) < 0 ) {
  2463.  
  2464. -
  2465.  
  2466. -               Log_Warning(COMPONENT_ID, "Fehler beim Senden\n");
  2467.  
  2468. -               return ERR_LIN_SEND_MESSAGE;
  2469.  
  2470. -       }
  2471.  
  2472. -
  2473.  
  2474. -       return 0;
  2475.  
  2476. -
  2477.  
  2478. -}  /* eofn: lin_send */  
  2479.  
  2480. -
  2481.  
  2482. -/******************************************************************************/
  2483.  
  2484. -/*!
  2485.  
  2486. -\fn        lin_send_breakbyte
  2487.  
  2488. -
  2489.  
  2490. -\brief     Breakbyte senden
  2491.  
  2492. -
  2493.  
  2494. -\return    Ergebnis
  2495.  
  2496. -           = 0 - OK
  2497.  
  2498. -                         < 0 - Fehler
  2499.  
  2500. -
  2501.  
  2502. -\param     keine
  2503.  
  2504. -
  2505.  
  2506. -*******************************************************************************/
  2507.  
  2508. -static int lin_send_breakbyte( void )
  2509.  
  2510. -{
  2511.  
  2512. -
  2513.  
  2514. -   unsigned char ucTmp = 0;
  2515.  
  2516. -
  2517.  
  2518. -   tcgetattr(iLinPort, &initial_settings);
  2519.  
  2520. -   new_settings = initial_settings;
  2521.  
  2522. -
  2523.  
  2524. -   /************************************/
  2525.  
  2526. -   /* Schnittstelleneinstellung setzen */
  2527.  
  2528. -   /************************************/
  2529.  
  2530. -   /* Baudrate */
  2531.  
  2532. -   if (cfsetispeed(&new_settings, BaudRate-1) != 0) {
  2533.  
  2534. -
  2535.  
  2536. -               Log_Warning(COMPONENT_ID, "Baudrate kann nicht initialsiert werden\n");
  2537.  
  2538. -      return ERR_LIN_BAUDRATE;
  2539.  
  2540. -   }
  2541.  
  2542. -
  2543.  
  2544. -   if (cfsetospeed(&new_settings, BaudRate-1) != 0) {
  2545.  
  2546. -
  2547.  
  2548. -               Log_Warning(COMPONENT_ID, "Baudrate kann nicht initialsiert werden\n");
  2549.  
  2550. -      return ERR_LIN_BAUDRATE;
  2551.  
  2552. -   }
  2553.  
  2554. -   cfmakeraw(&new_settings);
  2555.  
  2556. -
  2557.  
  2558. -   /* Flags */
  2559.  
  2560. -   new_settings.c_cflag &= ~CSTOPB;    /* 1 Stopbit */
  2561.  
  2562. -   new_settings.c_cflag &= ~PARENB; /* keine Paritaet */
  2563.  
  2564. -   new_settings.c_cflag &= ~CSIZE;  /* 8 Datenbits */
  2565.  
  2566. -   new_settings.c_cflag |= CS8;
  2567.  
  2568. -
  2569.  
  2570. -   if (tcsetattr(iLinPort, TCSANOW, &new_settings)  != 0) {
  2571.  
  2572. -
  2573.  
  2574. -               Log_Warning(COMPONENT_ID, "Schnittstlleneinstellung koennen nicht gesetzt werden\n");
  2575.  
  2576. -      return ERR_LIN_PORTSETTING;
  2577.  
  2578. -   }
  2579.  
  2580. -
  2581.  
  2582. -       /********************/
  2583.  
  2584. -       /* Breakbyte senden */
  2585.  
  2586. -       /********************/
  2587.  
  2588. -       lin_send( &ucTmp, 1 );
  2589.  
  2590. -
  2591.  
  2592. -       /*************************/
  2593.  
  2594. -       /* Echobyte zuruecklesen */
  2595.  
  2596. -       /*************************/
  2597.  
  2598. -       lin_recv( &ucTmp, 1, LIN_TIMEOUT_ECHO );
  2599.  
  2600. -
  2601.  
  2602. -   tcgetattr(iLinPort, &initial_settings);
  2603.  
  2604. -   new_settings = initial_settings;
  2605.  
  2606. -
  2607.  
  2608. -   /************************************/
  2609.  
  2610. -   /* Schnittstelleneinstellung setzen */
  2611.  
  2612. -   /************************************/
  2613.  
  2614. -
  2615.  
  2616. -   if (cfsetispeed(&new_settings, BaudRate) != 0) {
  2617.  
  2618. -      return ERR_LIN_BAUDRATE;
  2619.  
  2620. -   }
  2621.  
  2622. -   if (cfsetospeed(&new_settings, BaudRate) != 0) {
  2623.  
  2624. -      return ERR_LIN_BAUDRATE;
  2625.  
  2626. -   }
  2627.  
  2628. -
  2629.  
  2630. -   cfmakeraw(&new_settings);
  2631.  
  2632. -
  2633.  
  2634. -   /* Flags */
  2635.  
  2636. -   new_settings.c_cflag &= ~CSTOPB;    /* 1 Stopbit */
  2637.  
  2638. -   new_settings.c_cflag &= ~PARENB; /* keine Paritaet */
  2639.  
  2640. -   new_settings.c_cflag &= ~CSIZE;  /* 8 Datenbits */
  2641.  
  2642. -   new_settings.c_cflag |= CS8;
  2643.  
  2644. -
  2645.  
  2646. -   if (tcsetattr(iLinPort, TCSADRAIN, &new_settings)  != 0) {
  2647.  
  2648. -
  2649.  
  2650. -      Log_Warning(COMPONENT_ID, "Device konnte nicht initialsiert werden\n");
  2651.  
  2652. -      return ERR_LIN_PORTSETTING;
  2653.  
  2654. -   }
  2655.  
  2656. -
  2657.  
  2658. -   return 0;
  2659.  
  2660. -}  /* eofn: lin_send_breakbyte */
  2661.  
  2662. -
  2663.  
  2664. -/******************************************************************************/
  2665.  
  2666. -/*!
  2667.  
  2668. -\fn        lin_send_message
  2669.  
  2670. -
  2671.  
  2672. -\brief     Lin-Message senden
  2673.  
  2674. -
  2675.  
  2676. -\return    Ergebnis
  2677.  
  2678. -           = 0 - OK
  2679.  
  2680. -                         < 0 - Fehler
  2681.  
  2682. -
  2683.  
  2684. -\param     pucLinMsgData - Zeiger auf die Daten
  2685.  
  2686. -           iLinMsgLen    - Anzahl an Bytes
  2687.  
  2688. -                                                                                                        
  2689.  
  2690. -*******************************************************************************/
  2691.  
  2692. -static int lin_send_message( unsigned char *pucLinMsgData, int iLinMsgLen )
  2693.  
  2694. -{
  2695.  
  2696. -       int iRet = 0;
  2697.  
  2698. -
  2699.  
  2700. -       /******************************/
  2701.  
  2702. -       /* Breakbyte zunaechst senden */
  2703.  
  2704. -       /******************************/
  2705.  
  2706. -       if (( iRet = lin_send_breakbyte()) < 0 ) {
  2707.  
  2708. -
  2709.  
  2710. -               /* Break konnte nicht gesendet werden */
  2711.  
  2712. -               return iRet;
  2713.  
  2714. -       }
  2715.  
  2716. -
  2717.  
  2718. -       /******************/
  2719.  
  2720. -       /* Message senden */
  2721.  
  2722. -       /******************/
  2723.  
  2724. -   if (( iRet = lin_send( pucLinMsgData, iLinMsgLen )) < 0 ) {
  2725.  
  2726. -
  2727.  
  2728. -               /* Message konnte nicht gesendet werden */
  2729.  
  2730. -               return iRet;
  2731.  
  2732. -       }
  2733.  
  2734. -
  2735.  
  2736. -       /**************************/
  2737.  
  2738. -       /* Echobytes zuruecklesen */
  2739.  
  2740. -       /**************************/
  2741.  
  2742. -   if ( lin_recv( pucLinMsgData, iLinMsgLen, LIN_TIMEOUT_ECHO ) < 0 ) {
  2743.  
  2744. -
  2745.  
  2746. -               /* Timeout/Fehler beim Empfang des Echos */
  2747.  
  2748. -               return ERR_LIN_TIMEOUT_ECHO;
  2749.  
  2750. -       }
  2751.  
  2752. -
  2753.  
  2754. -       /****************/
  2755.  
  2756. -       /* Traceausgabe */
  2757.  
  2758. -       /****************/
  2759.  
  2760. -       #ifdef _DEBUG
  2761.  
  2762. -       lin_trace_message( MSG_TX_TRACE_DATA, pucLinMsgData, iLinMsgLen );
  2763.  
  2764. -       #endif
  2765.  
  2766. -
  2767.  
  2768. -       return 0;
  2769.  
  2770. -
  2771.  
  2772. -}  /* eofn: lin_send_message */  
  2773.  
  2774. -
  2775.  
  2776. -/******************************************************************************/
  2777.  
  2778. -/*!
  2779.  
  2780. -\fn        lin_pidbyte
  2781.  
  2782. -
  2783.  
  2784. -\brief     PID-Byte erzeugen
  2785.  
  2786. -
  2787.  
  2788. -\return    PID-Byte
  2789.  
  2790. -
  2791.  
  2792. -\param     ucVal - Wert fuer Kommando bzw Adresse
  2793.  
  2794. -
  2795.  
  2796. -*******************************************************************************/
  2797.  
  2798. -static unsigned char lin_pidbyte( unsigned char ucVal )
  2799.  
  2800. -{
  2801.  
  2802. -
  2803.  
  2804. -       unsigned char ucTmp = 0;
  2805.  
  2806. -
  2807.  
  2808. -   if ((ISBITSET(ucVal,0) ^ ISBITSET(ucVal,1) ^ ISBITSET(ucVal,2) ^ ISBITSET(ucVal,4)) != 0 )  {
  2809.  
  2810. -
  2811.  
  2812. -               ucTmp = 0x01;
  2813.  
  2814. -       }
  2815.  
  2816. -
  2817.  
  2818. -   if ((ISBITSET(ucVal,1) ^ ISBITSET(ucVal,3) ^ ISBITSET(ucVal,4) ^ ISBITSET(ucVal,5)) == 0 )  {
  2819.  
  2820. -
  2821.  
  2822. -               ucTmp |= 0x02;
  2823.  
  2824. -       }
  2825.  
  2826. -
  2827.  
  2828. -   return PID_PARITY(ucTmp) | ucVal;
  2829.  
  2830. -
  2831.  
  2832. -}  /* eofn: lin_pidbyte */
  2833.  
  2834. -
  2835.  
  2836. -/******************************************************************************/
  2837.  
  2838. -/*!
  2839.  
  2840. -\fn        lin_checksum
  2841.  
  2842. -
  2843.  
  2844. -\brief     Checksumme erzeugen
  2845.  
  2846. -
  2847.  
  2848. -\return    Checksumme
  2849.  
  2850. -
  2851.  
  2852. -\param     pucData  - Zeiger auf Daten
  2853.  
  2854. -           iDataLen - Datenlaenge
  2855.  
  2856. -
  2857.  
  2858. -*******************************************************************************/
  2859.  
  2860. -static unsigned char lin_checksum( unsigned char *pucData, int iDataLen )
  2861.  
  2862. -{
  2863.  
  2864. -       unsigned short usTmp = 0;
  2865.  
  2866. -       int i;
  2867.  
  2868. -
  2869.  
  2870. -   for ( i = 0; i < iDataLen; i++ ) {
  2871.  
  2872. -
  2873.  
  2874. -               usTmp += pucData[i];
  2875.  
  2876. -               /* Ueberlauf pruefen */
  2877.  
  2878. -               if ( usTmp > 0xFF ) {
  2879.  
  2880. -                       usTmp &= 0x00FF;
  2881.  
  2882. -                       usTmp++; /* Carrybit addrieren */
  2883.  
  2884. -               }
  2885.  
  2886. -   }
  2887.  
  2888. -
  2889.  
  2890. -   return (unsigned char)(~usTmp);
  2891.  
  2892. -
  2893.  
  2894. -}  /* eofn: lin_checksum */
  2895.  
  2896. -
  2897.  
  2898. -/******************************************************************************/
  2899.  
  2900. -/*!
  2901.  
  2902. -\fn        lin_master_alive
  2903.  
  2904. -
  2905.  
  2906. -\brief     Master Alive-Message senden
  2907.  
  2908. -
  2909.  
  2910. -\return    Ergebnis
  2911.  
  2912. -           = 0 - OK
  2913.  
  2914. -                         < 0 - Fehler
  2915.  
  2916. -
  2917.  
  2918. -\param     ucNextFreeAdr - Naechste freie Adresse
  2919.  
  2920. -           ucSlaves      - Anzahl Teilnehmer
  2921.  
  2922. -                         ucAliveFlags  - Flags
  2923.  
  2924. -                                              
  2925.  
  2926. -*******************************************************************************/
  2927.  
  2928. -static int lin_master_alive( unsigned char ucNextFreeAdr, unsigned char ucSlaves, unsigned char ucAliveFlags )
  2929.  
  2930. -{
  2931.  
  2932. -       int iRet;
  2933.  
  2934. -
  2935.  
  2936. -       DEBUG_PRINT("MasterAlive:\n");
  2937.  
  2938. -       DEBUG_PRINT("Naechste freie Adresse : %i\n", ucNextFreeAdr);
  2939.  
  2940. -       DEBUG_PRINT("Anzahl LIN-Teilnehmer  : %i\n", ucSlaves);
  2941.  
  2942. -       DEBUG_PRINT("Flags                  : %i\n", ucAliveFlags);
  2943.  
  2944. -       DEBUG_PRINT("\n");
  2945.  
  2946. -      
  2947.  
  2948. -       /* MasterALive-Message aufbauen */
  2949.  
  2950. -   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  2951.  
  2952. -   acLinMsgBuffer[1] = lin_pidbyte(CMD_MASTER_ALIVE);
  2953.  
  2954. -   acLinMsgBuffer[2] = ucNextFreeAdr;
  2955.  
  2956. -   acLinMsgBuffer[3] = 1 + ucSlaves; /* Master + Slaves */
  2957.  
  2958. -   acLinMsgBuffer[4] = ucAliveFlags;
  2959.  
  2960. -   acLinMsgBuffer[5] = LIN_PROTOKOLL_VERS;
  2961.  
  2962. -       acLinMsgBuffer[6] = lin_checksum( &acLinMsgBuffer[1], 5);
  2963.  
  2964. -       iRet = lin_send_message( acLinMsgBuffer, 7 );
  2965.  
  2966. -
  2967.  
  2968. -   return iRet;
  2969.  
  2970. -
  2971.  
  2972. -}  /* eofn: lin_master_alive */  
  2973.  
  2974. -
  2975.  
  2976. -/******************************************************************************/
  2977.  
  2978. -/*!
  2979.  
  2980. -\fn        lin_reset_all
  2981.  
  2982. -
  2983.  
  2984. -\brief     Alle Adressen loeschen
  2985.  
  2986. -
  2987.  
  2988. -\return    Ergebnis
  2989.  
  2990. -           = 0 - OK
  2991.  
  2992. -                         < 0 - Fehler
  2993.  
  2994. -
  2995.  
  2996. -\param     keine
  2997.  
  2998. -                                              
  2999.  
  3000. -*******************************************************************************/
  3001.  
  3002. -static int lin_reset_all( void )
  3003.  
  3004. -{
  3005.  
  3006. -       int iRet;
  3007.  
  3008. -
  3009.  
  3010. -       DEBUG_PRINT("ResetAll:\n");
  3011.  
  3012. -
  3013.  
  3014. -       /* Reset-Message aufbauen */
  3015.  
  3016. -   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  3017.  
  3018. -   acLinMsgBuffer[1] = lin_pidbyte(CMD_RESET_ADDR);
  3019.  
  3020. -   acLinMsgBuffer[2] = 0x52;
  3021.  
  3022. -   acLinMsgBuffer[3] = 0x45;
  3023.  
  3024. -   acLinMsgBuffer[4] = 0x53;
  3025.  
  3026. -   acLinMsgBuffer[5] = 0x45;
  3027.  
  3028. -   acLinMsgBuffer[6] = 0x54;
  3029.  
  3030. -   acLinMsgBuffer[7] = 0x4E;
  3031.  
  3032. -   acLinMsgBuffer[8] = 0x4F;
  3033.  
  3034. -   acLinMsgBuffer[9] = 0x57;
  3035.  
  3036. -       acLinMsgBuffer[10] = lin_checksum( &acLinMsgBuffer[1], 9);
  3037.  
  3038. -   iRet = lin_send_message( acLinMsgBuffer, 11 );
  3039.  
  3040. -
  3041.  
  3042. -   return iRet;
  3043.  
  3044. -
  3045.  
  3046. -}  /* eofn: lin_reset_all */
  3047.  
  3048. -
  3049.  
  3050. -/******************************************************************************/
  3051.  
  3052. -/*!
  3053.  
  3054. -\fn        lin_set_value
  3055.  
  3056. -    
  3057.  
  3058. -\brief     Sollwert setzen    
  3059.  
  3060. -
  3061.  
  3062. -\return    Ergebnis
  3063.  
  3064. -           = 0 - OK
  3065.  
  3066. -                         < 0 - Fehler
  3067.  
  3068. -
  3069.  
  3070. -\param     usAdr           - LinAdresse
  3071.  
  3072. -           usSollPos       - Sollposition
  3073.  
  3074. -                         ucClontrolFlags - Steuerflags
  3075.  
  3076. -                                                
  3077.  
  3078. -*******************************************************************************/
  3079.  
  3080. -static int lin_set_value( unsigned char ucAdr, unsigned short usSollPos, unsigned char ucControlFlags, unsigned char ucDeviceTyp )
  3081.  
  3082. -{
  3083.  
  3084. -       int iRet;
  3085.  
  3086. -
  3087.  
  3088. -       DEBUG_PRINT("SetValue:\n");
  3089.  
  3090. -       DEBUG_PRINT("Slave   : %i\n", ucAdr );
  3091.  
  3092. -       DEBUG_PRINT("SollPos : %i\n", usSollPos );
  3093.  
  3094. -       DEBUG_PRINT("Flags   : %i\n", ucControlFlags );
  3095.  
  3096. -       DEBUG_PRINT("Flags   : %i\n", ucControlFlags );
  3097.  
  3098. -       DEBUG_PRINT("\n");
  3099.  
  3100. -
  3101.  
  3102. -       /* SetValue-Message aufbauen */
  3103.  
  3104. -   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  3105.  
  3106. -   acLinMsgBuffer[1] = lin_pidbyte(CMD_SETVALUE(ucAdr));
  3107.  
  3108. -   acLinMsgBuffer[2] = ucDeviceTyp;
  3109.  
  3110. -   acLinMsgBuffer[3] = ucControlFlags;
  3111.  
  3112. -   acLinMsgBuffer[4] = (unsigned char)(0x00ff & usSollPos);
  3113.  
  3114. -   acLinMsgBuffer[5] = (unsigned char)( usSollPos >> 8);
  3115.  
  3116. -   acLinMsgBuffer[6] = lin_checksum( &acLinMsgBuffer[1], 5);
  3117.  
  3118. -   iRet = lin_send_message( acLinMsgBuffer, 7 );
  3119.  
  3120. -
  3121.  
  3122. -   return iRet;
  3123.  
  3124. -
  3125.  
  3126. -}  /* eofn: lin_set_value */  
  3127.  
  3128. -
  3129.  
  3130. -/******************************************************************************/
  3131.  
  3132. -/*!
  3133.  
  3134. -\fn        lin_face_value
  3135.  
  3136. -
  3137.  
  3138. -\brief     Istwert auslesen
  3139.  
  3140. -
  3141.  
  3142. -\return    Ergebnis
  3143.  
  3144. -           = 0 - OK
  3145.  
  3146. -                         < 0 - Fehler
  3147.  
  3148. -
  3149.  
  3150. -\param     usAdr           - Adresse
  3151.  
  3152. -           ptLinSlaveData  - Zeiger auf Slavedaten
  3153.  
  3154. -
  3155.  
  3156. -*******************************************************************************/
  3157.  
  3158. -static int lin_face_value( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData )
  3159.  
  3160. -{
  3161.  
  3162. -       int    iRet;
  3163.  
  3164. -
  3165.  
  3166. -       DEBUG_PRINT("FaceValue: \n");
  3167.  
  3168. -
  3169.  
  3170. -       /* Face-Message aufbauen */
  3171.  
  3172. -   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  3173.  
  3174. -   acLinMsgBuffer[1] = lin_pidbyte(CMD_FACEVALUE(ucAdr));
  3175.  
  3176. -   if (( iRet = lin_send_message( acLinMsgBuffer, 2 )) < 0 ) {
  3177.  
  3178. -
  3179.  
  3180. -               /* Fehler beim Senden des Kommandos FaceValue */
  3181.  
  3182. -               return iRet;
  3183.  
  3184. -       }
  3185.  
  3186. -
  3187.  
  3188. -       /* Response vom Slave auswerten */
  3189.  
  3190. -       if (( iRet = lin_recv_message( &acLinMsgBuffer[1], 7 )) < 0 ) {
  3191.  
  3192. -
  3193.  
  3194. -               /* Fehler beim Empfang */
  3195.  
  3196. -               return iRet;
  3197.  
  3198. -       }
  3199.  
  3200. -
  3201.  
  3202. -       /* Empfangsdaten uebernehmen */
  3203.  
  3204. -       ptLinSlaveData->tValue.ucFormat   = acLinMsgBuffer[2];
  3205.  
  3206. -       ptLinSlaveData->tValue.usIstPos   = acLinMsgBuffer[3];
  3207.  
  3208. -       ptLinSlaveData->tValue.usIstPos  |= acLinMsgBuffer[4] << 8;
  3209.  
  3210. -       ptLinSlaveData->tValue.ucStatus   = acLinMsgBuffer[5];
  3211.  
  3212. -       ptLinSlaveData->tValue.ucErrorCnt = acLinMsgBuffer[6];
  3213.  
  3214. -
  3215.  
  3216. -       DEBUG_PRINT("Format  : %i\n", ptLinSlaveData->tValue.ucFormat);
  3217.  
  3218. -       DEBUG_PRINT("IstPos  : %i\n", ptLinSlaveData->tValue.usIstPos);
  3219.  
  3220. -       DEBUG_PRINT("Status  : %i\n", ptLinSlaveData->tValue.ucStatus);
  3221.  
  3222. -       DEBUG_PRINT("Fehler  : %i\n", ptLinSlaveData->tValue.ucErrorCnt);
  3223.  
  3224. -       DEBUG_PRINT("\n");
  3225.  
  3226. -
  3227.  
  3228. -   return 0;
  3229.  
  3230. -
  3231.  
  3232. -}  /* eofn: lin_face_value */
  3233.  
  3234. -
  3235.  
  3236. -/******************************************************************************/
  3237.  
  3238. -/*!
  3239.  
  3240. -\fn       lin_get_version
  3241.  
  3242. -
  3243.  
  3244. -\brief    Version auslesen
  3245.  
  3246. -
  3247.  
  3248. -\return   Ergebnis
  3249.  
  3250. -          = 0 - OK
  3251.  
  3252. -                        < 0 - Fehler
  3253.  
  3254. -
  3255.  
  3256. -\param     ucAdr           - Adresse
  3257.  
  3258. -           ptLinSlaveData  - Zeiger auf Slavedaten
  3259.  
  3260. -                                        
  3261.  
  3262. -*******************************************************************************/
  3263.  
  3264. -static int lin_get_version( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData )
  3265.  
  3266. -{
  3267.  
  3268. -       int    iRet;
  3269.  
  3270. -
  3271.  
  3272. -       DEBUG_PRINT("GetVersion %i: \n", ucAdr);
  3273.  
  3274. -
  3275.  
  3276. -       /* Face-Message aufbauen */
  3277.  
  3278. -   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  3279.  
  3280. -   acLinMsgBuffer[1] = lin_pidbyte(CMD_VERSION(ucAdr));
  3281.  
  3282. -   if (( iRet = lin_send_message( acLinMsgBuffer, 2 )) < 0 ) {
  3283.  
  3284. -
  3285.  
  3286. -               /* Fehler beim Senden des Kommandos GetVersion */
  3287.  
  3288. -               return iRet;
  3289.  
  3290. -       }
  3291.  
  3292. -
  3293.  
  3294. -       /* Response vom Slave auswerten */
  3295.  
  3296. -       if (( iRet = lin_recv_message( &acLinMsgBuffer[1], 10 )) < 0 ) {
  3297.  
  3298. -
  3299.  
  3300. -               /* Fehler beim Empfang */
  3301.  
  3302. -               return iRet;
  3303.  
  3304. -       }
  3305.  
  3306. -
  3307.  
  3308. -       /* Empfangsdaten uebernehmen */
  3309.  
  3310. -       ptLinSlaveData->tVers.ucRelease   = acLinMsgBuffer[2];
  3311.  
  3312. -       ptLinSlaveData->tVers.ucVersion   = acLinMsgBuffer[3];
  3313.  
  3314. -       ptLinSlaveData->tVers.ucVariant   = acLinMsgBuffer[4];
  3315.  
  3316. -       ptLinSlaveData->tVers.ucFormat    = acLinMsgBuffer[5];
  3317.  
  3318. -       ptLinSlaveData->tVers.usManCode   = acLinMsgBuffer[6];
  3319.  
  3320. -       ptLinSlaveData->tVers.usManCode  |= acLinMsgBuffer[7]<<8;
  3321.  
  3322. -       ptLinSlaveData->tVers.usFunction  = acLinMsgBuffer[8];  
  3323.  
  3324. -       ptLinSlaveData->tVers.usFunction |= acLinMsgBuffer[9]<<8;
  3325.  
  3326. -
  3327.  
  3328. -       DEBUG_PRINT("Release : %i\n", ptLinSlaveData->tVers.ucRelease);
  3329.  
  3330. -       DEBUG_PRINT("Version : %i\n", ptLinSlaveData->tVers.ucVersion);
  3331.  
  3332. -       DEBUG_PRINT("Build   : %i\n", ptLinSlaveData->tVers.ucVariant);
  3333.  
  3334. -       DEBUG_PRINT("Format  : %i\n", ptLinSlaveData->tVers.ucFormat);
  3335.  
  3336. -       DEBUG_PRINT("ManCode : %i\n", ptLinSlaveData->tVers.usManCode);
  3337.  
  3338. -       DEBUG_PRINT("Function: %i\n", ptLinSlaveData->tVers.usFunction);
  3339.  
  3340. -       DEBUG_PRINT("\n");
  3341.  
  3342. -
  3343.  
  3344. -   return 0;
  3345.  
  3346. -
  3347.  
  3348. -}  /* eofn: lin_get_version */
  3349.  
  3350. -
  3351.  
  3352. -/******************************************************************************/
  3353.  
  3354. -/*!
  3355.  
  3356. -\fn            LIN_Open
  3357.  
  3358. -
  3359.  
  3360. -\brief         Schnittstelle fuer den LIN-Bus oeffnen
  3361.  
  3362. -
  3363.  
  3364. -\return         0  - Schnittstelle konnte geoffnet werden
  3365.  
  3366. -               -1  - Fehler beim Oeffnen
  3367.  
  3368. -
  3369.  
  3370. -\param         iSlaveCount - Anzahl der Linbus-Slaves
  3371.  
  3372. -               iIntervall  - Intervallzeit fuer Lin-Bus-Verarbeitung
  3373.  
  3374. -              
  3375.  
  3376. -*******************************************************************************/
  3377.  
  3378. -int LIN_Open( int iSlaveCount, int iIntervall )
  3379.  
  3380. -{
  3381.  
  3382. -   RTS_RESULT rtsResult;
  3383.  
  3384. -
  3385.  
  3386. -       /* pruefen ob Linbus bereits geoeffnet wurde */
  3387.  
  3388. -       if ( rtsMasterThreadHandle != RTS_INVALID_HANDLE ) {
  3389.  
  3390. -               /* Linbus schliessen */
  3391.  
  3392. -               LIN_Close();
  3393.  
  3394. -       }
  3395.  
  3396. -
  3397.  
  3398. -   /******************/                
  3399.  
  3400. -       /* Device oeffnen */
  3401.  
  3402. -       /******************/
  3403.  
  3404. -       iLinPort = open( cacDeviceName, O_RDWR);
  3405.  
  3406. -       if ( iLinPort < 0 ) {
  3407.  
  3408. -
  3409.  
  3410. -         Log_Warning(COMPONENT_ID, "Device kann nicht geoeffnet werden\n");
  3411.  
  3412. -         return ERR_LIN_DEVICE;
  3413.  
  3414. -       }
  3415.  
  3416. -
  3417.  
  3418. -       tcgetattr(iLinPort, &initial_settings);
  3419.  
  3420. -       new_settings = initial_settings;
  3421.  
  3422. -
  3423.  
  3424. -       /************************************/
  3425.  
  3426. -       /* Schnittstelleneinstellung setzen */
  3427.  
  3428. -       /************************************/
  3429.  
  3430. -       /* Baudrate */
  3431.  
  3432. -       BaudRate = LIN_BAUD_RATE;
  3433.  
  3434. -   if (cfsetispeed(&new_settings, BaudRate) != 0) {
  3435.  
  3436. -               return ERR_LIN_BAUDRATE;
  3437.  
  3438. -       }
  3439.  
  3440. -       cfmakeraw(&new_settings);
  3441.  
  3442. -
  3443.  
  3444. -       /* Flags */
  3445.  
  3446. -       new_settings.c_cflag &= ~CSTOPB;        /* 1 Stopbit */
  3447.  
  3448. -       new_settings.c_cflag &= ~PARENB; /* keine Paritaet */
  3449.  
  3450. -       new_settings.c_cflag &= ~CSIZE;  /* 8 Datenbits */
  3451.  
  3452. -       new_settings.c_cflag |= CS8;
  3453.  
  3454. -
  3455.  
  3456. -   if (tcsetattr(iLinPort, TCSAFLUSH, &new_settings)  != 0) {
  3457.  
  3458. -
  3459.  
  3460. -      Log_Warning(COMPONENT_ID, "Device konnte nicht initialsiert werden\n");
  3461.  
  3462. -      return ERR_LIN_PORTSETTING;
  3463.  
  3464. -       }
  3465.  
  3466. -
  3467.  
  3468. -       /*******************************/
  3469.  
  3470. -       /* Initialisierung uebernehmen */
  3471.  
  3472. -       /*******************************/
  3473.  
  3474. -       iLinSlaveCnt  = iSlaveCount;
  3475.  
  3476. -       iLinIntervall = iIntervall;
  3477.  
  3478. -
  3479.  
  3480. -       /*********************************/
  3481.  
  3482. -       /* Empfangspuffer initialisieren */
  3483.  
  3484. -       /*********************************/
  3485.  
  3486. -       iLinRxWrIndex = 0;
  3487.  
  3488. -       iLinRxRdIndex = 0;
  3489.  
  3490. -
  3491.  
  3492. -       /***************************/
  3493.  
  3494. -       /* Empfangsthread erzeugen */
  3495.  
  3496. -       /***************************/
  3497.  
  3498. -       rtsRxThreadHandle = CAL_SysTaskCreate( acRxThreadName, lin_rx_thread, NULL, RXTHREAD_PRIO, 0, 0, NULL, &rtsResult);
  3499.  
  3500. -       if ((rtsRxThreadHandle == RTS_INVALID_HANDLE) || (rtsResult != ERR_OK)) {
  3501.  
  3502. -
  3503.  
  3504. -               Log_Warning(COMPONENT_ID, "LIN_Open: Rx-Task kann nicht angelegt werden\n");
  3505.  
  3506. -               return ERR_LIN_DEVICE;
  3507.  
  3508. -       }
  3509.  
  3510. -
  3511.  
  3512. -       /* Task starten */
  3513.  
  3514. -       CAL_SysTaskResume(rtsRxThreadHandle);
  3515.  
  3516. -
  3517.  
  3518. -       /*************************/
  3519.  
  3520. -       /* Masterthread erzeugen */
  3521.  
  3522. -       /*************************/
  3523.  
  3524. -       rtsMasterThreadHandle = CAL_SysTaskCreate( acMasterThreadName, lin_master_thread, NULL, LINTHREAD_PRIO, 0, 0, NULL, &rtsResult);
  3525.  
  3526. -       if ((rtsMasterThreadHandle == RTS_INVALID_HANDLE) || (rtsResult != ERR_OK)) {
  3527.  
  3528. -
  3529.  
  3530. -               Log_Warning(COMPONENT_ID, "LIN_Open: Master-Task kann nicht angelegt werden\n");
  3531.  
  3532. -               return ERR_LIN_DEVICE;
  3533.  
  3534. -       }
  3535.  
  3536. -
  3537.  
  3538. -       /* Task starten */
  3539.  
  3540. -       CAL_SysTaskResume(rtsMasterThreadHandle);
  3541.  
  3542. -   iLinMasterState = LIN_MASTER_CHECK;
  3543.  
  3544. -
  3545.  
  3546. -       return 0;
  3547.  
  3548. -
  3549.  
  3550. -}  /* eofn: LIN_Open */
  3551.  
  3552. -
  3553.  
  3554. -
  3555.  
  3556. -/******************************************************************************/
  3557.  
  3558. -/*!
  3559.  
  3560. -\fn            LIN_Close
  3561.  
  3562. -
  3563.  
  3564. -\brief         Schnittstelle fuer den LIN-Bus schliessen
  3565.  
  3566. -
  3567.  
  3568. -\return         0  - Schnittstelle konnte geschlossen werden
  3569.  
  3570. -               -1  - Fehler beim Schliessen
  3571.  
  3572. -
  3573.  
  3574. -\param         keine
  3575.  
  3576. -              
  3577.  
  3578. -*******************************************************************************/
  3579.  
  3580. -int LIN_Close( void )
  3581.  
  3582. -{
  3583.  
  3584. -
  3585.  
  3586. -       unsigned char ucTmp = 0;
  3587.  
  3588. -
  3589.  
  3590. -       /*************************/
  3591.  
  3592. -       /* Mastertask schliessen */
  3593.  
  3594. -       /*************************/
  3595.  
  3596. -   if ( rtsMasterThreadHandle != RTS_INVALID_HANDLE ) {
  3597.  
  3598. -
  3599.  
  3600. -      CAL_SysTaskSetExit(rtsMasterThreadHandle);
  3601.  
  3602. -      CAL_SysTaskExit(rtsMasterThreadHandle, 1000);
  3603.  
  3604. -      rtsMasterThreadHandle = RTS_INVALID_HANDLE;
  3605.  
  3606. -   }
  3607.  
  3608. -
  3609.  
  3610. -       /***************************/
  3611.  
  3612. -       /* Empfangstask schliessen */
  3613.  
  3614. -       /***************************/
  3615.  
  3616. -   if ( rtsRxThreadHandle != RTS_INVALID_HANDLE ) {
  3617.  
  3618. -
  3619.  
  3620. -               lin_send( &ucTmp, 1 ); /* Dummy-Byte senden um Empfangsthread abzubrechen */
  3621.  
  3622. -
  3623.  
  3624. -      CAL_SysTaskSetExit(rtsRxThreadHandle);
  3625.  
  3626. -      CAL_SysTaskExit(rtsRxThreadHandle, 1000);
  3627.  
  3628. -      rtsRxThreadHandle = RTS_INVALID_HANDLE;
  3629.  
  3630. -   }
  3631.  
  3632. -
  3633.  
  3634. -   /*********************/                
  3635.  
  3636. -       /* Device schliessen */
  3637.  
  3638. -   /*********************/
  3639.  
  3640. -       if ( iLinPort >= 0 ) {
  3641.  
  3642. -
  3643.  
  3644. -               if ( close( iLinPort ) != 0 ) {
  3645.  
  3646. -
  3647.  
  3648. -                 Log_Warning(COMPONENT_ID, "Device kann nicht geschlossen werden\n");
  3649.  
  3650. -                 return ERR_LIN_DEVICE;
  3651.  
  3652. -               }
  3653.  
  3654. -       }
  3655.  
  3656. -
  3657.  
  3658. -       return 0;
  3659.  
  3660. -
  3661.  
  3662. -}  /* eofn: LIN_Close */
  3663.  
  3664. -
  3665.  
  3666. -/******************************************************************************/
  3667.  
  3668. -/*!
  3669.  
  3670. -\fn            LIN_GetMasterState
  3671.  
  3672. -
  3673.  
  3674. -\brief         Funktion liefert den Status des Linbus-Master
  3675.  
  3676. -
  3677.  
  3678. -\return        Status des Linbus-Masters
  3679.  
  3680. -
  3681.  
  3682. -\param         keine
  3683.  
  3684. -              
  3685.  
  3686. -*******************************************************************************/
  3687.  
  3688. -int LIN_GetMasterState( void )
  3689.  
  3690. -{
  3691.  
  3692. -       return iLinMasterState;
  3693.  
  3694. -
  3695.  
  3696. -}  /* eofn: LIN_GetMasterState */
  3697.  
  3698. -
  3699.  
  3700. -/******************************************************************************/
  3701.  
  3702. -/*!
  3703.  
  3704. -\fn            LIN_GetSlaveState
  3705.  
  3706. -
  3707.  
  3708. -\brief         Funktion liefert den Status des Linbus-Slave
  3709.  
  3710. -
  3711.  
  3712. -\return        Status des Linbus-Slave
  3713.  
  3714. -
  3715.  
  3716. -\param         iSlave - Linbus-Slave
  3717.  
  3718. -              
  3719.  
  3720. -*******************************************************************************/
  3721.  
  3722. -int LIN_GetSlaveState( int iSlave )
  3723.  
  3724. -{
  3725.  
  3726. -       if ( iSlave > MAX_LIN_SLAVE ) {
  3727.  
  3728. -
  3729.  
  3730. -               return -1;
  3731.  
  3732. -       }
  3733.  
  3734. -
  3735.  
  3736. -       return atLinSlaveData[iSlave].ucSlaveOnline;
  3737.  
  3738. -
  3739.  
  3740. -}  /* eofn: LIN_GetSlaveState */
  3741.  
  3742. -
  3743.  
  3744. -/******************************************************************************/
  3745.  
  3746. -/*!
  3747.  
  3748. -\fn            LIN_ResetAddress
  3749.  
  3750. -
  3751.  
  3752. -\brief         Alle Adressen der Linbus-Slaves loeschen
  3753.  
  3754. -
  3755.  
  3756. -\return        Adressen werden geloescht
  3757.  
  3758. -                0  - Loeschen wird ausgefuehrt
  3759.  
  3760. -                                       -1  - Fehler beim Loeschen
  3761.  
  3762. -
  3763.  
  3764. -\param         keine
  3765.  
  3766. -              
  3767.  
  3768. -*******************************************************************************/
  3769.  
  3770. -int LIN_ResetAddress( void )
  3771.  
  3772. -{
  3773.  
  3774. -
  3775.  
  3776. -       /* Reset ausfuehren */
  3777.  
  3778. -       iLinResetAddr = TRUE;
  3779.  
  3780. -
  3781.  
  3782. -       return 0;
  3783.  
  3784. -
  3785.  
  3786. -}  /* eofn: LIN_ResetAddress */
  3787.  
  3788. -
  3789.  
  3790. -/******************************************************************************/
  3791.  
  3792. -/*!
  3793.  
  3794. -\fn            LIN_SetAddress
  3795.  
  3796. -
  3797.  
  3798. -\brief         Adressen der Linbus-Slaves neu setzen
  3799.  
  3800. -
  3801.  
  3802. -\return        Adressen werden gesetzt
  3803.  
  3804. -                0  - Setzen wird ausgefuehrt
  3805.  
  3806. -
  3807.  
  3808. -\param         keine
  3809.  
  3810. -              
  3811.  
  3812. -*******************************************************************************/
  3813.  
  3814. -int LIN_SetAddress( void )
  3815.  
  3816. -{
  3817.  
  3818. -
  3819.  
  3820. -       /* Setzen ausfuehren */
  3821.  
  3822. -       iLinSetAddr = TRUE;
  3823.  
  3824. -
  3825.  
  3826. -       return 0;
  3827.  
  3828. -
  3829.  
  3830. -}  /* eofn: LIN_SetAddress */
  3831.  
  3832. -
  3833.  
  3834. -/******************************************************************************/
  3835.  
  3836. -/*!
  3837.  
  3838. -\fn            LIN_GetVersion
  3839.  
  3840. -
  3841.  
  3842. -\brief         Version des Linbus-Slaves auslesen
  3843.  
  3844. -
  3845.  
  3846. -\return        Versionsdaten gueltig
  3847.  
  3848. -                0  - Gueltig
  3849.  
  3850. -                                       -1  - Ungueltig
  3851.  
  3852. -
  3853.  
  3854. -\param         iSlave            - Linbus-Slave
  3855.  
  3856. -                                       ptLinSlaveVersion - Zeiger auf Versionsdaten des Slaves
  3857.  
  3858. -              
  3859.  
  3860. -*******************************************************************************/
  3861.  
  3862. -int LIN_GetVersion( int iSlave, LIN_SLAVE_VERSION_TR *ptLinSlaveVersion )
  3863.  
  3864. -{
  3865.  
  3866. -       if ( iSlave > MAX_LIN_SLAVE ) {
  3867.  
  3868. -
  3869.  
  3870. -               /* Slavenummer ist ungueltig */
  3871.  
  3872. -               return -1;
  3873.  
  3874. -       }
  3875.  
  3876. -
  3877.  
  3878. -       if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  3879.  
  3880. -
  3881.  
  3882. -               /* Slave nicht vorhanden; Versioneintrag loeschen */
  3883.  
  3884. -               memset(&atLinSlaveData[iSlave].tVers, 0, sizeof(LIN_SLAVE_VERSION_TR));
  3885.  
  3886. -       }
  3887.  
  3888. -
  3889.  
  3890. -       /* Versionseintrag uebernehmen */
  3891.  
  3892. -       memcpy( ptLinSlaveVersion, &atLinSlaveData[iSlave].tVers, sizeof(LIN_SLAVE_VERSION_TR));
  3893.  
  3894. -
  3895.  
  3896. -       return 0;
  3897.  
  3898. -
  3899.  
  3900. -}  /* eofn: LIN_GetVersion */
  3901.  
  3902. -
  3903.  
  3904. -/******************************************************************************/
  3905.  
  3906. -/*!
  3907.  
  3908. -\fn            LIN_GetFaceValue
  3909.  
  3910. -
  3911.  
  3912. -\brief         Istwert des Linbus-Slaves auslesen
  3913.  
  3914. -
  3915.  
  3916. -\return        Istwert des Linbus-Slaves
  3917.  
  3918. -               >=0  - Istwert gueltig
  3919.  
  3920. -                                        -1  - ungueltiger Wert
  3921.  
  3922. -
  3923.  
  3924. -\param         iSlave           - Linbus-Slave
  3925.  
  3926. -               ptLinSlaveValue  - Zeiger auf Istwerte des Slaves
  3927.  
  3928. -              
  3929.  
  3930. -*******************************************************************************/
  3931.  
  3932. -int LIN_GetFaceValue( int iSlave, LIN_SLAVE_VALUE_TR *ptLinSlaveValue )
  3933.  
  3934. -{
  3935.  
  3936. -
  3937.  
  3938. -       if ( iSlave > MAX_LIN_SLAVE ) {
  3939.  
  3940. -
  3941.  
  3942. -               return -1;
  3943.  
  3944. -       }
  3945.  
  3946. -
  3947.  
  3948. -       if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  3949.  
  3950. -
  3951.  
  3952. -               /* Slave nicht vorhanden; Versioneintrag loeschen */
  3953.  
  3954. -               memset(&atLinSlaveData[iSlave].tValue, 0, sizeof(LIN_SLAVE_VALUE_TR));
  3955.  
  3956. -       }
  3957.  
  3958. -
  3959.  
  3960. -       /* Werte uebernehmen */
  3961.  
  3962. -       memcpy( ptLinSlaveValue, &atLinSlaveData[iSlave].tValue, sizeof(LIN_SLAVE_VALUE_TR));
  3963.  
  3964. -
  3965.  
  3966. -       return 0;
  3967.  
  3968. -
  3969.  
  3970. -}      /* eofn: LIN_GetFaceValue */
  3971.  
  3972. -
  3973.  
  3974. -/******************************************************************************/
  3975.  
  3976. -/*!
  3977.  
  3978. -\fn            LIN_SetValue
  3979.  
  3980. -
  3981.  
  3982. -\brief         Sollwert des Linbus-Slaves setzen
  3983.  
  3984. -
  3985.  
  3986. -\return        Sollwert wird uebernommen
  3987.  
  3988. -                0  - Uebernahme wird ausgefuehrt
  3989.  
  3990. -                                       -1  - Fehler bei der Uebernahme
  3991.  
  3992. -
  3993.  
  3994. -\param         iSlave    - Linbus-Slave
  3995.  
  3996. -               usValue   - Sollwert
  3997.  
  3998. -                                       ucControl - Steuerflags
  3999.  
  4000. -                                      
  4001.  
  4002. -*******************************************************************************/
  4003.  
  4004. -int LIN_SetValue( int iSlave, unsigned short usValue, unsigned char ucControl, unsigned char ucDevice  )
  4005.  
  4006. -{
  4007.  
  4008. -       if ( iSlave > MAX_LIN_SLAVE ) {
  4009.  
  4010. -
  4011.  
  4012. -               /* Adressierung ungueltig */
  4013.  
  4014. -               return -1;
  4015.  
  4016. -       }
  4017.  
  4018. -
  4019.  
  4020. -       if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  4021.  
  4022. -
  4023.  
  4024. -               /* Slave nicht vorhanden */
  4025.  
  4026. -               return -1;
  4027.  
  4028. -       }
  4029.  
  4030. -
  4031.  
  4032. -       /* Werte uebernehmen */
  4033.  
  4034. -       atLinSlaveData[iSlave].ucSetNewValue = TRUE;
  4035.  
  4036. -       atLinSlaveData[iSlave].usSetValue    = usValue;
  4037.  
  4038. -       atLinSlaveData[iSlave].ucSetControl  = ucControl;
  4039.  
  4040. -       atLinSlaveData[iSlave].ucDevice  = ucDevice;
  4041.  
  4042. -
  4043.  
  4044. -       return 0;
  4045.  
  4046. -
  4047.  
  4048. -}      /* eofn: LIN_SetValue */
  4049.  
  4050. -
  4051.  
  4052. -/******************************************************************************/
  4053.  
  4054. -/*!
  4055.  
  4056. -\fn            LIN_MasterSetValue
  4057.  
  4058. -
  4059.  
  4060. -\brief         Sollwert fuer alle Linbus-Slaves setzen
  4061.  
  4062. -
  4063.  
  4064. -\return        Sollwert wird uebernommen
  4065.  
  4066. -                0  - Uebernahme wird ausgefuehrt
  4067.  
  4068. -                                       -1  - Fehler bei der Uebernahme
  4069.  
  4070. -
  4071.  
  4072. -\param         usValue   - Sollwert
  4073.  
  4074. -               ucControl - Steuerflags
  4075.  
  4076. -              
  4077.  
  4078. -*******************************************************************************/
  4079.  
  4080. -int LIN_MasterSetValue( unsigned short usValue, unsigned char ucControl, unsigned char ucDevice )
  4081.  
  4082. -{
  4083.  
  4084. -       if ( iLinMasterState != LIN_MASTER_ONLINE ) {
  4085.  
  4086. -
  4087.  
  4088. -               /* Master nicht Online */
  4089.  
  4090. -               return -1;
  4091.  
  4092. -       }
  4093.  
  4094. -
  4095.  
  4096. -       /* Werte uebernehmen */
  4097.  
  4098. -       ucLinMasterNewValue = TRUE;
  4099.  
  4100. -       usLinMasterValue    = usValue;
  4101.  
  4102. -       ucLinMasterControl  = ucControl;
  4103.  
  4104. -       ucLinMasterDevice   = ucDevice;
  4105.  
  4106. -      
  4107.  
  4108. -
  4109.  
  4110. -       return 0;
  4111.  
  4112. -
  4113.  
  4114. -}      /* eofn: LIN_MasterSetValue */
  4115.  
  4116. -
  4117.  
  4118. -/*--- eof  ---*/
  4119.  
  4120. -
  4121.  
  4122. +/******************************************************************************/
  4123. +/*!
  4124. +\file              $URL: https://subversion.eckelmann.local/svn/max/quantron_a/trunk/src/codesys/qa/linbus.c $
  4125. +
  4126. +\brief             Modul fuer die LIN-Bus-Kommunikation
  4127. +
  4128. +\author            $Author: HILTENKA $
  4129. +\date              $Date: 2011-03-09 17:18:26 +0100 (Mi, 09 Mrz 2011) $
  4130. +
  4131. +\version           $Rev: 1700 $
  4132. +
  4133. +\b                 ECKELMANN INDUSTRIEAUTOMATION, WIESBADEN\n
  4134. +                   � Copyright 2010
  4135. +
  4136. +*******************************************************************************/
  4137. +
  4138. +/*******************************************************************************
  4139. +@Includes
  4140. +*******************************************************************************/
  4141. +
  4142. +#include <time.h>
  4143. +#include <fcntl.h>
  4144. +#include <unistd.h>
  4145. +#include <sys/time.h>
  4146. +#include <sys/types.h>
  4147. +#include <sys/stat.h>
  4148. +#include <termios.h>
  4149. +
  4150. +/* Headerfiles Codesys-Componenten-Lib */
  4151. +#include "CmpStd.h"
  4152. +#include "CmpErrors.h"
  4153. +#include "CmpItf.h"
  4154. +
  4155. +/* Headerfile Dependend */
  4156. +#include "linbus_imp.h"
  4157. +#include "LinbusDep.h"
  4158. +
  4159. +
  4160. +
  4161. +#define ISBITSET(val, bit)    ( ((val) & (1 << (bit)))? 1:0 )
  4162. +
  4163. +
  4164. +
  4165. +/**************************/
  4166. +/* LIN-Kommandos/Adressen */
  4167. +/**************************/
  4168. +#define  ADDR(x)                               (x << 2)
  4169. +#define  PID_PARITY(x)                         (x << 6)
  4170. +
  4171. +#define  LIN_SLAVE_1             0x0
  4172. +#define  LIN_SLAVE_2             0x1
  4173. +#define  LIN_SLAVE_3             0x2
  4174. +#define  LIN_SLAVE_4             0x3
  4175. +#define  LIN_SLAVE_5             0x4
  4176. +#define  LIN_SLAVE_6             0x5
  4177. +#define  LIN_SLAVE_7             0x6
  4178. +#define  LIN_SLAVE_8             0x7
  4179. +#define  LIN_SLAVE_9             0x8
  4180. +#define  LIN_SLAVE_10            0x9
  4181. +#define  LIN_SLAVE_11            0xA
  4182. +#define  LIN_SLAVE_12            0xB
  4183. +#define  LIN_SLAVE_13            0xC
  4184. +#define  LIN_SLAVE_14            0xD
  4185. +#define  LIN_MASTER                               0xE
  4186. +#define  CMD_FACEVALUE(adr)            (ADDR(adr) | 0x0 )
  4187. +#define  CMD_SETVALUE(adr)             (ADDR(adr) | 0x1 )
  4188. +#define  CMD_RESERVED(adr)             (ADDR(adr) | 0x2 )
  4189. +#define  CMD_VERSION(adr)              (ADDR(adr) | 0x3 )
  4190. +
  4191. +#define  CMD_MASTER_ALIVE              (ADDR(LIN_MASTER) | 0x0 )
  4192. +#define  CMD_MASTER_SETVALUE           (ADDR(LIN_MASTER) | 0x1 )
  4193. +#define  CMD_RESET_ADDR                (ADDR(LIN_MASTER) | 0x3 )
  4194. +
  4195. +/**************************/
  4196. +/* LIN-Steuerflags Master */
  4197. +/**************************/
  4198. +#define  LIN_MASTER_INITFLAG     0x02
  4199. +
  4200. +/***********************************/
  4201. +/* LIN-Steuerflags Sollwert setzen */
  4202. +/***********************************/
  4203. +#define  LIN_SET_SOLL_POS        0x01
  4204. +#define  LIN_SET_SLOW            0x02
  4205. +#define  LIN_SET_MANUAL_OU       0x04
  4206. +#define  LIN_SET_MANUAL_IN       0x08
  4207. +#define  LIN_SET_SELFTEST        0x80
  4208. +
  4209. +/*******************/
  4210. +/* LIN-Fehlercodes */
  4211. +/*******************/
  4212. +#define  ERR_LIN_DEVICE          (-1)
  4213. +#define  ERR_LIN_PORTSETTING     (-2)
  4214. +#define  ERR_LIN_BAUDRATE        (-3)
  4215. +#define  ERR_LIN_TIMEOUT         (-4)
  4216. +#define  ERR_LIN_TIMEOUT_ECHO    (-5)
  4217. +#define  ERR_LIN_TIMEOUT_MSG     (-6)
  4218. +#define  ERR_LIN_SEND_MESSAGE    (-7)
  4219. +#define  ERR_LIN_CHECKSUM        (-8)
  4220. +
  4221. +/***************/
  4222. +/* LIN-Timeout */
  4223. +/***************/
  4224. +#define  LIN_TIMEOUT_ECHO                      50         /* 50 ms  Timeoutzeit fuer Echobytes */
  4225. +#define  LIN_TIMEOUT_MESSAGE     100        /* 100 ms Timeoutzeit fuer Clientantwort */
  4226. +
  4227. +/*************************/
  4228. +/* Sonstige Definitionen */
  4229. +/*************************/
  4230. +#define  LIN_BAUD_RATE                         B9600
  4231. +#define  MAX_LIN_FRAME_BUFFER          30
  4232. +#define  MAX_LIN_SLAVE           14
  4233. +#define  LIN_SYNCBYTE                  0x55
  4234. +#define  LIN_TYP_MOTOR                 0
  4235. +#define  LIN_PROTOKOLL_VERS      0
  4236. +#define  DRV_NAME_LEN                     20
  4237. +#define  LIN_MSG_RETRY           3
  4238. +
  4239. +#ifndef x86
  4240. +#define LINTHREAD_PRIO           38     /* RT-Linux; SCHED_FIFO */
  4241. +#else
  4242. +#define LINTHREAD_PRIO           54    /* kein RT-Linux; SCHED_OTHER */
  4243. +#endif
  4244. +#define LINTHREAD_ZYKLUS         10    /* 10ms Zykluszeit */
  4245. +
  4246. +#ifndef x86
  4247. +#define RXTHREAD_PRIO            38     /* RT-Linux; SCHED_FIFO */
  4248. +#else
  4249. +#define RXTHREAD_PRIO            54    /* kein RT-Linux; SCHED_OTHER */
  4250. +#endif
  4251. +
  4252. +
  4253. +/*******************************************************************************
  4254. +@Typdefinitionen (modullokal)
  4255. +*******************************************************************************/
  4256. +
  4257. +typedef struct LIN_SLAVE_DATA_R {
  4258. +    LIN_SLAVE_VERSION_TR tVers;                /* Version */
  4259. +    LIN_SLAVE_VALUE_TR   tValue;               /* FaceValue */
  4260. +    unsigned char  ucSlaveOnline;              /* Verbindungsstatus */
  4261. +    unsigned char  ucSetNewValue;      /* Flag fuer neuen Sollwert */
  4262. +    unsigned short usSetValue;         /* Sollwert */
  4263. +    unsigned char  ucSetControl;       /* Steuerbits fuer Sollwert */
  4264. +    unsigned char  ucDevice;
  4265. +}  LIN_SLAVE_DATA_TR;
  4266. +
  4267. +
  4268. +/*******************************************************************************
  4269. +@Konstanten (modullokal)
  4270. +*******************************************************************************/
  4271. +
  4272. +/*
  4273. + * Device name, Quantron uses /dev/ttymxc1, Jobrechner /dev/ttymxc3
  4274. + */
  4275. +static const char cacDeviceName[DRV_NAME_LEN] = { "/dev/ttymxc1"};
  4276. +
  4277. +/*******************************************************************************
  4278. +@Variablen (modullokal)
  4279. +*******************************************************************************/
  4280. +
  4281. +/* Variablen Linbus-Schnittstellen */
  4282. +static int     iLinPort = -1;                                                     /* Porthandle */
  4283. +static struct  termios initial_settings, new_settings;   /* Portsettings */
  4284. +static speed_t BaudRate;                                 /* Baudrate */
  4285. +
  4286. +/* Variablen Masterthread */
  4287. +static RTS_HANDLE rtsMasterThreadHandle = RTS_INVALID_HANDLE; /* Handle MasterThread */
  4288. +static char acMasterThreadName[64] = { "LinMasterThread" };
  4289. +static int  iLinMasterState;                             /* Zustand Master */
  4290. +
  4291. +/* Variablen Empfangsthread */
  4292. +static RTS_HANDLE rtsRxThreadHandle = RTS_INVALID_HANDLE;     /* Handle RxThread */
  4293. +static char acRxThreadName[64] = { "LinRxThread" };
  4294. +
  4295. +/* Variablen Empfang/Sendefunktion */
  4296. +static unsigned char  acLinMsgBuffer[MAX_LIN_FRAME_BUFFER];     /* Nachrichtenpuffer */
  4297. +static unsigned char  acLinRxBuffer[MAX_LIN_FRAME_BUFFER];      /* Empfangspuffer */
  4298. +static int            iLinRxWrIndex;                     /* Schreibzeiger Empfangspuffer */
  4299. +static int            iLinRxRdIndex;                     /* Lesezeiger Empfangspuffer */
  4300. +
  4301. +/* Zustaende von Master und Slaves */
  4302. +static LIN_SLAVE_DATA_TR atLinSlaveData[MAX_LIN_SLAVE];  /* Slavezustaende */
  4303. +static int            iLinSlaveCnt;                      /* Anzahl der konfigurieren Slaves */
  4304. +static int            iLinIntervall;                     /* Intervall fuer die Bearbeitung des Linbus */
  4305. +static int            iLinResetAddr;                     /* Flag fuer das Ruecksetzen der Adressen */
  4306. +static int            iLinSetAddr;                       /* Flag fuer das Setzen der Adressen */
  4307. +static unsigned char  ucLinMasterNewValue;               /* Flag fuer neuen Sollwert */
  4308. +static unsigned short usLinMasterValue;                  /* Neuer Sollwert fuer alle Slaves */
  4309. +static unsigned char  ucLinMasterControl;                /* Controlbyte fuer Sollwert aller Slaves */
  4310. +static unsigned char  ucLinMasterDevice;                           /* Device Type */
  4311. +static int            iLinAdrSlaveCnt;                   /* zu adressierender Lin-Slave */
  4312. +
  4313. +
  4314. +
  4315. +
  4316. +
  4317. +/*******************************************************************************
  4318. +@Prototypen der lokalen Funktionen
  4319. +*******************************************************************************/
  4320. +static int lin_getslaveversion( void );
  4321. +static int lin_getslavefacevalue( void );
  4322. +static int lin_setslavevalue( void );
  4323. +static int lin_clrslaveaddr( void );
  4324. +static int lin_setslaveaddr( int iSlave );
  4325. +static void lin_master_thread(SYS_TASK_PARAM *ptp);
  4326. +static int lin_missing_slave( void );
  4327. +static void lin_rx_thread(SYS_TASK_PARAM *ptp);
  4328. +static int lin_recv( unsigned char *pucLinData, int iLinByteCnt, int iTimeout );
  4329. +static int lin_recv_message( unsigned char *pucLinMsgData, int iLinMsgLen ) ;
  4330. +static int lin_send( unsigned char *pucLinData, int iLinBytesCnt );
  4331. +static int lin_send_breakbyte( void );
  4332. +static int lin_send_message( unsigned char *pucLinMsgData, int iLinMsgLen );
  4333. +static unsigned char lin_pidbyte( unsigned char ucVal );
  4334. +static unsigned char lin_checksum( unsigned char *pucData, int iDataLen );
  4335. +static int lin_master_alive( unsigned char ucNextFreeAdr, unsigned char ucSlaves, unsigned char ucAliveFlags );
  4336. +static int lin_reset_all( void );
  4337. +static int lin_set_value( unsigned char ucAdr, unsigned short usSollPos, unsigned char ucControlFlags, unsigned char ucDeviceTyp  );
  4338. +static int lin_face_value( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData  );
  4339. +static int lin_get_version( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData  );
  4340. +static IBase* CDECL CreateInstance(CLASSID cid, RTS_RESULT *pResult);
  4341. +static RTS_RESULT CDECL DeleteInstance(IBase *pIBase);
  4342. +static int CDECL ExportFunctions(void);
  4343. +static int CDECL ImportFunctions(void);
  4344. +static RTS_UI32 CDECL CmpGetVersion(void);
  4345. +static RTS_RESULT CDECL HookFunction(RTS_UI32 ulHook, RTS_UINTPTR ulParam1, RTS_UINTPTR ulParam2);
  4346. +static void GetQASettings( void );
  4347. +
  4348. +USE_SysSemCreate
  4349. +USE_SysSemDelete
  4350. +USE_SysSemEnter
  4351. +USE_SysSemLeave
  4352. +USE_SysTaskCreate
  4353. +USE_SysTaskResume
  4354. +USE_SysTaskSetExit
  4355. +USE_SysTaskJoin
  4356. +USE_SysTaskExit
  4357. +USE_SysTaskWaitSleep
  4358. +USE_SysTaskDestroy
  4359. +USE_SysTaskEnter
  4360. +USE_SysTaskLeave
  4361. +USE_SysTaskEnd
  4362. +
  4363. +
  4364. +/******************************************************************************/
  4365. +/*!
  4366. +\fn        lin_getslaveversion
  4367. +
  4368. +\brief     Version aller Slaves auslesen
  4369. +
  4370. +\return    Anzahl der nicht gefunden Slaves
  4371. +
  4372. +\param     keine
  4373. +
  4374. +*******************************************************************************/
  4375. +static int lin_getslaveversion( void )
  4376. +{
  4377. +    int iSlave;
  4378. +    int iRetry;
  4379. +    int iRet;
  4380. +
  4381. +    int iMissingSlaves = 0;
  4382. +
  4383. +    for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  4384. +
  4385. +        iRetry = 0;
  4386. +
  4387. +        do {
  4388. +            /* Version der Slaves auslesen */
  4389. +            iRet = lin_get_version( LIN_SLAVE_1 + iSlave, &atLinSlaveData[iSlave] );
  4390. +            if ( iRet < 0 ) {
  4391. +                /* Slave antwortet nicht; nochmal wiederholen */
  4392. +                iRetry++;
  4393. +            }
  4394. +        } while (( iRet < 0 ) && (iRetry <= LIN_MSG_RETRY ) );
  4395. +
  4396. +        if ( iRet < 0 ) {
  4397. +            /* Slave antwortet nicht */
  4398. +            atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  4399. +            iMissingSlaves++;
  4400. +        }
  4401. +        else {
  4402. +            atLinSlaveData[iSlave].ucSlaveOnline = TRUE;
  4403. +        }
  4404. +    }
  4405. +
  4406. +    return iMissingSlaves;
  4407. +
  4408. +}  /* eofn: lin_getslaveversion */
  4409. +
  4410. +/******************************************************************************/
  4411. +/*!
  4412. +\fn        lin_getslavefacevalue
  4413. +
  4414. +\brief     Istposition aller Slaves auslesen
  4415. +
  4416. +\return    0
  4417. +
  4418. +\param     keine
  4419. +
  4420. +*******************************************************************************/
  4421. +static int lin_getslavefacevalue( void )
  4422. +{
  4423. +    int iSlave;
  4424. +    int iRetry;
  4425. +    int iRet;
  4426. +
  4427. +    int iMissingSlaves = 0;
  4428. +
  4429. +    for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  4430. +
  4431. +        iRetry = 0;
  4432. +
  4433. +        do {
  4434. +            /* Version der Slaves auslesen */
  4435. +            iRet = lin_face_value( LIN_SLAVE_1 + iSlave, &atLinSlaveData[iSlave] );
  4436. +            if ( iRet < 0 ) {
  4437. +                /* Slave antwortet nicht; nochmal wiederholen */
  4438. +                iRetry++;
  4439. +            }
  4440. +        } while (( iRet < 0 ) && (iRetry <= LIN_MSG_RETRY ) );
  4441. +
  4442. +        if ( iRet < 0 ) {
  4443. +            /* Slave antwortet nicht */
  4444. +            atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  4445. +            iMissingSlaves++;
  4446. +        }
  4447. +        else {
  4448. +            atLinSlaveData[iSlave].ucSlaveOnline = TRUE;
  4449. +        }
  4450. +    }
  4451. +
  4452. +    return iMissingSlaves;
  4453. +
  4454. +}  /* eofn: lin_getslavefacevalue */
  4455. +
  4456. +/******************************************************************************/
  4457. +/*!
  4458. +\fn        lin_setslavevalue
  4459. +
  4460. +\brief     Sollposition fuer Slaves setzen
  4461. +
  4462. +\return    keine
  4463. +
  4464. +\param     keine
  4465. +
  4466. +*******************************************************************************/
  4467. +static int lin_setslavevalue( void )
  4468. +{
  4469. +   int iSlave;
  4470. +
  4471. +   /* Masterwert wurde geaendert */
  4472. +   if ( ucLinMasterNewValue == TRUE ) {
  4473. +      ucLinMasterNewValue = FALSE;
  4474. +
  4475. +      /* Neue Sollposition fuer alle uebernehmen senden */
  4476. +      lin_set_value(LIN_MASTER, usLinMasterValue, ucLinMasterControl, ucLinMasterDevice);
  4477. +   }
  4478. +   else {
  4479. +
  4480. +      for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  4481. +
  4482. +         if ( atLinSlaveData[iSlave].ucSetNewValue == TRUE ) {
  4483. +            atLinSlaveData[iSlave].ucSetNewValue = FALSE;
  4484. +
  4485. +            /* Neue Sollposition fuer Slave uebernehmen senden */
  4486. +            lin_set_value(LIN_SLAVE_1 + iSlave, atLinSlaveData[iSlave].usSetValue, atLinSlaveData[iSlave].ucSetControl, atLinSlaveData[iSlave].ucDevice);
  4487. +         }
  4488. +      }
  4489. +   }
  4490. +
  4491. +   return 0;
  4492. +
  4493. +}  /* eofn: lin_setslavevalue */
  4494. +
  4495. +
  4496. +/******************************************************************************/
  4497. +/*!
  4498. +\fn        lin_clrslaveaddr
  4499. +
  4500. +\brief     Slaveadressen neu setzen
  4501. +
  4502. +\return    kein
  4503. +
  4504. +\param     keine
  4505. +
  4506. +*******************************************************************************/
  4507. +static int lin_clrslaveaddr( void )
  4508. +{
  4509. +    int iSlave;
  4510. +
  4511. +    /* Kommando Reset senden */
  4512. +    lin_reset_all();
  4513. +
  4514. +    /* Alle Slaves alle nicht erkannt markieren */
  4515. +    for ( iSlave = 0; iSlave < iLinSlaveCnt; iSlave++ ) {
  4516. +
  4517. +        atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  4518. +    }
  4519. +
  4520. +    return 0;
  4521. +
  4522. +}  /* eofn: lin_clrlaveaddr */
  4523. +
  4524. +/******************************************************************************/
  4525. +/*!
  4526. +\fn        lin_setslaveaddr
  4527. +
  4528. +\brief     Slaveadressen neu setzen
  4529. +
  4530. +\return    Slavestatus
  4531. +            0 - Slave nicht vorhanden
  4532. +              -1 - Slave vorhanden
  4533. +
  4534. +\param     iSlave    - Slave
  4535. +
  4536. +*******************************************************************************/
  4537. +static int lin_setslaveaddr( int iSlave )
  4538. +{
  4539. +    /* Kommando Alive an alle Slaves senden */
  4540. +    lin_master_alive( iSlave, iLinSlaveCnt, LIN_MASTER_INITFLAG );
  4541. +
  4542. +    /* Kommando FaceValue an Slave senden */
  4543. +    if ( lin_face_value( iSlave, &atLinSlaveData[iSlave] ) < 0 ) {
  4544. +
  4545. +        atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  4546. +        return -1;
  4547. +    }
  4548. +
  4549. +    /* Kommando FaceValue an Slave senden */
  4550. +    if ( lin_get_version( iSlave, &atLinSlaveData[iSlave] ) < 0 ) {
  4551. +
  4552. +        atLinSlaveData[iSlave].ucSlaveOnline = FALSE;
  4553. +        return -1;
  4554. +    }
  4555. +    atLinSlaveData[iSlave].ucSlaveOnline = TRUE;
  4556. +
  4557. +    return 0;
  4558. +
  4559. +}  /* eofn: lin_setslaveaddr */
  4560. +
  4561. +/******************************************************************************/
  4562. +/*!
  4563. +\fn        lin_missing_slave
  4564. +
  4565. +\brief     Fehlenden Slave suchen
  4566. +
  4567. +\return    Slavenummer
  4568. +
  4569. +\param     keine
  4570. +
  4571. +*******************************************************************************/
  4572. +static int lin_missing_slave( void )
  4573. +{
  4574. +    int iSlave = 0;
  4575. +
  4576. +    do {
  4577. +
  4578. +        if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  4579. +
  4580. +            /* Slave ist nicht vorhanden */
  4581. +            return iSlave;
  4582. +        }
  4583. +        iSlave++;
  4584. +    }  while ( iSlave < iLinSlaveCnt );
  4585. +
  4586. +    return -1;
  4587. +
  4588. +}  /* eofn: lin_missing_slave */
  4589. +
  4590. +/******************************************************************************/
  4591. +/*!
  4592. +\fn        lin_master_thread
  4593. +
  4594. +\brief     Protokollverarbeitung Linbus Master
  4595. +
  4596. +\return    keine
  4597. +
  4598. +\param     keine
  4599. +
  4600. +*******************************************************************************/
  4601. +static void lin_master_thread(SYS_TASK_PARAM *ptp)
  4602. +{
  4603. +    int iMissingSlaves;
  4604. +
  4605. +   CAL_SysTaskEnter(ptp->hTask);
  4606. +
  4607. +   while(!ptp->bExit) {
  4608. +
  4609. +        #ifdef _DEBUG
  4610. +        printf("Zustand Master : %i\n", iLinMasterState);
  4611. +        printf("\n");
  4612. +        #endif
  4613. +
  4614. +        switch ( iLinMasterState ) {
  4615. +
  4616. +            /*********************************************************************/
  4617. +            case LIN_MASTER_CHECK : {
  4618. +            /*********************************************************************/
  4619. +                /* Kommando Alive an alle Slaves senden */
  4620. +                lin_master_alive( 0, iLinSlaveCnt, 0 );
  4621. +
  4622. +                /* Version der Slaves abfragen */
  4623. +                iMissingSlaves = lin_getslaveversion();
  4624. +                if ( iMissingSlaves == 1 ) {
  4625. +
  4626. +                    /* fehlenden Slave setzen */
  4627. +                    iLinAdrSlaveCnt = lin_missing_slave();
  4628. +
  4629. +                    /* Timeout eines Slaves */
  4630. +                    iLinMasterState = LIN_MASTER_INIT;
  4631. +                    break;
  4632. +                }
  4633. +                else if ( iMissingSlaves > 1 ) {
  4634. +
  4635. +                    /* Timeout mehrere Slaves */
  4636. +                    iLinMasterState = LIN_MASTER_REPAIR;
  4637. +                    break;
  4638. +                }
  4639. +
  4640. +                /* Slave haben sich gemeldet */
  4641. +                iLinMasterState = LIN_MASTER_ONLINE;
  4642. +            }  break;
  4643. +
  4644. +            /*********************************************************************/
  4645. +            case LIN_MASTER_INIT : {
  4646. +            /*********************************************************************/
  4647. +
  4648. +                /* Adressen fuer Slaves setzen */
  4649. +                lin_setslaveaddr( iLinAdrSlaveCnt );
  4650. +
  4651. +                /* Version der Slaves abfragen */
  4652. +                iMissingSlaves = lin_getslaveversion();
  4653. +                if ( iMissingSlaves == 0 ) {
  4654. +
  4655. +                    /* Alle Slave sind da */
  4656. +                    iLinMasterState = LIN_MASTER_ONLINE;
  4657. +                    break;
  4658. +                }
  4659. +                else if ( iMissingSlaves > 1 ) {
  4660. +
  4661. +                    /* Timeout mehrerr Slaves */
  4662. +                    iLinMasterState = LIN_MASTER_REPAIR;
  4663. +                    break;
  4664. +                }
  4665. +
  4666. +                if ( iLinResetAddr == TRUE ) {
  4667. +                    iLinResetAddr = FALSE;
  4668. +                    iLinSetAddr = FALSE;
  4669. +
  4670. +                    /* Slaveadresse loeschen */
  4671. +                    lin_clrslaveaddr();
  4672. +
  4673. +                    /* Adressen loeschen */
  4674. +                    iLinMasterState = LIN_MASTER_ADR_CLR;
  4675. +                    break;
  4676. +                }
  4677. +            }  break;
  4678. +
  4679. +            /*********************************************************************/
  4680. +            case LIN_MASTER_ONLINE : {
  4681. +            /*********************************************************************/
  4682. +
  4683. +                /* Kommando Alive an alle Slaves senden */
  4684. +                lin_master_alive( 0, iLinSlaveCnt, 0 );
  4685. +
  4686. +                /* Sollwert der Slaves senden */
  4687. +                lin_setslavevalue();
  4688. +
  4689. +                /* Istwert der Slaves abfragen */
  4690. +                iMissingSlaves = lin_getslavefacevalue();
  4691. +                if ( iMissingSlaves == 1 ) {
  4692. +
  4693. +                    /* fehlenden Slave setzen */
  4694. +                    iLinAdrSlaveCnt = lin_missing_slave();
  4695. +
  4696. +                    /* Timeout eines Slaves */
  4697. +                    iLinMasterState = LIN_MASTER_INIT;
  4698. +                    break;
  4699. +                }
  4700. +                else if ( iMissingSlaves > 1 ) {
  4701. +
  4702. +                    /* Timeout eines Slaves */
  4703. +                    iLinMasterState = LIN_MASTER_REPAIR;
  4704. +                    break;
  4705. +                }
  4706. +
  4707. +                if ( iLinResetAddr == TRUE ) {
  4708. +                    iLinResetAddr = FALSE;
  4709. +                    iLinSetAddr = FALSE;
  4710. +
  4711. +                    /* Slaveadresse loeschen */
  4712. +                    lin_clrslaveaddr();
  4713. +
  4714. +                    /* Adressen loeschen */
  4715. +                    iLinMasterState = LIN_MASTER_ADR_CLR;
  4716. +                    break;
  4717. +                }
  4718. +            }  break;
  4719. +
  4720. +            /*********************************************************************/
  4721. +            case LIN_MASTER_REPAIR : {
  4722. +            /*********************************************************************/
  4723. +
  4724. +                if ( iLinResetAddr == TRUE ) {
  4725. +                    iLinResetAddr = FALSE;
  4726. +                    iLinSetAddr = FALSE;
  4727. +
  4728. +                    /* Slaveadresse loeschen */
  4729. +                    lin_clrslaveaddr();
  4730. +
  4731. +                    /* Adressen loeschen */
  4732. +                    iLinMasterState = LIN_MASTER_ADR_CLR;
  4733. +                    break;
  4734. +                }
  4735. +               /* Version der Slaves abfragen */
  4736. +               iMissingSlaves = lin_getslaveversion();
  4737. +               if ( iMissingSlaves == 1 ) {
  4738. +
  4739. +                  /* fehlenden Slave setzen */
  4740. +                  iLinAdrSlaveCnt = lin_missing_slave();
  4741. +
  4742. +                  /* Timeout eines Slaves */
  4743. +                  iLinMasterState = LIN_MASTER_INIT;
  4744. +                  break;
  4745. +               }
  4746. +              
  4747. +      
  4748. +               /* Slave haben sich gemeldet */
  4749. +               iLinMasterState = LIN_MASTER_ONLINE;
  4750. +            }  break;
  4751. +
  4752. +            /***************************************************************/
  4753. +            case LIN_MASTER_ADR_CLR : {
  4754. +            /***************************************************************/
  4755. +
  4756. +                if ( iLinResetAddr == TRUE ) {
  4757. +                    iLinResetAddr = FALSE;
  4758. +
  4759. +                    /* Slaveadresse loeschen */
  4760. +                    lin_clrslaveaddr();
  4761. +                    break;
  4762. +                }
  4763. +
  4764. +                if ( iLinSetAddr == TRUE ) {
  4765. +                    iLinSetAddr = FALSE;
  4766. +
  4767. +                    /* Neuadressierung mit Adresse 0 */
  4768. +                    iLinAdrSlaveCnt = 0;
  4769. +
  4770. +                    /* Warte auf Slave */
  4771. +                    iLinMasterState = LIN_MASTER_WAIT_FOR_SLAVE;
  4772. +                    break;
  4773. +                }
  4774. +            }  break;
  4775. +
  4776. +            /***************************************************************/
  4777. +            case LIN_MASTER_WAIT_FOR_SLAVE : {
  4778. +            /***************************************************************/
  4779. +
  4780. +                /* Adressen fuer Slaves setzen */
  4781. +                lin_setslaveaddr( iLinAdrSlaveCnt );
  4782. +
  4783. +                /* pruefen ob Slave erkannt wurde */
  4784. +                if ( atLinSlaveData[iLinAdrSlaveCnt].ucSlaveOnline == TRUE ) {
  4785. +
  4786. +                    /* naechster Slave */
  4787. +                    iLinAdrSlaveCnt++;
  4788. +
  4789. +                    if ( iLinAdrSlaveCnt == iLinSlaveCnt ) {
  4790. +
  4791. +                        /* alle Slaves adressiert */
  4792. +                        iLinMasterState = LIN_MASTER_ONLINE;
  4793. +                        break;
  4794. +                    }
  4795. +                }
  4796. +
  4797. +                if ( iLinResetAddr == TRUE ) {
  4798. +                    iLinResetAddr = FALSE;
  4799. +                    iLinSetAddr = FALSE;
  4800. +
  4801. +                    /* Slaveadresse loeschen */
  4802. +                    lin_clrslaveaddr();
  4803. +
  4804. +                    /* Adressen loeschen */
  4805. +                    iLinMasterState = LIN_MASTER_ADR_CLR;
  4806. +                    break;
  4807. +                }
  4808. +            }  break;
  4809. +
  4810. +            /***************************************************************/
  4811. +            default : {
  4812. +            /***************************************************************/
  4813. +
  4814. +            }  break;
  4815. +        }
  4816. +
  4817. +        CAL_SysTaskWaitSleep(ptp->hTask, iLinIntervall);
  4818. +    }
  4819. +
  4820. +   CAL_SysTaskLeave(ptp->hTask);
  4821. +   CAL_SysTaskEnd(ptp->hTask, 0);
  4822. +
  4823. +    return;
  4824. +
  4825. +}  /* eofn: lin_master_thread */
  4826. +
  4827. +/******************************************************************************/
  4828. +/*!
  4829. +\fn        lin_rx_thread
  4830. +
  4831. +\brief     Empfangsthread
  4832. +
  4833. +\return    keine
  4834. +
  4835. +\param     arg
  4836. +
  4837. +*******************************************************************************/
  4838. +static void lin_rx_thread(SYS_TASK_PARAM *ptp)
  4839. +{
  4840. +   CAL_SysTaskEnter(ptp->hTask);
  4841. +
  4842. +   while(!ptp->bExit) {
  4843. +
  4844. +        if ( read( iLinPort, &acLinRxBuffer[iLinRxWrIndex], 1 ) > 0 ) {
  4845. +            iLinRxWrIndex++;
  4846. +            if ( iLinRxWrIndex >= MAX_LIN_FRAME_BUFFER  ) {
  4847. +
  4848. +                iLinRxWrIndex = 0;
  4849. +            }
  4850. +        }
  4851. +    }
  4852. +
  4853. +   CAL_SysTaskLeave(ptp->hTask);
  4854. +   CAL_SysTaskEnd(ptp->hTask, 0);
  4855. +
  4856. +    return;
  4857. +
  4858. +}  /* eofn: lin_rx_thread */
  4859. +
  4860. +/******************************************************************************/
  4861. +/*!
  4862. +\fn        lin_recv
  4863. +
  4864. +\brief     Lin-Bytes empfangen
  4865. +
  4866. +\return    Ergebnis
  4867. +           = 0 - OK
  4868. +              < 0 - Fehler
  4869. +
  4870. +\param     pucLinData  - Zeiger auf die Daten
  4871. +           iLinByteCnt - Anzahl an Bytes
  4872. +              iTimeout    - Timeoutzeit fuer das Lesen
  4873. +
  4874. +*******************************************************************************/
  4875. +static int lin_recv( unsigned char *pucLinData, int iLinByteCnt, int iTimeout )
  4876. +{
  4877. +    int iTimer = 0;
  4878. +    int iByteCnt = 0;
  4879. +
  4880. +    do {
  4881. +
  4882. +        if ( iLinRxRdIndex != iLinRxWrIndex ) {
  4883. +
  4884. +            pucLinData[iByteCnt] = acLinRxBuffer[iLinRxRdIndex];
  4885. +            iByteCnt++;
  4886. +
  4887. +            iLinRxRdIndex++;
  4888. +            if ( iLinRxRdIndex >= MAX_LIN_FRAME_BUFFER ) {
  4889. +
  4890. +                iLinRxRdIndex = 0;
  4891. +            }
  4892. +        }
  4893. +        else {
  4894. +
  4895. +            /* Timeoutzeit abwarten */
  4896. +            //TODO minimal granularity of system timers, CONFIG_HZ=200Hz => 5ms
  4897. +            usleep(1000);
  4898. +            iTimer++;
  4899. +        }
  4900. +
  4901. +    } while (( iByteCnt < iLinByteCnt ) && ( iTimer < iTimeout ));
  4902. +
  4903. +    /* pruefen ob alle Bytes gelesen wurden */
  4904. +    if ( iTimer >= iTimeout ) {
  4905. +
  4906. +        /* Fehler beim lesen; keine weiteren Bytes mehr lesen */
  4907. +        iLinRxRdIndex = 0;
  4908. +        iLinRxWrIndex = 0;
  4909. +        return ERR_LIN_TIMEOUT;
  4910. +    }
  4911. +
  4912. +    return 0;
  4913. +
  4914. +}  /* eofn: lin_recv */
  4915. +
  4916. +/******************************************************************************/
  4917. +/*!
  4918. +\fn        lin_recv_message
  4919. +
  4920. +\brief     Lin-Message empfangen
  4921. +
  4922. +\return    Ergebnis
  4923. +           = 0 - OK
  4924. +              < 0 - Fehler
  4925. +
  4926. +\param     pucLinData   - Zeiger auf die Daten
  4927. +           iLinBytesCnt - Anzahl an Bytes
  4928. +
  4929. +*******************************************************************************/
  4930. +static int lin_recv_message( unsigned char *pucLinMsgData, int iLinMsgLen )
  4931. +{
  4932. +    unsigned char ucChecksum;
  4933. +    int i = 0;
  4934. +
  4935. +    /************************************/
  4936. +    /* Response vom Client zuruecklesen */
  4937. +    /************************************/
  4938. +   if ( lin_recv( &pucLinMsgData[1], iLinMsgLen-1, LIN_TIMEOUT_MESSAGE ) < 0 ) {
  4939. +
  4940. +        /* Timeout/Fehler beim Empfang des Response */
  4941. +        return ERR_LIN_TIMEOUT_MSG;
  4942. +    }
  4943. +
  4944. +    /****************/
  4945. +    /* Traceausgabe */
  4946. +    /****************/
  4947. +    #ifdef _DEBUG
  4948. +    printf ("REC: ");
  4949. +    for (i = 0; i < iLinMsgLen; i++)
  4950. +    {
  4951. +         printf ("%02x ", pucLinMsgData[i]);
  4952. +    }
  4953. +    printf ("\n");
  4954. +    #endif
  4955. +
  4956. +    /*******************************/
  4957. +    /* Empfangsschecksumme pruefen */
  4958. +    /*******************************/
  4959. +    ucChecksum = lin_checksum(pucLinMsgData, iLinMsgLen -1);
  4960. +    if ( ucChecksum !=  pucLinMsgData[iLinMsgLen-1] ) {
  4961. +
  4962. +        /* Checksumme ist ungueltig */
  4963. +        printf("Checksumme ist ungueltig\n");
  4964. +        /* BUG 1898 - Clean Buffer */
  4965. +        // Kein Mutex benötigt
  4966. +        iLinRxWrIndex = 0;                     /* Schreibzeiger Empfangspuffer */
  4967. +        iLinRxRdIndex = 0;                     /* Lesezeiger Empfangspuffer */
  4968. +        /* Clean Buffer */
  4969. +
  4970. +        return ERR_LIN_CHECKSUM;
  4971. +    }
  4972. +
  4973. +    return 0;
  4974. +
  4975. +}  /* eofn: lin_recv_message */
  4976. +
  4977. +/******************************************************************************/
  4978. +/*!
  4979. +\fn        lin_send
  4980. +
  4981. +\brief     Lin-Bytes senden
  4982. +
  4983. +\return    Ergebnis
  4984. +           = 0 - OK
  4985. +              < 0 - Fehler
  4986. +
  4987. +\param     pcLinData    - Zeiger auf die Daten
  4988. +           iLinBytesCnt - Anzahl an Bytes
  4989. +
  4990. +*******************************************************************************/
  4991. +static int lin_send( unsigned char *pucLinData, int iLinBytesCnt )
  4992. +{
  4993. +   if ( write( iLinPort, pucLinData, iLinBytesCnt ) < 0 ) {
  4994. +
  4995. +        printf("Fehler beim Senden\n");
  4996. +        return ERR_LIN_SEND_MESSAGE;
  4997. +    }
  4998. +
  4999. +    return 0;
  5000. +
  5001. +}  /* eofn: lin_send */
  5002. +
  5003. +/******************************************************************************/
  5004. +/*!
  5005. +\fn        lin_send_breakbyte
  5006. +
  5007. +\brief     Breakbyte senden
  5008. +
  5009. +\return    Ergebnis
  5010. +           = 0 - OK
  5011. +              < 0 - Fehler
  5012. +
  5013. +\param     keine
  5014. +
  5015. +*******************************************************************************/
  5016. +static int lin_send_breakbyte( void )
  5017. +{
  5018. +
  5019. +   unsigned char ucTmp = 0x80;
  5020. +
  5021. +   tcgetattr(iLinPort, &initial_settings);
  5022. +   new_settings = initial_settings;
  5023. +
  5024. +   /************************************/
  5025. +   /* Schnittstelleneinstellung setzen */
  5026. +   /************************************/
  5027. +   /* Baudrate */
  5028. +   if (cfsetspeed(&new_settings, BaudRate-1) != 0) {
  5029. +
  5030. +        printf("Baudrate kann nicht initialsiert werden\n");
  5031. +      return ERR_LIN_BAUDRATE;
  5032. +   }
  5033. +
  5034. +
  5035. +   cfmakeraw(&new_settings);
  5036. +
  5037. +   /* Flags */
  5038. +   new_settings.c_cflag &= ~CSTOPB;    /* 1 Stopbit */
  5039. +   new_settings.c_cflag &= ~PARENB; /* keine Paritaet */
  5040. +   new_settings.c_cflag &= ~CSIZE;  /* 8 Datenbits */
  5041. +   new_settings.c_cflag |= CS8;
  5042. +
  5043. +   if (tcsetattr(iLinPort, TCSANOW, &new_settings)  != 0) {
  5044. +
  5045. +        printf("Schnittstlleneinstellung koennen nicht gesetzt werden\n");
  5046. +      return ERR_LIN_PORTSETTING;
  5047. +   }
  5048. +
  5049. +    /********************/
  5050. +    /* Breakbyte senden */
  5051. +    /********************/
  5052. +    lin_send( &ucTmp, 1 );
  5053. +
  5054. +    /*************************/
  5055. +    /* Echobyte zuruecklesen */
  5056. +    /*************************/
  5057. +    lin_recv( &ucTmp, 1, LIN_TIMEOUT_ECHO );
  5058. +
  5059. +   tcgetattr(iLinPort, &initial_settings);
  5060. +   new_settings = initial_settings;
  5061. +
  5062. +   /************************************/
  5063. +   /* Schnittstelleneinstellung setzen */
  5064. +   /************************************/
  5065. +
  5066. +   if (cfsetspeed(&new_settings, BaudRate) != 0) {
  5067. +      return ERR_LIN_BAUDRATE;
  5068. +   }
  5069. +
  5070. +   cfmakeraw(&new_settings);
  5071. +
  5072. +   /* Flags */
  5073. +   new_settings.c_cflag &= ~CSTOPB;    /* 1 Stopbit */
  5074. +   new_settings.c_cflag &= ~PARENB; /* keine Paritaet */
  5075. +   new_settings.c_cflag &= ~CSIZE;  /* 8 Datenbits */
  5076. +   new_settings.c_cflag |= CS8;
  5077. +
  5078. +   if (tcsetattr(iLinPort, TCSADRAIN, &new_settings)  != 0) {
  5079. +
  5080. +      printf("Device konnte nicht initialsiert werden\n");
  5081. +      return ERR_LIN_PORTSETTING;
  5082. +   }
  5083. +
  5084. +   return 0;
  5085. +}  /* eofn: lin_send_breakbyte */
  5086. +
  5087. +/******************************************************************************/
  5088. +/*!
  5089. +\fn        lin_send_message
  5090. +
  5091. +\brief     Lin-Message senden
  5092. +
  5093. +\return    Ergebnis
  5094. +           = 0 - OK
  5095. +              < 0 - Fehler
  5096. +
  5097. +\param     pucLinMsgData - Zeiger auf die Daten
  5098. +           iLinMsgLen    - Anzahl an Bytes
  5099. +
  5100. +*******************************************************************************/
  5101. +static int lin_send_message( unsigned char *pucLinMsgData, int iLinMsgLen )
  5102. +{
  5103. +    int iRet = 0;
  5104. +    int i = 0;
  5105. +
  5106. +    /******************************/
  5107. +    /* Breakbyte zunaechst senden */
  5108. +    /******************************/
  5109. +    if (( iRet = lin_send_breakbyte()) < 0 ) {
  5110. +
  5111. +        /* Break konnte nicht gesendet werden */
  5112. +        return iRet;
  5113. +    }
  5114. +
  5115. +    /******************/
  5116. +    /* Message senden */
  5117. +    /******************/
  5118. +   if (( iRet = lin_send( pucLinMsgData, iLinMsgLen )) < 0 ) {
  5119. +
  5120. +        /* Message konnte nicht gesendet werden */
  5121. +        return iRet;
  5122. +    }
  5123. +
  5124. +    /**************************/
  5125. +    /* Echobytes zuruecklesen */
  5126. +    /**************************/
  5127. +   if ( lin_recv( pucLinMsgData, iLinMsgLen, LIN_TIMEOUT_ECHO ) < 0 ) {
  5128. +
  5129. +        /* Timeout/Fehler beim Empfang des Echos */
  5130. +        return ERR_LIN_TIMEOUT_ECHO;
  5131. +    }
  5132. +
  5133. +   usleep(15000);
  5134. +    /****************/
  5135. +    /* Traceausgabe */
  5136. +    /****************/
  5137. +    #ifdef _DEBUG
  5138. +    printf ("SEND: ");
  5139. +    for (i = 0; i < iLinMsgLen; i++)
  5140. +    {
  5141. +         printf ("%02x ", pucLinMsgData[i]);
  5142. +    }
  5143. +    printf ("\n");
  5144. +    #endif
  5145. +
  5146. +    return 0;
  5147. +
  5148. +}  /* eofn: lin_send_message */
  5149. +
  5150. +/******************************************************************************/
  5151. +/*!
  5152. +\fn        lin_pidbyte
  5153. +
  5154. +\brief     PID-Byte erzeugen
  5155. +
  5156. +\return    PID-Byte
  5157. +
  5158. +\param     ucVal - Wert fuer Kommando bzw Adresse
  5159. +
  5160. +*******************************************************************************/
  5161. +static unsigned char lin_pidbyte( unsigned char ucVal )
  5162. +{
  5163. +
  5164. +    unsigned char ucTmp = 0;
  5165. +
  5166. +   if ((ISBITSET(ucVal,0) ^ ISBITSET(ucVal,1) ^ ISBITSET(ucVal,2) ^ ISBITSET(ucVal,4)) != 0 )  {
  5167. +
  5168. +        ucTmp = 0x01;
  5169. +    }
  5170. +
  5171. +   if ((ISBITSET(ucVal,1) ^ ISBITSET(ucVal,3) ^ ISBITSET(ucVal,4) ^ ISBITSET(ucVal,5)) == 0 )  {
  5172. +
  5173. +        ucTmp |= 0x02;
  5174. +    }
  5175. +
  5176. +   return PID_PARITY(ucTmp) | ucVal;
  5177. +
  5178. +}  /* eofn: lin_pidbyte */
  5179. +
  5180. +/******************************************************************************/
  5181. +/*!
  5182. +\fn        lin_checksum
  5183. +
  5184. +\brief     Checksumme erzeugen
  5185. +
  5186. +\return    Checksumme
  5187. +
  5188. +\param     pucData  - Zeiger auf Daten
  5189. +           iDataLen - Datenlaenge
  5190. +
  5191. +*******************************************************************************/
  5192. +static unsigned char lin_checksum( unsigned char *pucData, int iDataLen )
  5193. +{
  5194. +    unsigned short usTmp = 0;
  5195. +    int i;
  5196. +
  5197. +   for ( i = 0; i < iDataLen; i++ ) {
  5198. +
  5199. +        usTmp += pucData[i];
  5200. +        /* Ueberlauf pruefen */
  5201. +        if ( usTmp > 0xFF ) {
  5202. +            usTmp &= 0x00FF;
  5203. +            usTmp++; /* Carrybit addrieren */
  5204. +        }
  5205. +   }
  5206. +
  5207. +   return (unsigned char)(~usTmp);
  5208. +
  5209. +}  /* eofn: lin_checksum */
  5210. +
  5211. +/******************************************************************************/
  5212. +/*!
  5213. +\fn        lin_master_alive
  5214. +
  5215. +\brief     Master Alive-Message senden
  5216. +
  5217. +\return    Ergebnis
  5218. +           = 0 - OK
  5219. +              < 0 - Fehler
  5220. +
  5221. +\param     ucNextFreeAdr - Naechste freie Adresse
  5222. +           ucSlaves      - Anzahl Teilnehmer
  5223. +              ucAliveFlags  - Flags
  5224. +
  5225. +*******************************************************************************/
  5226. +static int lin_master_alive( unsigned char ucNextFreeAdr, unsigned char ucSlaves, unsigned char ucAliveFlags )
  5227. +{
  5228. +    int iRet;
  5229. +
  5230. +    /*printf("MasterAlive:\n");
  5231. +    printf("Naechste freie Adresse : %i\n", ucNextFreeAdr);
  5232. +    printf("Anzahl LIN-Teilnehmer  : %i\n", ucSlaves);
  5233. +    printf("Flags                  : %i\n", ucAliveFlags);
  5234. +    printf("\n");*/
  5235. +
  5236. +    /* MasterALive-Message aufbauen */
  5237. +   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  5238. +   acLinMsgBuffer[1] = lin_pidbyte(CMD_MASTER_ALIVE);
  5239. +   acLinMsgBuffer[2] = ucNextFreeAdr;
  5240. +   acLinMsgBuffer[3] = 1 + ucSlaves; /* Master + Slaves */
  5241. +   acLinMsgBuffer[4] = ucAliveFlags;
  5242. +   acLinMsgBuffer[5] = LIN_PROTOKOLL_VERS;
  5243. +    acLinMsgBuffer[6] = lin_checksum( &acLinMsgBuffer[1], 5);
  5244. +    iRet = lin_send_message( acLinMsgBuffer, 7 );
  5245. +
  5246. +   return iRet;
  5247. +
  5248. +}  /* eofn: lin_master_alive */
  5249. +
  5250. +/******************************************************************************/
  5251. +/*!
  5252. +\fn        lin_reset_all
  5253. +
  5254. +\brief     Alle Adressen loeschen
  5255. +
  5256. +\return    Ergebnis
  5257. +           = 0 - OK
  5258. +              < 0 - Fehler
  5259. +
  5260. +\param     keine
  5261. +
  5262. +*******************************************************************************/
  5263. +static int lin_reset_all( void )
  5264. +{
  5265. +    int iRet;
  5266. +
  5267. +    //printf("ResetAll:\n");
  5268. +
  5269. +    /* Reset-Message aufbauen */
  5270. +   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  5271. +   acLinMsgBuffer[1] = lin_pidbyte(CMD_RESET_ADDR);
  5272. +   acLinMsgBuffer[2] = 0x52;
  5273. +   acLinMsgBuffer[3] = 0x45;
  5274. +   acLinMsgBuffer[4] = 0x53;
  5275. +   acLinMsgBuffer[5] = 0x45;
  5276. +   acLinMsgBuffer[6] = 0x54;
  5277. +   acLinMsgBuffer[7] = 0x4E;
  5278. +   acLinMsgBuffer[8] = 0x4F;
  5279. +   acLinMsgBuffer[9] = 0x57;
  5280. +    acLinMsgBuffer[10] = lin_checksum( &acLinMsgBuffer[1], 9);
  5281. +   iRet = lin_send_message( acLinMsgBuffer, 11 );
  5282. +
  5283. +   return iRet;
  5284. +
  5285. +}  /* eofn: lin_reset_all */
  5286. +
  5287. +/******************************************************************************/
  5288. +/*!
  5289. +\fn        lin_set_value
  5290. +
  5291. +\brief     Sollwert setzen
  5292. +
  5293. +\return    Ergebnis
  5294. +           = 0 - OK
  5295. +              < 0 - Fehler
  5296. +
  5297. +\param     usAdr           - LinAdresse
  5298. +           usSollPos       - Sollposition
  5299. +              ucClontrolFlags - Steuerflags
  5300. +
  5301. +*******************************************************************************/
  5302. +static int lin_set_value( unsigned char ucAdr, unsigned short usSollPos, unsigned char ucControlFlags, unsigned char ucDeviceTyp)
  5303. +{
  5304. +    int iRet;
  5305. +
  5306. +   /* printf("SetValue:\n");
  5307. +    printf("Slave   : %i\n", ucAdr );
  5308. +    printf("SollPos : %i\n", usSollPos );
  5309. +    printf("Flags   : %i\n", ucControlFlags );
  5310. +    printf("\n");*/
  5311. +
  5312. +    /* SetValue-Message aufbauen */
  5313. +   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  5314. +   acLinMsgBuffer[1] = lin_pidbyte(CMD_SETVALUE(ucAdr));
  5315. +   acLinMsgBuffer[2] = ucDeviceTyp;
  5316. +   acLinMsgBuffer[3] = ucControlFlags;
  5317. +   acLinMsgBuffer[4] = (unsigned char)(0x00ff & usSollPos);
  5318. +   acLinMsgBuffer[5] = (unsigned char)( usSollPos >> 8);
  5319. +   acLinMsgBuffer[6] = lin_checksum( &acLinMsgBuffer[1], 5);
  5320. +   iRet = lin_send_message( acLinMsgBuffer, 7 );
  5321. +
  5322. +   return iRet;
  5323. +
  5324. +}  /* eofn: lin_set_value */
  5325. +
  5326. +/******************************************************************************/
  5327. +/*!
  5328. +\fn        lin_face_value
  5329. +
  5330. +\brief     Istwert auslesen
  5331. +
  5332. +\return    Ergebnis
  5333. +           = 0 - OK
  5334. +              < 0 - Fehler
  5335. +
  5336. +\param     usAdr           - Adresse
  5337. +           ptLinSlaveData  - Zeiger auf Slavedaten
  5338. +
  5339. +*******************************************************************************/
  5340. +static int lin_face_value( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData )
  5341. +{
  5342. +    int    iRet;
  5343. +
  5344. +    //printf("FaceValue: \n");
  5345. +
  5346. +    /* Face-Message aufbauen */
  5347. +   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  5348. +   acLinMsgBuffer[1] = lin_pidbyte(CMD_FACEVALUE(ucAdr));
  5349. +   if (( iRet = lin_send_message( acLinMsgBuffer, 2 )) < 0 ) {
  5350. +
  5351. +        /* Fehler beim Senden des Kommandos FaceValue */
  5352. +        return iRet;
  5353. +    }
  5354. +
  5355. +    /* Response vom Slave auswerten */
  5356. +    if (( iRet = lin_recv_message( &acLinMsgBuffer[1], 7 )) < 0 ) {
  5357. +
  5358. +        /* Fehler beim Empfang */
  5359. +        return iRet;
  5360. +    }
  5361. +
  5362. +    /* Empfangsdaten uebernehmen */
  5363. +    ptLinSlaveData->tValue.ucFormat   = acLinMsgBuffer[2];
  5364. +    ptLinSlaveData->tValue.usIstPos   = acLinMsgBuffer[3];
  5365. +    ptLinSlaveData->tValue.usIstPos  |= acLinMsgBuffer[4] << 8;
  5366. +    ptLinSlaveData->tValue.ucStatus   = acLinMsgBuffer[5];
  5367. +    ptLinSlaveData->tValue.ucErrorCnt = acLinMsgBuffer[6];
  5368. +
  5369. +    //printf("Format  : %i\n", ptLinSlaveData->tValue.ucFormat);
  5370. +    //printf("IstPos  : %i\n", ptLinSlaveData->tValue.usIstPos);
  5371. +    //printf("Status  : %i\n", ptLinSlaveData->tValue.ucStatus);
  5372. +    //printf("Fehler  : %i\n", ptLinSlaveData->tValue.ucErrorCnt);
  5373. +    //printf("\n");
  5374. +
  5375. +   return 0;
  5376. +
  5377. +}  /* eofn: lin_face_value */
  5378. +
  5379. +/******************************************************************************/
  5380. +/*!
  5381. +\fn       lin_get_version
  5382. +
  5383. +\brief    Version auslesen
  5384. +
  5385. +\return   Ergebnis
  5386. +          = 0 - OK
  5387. +             < 0 - Fehler
  5388. +
  5389. +\param     ucAdr           - Adresse
  5390. +           ptLinSlaveData  - Zeiger auf Slavedaten
  5391. +
  5392. +*******************************************************************************/
  5393. +static int lin_get_version( unsigned char ucAdr, LIN_SLAVE_DATA_TR *ptLinSlaveData )
  5394. +{
  5395. +    int    iRet;
  5396. +
  5397. +    //printf("GetVersion %i: \n", ucAdr);
  5398. +
  5399. +    /* Face-Message aufbauen */
  5400. +   acLinMsgBuffer[0] = LIN_SYNCBYTE;
  5401. +   acLinMsgBuffer[1] = lin_pidbyte(CMD_VERSION(ucAdr));
  5402. +   if (( iRet = lin_send_message( acLinMsgBuffer, 2 )) < 0 ) {
  5403. +
  5404. +        /* Fehler beim Senden des Kommandos GetVersion */
  5405. +        return iRet;
  5406. +    }
  5407. +
  5408. +    /* Response vom Slave auswerten */
  5409. +    if (( iRet = lin_recv_message( &acLinMsgBuffer[1], 10 )) < 0 ) {
  5410. +
  5411. +        /* Fehler beim Empfang */
  5412. +        return iRet;
  5413. +    }
  5414. +
  5415. +    /* Empfangsdaten uebernehmen */
  5416. +    ptLinSlaveData->tVers.ucRelease   = acLinMsgBuffer[2];
  5417. +    ptLinSlaveData->tVers.ucVersion   = acLinMsgBuffer[3];
  5418. +    ptLinSlaveData->tVers.ucVariant   = acLinMsgBuffer[4];
  5419. +    ptLinSlaveData->tVers.ucFormat    = acLinMsgBuffer[5];
  5420. +    ptLinSlaveData->tVers.usManCode   = acLinMsgBuffer[6];
  5421. +    ptLinSlaveData->tVers.usManCode  |= acLinMsgBuffer[7]<<8;
  5422. +    ptLinSlaveData->tVers.usFunction  = acLinMsgBuffer[8];
  5423. +    ptLinSlaveData->tVers.usFunction |= acLinMsgBuffer[9]<<8;
  5424. +
  5425. +   // printf("Release : %i\n", ptLinSlaveData->tVers.ucRelease);
  5426. +   // printf("Version : %i\n", ptLinSlaveData->tVers.ucVersion);
  5427. +   // printf("Build   : %i\n", ptLinSlaveData->tVers.ucVariant);
  5428. +   // printf("Format  : %i\n", ptLinSlaveData->tVers.ucFormat);
  5429. +   // printf("ManCode : %i\n", ptLinSlaveData->tVers.usManCode);
  5430. +   // printf("Function: %i\n", ptLinSlaveData->tVers.usFunction);
  5431. +   // printf("\n");
  5432. +
  5433. +   return 0;
  5434. +
  5435. +}  /* eofn: lin_get_version */
  5436. +
  5437. +/******************************************************************************/
  5438. +/*!
  5439. +\fn            LIN_Open
  5440. +
  5441. +\brief         Schnittstelle fuer den LIN-Bus oeffnen
  5442. +
  5443. +\return         0  - Schnittstelle konnte geoffnet werden
  5444. +               -1  - Fehler beim Oeffnen
  5445. +
  5446. +\param         iSlaveCount - Anzahl der Linbus-Slaves
  5447. +               iIntervall  - Intervallzeit fuer Lin-Bus-Verarbeitung
  5448. +
  5449. +*******************************************************************************/
  5450. +int LIN_Open( int iSlaveCount, int iIntervall )
  5451. +{
  5452. +
  5453. +
  5454. +   RTS_RESULT rtsResult;
  5455. +
  5456. +    /* pruefen ob Linbus bereits geoeffnet wurde */
  5457. +    if ( rtsMasterThreadHandle != RTS_INVALID_HANDLE ) {
  5458. +        /* Linbus schliessen */
  5459. +        LIN_Close();
  5460. +    }
  5461. +
  5462. +   /******************/
  5463. +    /* Device oeffnen */
  5464. +    /******************/
  5465. +    iLinPort = open( cacDeviceName, O_RDWR);
  5466. +    if ( iLinPort < 0 ) {
  5467. +
  5468. +      printf("Device kann nicht geoeffnet werden\n");
  5469. +      return ERR_LIN_DEVICE;
  5470. +    }
  5471. +
  5472. +    tcgetattr(iLinPort, &initial_settings);
  5473. +    new_settings = initial_settings;
  5474. +
  5475. +    /************************************/
  5476. +    /* Schnittstelleneinstellung setzen */
  5477. +    /************************************/
  5478. +    /* Baudrate */
  5479. +    BaudRate = LIN_BAUD_RATE;
  5480. +   if (cfsetspeed(&new_settings, BaudRate) != 0) {
  5481. +        return ERR_LIN_BAUDRATE;
  5482. +    }
  5483. +    cfmakeraw(&new_settings);
  5484. +
  5485. +    /* Flags */
  5486. +    new_settings.c_cflag &= ~CSTOPB;   /* 1 Stopbit */
  5487. +    new_settings.c_cflag &= ~PARENB; /* keine Paritaet */
  5488. +    new_settings.c_cflag &= ~CSIZE;  /* 8 Datenbits */
  5489. +    new_settings.c_cflag |= CS8;
  5490. +
  5491. +   if (tcsetattr(iLinPort, TCSAFLUSH, &new_settings)  != 0) {
  5492. +
  5493. +      printf("Device konnte nicht initialsiert werden\n");
  5494. +      return ERR_LIN_PORTSETTING;
  5495. +    }
  5496. +
  5497. +    /*******************************/
  5498. +    /* Initialisierung uebernehmen */
  5499. +    /*******************************/
  5500. +    iLinSlaveCnt  = iSlaveCount;
  5501. +    iLinIntervall = iIntervall;
  5502. +
  5503. +    /*********************************/
  5504. +    /* Empfangspuffer initialisieren */
  5505. +    /*********************************/
  5506. +    iLinRxWrIndex = 0;
  5507. +    iLinRxRdIndex = 0;
  5508. +
  5509. +    /***************************/
  5510. +    /* Empfangsthread erzeugen */
  5511. +    /***************************/
  5512. +    rtsRxThreadHandle = CAL_SysTaskCreate( acRxThreadName, lin_rx_thread, NULL, RXTHREAD_PRIO, 0, 0, NULL, &rtsResult);
  5513. +    if ((rtsRxThreadHandle == RTS_INVALID_HANDLE) || (rtsResult != ERR_OK)) {
  5514. +
  5515. +        printf("LIN_Open: Rx-Task kann nicht angelegt werden\n");
  5516. +        return ERR_LIN_DEVICE;
  5517. +    }
  5518. +
  5519. +    /* Task starten */
  5520. +    CAL_SysTaskResume(rtsRxThreadHandle);
  5521. +
  5522. +    /*************************/
  5523. +    /* Masterthread erzeugen */
  5524. +    /*************************/
  5525. +    rtsMasterThreadHandle = CAL_SysTaskCreate( acMasterThreadName, lin_master_thread, NULL, LINTHREAD_PRIO, 0, 0, NULL, &rtsResult);
  5526. +    if ((rtsMasterThreadHandle == RTS_INVALID_HANDLE) || (rtsResult != ERR_OK)) {
  5527. +
  5528. +        printf("LIN_Open: Master-Task kann nicht angelegt werden\n");
  5529. +        return ERR_LIN_DEVICE;
  5530. +    }
  5531. +
  5532. +    /* Task starten */
  5533. +    CAL_SysTaskResume(rtsMasterThreadHandle);
  5534. +   iLinMasterState = LIN_MASTER_CHECK;
  5535. +
  5536. +    return 0;
  5537. +
  5538. +}  /* eofn: LIN_Open */
  5539. +
  5540. +
  5541. +/******************************************************************************/
  5542. +/*!
  5543. +\fn            LIN_Close
  5544. +
  5545. +\brief         Schnittstelle fuer den LIN-Bus schliessen
  5546. +
  5547. +\return         0  - Schnittstelle konnte geschlossen werden
  5548. +               -1  - Fehler beim Schliessen
  5549. +
  5550. +\param         keine
  5551. +
  5552. +*******************************************************************************/
  5553. +int LIN_Close( void )
  5554. +{
  5555. +
  5556. +    unsigned char ucTmp = 0;
  5557. +
  5558. +
  5559. +    /*************************/
  5560. +    /* Mastertask schliessen */
  5561. +    /*************************/
  5562. +   if ( rtsMasterThreadHandle != RTS_INVALID_HANDLE ) {
  5563. +
  5564. +      CAL_SysTaskSetExit(rtsMasterThreadHandle);
  5565. +      CAL_SysTaskExit(rtsMasterThreadHandle, 1000);
  5566. +      rtsMasterThreadHandle = RTS_INVALID_HANDLE;
  5567. +   }
  5568. +
  5569. +    /***************************/
  5570. +    /* Empfangstask schliessen */
  5571. +    /***************************/
  5572. +   if ( rtsRxThreadHandle != RTS_INVALID_HANDLE ) {
  5573. +
  5574. +        //lin_send( &ucTmp, 1 ); /* Dummy-Byte senden um Empfangsthread abzubrechen */
  5575. +
  5576. +      CAL_SysTaskSetExit(rtsRxThreadHandle);
  5577. +      CAL_SysTaskExit(rtsRxThreadHandle, 1000);
  5578. +      rtsRxThreadHandle = RTS_INVALID_HANDLE;
  5579. +   }
  5580. +
  5581. +   /*********************/
  5582. +    /* Device schliessen */
  5583. +   /*********************/
  5584. +    if ( iLinPort >= 0 ) {
  5585. +
  5586. +        if ( close( iLinPort ) != 0 ) {
  5587. +
  5588. +          printf("Device kann nicht geschlossen werden\n");
  5589. +          return ERR_LIN_DEVICE;
  5590. +        }
  5591. +    }
  5592. +
  5593. +    return 0;
  5594. +
  5595. +}  /* eofn: LIN_Close */
  5596. +
  5597. +/******************************************************************************/
  5598. +/*!
  5599. +\fn            LIN_GetMasterState
  5600. +
  5601. +\brief         Funktion liefert den Status des Linbus-Master
  5602. +
  5603. +\return        Status des Linbus-Masters
  5604. +
  5605. +\param         keine
  5606. +
  5607. +*******************************************************************************/
  5608. +int LIN_GetMasterState( void )
  5609. +{
  5610. +    return iLinMasterState;
  5611. +
  5612. +}  /* eofn: LIN_GetMasterState */
  5613. +
  5614. +/******************************************************************************/
  5615. +/*!
  5616. +\fn            LIN_GetSlaveState
  5617. +
  5618. +\brief         Funktion liefert den Status des Linbus-Slave
  5619. +
  5620. +\return        Status des Linbus-Slave
  5621. +
  5622. +\param         iSlave - Linbus-Slave
  5623. +
  5624. +*******************************************************************************/
  5625. +int LIN_GetSlaveState( int iSlave )
  5626. +{
  5627. +    if ( iSlave > MAX_LIN_SLAVE ) {
  5628. +
  5629. +        return -1;
  5630. +    }
  5631. +
  5632. +    return atLinSlaveData[iSlave].ucSlaveOnline;
  5633. +
  5634. +}  /* eofn: LIN_GetSlaveState */
  5635. +
  5636. +/******************************************************************************/
  5637. +/*!
  5638. +\fn            LIN_ResetAddress
  5639. +
  5640. +\brief         Alle Adressen der Linbus-Slaves loeschen
  5641. +
  5642. +\return        Adressen werden geloescht
  5643. +                0  - Loeschen wird ausgefuehrt
  5644. +                    -1  - Fehler beim Loeschen
  5645. +
  5646. +\param         keine
  5647. +
  5648. +*******************************************************************************/
  5649. +int LIN_ResetAddress( void )
  5650. +{
  5651. +
  5652. +    /* Reset ausfuehren */
  5653. +    iLinResetAddr = TRUE;
  5654. +
  5655. +    return 0;
  5656. +
  5657. +}  /* eofn: LIN_ResetAddress */
  5658. +
  5659. +/******************************************************************************/
  5660. +/*!
  5661. +\fn            LIN_SetAddress
  5662. +
  5663. +\brief         Adressen der Linbus-Slaves neu setzen
  5664. +
  5665. +\return        Adressen werden gesetzt
  5666. +                0  - Setzen wird ausgefuehrt
  5667. +
  5668. +\param         keine
  5669. +
  5670. +*******************************************************************************/
  5671. +int LIN_SetAddress( void )
  5672. +{
  5673. +
  5674. +    /* Setzen ausfuehren */
  5675. +    iLinSetAddr = TRUE;
  5676. +
  5677. +    return 0;
  5678. +
  5679. +}  /* eofn: LIN_SetAddress */
  5680. +
  5681. +/******************************************************************************/
  5682. +/*!
  5683. +\fn            LIN_GetVersion
  5684. +
  5685. +\brief         Version des Linbus-Slaves auslesen
  5686. +
  5687. +\return        Versionsdaten gueltig
  5688. +                0  - Gueltig
  5689. +                    -1  - Ungueltig
  5690. +
  5691. +\param         iSlave            - Linbus-Slave
  5692. +                    ptLinSlaveVersion - Zeiger auf Versionsdaten des Slaves
  5693. +
  5694. +*******************************************************************************/
  5695. +int LIN_GetVersion( int iSlave, LIN_SLAVE_VERSION_TR *ptLinSlaveVersion )
  5696. +{
  5697. +    if ( iSlave > MAX_LIN_SLAVE ) {
  5698. +
  5699. +        /* Slavenummer ist ungueltig */
  5700. +        return -1;
  5701. +    }
  5702. +
  5703. +    if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  5704. +
  5705. +        /* Slave nicht vorhanden; Versioneintrag loeschen */
  5706. +        memset(&atLinSlaveData[iSlave].tVers, 0, sizeof(LIN_SLAVE_VERSION_TR));
  5707. +    }
  5708. +
  5709. +    /* Versionseintrag uebernehmen */
  5710. +    memcpy( ptLinSlaveVersion, &atLinSlaveData[iSlave].tVers, sizeof(LIN_SLAVE_VERSION_TR));
  5711. +
  5712. +    return 0;
  5713. +
  5714. +}  /* eofn: LIN_GetVersion */
  5715. +
  5716. +/******************************************************************************/
  5717. +/*!
  5718. +\fn            LIN_GetFaceValue
  5719. +
  5720. +\brief         Istwert des Linbus-Slaves auslesen
  5721. +
  5722. +\return        Istwert des Linbus-Slaves
  5723. +               >=0  - Istwert gueltig
  5724. +                     -1  - ungueltiger Wert
  5725. +
  5726. +\param         iSlave           - Linbus-Slave
  5727. +               ptLinSlaveValue  - Zeiger auf Istwerte des Slaves
  5728. +
  5729. +*******************************************************************************/
  5730. +int LIN_GetFaceValue( int iSlave, LIN_SLAVE_VALUE_TR *ptLinSlaveValue )
  5731. +{
  5732. +
  5733. +    if ( iSlave > MAX_LIN_SLAVE ) {
  5734. +
  5735. +        return -1;
  5736. +    }
  5737. +
  5738. +    if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  5739. +
  5740. +        /* Slave nicht vorhanden; Versioneintrag loeschen */
  5741. +        memset(&atLinSlaveData[iSlave].tValue, 0, sizeof(LIN_SLAVE_VALUE_TR));
  5742. +    }
  5743. +
  5744. +    /* Werte uebernehmen */
  5745. +    memcpy( ptLinSlaveValue, &atLinSlaveData[iSlave].tValue, sizeof(LIN_SLAVE_VALUE_TR));
  5746. +
  5747. +    return 0;
  5748. +
  5749. +}      /* eofn: LIN_GetFaceValue */
  5750. +
  5751. +/******************************************************************************/
  5752. +/*!
  5753. +\fn            LIN_SetValue
  5754. +
  5755. +\brief         Sollwert des Linbus-Slaves setzen
  5756. +
  5757. +\return        Sollwert wird uebernommen
  5758. +                0  - Uebernahme wird ausgefuehrt
  5759. +                    -1  - Fehler bei der Uebernahme
  5760. +
  5761. +\param         iSlave    - Linbus-Slave
  5762. +               usValue   - Sollwert
  5763. +                    ucControl - Steuerflags
  5764. +
  5765. +*******************************************************************************/
  5766. +int LIN_SetValue( int iSlave, unsigned short usValue, unsigned char ucControl, unsigned char ucDevice  )
  5767. +{
  5768. +   if ( iSlave > MAX_LIN_SLAVE ) {
  5769. +
  5770. +      /* Adressierung ungueltig */
  5771. +      return -1;
  5772. +   }
  5773. +
  5774. +   if ( atLinSlaveData[iSlave].ucSlaveOnline == FALSE ) {
  5775. +
  5776. +      /* Slave nicht vorhanden */
  5777. +      return -1;
  5778. +   }
  5779. +
  5780. +   /* Werte uebernehmen */
  5781. +   atLinSlaveData[iSlave].ucSetNewValue = TRUE;
  5782. +   atLinSlaveData[iSlave].usSetValue    = usValue;
  5783. +   atLinSlaveData[iSlave].ucSetControl  = ucControl;
  5784. +   atLinSlaveData[iSlave].ucDevice  = ucDevice;
  5785. +
  5786. +   return 0;
  5787. +
  5788. +}      /* eofn: LIN_SetValue */
  5789. +
  5790. +/******************************************************************************/
  5791. +/*!
  5792. +\fn            LIN_MasterSetValue
  5793. +
  5794. +\brief         Sollwert fuer alle Linbus-Slaves setzen
  5795. +
  5796. +\return        Sollwert wird uebernommen
  5797. +                0  - Uebernahme wird ausgefuehrt
  5798. +                    -1  - Fehler bei der Uebernahme
  5799. +
  5800. +\param         usValue   - Sollwert
  5801. +               ucControl - Steuerflags
  5802. +
  5803. +*******************************************************************************/
  5804. +int LIN_MasterSetValue( unsigned short usValue, unsigned char ucControl, unsigned char ucDevice )
  5805. +{
  5806. +   if ( iLinMasterState != LIN_MASTER_ONLINE ) {
  5807. +
  5808. +      /* Master nicht Online */
  5809. +      return -1;
  5810. +   }
  5811. +
  5812. +   /* Werte uebernehmen */
  5813. +   ucLinMasterNewValue = TRUE;
  5814. +   usLinMasterValue    = usValue;
  5815. +   ucLinMasterControl  = ucControl;
  5816. +   ucLinMasterDevice   = ucDevice;
  5817. +
  5818. +
  5819. +   return 0;
  5820. +
  5821. +}      /* eofn: LIN_MasterSetValue */
  5822. +/*--- eof  ---*/
  5823. +
  5824. diff --git a/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.h b/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.h
  5825. index e7362c5..4167cf9 100755
  5826. --- a/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.h
  5827. +++ b/ptxdist/local_src/ecu01-codesys/linbus/linbus_imp.h
  5828. @@ -1,99 +1,99 @@
  5829. -/******************************************************************************/
  5830.  
  5831. -/*!
  5832.  
  5833. -\file              $URL: https://svn.eckelmann.group/svn/max/quantron_a/trunk/src/codesys/qa/linbus.h $
  5834.  
  5835. -
  5836.  
  5837. -\brief             Modul fuer die LIN-Bus-Kommunikation
  5838.  
  5839. -
  5840.  
  5841. -\author            $Author: gudertm $
  5842.  
  5843. -\date              $Date: 2015-07-01 15:07:27 +0200 (Mi, 01 Jul 2015) $
  5844.  
  5845. -
  5846.  
  5847. -\version           $Rev: 3724 $
  5848.  
  5849. -
  5850.  
  5851. -\b                 ECKELMANN INDUSTRIEAUTOMATION, WIESBADEN\n
  5852.  
  5853. -                   © Copyright 2010
  5854.  
  5855. -
  5856.  
  5857. -*******************************************************************************/
  5858.  
  5859. -
  5860.  
  5861. -#ifndef __LINBUS_H__
  5862.  
  5863. -#define __LINBUS_H__
  5864.  
  5865. -
  5866.  
  5867. -/*******************************************************************************
  5868.  
  5869. -@Includes
  5870.  
  5871. -*******************************************************************************/
  5872.  
  5873. -
  5874.  
  5875. -/*******************************************************************************
  5876.  
  5877. -@Konstanten (modulglobal)
  5878.  
  5879. -*******************************************************************************/
  5880.  
  5881. -
  5882.  
  5883. -/************************/
  5884.  
  5885. -/* LIN-Master-Zustaende */
  5886.  
  5887. -/************************/
  5888.  
  5889. -#define  LIN_MASTER_CHECK           0
  5890.  
  5891. -#define  LIN_MASTER_INIT            1
  5892.  
  5893. -#define  LIN_MASTER_ONLINE          2
  5894.  
  5895. -#define  LIN_MASTER_REPAIR          4
  5896.  
  5897. -#define  LIN_MASTER_ADR_CLR         5
  5898.  
  5899. -#define  LIN_MASTER_WAIT_FOR_SLAVE  6
  5900.  
  5901. -
  5902.  
  5903. -/*******************************************************************************
  5904.  
  5905. -@Typdefinitionen (modulglobal)
  5906.  
  5907. -*******************************************************************************/
  5908.  
  5909. -
  5910.  
  5911. -typedef struct LIN_SLAVE_VERSION_R {
  5912.  
  5913. -       unsigned char  ucRelease;                               /* Software Release */
  5914.  
  5915. -       unsigned char  ucVersion;                               /* Software Version */
  5916.  
  5917. -       unsigned char  ucVariant;                               /* Software Variante */
  5918.  
  5919. -       unsigned char  ucFormat;                                /* Geraetetyp */
  5920.  
  5921. -       unsigned short usManCode;                               /* Herstellercode 5248hex */
  5922.  
  5923. -       unsigned short usFunction;                              /* Sachnummer */
  5924.  
  5925. -}  LIN_SLAVE_VERSION_TR;
  5926.  
  5927. -
  5928.  
  5929. -typedef struct LIN_SLAVE_VALUE_R {
  5930.  
  5931. -       unsigned char  ucFormat;                                /* Geraetetyp */
  5932.  
  5933. -       unsigned short usIstPos;                                /* Istposition */
  5934.  
  5935. -       unsigned char  ucStatus;                                /* Statusbyte */
  5936.  
  5937. -       unsigned char  ucErrorCnt;                              /* Fehlerzaehler */
  5938.  
  5939. -}  LIN_SLAVE_VALUE_TR;
  5940.  
  5941. -
  5942.  
  5943. -/*******************************************************************************
  5944.  
  5945. -@Makros (modulglobal)
  5946.  
  5947. -*******************************************************************************/
  5948.  
  5949. -
  5950.  
  5951. -/*******************************************************************************
  5952.  
  5953. -@Prototypen der globalen Funktionen
  5954.  
  5955. -*******************************************************************************/
  5956.  
  5957. -
  5958.  
  5959. -/* \brief Schnittstelle fuer den LIN-Bus oeffnen */
  5960.  
  5961. -int LIN_Open( int iSlaveCount, int iIntervall );
  5962.  
  5963. -
  5964.  
  5965. -/* \brief Schnittstelle fuer den LIN-Bus schliessen */
  5966.  
  5967. -int LIN_Close( void );
  5968.  
  5969. -
  5970.  
  5971. -/* \brief Status des Linbus-Master */
  5972.  
  5973. -int LIN_GetMasterState( void );
  5974.  
  5975. -
  5976.  
  5977. -/* \brief Status des Linbus-Slaves */
  5978.  
  5979. -int LIN_GetSlaveState( int iSlave );
  5980.  
  5981. -
  5982.  
  5983. -/* \brief Alle Adressen der Linbus-Slaves loeschen */
  5984.  
  5985. -int LIN_ResetAddress( void );
  5986.  
  5987. -
  5988.  
  5989. -/* \brief Adressen der Linbus-Slaves neu setzen */
  5990.  
  5991. -int LIN_SetAddress( void );
  5992.  
  5993. -
  5994.  
  5995. -/* \brief Version des Linbus-Slaves auslesen */
  5996.  
  5997. -int LIN_GetVersion( int iSlave, LIN_SLAVE_VERSION_TR *ptLinSlaveVersion );
  5998.  
  5999. -
  6000.  
  6001. -/* \brief Istwert des Linbus-Slaves auslesen */
  6002.  
  6003. -int LIN_GetFaceValue( int iSlave, LIN_SLAVE_VALUE_TR *ptLinSlaveValue );
  6004.  
  6005. -
  6006.  
  6007. -/* \brief Sollwert des Linbus-Slaves setzen */
  6008.  
  6009. -int LIN_SetValue( int iSlave, unsigned short usValue, unsigned char ucFlags, unsigned char ucDevice  );
  6010.  
  6011. -
  6012.  
  6013. -/* \brief Sollwert fuer alle Linbus-Slaves setzen */
  6014.  
  6015. -int LIN_MasterSetValue( unsigned short usValue, unsigned char ucFlags, unsigned char ucDevice );
  6016.  
  6017. -
  6018.  
  6019. -#endif /* __LINBUS_H__ */
  6020.  
  6021. -
  6022.  
  6023. -/*--- eof ---*/
  6024.  
  6025. -
  6026.  
  6027. +/******************************************************************************/
  6028. +/*!
  6029. +\file              $URL: https://subversion.eckelmann.local/svn/max/quantron_a/trunk/src/codesys/qa/linbus.h $
  6030. +
  6031. +\brief             Modul fuer die LIN-Bus-Kommunikation
  6032. +
  6033. +\author            $Author: HILTENKA $
  6034. +\date              $Date: 2011-03-04 13:25:07 +0100 (Fr, 04 Mrz 2011) $
  6035. +
  6036. +\version           $Rev: 1686 $
  6037. +
  6038. +\b                 ECKELMANN INDUSTRIEAUTOMATION, WIESBADEN\n
  6039. +                   © Copyright 2010
  6040. +
  6041. +*******************************************************************************/
  6042. +
  6043. +#ifndef __LINBUS_H__
  6044. +#define __LINBUS_H__
  6045. +
  6046. +/*******************************************************************************
  6047. +@Includes
  6048. +*******************************************************************************/
  6049. +
  6050. +/*******************************************************************************
  6051. +@Konstanten (modulglobal)
  6052. +*******************************************************************************/
  6053. +
  6054. +/************************/
  6055. +/* LIN-Master-Zustaende */
  6056. +/************************/
  6057. +#define  LIN_MASTER_CHECK           0
  6058. +#define  LIN_MASTER_INIT            1
  6059. +#define  LIN_MASTER_ONLINE          2
  6060. +#define  LIN_MASTER_REPAIR          4
  6061. +#define  LIN_MASTER_ADR_CLR         5
  6062. +#define  LIN_MASTER_WAIT_FOR_SLAVE  6
  6063. +
  6064. +/*******************************************************************************
  6065. +@Typdefinitionen (modulglobal)
  6066. +*******************************************************************************/
  6067. +
  6068. +typedef struct LIN_SLAVE_VERSION_R {
  6069. +       unsigned char  ucRelease;                               /* Software Release */
  6070. +       unsigned char  ucVersion;                               /* Software Version */
  6071. +       unsigned char  ucVariant;                               /* Software Variante */
  6072. +       unsigned char  ucFormat;                                /* Geraetetyp */
  6073. +       unsigned short usManCode;                               /* Herstellercode 5248hex */
  6074. +       unsigned short usFunction;                              /* Sachnummer */
  6075. +}  LIN_SLAVE_VERSION_TR;
  6076. +
  6077. +typedef struct LIN_SLAVE_VALUE_R {
  6078. +       unsigned char  ucFormat;                                /* Geraetetyp */
  6079. +       unsigned short usIstPos;                                /* Istposition */
  6080. +       unsigned char  ucStatus;                                /* Statusbyte */
  6081. +       unsigned char  ucErrorCnt;                              /* Fehlerzaehler */
  6082. +}  LIN_SLAVE_VALUE_TR;
  6083. +
  6084. +/*******************************************************************************
  6085. +@Makros (modulglobal)
  6086. +*******************************************************************************/
  6087. +
  6088. +/*******************************************************************************
  6089. +@Prototypen der globalen Funktionen
  6090. +*******************************************************************************/
  6091. +
  6092. +/* \brief Schnittstelle fuer den LIN-Bus oeffnen */
  6093. +int LIN_Open( int iSlaveCount, int iIntervall );
  6094. +
  6095. +/* \brief Schnittstelle fuer den LIN-Bus schliessen */
  6096. +int LIN_Close( void );
  6097. +
  6098. +/* \brief Status des Linbus-Master */
  6099. +int LIN_GetMasterState( void );
  6100. +
  6101. +/* \brief Status des Linbus-Slaves */
  6102. +int LIN_GetSlaveState( int iSlave );
  6103. +
  6104. +/* \brief Alle Adressen der Linbus-Slaves loeschen */
  6105. +int LIN_ResetAddress( void );
  6106. +
  6107. +/* \brief Adressen der Linbus-Slaves neu setzen */
  6108. +int LIN_SetAddress( void );
  6109. +
  6110. +/* \brief Version des Linbus-Slaves auslesen */
  6111. +int LIN_GetVersion( int iSlave, LIN_SLAVE_VERSION_TR *ptLinSlaveVersion );
  6112. +
  6113. +/* \brief Istwert des Linbus-Slaves auslesen */
  6114. +int LIN_GetFaceValue( int iSlave, LIN_SLAVE_VALUE_TR *ptLinSlaveValue );
  6115. +
  6116. +/* \brief Sollwert des Linbus-Slaves setzen */
  6117. +int LIN_SetValue( int iSlave, unsigned short usValue, unsigned char ucFlags, unsigned char ucDevice  );
  6118. +
  6119. +/* \brief Sollwert fuer alle Linbus-Slaves setzen */
  6120. +int LIN_MasterSetValue( unsigned short usValue, unsigned char ucFlags, unsigned char ucDevice );
  6121. +
  6122. +#endif /* __LINBUS_H__ */
  6123. +
  6124. +/*--- eof ---*/
  6125. +

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