src/lss.c
author etisserant
Fri, 01 Feb 2008 18:01:36 +0100
changeset 377 bea5a1576cbd
parent 370 6fecf36df407
child 381 854c43cdc24a
permissions -rw-r--r--
Enhanced cleanup of TCP CAN client/server
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"
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    44
#include "sysdep.h"
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    45
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    46
//#define LSS_TIMEOUT_MS	(TIMEVAL)1000  /* ms */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    47
//#define LSS_FS_TIMEOUT_MS	(TIMEVAL)100  /* ms */
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    48
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    49
/* Returns the LSS ident field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    50
#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
    51
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    52
/* Returns the LSS switch delay field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    53
#define getLSSDelay(msg) ((msg->data[2] << 8) | (msg->data[1]))
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    54
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    55
/* Returns the LSS FastScan BitCheck field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    56
#define getLSSBitCheck(msg) msg->data[5]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    57
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    58
/* Returns the LSS FastScan LSSSub field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    59
#define getLSSSub(msg) msg->data[6]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    60
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    61
/* Returns the LSS FastScan LSSNext field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    62
#define getLSSNext(msg) msg->data[7]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    63
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    64
/* Prototypes for internals functions */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    65
void LssAlarm(CO_Data* d, UNS32 id);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    66
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    67
#define StopLSS_TIMER(id){\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    68
 MSG_WAR(0x3D01, "StopLSS_TIMER for timer : ", id);\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    69
 d->lss_transfer.timers[id] = DelAlarm(d->lss_transfer.timers[id]);}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    70
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    71
#define StartLSS_MSG_TIMER(){\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    72
 MSG_WAR(0x3D02, "StartLSS_TIMER for MSG_TIMER",0);\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    73
 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
    74
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    75
#define StartLSS_SDELAY_TIMER(){\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    76
 MSG_WAR(0x3D03, "StartLSS_TIMER for SDELAY_TIMER",0);\
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    77
 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
    78
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    79
#define StartLSS_FS_TIMER(){\
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    80
 MSG_WAR(0x3D04, "StartLSS_TIMER for FS_TIMER",0);\
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    81
 d->lss_transfer.timers[LSS_FS_TIMER] = SetAlarm(d,LSS_FS_TIMER,&LssAlarm,MS_TO_TIMEVAL(LSS_FS_TIMEOUT_MS),0);}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    82
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    83
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    84
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    85
/*!                                                                                                
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
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    88
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    89
** @param id                                                                                       
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    90
**/   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    91
//struct timeval current_time,init_time;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    92
void LssAlarm(CO_Data* d, UNS32 id)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    93
{	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    94
	/*unsigned long time_period;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    95
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    96
	gettimeofday(&current_time,NULL);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    97
 	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
    98
 	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
    99
 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   100
	switch(id){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   101
	case LSS_MSG_TIMER:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   102
	 	StopLSS_TIMER(LSS_MSG_TIMER);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   103
#ifdef CO_ENABLE_LSS_FS
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   104
		if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   105
			if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   106
   				/* if at least one node had answered before the timer expired, start the FastScan protocol*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   107
   				if(d->lss_transfer.LSSanswer!=0){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   108
   					d->lss_transfer.LSSanswer=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   109
   					d->lss_transfer.BitChecked=31;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   110
   					d->lss_transfer.IDNumber=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   111
   					d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   112
   					StartLSS_FS_TIMER();
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   113
   					sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   114
   					return;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   115
   				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   116
   				else{ 
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   117
   				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   118
    				d->lss_transfer.state = LSS_FINISHED;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   119
    				/* Inform the application that there aren't not configured nodes in the net  */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   120
    				d->lss_transfer.dat1=1;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   121
   				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   122
   			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   123
   			else{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   124
				/* This should not happen, an error ocurred*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   125
				MSG_ERR(0x1D05, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   126
   			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   127
		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   128
		else
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   129
#endif
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   130
		{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   131
			MSG_ERR(0x1D06, "LSS timeout. LSS response not received.", 0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   132
    		MSG_WAR(0x2D07, "LSS timeout command specifier : ", d->lss_transfer.command);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   133
    		/* Set aborted state */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   134
    		d->lss_transfer.state = LSS_ABORTED_INTERNAL;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   135
    	}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   136
    	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   137
    	/* Call the user function to inform of the problem.*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   138
    	if(d->lss_transfer.Callback){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   139
	    	/*If there is a callback, it is responsible of the error*/
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   140
    		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   141
    	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   142
    break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   143
    case LSS_SWITCH_DELAY_TIMER:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   144
  		/* The first switch_delay period expired. Store the node state, change it 
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   145
 		 * 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
   146
   		if(d->lss_transfer.switchDelayState==SDELAY_FIRST){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   147
   			MSG_WAR(0x3D08, "LSS switch delay first period expired",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   148
    		d->lss_transfer.switchDelayState=SDELAY_SECOND;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   149
    		(*d->lss_ChangeBaudRate)(d->lss_transfer.baudRate);
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
    	else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   152
    		MSG_WAR(0x3D09, "LSS switch delay second period expired",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   153
    		d->lss_transfer.switchDelayState=SDELAY_OFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   154
    		StopLSS_TIMER(LSS_SWITCH_DELAY_TIMER);
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
    		setState(d, d->lss_transfer.currentState);
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
     break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   159
#ifdef CO_ENABLE_LSS_FS
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   160
     case LSS_FS_TIMER:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   161
	 	StopLSS_TIMER(LSS_FS_TIMER);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   162
		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   163
		switch(d->lss_transfer.FastScan_SM){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   164
   		case LSS_FS_RESET:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   165
   		{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   166
   		   	/* This should not happen, an error ocurred*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   167
			MSG_ERR(0x1D0A, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   168
   		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   169
   		break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   170
		case LSS_FS_PROCESSING:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   171
		{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   172
			/* If there isn't any answer, set the bit */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   173
			if(d->lss_transfer.LSSanswer==0){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   174
				UNS32 Mask=0x1;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   175
				Mask<<=d->lss_transfer.BitChecked;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   176
				d->lss_transfer.IDNumber|=Mask;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   177
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   178
			
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   179
			if(d->lss_transfer.BitChecked==0){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   180
				/* We finished with the current LSS-ID[sub], confirm it */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   181
				d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   182
				if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   183
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   184
			else{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   185
				d->lss_transfer.BitChecked--;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   186
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   187
   			
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   188
   			d->lss_transfer.LSSanswer=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   189
  			StartLSS_FS_TIMER();
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   190
   			sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   191
   			return;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   192
   		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   193
		break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   194
		case LSS_FS_CONFIRMATION:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   195
		{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   196
			if(d->lss_transfer.LSSanswer!=0){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   197
				d->lss_transfer.LSSanswer=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   198
				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   199
				if(d->lss_transfer.LSSSub==3){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   200
					/* The LSS FastScan protocol finished correctly. Restore the parameters */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   201
					d->lss_transfer.BitChecked=128;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   202
					d->lss_transfer.FastScan_SM=LSS_FS_RESET;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   203
					d->lss_transfer.LSSSub=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   204
					d->lss_transfer.LSSNext=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   205
   					d->lss_transfer.IDNumber=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   206
					
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   207
					/* Inform the application that the FastScan finished correctly */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   208
					d->lss_transfer.state = LSS_FINISHED;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   209
					d->lss_transfer.dat1=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   210
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   211
				else{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   212
					/* Start with the next LSS-ID[sub] */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   213
					d->lss_transfer.LSSSub++;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   214
					d->lss_transfer.BitChecked=31;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   215
   					d->lss_transfer.IDNumber=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   216
   					d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   217
   					StartLSS_FS_TIMER();
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   218
   					sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   219
   					return;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   220
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   221
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   222
			else{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   223
				/* This should not happen, an error ocurred*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   224
				MSG_ERR(0x1D0B, "LSS FastScan timeout. FastScan response not received.", 0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   225
				/* Set aborted state */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   226
    			d->lss_transfer.state = LSS_ABORTED_INTERNAL;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   227
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   228
		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   229
		break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   230
   		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   231
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   232
    	/* Call the user function to inform of the problem.*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   233
    	if(d->lss_transfer.Callback){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   234
	    	/*If there is a callback, it is responsible of the error*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   235
    		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   236
    	}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   237
    break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   238
#endif
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   239
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   240
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   241
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   242
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   243
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   244
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   245
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   246
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   247
void startLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   248
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   249
	/*MSG_WAR(0x3D09, "LSS services started",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   250
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   251
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   252
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   253
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   254
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   255
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   256
**/   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   257
void stopLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   258
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   259
	/*MSG_WAR(0x3D09, "LSS services stopped",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   260
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   261
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   262
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   263
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   264
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   265
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   266
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   267
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   268
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   269
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   270
UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   271
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   272
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   273
  UNS8 i;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   274
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   275
  if (!d->CurrentCommunicationState.csLSS){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   276
  	MSG_WAR(0x2D0C, "unable to send the LSS message, not in the proper state =>", d->nodeState);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   277
  	return 0xFF;
343
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
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   281
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   282
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   283
  m.data[0]=command;
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
   284
  m.cob_id=UNS16_LE(SLSS_ADRESS);
343
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
  /* Tha data sent with the msg depends on the command */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   287
  switch(command){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   288
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   289
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   290
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   291
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   292
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   293
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   294
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   295
  	m.data[2]=*(UNS8 *)dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   296
  	break; 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   297
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   298
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   299
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   300
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   301
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   302
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   303
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   304
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   305
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   306
  case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   307
  case LSS_IDENT_SLAVE: /* LSS Identify Slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   308
  case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   309
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   310
  default:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   311
  	MSG_ERR(0x1D0D, "send Slave LSS command not implemented", command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   312
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   313
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   314
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   315
  return canSend(d->canHandle,&m);
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
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   318
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   319
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   320
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   321
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   322
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   323
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   324
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   325
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   326
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   327
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   328
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   329
  UNS8 i;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   330
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   331
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   332
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   333
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   334
  m.data[0]=command;
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
   335
  m.cob_id=UNS16_LE(MLSS_ADRESS);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   336
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   337
  /* Tha data sent with the msg depends on the command */	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   338
  switch(command){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   339
  case LSS_SM_GLOBAL: /* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   340
  	d->lss_transfer.state=LSS_FINISHED;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   341
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   342
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   343
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   344
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   345
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   346
  	m.data[2]=*(UNS8 *)dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   347
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   348
  case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   349
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   350
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   351
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   352
  case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   353
  case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   354
  case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   355
  case LSS_SM_SELECTIVE_SERIAL:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   356
  case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   357
  case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   358
  case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   359
  case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   360
  case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   361
  case LSS_IDENT_REMOTE_SERIAL_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   362
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   363
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   364
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   365
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   366
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   367
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   368
  case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   369
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   370
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   371
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   372
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   373
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   374
  	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   375
#ifdef CO_ENABLE_LSS_FS
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   376
  case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   377
		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   378
		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   379
		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   380
		m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   381
		m.data[5]=d->lss_transfer.BitChecked;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   382
		m.data[6]=d->lss_transfer.LSSSub;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   383
		m.data[7]=d->lss_transfer.LSSNext;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   384
	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   385
#endif
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   386
  default:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   387
   	MSG_ERR(0x1D0E, "send Master LSS command not implemented", command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   388
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   389
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   390
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   391
  return canSend(d->canHandle,&m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   392
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   393
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   394
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   395
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   396
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   397
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   398
** @param cob_id                                                                                   
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
** @return                                                                                         
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
UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   403
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   404
  UNS8 res=1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   405
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   406
  /* 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
   407
  if (*(d->iam_a_slave)){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   408
  	res = sendSlaveLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   409
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   410
  else {/* It is a Master */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   411
  	res = sendMasterLSSMessage(d, command,dat1,dat2);
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
  return res ;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   414
}
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
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   418
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   419
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   420
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   421
** @param m                                                                                        
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
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   424
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   425
UNS8 proceedLSS_Master(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   426
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   427
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   428
	UNS32 Dat1=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   429
	UNS8 Dat2=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   430
	
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   431
	if(d->lss_transfer.state!=LSS_TRANS_IN_PROGRESS)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   432
	{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   433
		//MSG_WAR(0x3D0D, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   434
		//return 0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   435
		goto ErrorProcessMaster;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   436
	}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   437
	
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   438
	//#ifdef CO_ENABLE_LSS_FS
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   439
	/* The FastScan protocol doesn't stops the timers when a message has been received */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   440
	/*if(d->lss_transfer.command!=LSS_IDENT_FASTSCAN)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   441
#endif
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   442
	{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   443
		StopLSS_TIMER(LSS_MSG_TIMER);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   444
    	d->lss_transfer.state = LSS_FINISHED;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   445
	}*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   446
	
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   447
 	MSG_WAR(0x3D0F, "MasterLSS proceedLSS; command ", m->data[0]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   448
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   449
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   450
   		case LSS_INQ_NODE_ID: /* Inquire Node-ID */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   451
   			if(d->lss_transfer.command!=LSS_INQ_NODE_ID)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   452
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   453
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   454
   		case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   455
   		case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   456
   		case LSS_CONF_STORE: /* Store Configured Parameters */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   457
   			if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   458
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   459
   			Dat2=m->data[2];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   460
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   461
   		case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   462
   		case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   463
   		case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   464
   		case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   465
   			if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   466
   			Dat1=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   467
 			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   468
 		case LSS_IDENT_SLAVE: /* LSS Identify Slave */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   469
#ifdef CO_ENABLE_LSS_FS
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   470
   			if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   471
   				/* A message arrived during the timer period */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   472
   				d->lss_transfer.LSSanswer=1;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   473
   				return 0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   474
  			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   475
  			else
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   476
#endif
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   477
			if(d->lss_transfer.command!=LSS_IDENT_REMOTE_VENDOR && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   478
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_PRODUCT && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   479
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_LOW && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   480
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_HIGH && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   481
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_LOW && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   482
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_HIGH )
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   483
 					goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   484
  		break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   485
 		case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   486
 			if(d->lss_transfer.command!=LSS_SM_SELECTIVE_VENDOR && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   487
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_PRODUCT && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   488
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_REVISION && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   489
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_SERIAL )
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   490
 					goto ErrorProcessMaster;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   491
 			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   492
   		case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   493
   			if(d->lss_transfer.command!=LSS_IDENT_REMOTE_NON_CONF)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   494
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   495
   		default:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   496
   			MSG_ERR(0x1D10, "Master LSS command not implemented", msg_cs);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   497
  			return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   498
   	}
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   499
	
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   500
	StopLSS_TIMER(LSS_MSG_TIMER);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   501
    d->lss_transfer.state = LSS_FINISHED;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   502
    	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   503
	d->lss_transfer.dat1=Dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   504
	d->lss_transfer.dat2=Dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   505
 	/* If there is a callback, it is responsible of the received response */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   506
	if(d->lss_transfer.Callback)
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   507
    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   508
    			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   509
   return 0;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   510
   
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   511
ErrorProcessMaster:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   512
    MSG_WAR(0x3D11, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   513
	return 0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   514
		
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   515
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   516
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
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   520
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   521
** @param m                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   522
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   523
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   524
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   525
UNS8 proceedLSS_Slave(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   526
{  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   527
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   528
	
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   529
  	MSG_WAR(0x3D12, "SlaveLSS proceedLSS; command ", m->data[0]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   530
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   531
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   532
   	case LSS_SM_GLOBAL:		/* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   533
   		/* if there is not a mode change break*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   534
   		if(m->data[1] == d->lss_transfer.mode){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   535
   			MSG_WAR(0x3D13, "SlaveLSS already in the mode ", m->data[1]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   536
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   537
   		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   538
   		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   539
		if(m->data[1]==LSS_CONFIGURATION_MODE)	{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   540
			MSG_WAR(0x3D14, "SlaveLSS switching to configuration mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   541
			/* Store the NodeId in case it will be changed */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   542
			d->lss_transfer.nodeID=getNodeId(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   543
			d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   544
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   545
		else if(m->data[1]==LSS_WAITING_MODE){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   546
			MSG_WAR(0x3D15, "SlaveLSS switching to operational mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   547
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   548
			if(d->lss_transfer.switchDelayState==SDELAY_OFF){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   549
				/* 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
   550
				if(d->lss_transfer.nodeID!=getNodeId(d)){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   551
					MSG_WAR(0x3D16, "The node Id has changed. Reseting to Initialisation state",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   552
					setNodeId(d, d->lss_transfer.nodeID);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   553
					setState(d, Initialisation);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   554
				}
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
			d->lss_transfer.mode=LSS_WAITING_MODE;
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
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   559
	case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   560
	{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   561
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   562
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   563
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   564
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   565
			if(m->data[1]>127 && m->data[1]!=0xFF){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   566
				MSG_ERR(0x1D17, "NodeID out of range",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   567
				error_code=1; /* NodeID out of range */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   568
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   569
			else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   570
				d->lss_transfer.nodeID=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   571
			}
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{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   574
			MSG_WAR(0x3D18, "SlaveLSS not in configuration mode",0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   575
			//error_code=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   576
			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   577
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   578
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
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
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   581
	case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   582
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   583
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   584
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   585
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   586
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   587
			/* Change the baud rate only if the function lss_ChangeBaudRate 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   588
			 * has been implemented. If not send an error.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   589
			 */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   590
			if(d->lss_ChangeBaudRate){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   591
				/* If a baud rate is not supported just comment the line. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   592
				switch(m->data[2]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   593
				case 0x00:d->lss_transfer.baudRate="1M";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   594
				case 0x01:d->lss_transfer.baudRate="800K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   595
				case 0x02:d->lss_transfer.baudRate="500K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   596
				case 0x03:d->lss_transfer.baudRate="250K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   597
				case 0x04:d->lss_transfer.baudRate="125K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   598
				case 0x05:d->lss_transfer.baudRate="100K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   599
				case 0x06:d->lss_transfer.baudRate="50K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   600
				case 0x07:d->lss_transfer.baudRate="20K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   601
				case 0x08:d->lss_transfer.baudRate="10K";break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   602
				default:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   603
					MSG_ERR(0x1D19, "Baud rate not supported",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   604
					error_code=0xFF; /* Baud rate not supported*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   605
					break; 
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
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   608
			else
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   609
			{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   610
				MSG_ERR(0x1D1A, "Bit timing not supported",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   611
				error_code=0x01; /* bit timing not supported */
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
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   614
		else{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   615
			MSG_WAR(0x3D1B, "SlaveLSS not in configuration mode",0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   616
			//error_code=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   617
			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   618
		}
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
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   621
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   622
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   623
	case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
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
		if(d->lss_transfer.mode!=LSS_CONFIGURATION_MODE){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   626
			MSG_ERR(0x3D1C, "SlaveLSS not in configuration mode",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   627
			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   628
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   629
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   630
		if(d->lss_transfer.baudRate!="none"){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   631
			d->lss_transfer.switchDelay=getLSSDelay(m);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   632
			MSG_WAR(0x3D1D, "Slave Switch Delay set to: ",d->lss_transfer.switchDelay);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   633
			d->lss_transfer.switchDelayState=SDELAY_FIRST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   634
			d->lss_transfer.currentState=getState(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   635
			setState(d, LssTimingDelay);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   636
			StartLSS_SDELAY_TIMER();
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   637
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   638
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   639
	case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   640
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   641
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   642
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   643
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   644
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   645
			if(d->lss_StoreConfiguration){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   646
				 /* call lss_StoreConfiguration with NodeId */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   647
	  			(*d->lss_StoreConfiguration)(&error_code,&spec_error);
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
			else{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   650
				MSG_ERR(0x1D1E, "Store configuration not supported",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   651
				error_code=1; /* store configuration is not supported */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   652
			}	
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
		else{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   655
			MSG_WAR(0x3D1F, "SlaveLSS not in configuration mode",0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   656
			//error_code=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   657
			break;
343
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
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   660
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   661
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   662
	case LSS_SM_SELECTIVE_VENDOR:	/* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   663
	case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   664
	case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   665
	case LSS_SM_SELECTIVE_SERIAL:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   666
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   667
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   668
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   669
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   670
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   671
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   672
  		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   673
  		{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   674
  			MSG_ERR(0x1D20, "Switch Mode Selective only supported in operational mode",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   675
  			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   676
  		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   677
  			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   678
		_SpecificNodeInfo=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   679
				
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   680
		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   681
		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
   682
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   683
			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
   684
			/* If all the fields has been set */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   685
			if(d->lss_transfer.addr_sel_match==0x0F){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   686
				
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   687
				MSG_WAR(0x3D21, "SlaveLSS switching to configuration mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   688
				d->lss_transfer.addr_sel_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   689
				d->lss_transfer.nodeID=getNodeId(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   690
				d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   691
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   692
				sendSlaveLSSMessage(d,LSS_SM_SELECTIVE_RESP,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   693
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   694
		}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   695
		else {
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   696
			MSG_WAR(0x3D22, "LSS identity field doesn't match ", _SpecificNodeInfo);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   697
			d->lss_transfer.addr_sel_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   698
		}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   699
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   700
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   701
	case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   702
	case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   703
	case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   704
	case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   705
	case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   706
	case LSS_IDENT_REMOTE_SERIAL_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   707
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   708
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   709
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   710
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   711
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   712
  		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   713
		_SpecificNodeInfo=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   714
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   715
		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   716
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   717
		/* Check if the data match the identity object. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   718
		switch(msg_cs){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   719
		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
   720
		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
   721
		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
   722
		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
   723
		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
   724
		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
   725
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   726
		/* If all the fields has been set.. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   727
		if(d->lss_transfer.addr_ident_match==0x3F){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   728
			MSG_WAR(0x3D23, "SlaveLSS identified ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   729
			d->lss_transfer.addr_ident_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   730
			sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   731
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   732
		else if(d->lss_transfer.addr_ident_match==0){
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   733
			MSG_WAR(0x3D24, "LSS identify field doesn't match ", _SpecificNodeInfo);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   734
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   735
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   736
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   737
	case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   738
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   739
		if(getNodeId(d)==0xFF){		
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   740
			MSG_WAR(0x3D25, "SlaveLSS non-configured ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   741
			sendSlaveLSSMessage(d,LSS_IDENT_NON_CONF_SLAVE,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   742
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   743
		else{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   744
			MSG_WAR(0x3D26, "SlaveLSS already configured ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   745
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   746
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   747
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   748
	case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   749
	case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   750
	case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   751
	case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   752
	if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   753
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   754
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   755
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   756
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   757
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   758
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   759
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   760
  		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   761
  		_SpecificNodeInfo=*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_INQ_VENDOR_ID-1)].pObject;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   762
  		MSG_WAR(0x3D27, "SlaveLSS identity field inquired ", _SpecificNodeInfo);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   763
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   764
		sendSlaveLSSMessage(d,msg_cs,&_SpecificNodeInfo,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   765
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   766
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   767
	case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   768
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   769
		{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   770
			UNS8 NodeID;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   771
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   772
			NodeID=getNodeId(d);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   773
			MSG_WAR(0x3D28, "SlaveLSS Node ID inquired ", NodeID);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   774
			sendSlaveLSSMessage(d,msg_cs,&NodeID,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   775
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   776
		else{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   777
			MSG_WAR(0x3D29, "SlaveLSS not in configuration mode",0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   778
		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   779
	break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   780
#ifdef CO_ENABLE_LSS_FS
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   781
	case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   782
	{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   783
		/* If the nodeID isn't 0xFF the slave shall not participate  */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   784
		if(getNodeId(d)!=0xFF)break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   785
		if(getLSSBitCheck(m)==128)d->lss_transfer.FastScan_SM=LSS_FS_RESET;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   786
		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   787
   		switch(d->lss_transfer.FastScan_SM){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   788
   		case LSS_FS_RESET:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   789
   		{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   790
   			UNS32 errorCode;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   791
  			const indextable *ptrTable;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   792
  			ODCallback_t *Callback;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   793
  				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   794
			MSG_WAR(0x3D2A, "SlaveLSS Reseting LSSPos", 0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   795
			d->lss_transfer.LSSPos=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   796
			d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   797
			
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   798
  			ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   799
  			d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   800
			
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   801
			sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   802
   		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   803
		break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   804
		case LSS_FS_PROCESSING:/*if(getLSSBitCheck(m)<32)*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   805
			if(d->lss_transfer.LSSPos==getLSSSub(m))
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   806
			{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   807
				UNS32 Mask=0xFFFFFFFF<<getLSSBitCheck(m);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   808
				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   809
				MSG_WAR(0x3D2B, "SlaveLSS FastScan IDNumber", getLSSIdent(m));
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   810
				MSG_WAR(0x3D2C, "SlaveLSS FastScan BitMask ", Mask);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   811
				MSG_WAR(0x3D2D, "SlaveLSS FastScan LSS-ID  ", d->lss_transfer.IDNumber);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   812
				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   813
				if((getLSSIdent(m) & Mask)==(d->lss_transfer.IDNumber & Mask))
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   814
				{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   815
					sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   816
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   817
				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   818
				if(getLSSBitCheck(m)==0)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   819
				{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   820
					d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   821
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   822
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   823
			break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   824
		case LSS_FS_CONFIRMATION:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   825
			if(d->lss_transfer.LSSPos==getLSSSub(m))
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   826
			{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   827
				if(getLSSIdent(m)==d->lss_transfer.IDNumber)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   828
				{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   829
					/* Current LSS-ID[sub] confirmed correctly */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   830
					MSG_WAR(0x3D2E, "SlaveLSS FastScan IDNumber and LSS-ID match=>", d->lss_transfer.IDNumber);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   831
					if(d->lss_transfer.LSSPos==3)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   832
					{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   833
						/* All LSS-ID[sub] identified correctly, switching to configuration mode */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   834
						MSG_WAR(0x3D2F, "SlaveLSS switching to configuration mode ", 0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   835
			   			d->lss_transfer.nodeID=getNodeId(d);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   836
			   			d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   837
			    		d->lss_transfer.FastScan_SM=LSS_FS_RESET;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   838
			    		d->lss_transfer.LSSPos=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   839
					}		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   840
					else
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   841
					{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   842
						/* Switch to the next LSS-ID[sub] */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   843
						UNS32 errorCode;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   844
  						const indextable *ptrTable;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   845
  						ODCallback_t *Callback;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   846
		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   847
						d->lss_transfer.LSSPos=getLSSNext(m);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   848
						ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   849
  						d->lss_transfer.IDNumber=*(UNS32*)ptrTable->pSubindex[d->lss_transfer.LSSPos+1].pObject;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   850
						d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;						
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   851
					}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   852
					sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   853
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   854
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   855
			break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   856
		}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   857
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   858
	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   859
#endif
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   860
   	default:
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   861
   		MSG_ERR(0x1D30, "SlaveLSS command not implemented", msg_cs);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   862
  		return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   863
   	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   864
   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   865
    return 0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   866
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   867
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   868
UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   869
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   870
	return sendMasterLSSMessage(d,command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   871
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   872
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   873
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
   874
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   875
	d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   876
	d->lss_transfer.Callback=Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   877
	d->lss_transfer.command=command;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   878
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   879
	StopLSS_TIMER(LSS_MSG_TIMER);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   880
  	StartLSS_MSG_TIMER();
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   881
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   882
	return sendMasterLSSMessage(d,command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   883
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   884
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   885
UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   886
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   887
  *dat1=d->lss_transfer.dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   888
  *dat2=d->lss_transfer.dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   889
  return d->lss_transfer.state;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   890
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   891
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   892
//void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   893
//void _lss_ChangeBaudRate(char *BaudRate){printf("_lss_ChangeBaudRate\n");}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   894
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   895
#endif