src/sync.c
author lbessard
Wed, 13 Jun 2007 10:28:25 +0200
changeset 220 b7fb826c66d9
parent 217 94c3f89bc3cc
child 235 f812bf6b7237
permissions -rw-r--r--
Bug on NodeManager corrected :
Mandatory indexes was not added by default when creating a node
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    23
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    24
** @file   sync.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    25
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    26
** @date   Tue Jun  5 09:32:32 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    27
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    28
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    29
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    30
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    31
*/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    32
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include "data.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include "sync.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 85
diff changeset
    35
#include "canfestival.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    37
/* Prototypes for internals functions */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    38
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    39
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    40
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    41
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    42
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    43
** @param id                                                                                       
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    44
**/  
53
73bc47a0db55 Add prototypes
frdupin
parents: 31
diff changeset
    45
void SyncAlarm(CO_Data* d, UNS32 id);
73bc47a0db55 Add prototypes
frdupin
parents: 31
diff changeset
    46
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, 
73bc47a0db55 Add prototypes
frdupin
parents: 31
diff changeset
    47
	UNS8 unsused_bSubindex);
73bc47a0db55 Add prototypes
frdupin
parents: 31
diff changeset
    48
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    49
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    50
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    51
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    52
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    53
** @param id                                                                                       
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    54
**/   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
void SyncAlarm(CO_Data* d, UNS32 id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
	sendSYNC(d, *d->COB_ID_Sync & 0x1FFFFFFF) ;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    60
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    61
** This is called when Index 0x1005 is updated.                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    62
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    63
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    64
** @param unsused_indextable                                                                       
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    65
** @param unsused_bSubindex                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    66
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    67
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    68
**/  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
UNS32 OnCOB_ID_SyncUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
	startSYNC(d);
31
a82b70738e5c Code clean-up and fixed xenomai compile problem
lbessard
parents: 0
diff changeset
    72
	return 0;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    75
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    76
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    77
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    78
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    79
**/ 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
void startSYNC(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
	RegisterSetODentryCallBack(d, 0x1005, 0, &OnCOB_ID_SyncUpdate);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
	RegisterSetODentryCallBack(d, 0x1006, 0, &OnCOB_ID_SyncUpdate);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
	if(d->syncTimer != TIMER_NONE){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
		stopSYNC(d);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
	if(*d->COB_ID_Sync & 0x40000000 && *d->Sync_Cycle_Period)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
		d->syncTimer = SetAlarm(
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
				d,
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    93
				0 /*No id needed*/,
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
				&SyncAlarm,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
				US_TO_TIMEVAL(*d->Sync_Cycle_Period), 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
				US_TO_TIMEVAL(*d->Sync_Cycle_Period));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   100
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   101
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   102
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   103
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   104
**/   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
void stopSYNC(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
	d->syncTimer = DelAlarm(d->syncTimer);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   110
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   111
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   112
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   113
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   114
** @param cob_id                                                                                   
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   115
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   116
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   117
**/  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
UNS8 sendSYNC(CO_Data* d, UNS32 cob_id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
  UNS8 resultat ;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
  MSG_WAR(0x3001, "sendSYNC ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
  m.cob_id.w = cob_id ;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
  m.len = 0;
149
fe50ada8020b Changes in the API:
etisserant
parents: 85
diff changeset
   128
  resultat = canSend(d->canHandle,&m) ;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
  proceedSYNC(d, &m) ; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
  return resultat ;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   133
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   134
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   135
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   136
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   137
** @param m                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   138
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   139
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   140
**/ 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
UNS8 proceedSYNC(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   144
  UNS8 	pdoNum,       /* number of the actual processed pdo-nr. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   145
        prp_j;
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   146
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   147
  const UNS8 *     pMappingCount = NULL;      /* count of mapped objects...*/
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   148
  /* pointer to the var which is mapped to a pdo */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   149
  /* void *     pMappedAppObject = NULL; */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   150
  /* pointer fo the var which holds the mapping parameter of an mapping entry  */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
  UNS32 *    pMappingParameter = NULL;  
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   152
  /* pointer to the transmissiontype...*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
  UNS8 *     pTransmissionType = NULL;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  UNS32 *    pwCobId = NULL;	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   156
  UNS8 dataType;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
  UNS16 index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
  UNS8 subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
  UNS8 offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
  UNS8 status;
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   161
  UNS8 Size;
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   162
  UNS32 objDict;	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
  UNS16 offsetObjdict;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
  UNS16 offsetObjdictMap;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
  UNS16 lastIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   166
  
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   167
  status = state3;
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   168
  pdoNum = 0x00;
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   169
  prp_j = 0x00;
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   170
  offset = 0x00;
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   171
  
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   172
  MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   173
  
153
1c1ad874fe8f Post_sync have to be called even if in pre-op state. Fixed.
etisserant
parents: 149
diff changeset
   174
  (*d->post_sync)();
1c1ad874fe8f Post_sync have to be called even if in pre-op state. Fixed.
etisserant
parents: 149
diff changeset
   175
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   176
  /* only operational state allows PDO transmission */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
  if( d->nodeState != Operational ) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
  
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   180
  /* So, the node is in operational state */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   181
  /* study all PDO stored in the objects dictionary */	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
  offsetObjdict = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
  lastIndex = d->lastIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
  offsetObjdictMap = d->firstIndex->PDO_TRS_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
  if(offsetObjdict) while( offsetObjdict <= lastIndex) {  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
    switch( status ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
                    
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   190
    case state3:    /* get the PDO transmission type */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
      if (d->objdict[offsetObjdict].bSubCount <= 2) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
	  MSG_ERR(0x1004, "Subindex 2  not found at index ", 0x1800 + pdoNum);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
	}
217
94c3f89bc3cc Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents: 215
diff changeset
   195
      pTransmissionType = (UNS8*) d->objdict[offsetObjdict].pSubindex[2].pObject;    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
      MSG_WAR(0x3005, "Reading PDO at index : ", 0x1800 + pdoNum);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
      status = state4; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
      break;     
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   199
    case state4:	/* check if transmission type is after (this) SYNC */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   200
                        /* The message may not be transmited every SYNC but every n SYNC */      
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
      if( (*pTransmissionType >= TRANS_SYNC_MIN) && (*pTransmissionType <= TRANS_SYNC_MAX) &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
          (++d->count_sync[pdoNum] == *pTransmissionType) ) {	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
	d->count_sync[pdoNum] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
	MSG_WAR(0x3007, "  PDO is on SYNCHRO. Trans type : ", *pTransmissionType);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
	status = state5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
	break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
      else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
	MSG_WAR(0x3008, "  Not on synchro or not at this SYNC. Trans type : ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
		*pTransmissionType);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
	pdoNum++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
	offsetObjdict++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
	offsetObjdictMap++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
	status = state11;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
	break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
      }      
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   217
    case state5:	/* get PDO CobId */
217
94c3f89bc3cc Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents: 215
diff changeset
   218
        pwCobId = (UNS32*) d->objdict[offsetObjdict].pSubindex[1].pObject;     
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
	MSG_WAR(0x3009, "  PDO CobId is : ", *pwCobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
	status = state7;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
	break;     
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   222
    case state7:  /* get mapped objects number to transmit with this PDO */
217
94c3f89bc3cc Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents: 215
diff changeset
   223
      pMappingCount = (UNS8*) d->objdict[offsetObjdictMap].pSubindex[0].pObject;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
	MSG_WAR(0x300D, "  Number of objects mapped : ",*pMappingCount );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
	status = state8;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   226
    case state8:	/* get mapping parameters */
217
94c3f89bc3cc Fixed compile error because of missed type casting in certain compiler (http://www.iar.se/). Thanks to Raphael Studer
etisserant
parents: 215
diff changeset
   227
      pMappingParameter = (UNS32*) d->objdict[offsetObjdictMap].pSubindex[prp_j + 1].pObject;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
	MSG_WAR(0x300F, "  got mapping parameter : ", *pMappingParameter);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
	MSG_WAR(0x3050, "    at index : ", 0x1A00 + pdoNum);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
	MSG_WAR(0x3051, "    sub-index : ", prp_j + 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
	status = state9;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
    
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   233
    case state9:	/* get data to transmit */ 
204
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 201
diff changeset
   234
	{
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   235
	  UNS8 ByteSize;
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   236
	  UNS8 tmp[]= {0,0,0,0,0,0,0,0};
204
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 201
diff changeset
   237
	  index = (UNS16)((*pMappingParameter) >> 16);
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 201
diff changeset
   238
          subIndex = (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF);
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   239
	  Size = (UNS8)(*pMappingParameter); /* Size in bits */
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   240
	  ByteSize = 1 + ((Size - 1) >> 3); /*1->8 => 1 ; 9->16 => 2, ... */
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   241
	  objDict = getODentry(d, index, subIndex, tmp, &ByteSize, &dataType, 0 );
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   242
	  /* copy bit per bit in little endian*/
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   243
	  CopyBits(Size, ((UNS8*)tmp), 0 , 0, (UNS8*)&d->process_var.data[offset>>3], offset%8, 0);
204
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 201
diff changeset
   244
	}   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
        if( objDict != OD_SUCCESSFUL ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
          MSG_ERR(0x1013, " Couldn't find mapped variable at index-subindex-size : ", (UNS16)(*pMappingParameter));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
          return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
	
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   250
	offset += Size ;
2966cd34162a Boolean variable mapped in PDO
greg
parents: 153
diff changeset
   251
	d->process_var.count = 1 + ((offset - 1) >> 3);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
	prp_j++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
	status = state10;	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
	break;					
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
      
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   256
    case state10:	/* loop to get all the data to transmit */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
      if( prp_j < *pMappingCount ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
	MSG_WAR(0x3014, "  next variable mapped : ", prp_j);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
	status = state8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
	break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
      else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
	MSG_WAR(0x3015, "  End scan mapped variable", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
	PDOmGR( d, *pwCobId );	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
	MSG_WAR(0x3016, "  End of this pdo. Should have been sent", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
	pdoNum++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
	offsetObjdict++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
	offsetObjdictMap++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
	offset = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
	prp_j = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
	status = state11;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
	break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
    case state11:     
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
      MSG_WAR(0x3017, "next pdo index : ", pdoNum);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
      status = state3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
    default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
      MSG_ERR(0x1019,"Unknown state has been reached : %d",status);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
      return 0xFF;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   283
    }/* end switch case */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
    
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   285
  }/* end while( prp_i<dict_cstes.max_count_of_PDO_transmit ) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
  (*d->post_TPDO)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
149
fe50ada8020b Changes in the API:
etisserant
parents: 85
diff changeset
   293
void _post_sync(){}
fe50ada8020b Changes in the API:
etisserant
parents: 85
diff changeset
   294
void _post_TPDO(){}