src/lss.c
author etisserant
Fri, 11 Jan 2008 09:39:49 +0100
changeset 352 3347581c3140
parent 343 118c1cabd0b0
child 361 2220813498f2
permissions -rw-r--r--
Fixed timer problem on late Heartbeat. Thanks to Jorge.
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     1
/*
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     3
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     4
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     5
Copyright (C): Jorge Berzosa
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     6
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     7
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     8
See COPYING file for copyrights details.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     9
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    10
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    11
This library is free software; you can redistribute it and/or
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    12
modify it under the terms of the GNU Lesser General Public
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    13
License as published by the Free Software Foundation; either
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    14
version 2.1 of the License, or (at your option) any later version.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    15
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    16
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    17
This library is distributed in the hope that it will be useful,
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    18
but WITHOUT ANY WARRANTY; without even the implied warranty of
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    20
Lesser General Public License for more details.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    21
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    22
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    23
You should have received a copy of the GNU Lesser General Public
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    24
License along with this library; if not, write to the Free Software
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    25
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    26
*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    27
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    28
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    29
/*!
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    30
** @file   lss.c
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    31
** @author Jorge Berzosa
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    32
** @date   Mon Oct  22 05:44:32 2007
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    33
**
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    34
** @brief
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    35
**
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    36
**
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    37
*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    38
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    39
#ifdef CO_ENABLE_LSS
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    40
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    41
#include "data.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    42
#include "lss.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    43
#include "canfestival.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    44
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    45
#define LSS_TIMEOUT_MS	(TIMEVAL)1000  /* ms */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    46
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    47
/* Returns the LSS ident field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    48
#define getLSSIdent(msg) ((msg->data[4] << 24) | (msg->data[3] << 16) | (msg->data[2] << 8) | (msg->data[1]))
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    49
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    50
/* Returns the LSS switch delay field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    51
#define getLSSDelay(msg) ((msg->data[2] << 8) | (msg->data[1]))
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    52
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    53
/* Returns the LSS FastScan BitCheck field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    54
#define getLSSBitCheck(msg) msg->data[5]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    55
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    56
/* Returns the LSS FastScan LSSSub field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    57
#define getLSSSub(msg) msg->data[6]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    58
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    59
/* Returns the LSS FastScan LSSNext field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    60
#define getLSSNext(msg) msg->data[7]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    61
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    62
/* Prototypes for internals functions */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    63
void LssAlarm(CO_Data* d, UNS32 id);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    64
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    65
#define StopLSS_TIMER(id){\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    66
 MSG_WAR(0x3D01, "StopLSS_TIMER for timer : ", id);\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    67
 d->lss_transfer.timers[id] = DelAlarm(d->lss_transfer.timers[id]);}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    68
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    69
#define StartLSS_MSG_TIMER(){\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    70
 MSG_WAR(0x3D02, "StartLSS_TIMER for MSG_TIMER",0);\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    71
 d->lss_transfer.timers[LSS_MSG_TIMER] = SetAlarm(d,LSS_MSG_TIMER,&LssAlarm,MS_TO_TIMEVAL(LSS_TIMEOUT_MS),0);}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    72
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    73
#define StartLSS_SDELAY_TIMER(){\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    74
 MSG_WAR(0x3D03, "StartLSS_TIMER for SDELAY_TIMER",0);\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    75
 d->lss_transfer.timers[LSS_SWITCH_DELAY_TIMER] = SetAlarm(d,LSS_SWITCH_DELAY_TIMER,&LssAlarm,MS_TO_TIMEVAL(d->lss_transfer.switchDelay),MS_TO_TIMEVAL(d->lss_transfer.switchDelay));}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    76
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    77
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    78
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    79
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    80
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    81
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    82
** @param id                                                                                       
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    83
**/   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    84
//struct timeval current_time,init_time;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    85
void LssAlarm(CO_Data* d, UNS32 id)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    86
{	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    87
	/*unsigned long time_period;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    88
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    89
	gettimeofday(&current_time,NULL);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    90
 	time_period=(current_time.tv_sec - init_time.tv_sec)* 1000000 + current_time.tv_usec - init_time.tv_usec;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    91
 	printf("%3ld.%3ld.%3ld --",time_period/1000000,(time_period%1000000)/1000,time_period%1000);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    92
 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    93
	switch(id){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    94
	case LSS_MSG_TIMER:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    95
	 	MSG_ERR(0x1D04, "LSS timeout. LSS response not received.", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    96
    	MSG_WAR(0x2D05, "LSS timeout command specifier : ", d->lss_transfer.command);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    97
    
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    98
		StopLSS_TIMER(LSS_MSG_TIMER);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    99
    	/* Set aborted state */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   100
    	d->lss_transfer.state = LSS_ABORTED_INTERNAL;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   101
    	/* Call the user function to inform of the problem.*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   102
    	if(d->lss_transfer.Callback){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   103
    		/*If there is a callback, it is responsible of the error*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   104
    		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   105
    	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   106
    break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   107
    case LSS_SWITCH_DELAY_TIMER:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   108
  		/* The first switch_delay period has expired. Store the node state, change it 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   109
 		 * so no CAN messages will be sent or received, call the ChangeBaudRate function*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   110
   		if(d->lss_transfer.switchDelayState==SDELAY_FIRST){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   111
   			MSG_WAR(0x3D06, "LSS switch delay first period expired",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   112
    		d->lss_transfer.switchDelayState=SDELAY_SECOND;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   113
    		//d->lss_transfer.currentState=getState(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   114
    		//setState(d, LssTimingDelay);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   115
    		(*d->lss_ChangeBaudRate)(d->lss_transfer.baudRate);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   116
    	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   117
    	else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   118
    		MSG_WAR(0x3D07, "LSS switch delay second period expired",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   119
    		d->lss_transfer.switchDelayState=SDELAY_OFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   120
    		StopLSS_TIMER(LSS_SWITCH_DELAY_TIMER);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   121
    		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   122
    		setState(d, d->lss_transfer.currentState);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   123
    	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   124
     break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   125
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   126
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   127
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   128
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   129
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   130
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   131
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   132
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   133
void startLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   134
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   135
	/*MSG_WAR(0x3D09, "LSS services started",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   136
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   137
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   138
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   139
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   140
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   141
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   142
**/   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   143
void stopLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   144
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   145
	/*MSG_WAR(0x3D09, "LSS services stopped",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   146
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   147
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   148
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   149
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   150
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   151
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   152
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   153
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   154
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   155
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   156
UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   157
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   158
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   159
  UNS8 i;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   160
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   161
  if (!d->CurrentCommunicationState.csLSS){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   162
  	MSG_WAR(0x2D0A, "unable to send the LSS message (not in stop or pre-op mode", d->nodeState);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   163
  	return 0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   164
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   165
   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   166
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   167
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   168
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   169
  m.data[0]=command;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   170
  m.cob_id.w=SLSS_ADRESS;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   171
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   172
  /* Tha data sent with the msg depends on the command */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   173
  switch(command){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   174
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   175
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   176
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   177
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   178
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   179
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   180
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   181
  	m.data[2]=*(UNS8 *)dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   182
  	break; 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   183
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   184
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   185
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   186
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   187
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   188
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   189
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   190
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   191
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   192
  case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   193
  case LSS_IDENT_SLAVE: /* LSS Identify Slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   194
  case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   195
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   196
  default:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   197
  	MSG_ERR(0x1D0B, "send Slave LSS command not implemented", command);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   198
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   199
  break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   200
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   201
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   202
  return canSend(d->canHandle,&m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   203
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   204
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   205
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   206
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   207
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   208
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   209
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   210
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   211
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   212
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   213
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   214
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   215
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   216
  UNS8 i;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   217
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   218
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   219
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   220
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   221
  m.data[0]=command;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   222
  m.cob_id.w=MLSS_ADRESS;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   223
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   224
  /* Tha data sent with the msg depends on the command */	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   225
  switch(command){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   226
  case LSS_SM_GLOBAL: /* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   227
  	d->lss_transfer.state=LSS_FINISHED;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   228
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   229
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   230
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   231
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   232
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   233
  	m.data[2]=*(UNS8 *)dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   234
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   235
  case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   236
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   237
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   238
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   239
  case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   240
  case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   241
  case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   242
  case LSS_SM_SELECTIVE_SERIAL:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   243
  case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   244
  case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   245
  case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   246
  case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   247
  case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   248
  case LSS_IDENT_REMOTE_SERIAL_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   249
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   250
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   251
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   252
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   253
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   254
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   255
  case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   256
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   257
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   258
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   259
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   260
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   261
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   262
  case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   263
		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   264
		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   265
		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   266
		m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   267
		m.data[5]=d->lss_transfer.BitChecked;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   268
		m.data[6]=d->lss_transfer.LSSSub;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   269
		m.data[7]=d->lss_transfer.LSSNext;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   270
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   271
  default:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   272
   	MSG_ERR(0x1D0C, "send Master LSS command not implemented", command);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   273
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   274
  break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   275
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   276
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   277
  return canSend(d->canHandle,&m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   278
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   279
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   280
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   281
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   282
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   283
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   284
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   285
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   286
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   287
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   288
UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   289
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   290
  UNS8 res=1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   291
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   292
  /* Tha data sent with the msg depends on the command and if the sender is a master or a slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   293
  if (*(d->iam_a_slave)){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   294
  	res = sendSlaveLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   295
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   296
  else {/* It is a Master */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   297
  	res = sendMasterLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   298
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   299
  return res ;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   300
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   301
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   302
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   303
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   304
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   305
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   306
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   307
** @param m                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   308
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   309
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   310
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   311
UNS8 proceedLSS_Master(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   312
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   313
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   314
	UNS32 Dat1=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   315
	UNS8 Dat2=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   316
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   317
 	MSG_WAR(0x3D0D, "MasterLSS proceedLSS; command ", m->data[0]);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   318
	StopLSS_TIMER(LSS_MSG_TIMER);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   319
    /* Set state */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   320
    d->lss_transfer.state = LSS_FINISHED;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   321
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   322
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   323
   		case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   324
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   325
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   326
   		case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   327
   		case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   328
   		case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   329
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   330
   			Dat2=m->data[2];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   331
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   332
   		case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   333
   		case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   334
   		case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   335
   		case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   336
   			Dat1=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   337
 			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   338
 		case LSS_IDENT_SLAVE: /* LSS Identify Slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   339
   			/*if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   340
   			 * ************ TODO *******************
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   341
  			}*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   342
  		break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   343
 		case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   344
   		case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   345
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   346
   		default:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   347
   			MSG_ERR(0x1D0E, "Master LSS command not implemented", msg_cs);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   348
  			return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   349
   		break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   350
   	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   351
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   352
	d->lss_transfer.dat1=Dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   353
	d->lss_transfer.dat2=Dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   354
 	/* If there is a callback, it is responsible of the received response */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   355
	if(d->lss_transfer.Callback)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   356
    	(*d->lss_transfer.Callback)(d,msg_cs);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   357
    			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   358
   return 0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   359
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   360
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   361
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   362
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   363
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   364
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   365
** @param m                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   366
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   367
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   368
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   369
UNS8 proceedLSS_Slave(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   370
{  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   371
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   372
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   373
  	MSG_WAR(0x3D0F, "SlaveLSS proceedLSS; command ", m->data[0]);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   374
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   375
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   376
   	case LSS_SM_GLOBAL:		/* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   377
   		/* if there is not a mode change break*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   378
   		if(m->data[1] == d->lss_transfer.mode){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   379
   			MSG_WAR(0x3D10, "SlaveLSS already in the mode ", m->data[1]);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   380
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   381
   		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   382
   		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   383
		if(m->data[1]==LSS_CONFIGURATION_MODE)	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   384
			MSG_WAR(0x3D11, "SlaveLSS switching to configuration mode ", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   385
			/* Store the NodeId in case it will be changed */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   386
			d->lss_transfer.nodeID=getNodeId(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   387
			d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   388
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   389
		else if(m->data[1]==LSS_WAITING_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   390
			MSG_WAR(0x3D12, "SlaveLSS switching to operational mode ", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   391
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   392
			if(d->lss_transfer.switchDelayState==SDELAY_OFF){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   393
				/* If the nodeID has changed update it and put the node state to Initialisation. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   394
				if(d->lss_transfer.nodeID!=getNodeId(d)){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   395
					MSG_WAR(0x3D13, "The node Id has changed. Reseting to Initialisation state",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   396
					setNodeId(d, d->lss_transfer.nodeID);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   397
					setState(d, Initialisation);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   398
				}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   399
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   400
			d->lss_transfer.mode=LSS_WAITING_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   401
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   402
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   403
	case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   404
	{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   405
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   406
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   407
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   408
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   409
			if(m->data[1]>127 && m->data[1]!=0xFF){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   410
				MSG_ERR(0x1D14, "NodeID out of range",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   411
				error_code=1; /* NodeID out of range */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   412
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   413
			else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   414
				d->lss_transfer.nodeID=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   415
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   416
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   417
		else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   418
			MSG_ERR(0x1D15, "SlaveLSS not in configuration mode",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   419
			error_code=0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   420
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   421
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   422
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   423
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   424
	case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   425
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   426
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   427
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   428
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   429
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   430
			/* Change the baud rate only if the function lss_ChangeBaudRate 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   431
			 * has been implemented. If not send an error.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   432
			 */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   433
			if(d->lss_ChangeBaudRate){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   434
				/* If a baud rate is not supported just comment the line. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   435
				switch(m->data[2]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   436
				case 0x00:d->lss_transfer.baudRate="1M";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   437
				case 0x01:d->lss_transfer.baudRate="800K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   438
				case 0x02:d->lss_transfer.baudRate="500K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   439
				case 0x03:d->lss_transfer.baudRate="250K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   440
				case 0x04:d->lss_transfer.baudRate="125K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   441
				case 0x05:d->lss_transfer.baudRate="100K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   442
				case 0x06:d->lss_transfer.baudRate="50K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   443
				case 0x07:d->lss_transfer.baudRate="20K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   444
				case 0x08:d->lss_transfer.baudRate="10K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   445
				default:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   446
					MSG_ERR(0x1D16, "Baud rate not supported",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   447
					error_code=0xFF; /* Baud rate not supported*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   448
					break; 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   449
				}		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   450
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   451
			else
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   452
			{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   453
				MSG_ERR(0x1D17, "Bit timing not supported",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   454
				error_code=0x01; /* bit timing not supported */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   455
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   456
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   457
		else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   458
			MSG_ERR(0x1D18, "SlaveLSS not in configuration mode",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   459
			error_code=0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   460
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   461
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   462
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   463
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   464
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   465
	case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   466
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   467
		if(d->lss_transfer.mode!=LSS_CONFIGURATION_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   468
			MSG_ERR(0x1D19, "SlaveLSS not in configuration mode",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   469
			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   470
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   471
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   472
		if(d->lss_transfer.baudRate!="none"){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   473
			d->lss_transfer.switchDelay=getLSSDelay(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   474
			MSG_WAR(0x3D1A, "Slave Switch Delay set to: ",d->lss_transfer.switchDelay);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   475
			d->lss_transfer.switchDelayState=SDELAY_FIRST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   476
			d->lss_transfer.currentState=getState(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   477
			setState(d, LssTimingDelay);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   478
			StartLSS_SDELAY_TIMER();
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   479
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   480
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   481
	case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   482
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   483
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   484
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   485
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   486
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   487
			if(d->lss_StoreConfiguration){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   488
				 /* call lss_StoreConfiguration with NodeId */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   489
	  			(*d->lss_StoreConfiguration)(&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   490
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   491
			else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   492
				MSG_ERR(0x1D1B, "Store configuration not supported",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   493
				error_code=1; /* store configuration is not supported */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   494
			}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   495
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   496
		else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   497
			MSG_ERR(0x1D1C, "SlaveLSS not in configuration mode",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   498
			error_code=0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   499
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   500
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   501
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   502
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   503
	case LSS_SM_SELECTIVE_VENDOR:	/* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   504
	case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   505
	case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   506
	case LSS_SM_SELECTIVE_SERIAL:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   507
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   508
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   509
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   510
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   511
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   512
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   513
  		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   514
  		{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   515
  			MSG_ERR(0x1D1D, "Switch Mode Selective only supported in operational mode",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   516
  			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   517
  		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   518
  			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   519
		_SpecificNodeInfo=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   520
				
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   521
		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   522
		if(_SpecificNodeInfo==*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_SM_SELECTIVE_VENDOR-1)].pObject){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   523
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   524
			d->lss_transfer.addr_sel_match|=(0x01<<(msg_cs-LSS_SM_SELECTIVE_VENDOR));
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   525
			/* If all the fields has been set */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   526
			if(d->lss_transfer.addr_sel_match==0x0F){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   527
				
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   528
				MSG_WAR(0x3D1E, "SlaveLSS switching to configuration mode ", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   529
				d->lss_transfer.addr_sel_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   530
				d->lss_transfer.nodeID=getNodeId(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   531
				d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   532
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   533
				sendSlaveLSSMessage(d,LSS_SM_SELECTIVE_RESP,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   534
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   535
		}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   536
		else {
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   537
			MSG_WAR(0x3D1F, "LSS identity field doesn't match ", _SpecificNodeInfo);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   538
			d->lss_transfer.addr_sel_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   539
		}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   540
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   541
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   542
	case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   543
	case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   544
	case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   545
	case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   546
	case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   547
	case LSS_IDENT_REMOTE_SERIAL_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   548
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   549
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   550
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   551
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   552
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   553
  		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   554
		_SpecificNodeInfo=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   555
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   556
		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   557
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   558
		/* Check if the data match the identity object. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   559
		switch(msg_cs){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   560
		case LSS_IDENT_REMOTE_VENDOR:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo == *(UNS32*)ptrTable->pSubindex[1].pObject)? d->lss_transfer.addr_ident_match|0x01:0;	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   561
		case LSS_IDENT_REMOTE_PRODUCT:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo == *(UNS32*)ptrTable->pSubindex[2].pObject)? d->lss_transfer.addr_ident_match|0x02:0;	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   562
		case LSS_IDENT_REMOTE_REV_LOW:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo <= *(UNS32*)ptrTable->pSubindex[3].pObject)? d->lss_transfer.addr_ident_match|0x04:0; break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   563
		case LSS_IDENT_REMOTE_REV_HIGH:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo >= *(UNS32*)ptrTable->pSubindex[3].pObject)? d->lss_transfer.addr_ident_match|0x08:0;	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   564
		case LSS_IDENT_REMOTE_SERIAL_LOW:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo <= *(UNS32*)ptrTable->pSubindex[4].pObject)? d->lss_transfer.addr_ident_match|0x10:0;	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   565
		case LSS_IDENT_REMOTE_SERIAL_HIGH:d->lss_transfer.addr_ident_match=(_SpecificNodeInfo >= *(UNS32*)ptrTable->pSubindex[4].pObject)? d->lss_transfer.addr_ident_match|0x20:0;	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   566
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   567
		/* If all the fields has been set.. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   568
		if(d->lss_transfer.addr_ident_match==0x3F){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   569
			MSG_WAR(0x3D20, "SlaveLSS identified ", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   570
			d->lss_transfer.addr_ident_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   571
			sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   572
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   573
		else if(d->lss_transfer.addr_ident_match==0){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   574
			MSG_WAR(0x3D21, "LSS identify field doesn't match ", _SpecificNodeInfo);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   575
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   576
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   577
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   578
	case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   579
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   580
		if(getNodeId(d)==0xFF){		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   581
			MSG_WAR(0x3D22, "SlaveLSS non-configured ", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   582
			sendSlaveLSSMessage(d,LSS_IDENT_NON_CONF_SLAVE,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   583
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   584
		else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   585
			MSG_WAR(0x3D23, "SlaveLSS already configured ", 0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   586
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   587
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   588
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   589
	case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   590
	case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   591
	case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   592
	case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   593
	if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   594
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   595
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   596
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   597
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   598
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   599
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   600
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   601
  		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   602
  		_SpecificNodeInfo=*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_INQ_VENDOR_ID-1)].pObject;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   603
  		MSG_WAR(0x3D24, "SlaveLSS identity field inquired ", _SpecificNodeInfo);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   604
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   605
		sendSlaveLSSMessage(d,msg_cs,&_SpecificNodeInfo,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   606
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   607
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   608
	case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   609
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   610
		{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   611
			UNS8 NodeID;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   612
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   613
			NodeID=getNodeId(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   614
			MSG_WAR(0x3D25, "SlaveLSS Node ID inquired ", NodeID);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   615
			sendSlaveLSSMessage(d,msg_cs,&NodeID,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   616
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   617
		else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   618
			MSG_ERR(0x1D26, "SlaveLSS not in configuration mode",0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   619
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   620
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   621
	case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   622
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   623
		/******* TODO *******/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   624
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   625
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   626
   	default:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   627
   		MSG_ERR(0x1D27, "SlaveLSS command not implemented", msg_cs);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   628
  		return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   629
  		break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   630
   	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   631
   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   632
    return 0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   633
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   634
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   635
UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   636
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   637
	return sendMasterLSSMessage(d,command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   638
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   639
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   640
UNS8 configNetworkNodeCallBack (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   641
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   642
	d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   643
	d->lss_transfer.Callback=Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   644
	d->lss_transfer.command=command;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   645
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   646
	StopLSS_TIMER(LSS_MSG_TIMER);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   647
  	StartLSS_MSG_TIMER();
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   648
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   649
	return sendMasterLSSMessage(d,command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   650
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   651
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   652
UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   653
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   654
  *dat1=d->lss_transfer.dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   655
  *dat2=d->lss_transfer.dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   656
  return d->lss_transfer.state;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   657
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   658
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   659
//void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   660
//void _lss_ChangeBaudRate(char *BaudRate){printf("_lss_ChangeBaudRate\n");}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   661
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   662
#endif