src/sync.c
author etisserant
Mon, 06 Aug 2007 17:59:06 +0200
changeset 250 39e22f84ce6e
parent 236 905677ed00f3
child 252 b0dd37421d28
permissions -rw-r--r--
Attic problem. Removed old unused dirs.
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
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   144
  UNS8 res;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   145
  
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   146
  MSG_WAR(0x3002, "SYNC received. Proceed. ", 0);
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   147
  
153
1c1ad874fe8f Post_sync have to be called even if in pre-op state. Fixed.
etisserant
parents: 149
diff changeset
   148
  (*d->post_sync)();
1c1ad874fe8f Post_sync have to be called even if in pre-op state. Fixed.
etisserant
parents: 149
diff changeset
   149
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   150
  /* only operational state allows PDO transmission */
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   151
  if(! d->CurrentCommunicationState.csPDO) 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
    return 0;
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   153
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   154
  res = _sendPDOevent(d, 1 /*isSyncEvent*/ );
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
  
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   156
  /*Call user app callback*/
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   157
  (*d->post_TPDO)();
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
  
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   159
  return res;
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   160
  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
149
fe50ada8020b Changes in the API:
etisserant
parents: 85
diff changeset
   164
void _post_sync(){}
fe50ada8020b Changes in the API:
etisserant
parents: 85
diff changeset
   165
void _post_TPDO(){}