src/lss.c
author etisserant
Fri, 25 Jul 2008 10:57:20 +0200
changeset 504 ad574af3628d
parent 482 ec49f7132e36
child 517 003679edc437
permissions -rw-r--r--
Added removal of dynamically loaded CAN driver interface library in clean make target
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
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    40
#include "data.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    41
#include "lss.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    42
#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
    43
#include "sysdep.h"
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    44
482
ec49f7132e36 LSS patch from Edward. Now, SetNodeId is not called from nmtslave anymore in case of LSS.
etisserant
parents: 436
diff changeset
    45
#ifdef CO_ENABLE_LSS
ec49f7132e36 LSS patch from Edward. Now, SetNodeId is not called from nmtslave anymore in case of LSS.
etisserant
parents: 436
diff changeset
    46
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    47
//#define LSS_TIMEOUT_MS	(TIMEVAL)1000  /* ms */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    48
//#define LSS_FS_TIMEOUT_MS	(TIMEVAL)100  /* ms */
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    49
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    50
/* Returns the LSS ident field from a Message struct */
436
77796b3e3428 Fixed suspicious code in lss.c
etisserant
parents: 399
diff changeset
    51
#define getLSSIdent(msg) (((UNS32)msg->data[4] << 24) | ((UNS32)msg->data[3] << 16) | (msg->data[2] << 8) | (msg->data[1]))
77796b3e3428 Fixed suspicious code in lss.c
etisserant
parents: 399
diff changeset
    52
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    53
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    54
/* Returns the LSS switch delay field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    55
#define getLSSDelay(msg) ((msg->data[2] << 8) | (msg->data[1]))
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    56
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    57
/* Returns the LSS FastScan BitCheck field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    58
#define getLSSBitCheck(msg) msg->data[5]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    59
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    60
/* Returns the LSS FastScan LSSSub field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    61
#define getLSSSub(msg) msg->data[6]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    62
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    63
/* Returns the LSS FastScan LSSNext field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    64
#define getLSSNext(msg) msg->data[7]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    65
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    66
/* Prototypes for internals functions */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    67
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    68
void LssAlarmMSG(CO_Data* d, UNS32 id);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    69
void LssAlarmSDELAY(CO_Data* d, UNS32 id);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    70
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    71
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    72
#define StopLSS_MSG_TIMER(){\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    73
 MSG_WAR(0x3D01, "StopLSS_MSG_TIMER", 0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    74
 d->lss_transfer.timerMSG = DelAlarm(d->lss_transfer.timerMSG);}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    75
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    76
#define StartLSS_MSG_TIMER(){\
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    77
 MSG_WAR(0x3D02, "StartLSS_MSG_TIMER",0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    78
 d->lss_transfer.timerMSG = SetAlarm(d,0,&LssAlarmMSG,MS_TO_TIMEVAL(LSS_TIMEOUT_MS),0);}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    79
 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    80
#define StopLSS_SDELAY_TIMER(){\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    81
 MSG_WAR(0x3D03, "StopLSS_SDELAY_TIMER", 0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    82
 d->lss_transfer.timerSDELAY = DelAlarm(d->lss_transfer.timerSDELAY);}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    83
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    84
#define StartLSS_SDELAY_TIMER(){\
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    85
 MSG_WAR(0x3D04, "StartLSS_SDELAY_TIMER",0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    86
 d->lss_transfer.timerSDELAY= SetAlarm(d,0,&LssAlarmSDELAY,MS_TO_TIMEVAL(d->lss_transfer.switchDelay),MS_TO_TIMEVAL(d->lss_transfer.switchDelay));}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    87
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    88
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    89
#ifdef CO_ENABLE_LSS_FS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    90
/* Prototypes for internals functions */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    91
void LssAlarmFS(CO_Data* d, UNS32 id);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    92
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    93
#define StopLSS_FS_TIMER(){\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    94
 MSG_WAR(0x3D05, "StopLSS_FS_TIMER", id);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    95
 d->lss_transfer.timerFS = DelAlarm(d->lss_transfer.timerFS);}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    96
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    97
#define StartLSS_FS_TIMER(){\
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    98
 MSG_WAR(0x3D06, "StartLSS_FS_TIMER",0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    99
 d->lss_transfer.timerFS = SetAlarm(d,0,&LssAlarmFS,MS_TO_TIMEVAL(LSS_FS_TIMEOUT_MS),0);}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   100
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   101
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   102
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   103
void LssAlarmMSG(CO_Data* d, UNS32 id)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   104
{	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   105
 	StopLSS_MSG_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   106
#ifdef CO_ENABLE_LSS_FS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   107
	if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   108
		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   109
   			/* if at least one node had answered before the timer expired, start the FastScan protocol*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   110
   			if(d->lss_transfer.LSSanswer!=0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   111
   				d->lss_transfer.LSSanswer=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   112
   				d->lss_transfer.BitChecked=31;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   113
   				d->lss_transfer.IDNumber=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   114
   				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   115
   				StartLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   116
   				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   117
   				return;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   118
   			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   119
   			else{ 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   120
   			
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   121
    			d->lss_transfer.state = LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   122
    			/* Inform the application that there aren't not configured nodes in the net  */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   123
    			d->lss_transfer.dat1=1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   124
   			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   125
   		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   126
   		else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   127
			/* This should not happen, an error ocurred*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   128
			MSG_ERR(0x1D07, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   129
   		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   130
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   131
	else
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   132
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   133
	if(d->lss_transfer.command==LSS_IDENT_REMOTE_NON_CONF){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   134
			MSG_WAR(0x2D08, "LSS timeout. There are not no-configured slaves in the net", 0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   135
			d->lss_transfer.state = LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   136
			d->lss_transfer.dat1=1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   137
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   138
	else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   139
		MSG_ERR(0x1D09, "LSS timeout. LSS response not received.", 0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   140
    	MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   141
    	/* Set aborted state */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   142
    	d->lss_transfer.state = LSS_ABORTED_INTERNAL;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   143
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   144
    	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   145
    /* Call the user function to inform of the problem.*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   146
    if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   147
	   	/*If there is a callback, it is responsible of the error*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   148
    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   149
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   150
}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   151
    
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   152
    
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   153
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   154
**                                                                                                 
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   157
** @param id                                                                                       
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   158
**/   
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   159
void LssAlarmSDELAY(CO_Data* d, UNS32 id)
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   160
{	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   161
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   162
	/* The first switch_delay period expired. Store the node state, change it 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   163
 	 * so no CAN messages will be sent or received, call the ChangeBaudRate function*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   164
   	if(d->lss_transfer.switchDelayState==SDELAY_FIRST){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   165
   		MSG_WAR(0x3D0B, "LSS switch delay first period expired",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   166
    	d->lss_transfer.switchDelayState=SDELAY_SECOND;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   167
    	//(*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate);
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   168
    	canChangeBaudRate(d->lss_transfer.canHandle_t, d->lss_transfer.baudRate);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   169
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   170
    else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   171
    	MSG_WAR(0x3D0C, "LSS switch delay second period expired",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   172
    	d->lss_transfer.switchDelayState=SDELAY_OFF;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   173
    	StopLSS_SDELAY_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   174
    		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   175
    	if (*(d->iam_a_slave))
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   176
    		d->canHandle=d->lss_transfer.canHandle_t;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   177
    	else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   178
    		d->lss_transfer.dat1=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   179
    		d->lss_transfer.state=LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   180
    		/* Call the user function */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   181
    		if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   182
	    		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   183
    		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   184
    	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   185
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   186
} 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   187
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   188
#ifdef CO_ENABLE_LSS_FS
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   189
/*!                                                                                                
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   190
**                                                                                                 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   191
**                                                                                                 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   192
** @param d                                                                                        
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   193
** @param id                                                                                       
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   194
**/   
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   195
void LssAlarmFS(CO_Data* d, UNS32 id)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   196
{	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   197
	StopLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   198
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   199
	switch(d->lss_transfer.FastScan_SM){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   200
   	case LSS_FS_RESET:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   201
   	{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   202
   	   	/* This should not happen, an error ocurred*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   203
		MSG_ERR(0x1D0D, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   204
   	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   205
   	break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   206
	case LSS_FS_PROCESSING:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   207
	{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   208
		/* If there isn't any answer, set the bit */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   209
		if(d->lss_transfer.LSSanswer==0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   210
			UNS32 Mask=0x1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   211
			Mask<<=d->lss_transfer.BitChecked;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   212
			d->lss_transfer.IDNumber|=Mask;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   213
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   214
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   215
		if(d->lss_transfer.BitChecked==0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   216
			/* We finished with the current LSS-ID[sub], confirm it */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   217
			d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   218
			if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   219
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   220
		else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   221
			d->lss_transfer.BitChecked--;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   222
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   223
   			
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   224
   		d->lss_transfer.LSSanswer=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   225
  		StartLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   226
   		sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   227
   		return;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   228
   	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   229
	break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   230
	case LSS_FS_CONFIRMATION:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   231
	{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   232
		if(d->lss_transfer.LSSanswer!=0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   233
			d->lss_transfer.LSSanswer=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   234
			
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   235
			if(d->lss_transfer.LSSSub==3){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   236
				/* The LSS FastScan protocol finished correctly. Restore the parameters */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   237
				d->lss_transfer.BitChecked=128;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   238
				d->lss_transfer.FastScan_SM=LSS_FS_RESET;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   239
				d->lss_transfer.LSSSub=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   240
				d->lss_transfer.LSSNext=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   241
   				d->lss_transfer.IDNumber=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   242
				
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   243
				/* Inform the application that the FastScan finished correctly */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   244
				d->lss_transfer.state = LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   245
				d->lss_transfer.dat1=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   246
			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   247
			else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   248
				/* Start with the next LSS-ID[sub] */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   249
				d->lss_transfer.LSSSub++;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   250
				d->lss_transfer.BitChecked=31;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   251
   				d->lss_transfer.IDNumber=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   252
   				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   253
   				StartLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   254
   				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   255
   				return;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   256
			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   257
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   258
		else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   259
			/* This should not happen, an error ocurred*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   260
			MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   261
			/* Set aborted state */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   262
    		d->lss_transfer.state = LSS_ABORTED_INTERNAL;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   263
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   264
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   265
	break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   266
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   267
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   268
   	/* Call the user function to inform of the problem.*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   269
   	if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   270
    	/*If there is a callback, it is responsible of the error*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   271
   		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   272
   	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   273
}
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   274
#endif
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   275
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   276
	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   277
/*!                                                                                                
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   281
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   282
void startLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   283
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   284
	/*MSG_WAR(0x3D09, "LSS services started",0);*/
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
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   287
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   288
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   289
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   290
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   291
**/   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   292
void stopLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   293
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   294
	/*MSG_WAR(0x3D09, "LSS services stopped",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   295
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   296
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   297
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   298
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   299
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   300
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   301
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   302
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   303
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   304
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   305
UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   306
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   307
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   308
  UNS8 i;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   309
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   310
  if (!d->CurrentCommunicationState.csLSS){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   311
  	MSG_WAR(0x2D17, "unable to send the LSS message, not in the proper state =>", d->nodeState);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   312
  	return 0xFF;
343
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
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   316
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   317
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   318
  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
   319
  m.cob_id=UNS16_LE(SLSS_ADRESS);
343
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
  /* Tha data sent with the msg depends on the command */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   322
  switch(command){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   323
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   324
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   325
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   326
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   327
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   328
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   329
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   330
  	m.data[2]=*(UNS8 *)dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   331
  	break; 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   332
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   333
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   334
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   335
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   336
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   337
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   338
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   339
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   340
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   341
  case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   342
  case LSS_IDENT_SLAVE: /* LSS Identify Slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   343
  case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   344
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   345
  default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   346
  	MSG_ERR(0x1D18, "send Slave LSS command not implemented", command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   347
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   348
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   349
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   350
  return canSend(d->canHandle,&m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   351
}
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   352
			
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   353
/* If a baud rate is not supported just comment the line. */
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   354
static UNS8 CO_TranslateBaudRate(char* optarg){
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   355
	if(!strcmp( optarg, "1M")) return 0x00;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   356
	if(!strcmp( optarg, "800K")) return 0x01;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   357
	if(!strcmp( optarg, "500K")) return 0x02;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   358
	if(!strcmp( optarg, "250K")) return 0x03;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   359
	if(!strcmp( optarg, "125K")) return 0x04;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   360
	if(!strcmp( optarg, "100K")) return 0x05;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   361
	if(!strcmp( optarg, "50K")) return 0x06;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   362
	if(!strcmp( optarg, "20K")) return 0x07;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   363
	if(!strcmp( optarg, "10K")) return 0x08;
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   364
	return 0xFF;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   365
}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   366
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   367
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   368
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   369
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   370
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   371
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   372
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   373
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   374
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   375
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   376
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   377
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   378
  UNS8 i;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   379
  UNS8 res;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   380
  UNS8 hasResponse=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   381
   
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   382
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   383
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   384
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   385
  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
   386
  m.cob_id=UNS16_LE(MLSS_ADRESS);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   387
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   388
  /* Tha data sent with the msg depends on the command */	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   389
  switch(command){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   390
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   391
  	hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   392
  case LSS_SM_GLOBAL: /* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   393
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   394
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   395
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   396
  	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   397
  	m.data[1]=*(UNS8 *)dat1;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   398
  	d->lss_transfer.baudRate=*(char **)dat2;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   399
  	
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   400
  	if((m.data[2]=CO_TranslateBaudRate(d->lss_transfer.baudRate))!=0xFF){
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   401
  		hasResponse=1;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   402
		break;	 
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   403
  	}
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   404
  		
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   405
	MSG_ERR(0x1D19, "Master-> Baud rate not supported",0);
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   406
	d->lss_transfer.dat1=0xFF;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   407
	
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   408
	/* if bit timing is not supported comment the previous code and uncomment the following one*/
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   409
	/*{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   410
		MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   411
		d->lss_transfer.dat1=0x01;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   412
	}*/
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   413
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   414
	d->lss_transfer.dat2=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   415
 	/* If there is a callback, it is responsible of the error */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   416
	if(d->lss_transfer.Callback)
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   417
	   	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   418
	return 0xFF;
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   419
  	//break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   420
  case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   421
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   422
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   423
	if(d->lss_transfer.baudRate!="none"){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   424
		d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   425
		d->lss_transfer.switchDelayState=SDELAY_FIRST;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   426
		d->lss_transfer.canHandle_t=d->canHandle;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   427
		res=canSend(d->canHandle,&m);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   428
  		if(res==0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   429
  			StartLSS_SDELAY_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   430
  			d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   431
  		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   432
  		return res;	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   433
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   434
	else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   435
		MSG_ERR(0x1D1B, "Master-> Baud rate not specified",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   436
		d->lss_transfer.dat1=1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   437
    	/* If there is a callback, it is responsible of the error */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   438
    	if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   439
	    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   440
    	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   441
		return 0xFF;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   442
	}
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   443
  	//break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   444
  case LSS_SM_SELECTIVE_SERIAL:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   445
  case LSS_IDENT_REMOTE_SERIAL_HIGH:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   446
  	hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   447
  case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   448
  case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   449
  case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   450
  case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   451
  case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   452
  case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   453
  case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   454
  case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   455
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   456
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   457
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   458
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   459
	break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   460
	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   461
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   462
  case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   463
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   464
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   465
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   466
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   467
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   468
	 hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   469
  	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   470
#ifdef CO_ENABLE_LSS_FS
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   471
  case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   472
		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   473
		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   474
		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   475
		m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   476
		m.data[5]=d->lss_transfer.BitChecked;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   477
		m.data[6]=d->lss_transfer.LSSSub;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   478
		m.data[7]=d->lss_transfer.LSSNext;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   479
		/* it will generate a response only if it is the start of the FastScan protocol*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   480
		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET)hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   481
	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   482
#endif
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   483
  default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   484
   	MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   485
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   486
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   487
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   488
  res=canSend(d->canHandle,&m);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   489
  if(res==0 && hasResponse==1){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   490
  	StartLSS_MSG_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   491
  	d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   492
  }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   493
  return res;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   494
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   495
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   496
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   497
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   498
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   499
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   500
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   501
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   502
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   503
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   504
UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   505
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   506
  UNS8 res=1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   507
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   508
  /* 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
   509
  if (*(d->iam_a_slave)){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   510
  	res = sendSlaveLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   511
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   512
  else {/* It is a Master */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   513
  	res = sendMasterLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   514
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   515
  return res ;
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
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   521
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   522
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   523
** @param m                                                                                        
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
** @return                                                                                         
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 proceedLSS_Master(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   528
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   529
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   530
	UNS32 Dat1=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   531
	UNS8 Dat2=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   532
	
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   533
	if(d->lss_transfer.state!=LSS_TRANS_IN_PROGRESS)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   534
	{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   535
		//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
   536
		//return 0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   537
		goto ErrorProcessMaster;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   538
	}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   539
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   540
 	MSG_WAR(0x3D1E, "MasterLSS proceedLSS; command ", m->data[0]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   541
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   542
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   543
   		case LSS_INQ_NODE_ID: /* Inquire Node-ID */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   544
   			if(d->lss_transfer.command!=LSS_INQ_NODE_ID)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   545
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   546
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   547
   		case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   548
   		case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   549
   		case LSS_CONF_STORE: /* Store Configured Parameters */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   550
   			if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   551
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   552
   			Dat2=m->data[2];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   553
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   554
   		case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   555
   		case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   556
   		case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   557
   		case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   558
   			if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   559
   			Dat1=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   560
 			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   561
 		case LSS_IDENT_SLAVE: /* LSS Identify Slave */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   562
#ifdef CO_ENABLE_LSS_FS
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   563
   			if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   564
   				/* A message arrived during the timer period */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   565
   				d->lss_transfer.LSSanswer=1;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   566
   				return 0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   567
  			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   568
  			else
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   569
#endif
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   570
			if(d->lss_transfer.command!=LSS_IDENT_REMOTE_VENDOR && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   571
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_PRODUCT && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   572
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_LOW && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   573
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_HIGH && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   574
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_LOW && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   575
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_HIGH )
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   576
 					goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   577
  		break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   578
 		case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   579
 			if(d->lss_transfer.command!=LSS_SM_SELECTIVE_VENDOR && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   580
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_PRODUCT && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   581
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_REVISION && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   582
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_SERIAL )
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   583
 					goto ErrorProcessMaster;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   584
 			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   585
   		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
   586
   			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
   587
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   588
   		default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   589
   			MSG_ERR(0x1D1F, "Master LSS command not implemented", msg_cs);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   590
  			return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   591
   	}
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   592
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   593
	StopLSS_MSG_TIMER();
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   594
    d->lss_transfer.state = LSS_FINISHED;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   595
    	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   596
	d->lss_transfer.dat1=Dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   597
	d->lss_transfer.dat2=Dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   598
 	/* If there is a callback, it is responsible of the received response */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   599
	if(d->lss_transfer.Callback)
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   600
    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   601
    			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   602
   return 0;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   603
   
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   604
ErrorProcessMaster:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   605
    MSG_WAR(0x3D20, "MasterLSS proceedLSS; unexpected message arrived;command ", m->data[0]);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   606
	return 0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   607
		
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   608
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   609
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   610
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   611
**                                                                                                 
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   614
** @param m                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   615
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   616
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   617
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   618
UNS8 proceedLSS_Slave(CO_Data* d, Message* m )
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
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   621
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   622
  	MSG_WAR(0x3D21, "SlaveLSS proceedLSS; command ", m->data[0]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   623
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   624
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   625
   	case LSS_SM_GLOBAL:		/* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   626
   		/* if there is not a mode change break*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   627
   		if(m->data[1] == d->lss_transfer.mode){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   628
   			MSG_WAR(0x3D22, "SlaveLSS already in the mode ", m->data[1]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   629
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   630
   		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   631
   		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   632
		if(m->data[1]==LSS_CONFIGURATION_MODE)	{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   633
			MSG_WAR(0x3D23, "SlaveLSS switching to configuration mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   634
			/* Store the NodeId in case it will be changed */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   635
			//d->lss_transfer.nodeID=getNodeId(d);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   636
			d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
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
		else if(m->data[1]==LSS_WAITING_MODE){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   639
			MSG_WAR(0x3D24, "SlaveLSS switching to operational mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   640
			
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   641
			/* If the nodeID has changed update it and put the node state to Initialisation. */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   642
			if(d->lss_transfer.nodeID!=getNodeId(d)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   643
				if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   644
					MSG_WAR(0x3D25, "The node Id has changed. Reseting to Initialisation state",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   645
					setNodeId(d, d->lss_transfer.nodeID);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   646
					setState(d, Initialisation);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   647
				}
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   648
				else{/* The nodeID will be changed on NMT_Reset Request*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   649
				}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   650
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   651
			d->lss_transfer.mode=LSS_WAITING_MODE;
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
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   654
	case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   655
	{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   656
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   657
		UNS8 spec_error=0;
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
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   660
			if(m->data[1]>127 && m->data[1]!=0xFF){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   661
				MSG_ERR(0x1D26, "NodeID out of range",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   662
				error_code=1; /* NodeID out of range */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   663
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   664
			else{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   665
				d->lss_transfer.nodeID=m->data[1];
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
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   668
		else{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   669
			MSG_WAR(0x3D27, "SlaveLSS not in configuration mode",0);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   670
			//error_code=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   671
			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   672
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   673
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   674
	}	
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
	case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
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
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   679
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   680
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   681
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   682
			/* If a baud rate is not supported just comment the line. */
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   683
			switch(m->data[2]){
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   684
			case 0x00:d->lss_transfer.baudRate="1M";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   685
			case 0x01:d->lss_transfer.baudRate="800K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   686
			case 0x02:d->lss_transfer.baudRate="500K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   687
			case 0x03:d->lss_transfer.baudRate="250K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   688
			case 0x04:d->lss_transfer.baudRate="125K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   689
			case 0x05:d->lss_transfer.baudRate="100K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   690
			case 0x06:d->lss_transfer.baudRate="50K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   691
			case 0x07:d->lss_transfer.baudRate="20K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   692
			case 0x08:d->lss_transfer.baudRate="10K";break;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   693
			default:
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   694
				MSG_ERR(0x1D28, "Baud rate not supported",0);
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   695
				error_code=0xFF; /* Baud rate not supported*/
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   696
				break; 		
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   697
			}
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
		else{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   700
			MSG_WAR(0x3D2A, "SlaveLSS not in configuration mode",0);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   701
			//error_code=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   702
			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   703
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   704
		
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   705
		/* if bit timing is not supported comment the previous code and uncomment the following */
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   706
		/*{
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   707
			MSG_ERR(0x1D29, "Bit timing not supported",0);
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   708
			error_code=0x01; // bit timing not supported 
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   709
		}*/
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   710
			
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   711
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
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
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   714
	case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   715
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   716
		if(d->lss_transfer.mode!=LSS_CONFIGURATION_MODE){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   717
			MSG_ERR(0x3D2B, "SlaveLSS not in configuration mode",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   718
			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   719
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   720
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   721
		if(d->lss_transfer.baudRate!="none"){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   722
			d->lss_transfer.switchDelay=getLSSDelay(m);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   723
			MSG_WAR(0x3D2C, "Slave Switch Delay set to: ",d->lss_transfer.switchDelay);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   724
			d->lss_transfer.switchDelayState=SDELAY_FIRST;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   725
			//d->lss_transfer.currentState=getState(d);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   726
			//setState(d, LssTimingDelay);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   727
			d->lss_transfer.canHandle_t=d->canHandle;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   728
			d->canHandle=NULL;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   729
			StartLSS_SDELAY_TIMER();
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   730
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   731
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   732
	case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   733
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   734
		UNS8 error_code=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   735
		UNS8 spec_error=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   736
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   737
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   738
			if(d->lss_StoreConfiguration){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   739
				 /* call lss_StoreConfiguration with NodeId */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   740
	  			(*d->lss_StoreConfiguration)(d,&error_code,&spec_error);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   741
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   742
			else{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   743
				MSG_ERR(0x1D2E, "Store configuration not supported",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   744
				error_code=1; /* store configuration is not supported */
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
		else{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   748
			MSG_WAR(0x3D2F, "SlaveLSS not in configuration mode",0);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   749
			//error_code=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   750
			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   751
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   752
		sendSlaveLSSMessage(d,msg_cs,&error_code,&spec_error);
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
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   755
	case LSS_SM_SELECTIVE_VENDOR:	/* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   756
	case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   757
	case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   758
	case LSS_SM_SELECTIVE_SERIAL:
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
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   761
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   762
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   763
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   764
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   765
  		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   766
  		{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   767
  			MSG_ERR(0x1D30, "Switch Mode Selective only supported in operational mode",0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   768
  			break;
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
  			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   771
		_SpecificNodeInfo=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   772
				
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   773
		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   774
		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
   775
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   776
			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
   777
			/* If all the fields has been set */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   778
			if(d->lss_transfer.addr_sel_match==0x0F){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   779
				
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   780
				MSG_WAR(0x3D31, "SlaveLSS switching to configuration mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   781
				d->lss_transfer.addr_sel_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   782
				d->lss_transfer.nodeID=getNodeId(d);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   783
				d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   784
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   785
				sendSlaveLSSMessage(d,LSS_SM_SELECTIVE_RESP,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   786
			}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   787
		}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   788
		else {
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   789
			MSG_WAR(0x3D32, "LSS identity field doesn't match ", _SpecificNodeInfo);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   790
			d->lss_transfer.addr_sel_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   791
		}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   792
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   793
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   794
	case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   795
	case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   796
	case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   797
	case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   798
	case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   799
	case LSS_IDENT_REMOTE_SERIAL_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   800
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   801
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   802
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   803
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   804
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   805
  		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   806
		_SpecificNodeInfo=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   807
		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   808
		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   809
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   810
		/* Check if the data match the identity object. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   811
		switch(msg_cs){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   812
		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
   813
		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
   814
		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
   815
		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
   816
		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
   817
		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
   818
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   819
		/* If all the fields has been set.. */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   820
		if(d->lss_transfer.addr_ident_match==0x3F){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   821
			MSG_WAR(0x3D33, "SlaveLSS identified ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   822
			d->lss_transfer.addr_ident_match=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   823
			sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   824
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   825
		else if(d->lss_transfer.addr_ident_match==0){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   826
			MSG_WAR(0x3D34, "LSS identify field doesn't match ", _SpecificNodeInfo);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   827
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   828
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   829
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   830
	case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   831
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   832
		if(getNodeId(d)==0xFF){		
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   833
			MSG_WAR(0x3D35, "SlaveLSS non-configured ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   834
			sendSlaveLSSMessage(d,LSS_IDENT_NON_CONF_SLAVE,0,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   835
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   836
		else{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   837
			MSG_WAR(0x3D36, "SlaveLSS already configured ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   838
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   839
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   840
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   841
	case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   842
	case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   843
	case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   844
	case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   845
	if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   846
	{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   847
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   848
		UNS32 errorCode;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   849
  		const indextable *ptrTable;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   850
  		ODCallback_t *Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   851
  		UNS32 _SpecificNodeInfo;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   852
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   853
  		ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   854
  		_SpecificNodeInfo=*(UNS32*)ptrTable->pSubindex[msg_cs-(LSS_INQ_VENDOR_ID-1)].pObject;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   855
  		MSG_WAR(0x3D37, "SlaveLSS identity field inquired ", _SpecificNodeInfo);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   856
			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   857
		sendSlaveLSSMessage(d,msg_cs,&_SpecificNodeInfo,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   858
	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   859
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   860
	case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   861
		if(d->lss_transfer.mode==LSS_CONFIGURATION_MODE)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   862
		{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   863
			UNS8 NodeID;
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
			NodeID=getNodeId(d);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   866
			MSG_WAR(0x3D38, "SlaveLSS Node ID inquired ", NodeID);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   867
			sendSlaveLSSMessage(d,msg_cs,&NodeID,0);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   868
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   869
		else{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   870
			MSG_WAR(0x3D39, "SlaveLSS not in configuration mode",0);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   871
		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   872
	break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   873
#ifdef CO_ENABLE_LSS_FS
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   874
	case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   875
	{
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   876
		/* If the nodeID isn't 0xFF the slave shall not participate  */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   877
		if(getNodeId(d)!=0xFF)break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   878
		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
   879
		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   880
   		switch(d->lss_transfer.FastScan_SM){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   881
   		case LSS_FS_RESET:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   882
   		{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   883
   			UNS32 errorCode;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   884
  			const indextable *ptrTable;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   885
  			ODCallback_t *Callback;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   886
  				
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   887
			MSG_WAR(0x3D3A, "SlaveLSS Reseting LSSPos", 0);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   888
			d->lss_transfer.LSSPos=0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   889
			d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   890
			
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   891
  			ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   892
  			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
   893
			
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   894
			sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   895
   		}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   896
		break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   897
		case LSS_FS_PROCESSING:/*if(getLSSBitCheck(m)<32)*/
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   898
			if(d->lss_transfer.LSSPos==getLSSSub(m))
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   899
			{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   900
				UNS32 Mask=0xFFFFFFFF<<getLSSBitCheck(m);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   901
				
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   902
				MSG_WAR(0x3D3B, "SlaveLSS FastScan IDNumber", getLSSIdent(m));
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   903
				MSG_WAR(0x3D3C, "SlaveLSS FastScan BitMask ", Mask);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   904
				MSG_WAR(0x3D3D, "SlaveLSS FastScan LSS-ID  ", d->lss_transfer.IDNumber);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   905
				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   906
				if((getLSSIdent(m) & Mask)==(d->lss_transfer.IDNumber & Mask))
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   907
				{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   908
					sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   909
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   910
				
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   911
				if(getLSSBitCheck(m)==0)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   912
				{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   913
					d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   914
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   915
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   916
			break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   917
		case LSS_FS_CONFIRMATION:
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   918
			if(d->lss_transfer.LSSPos==getLSSSub(m))
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   919
			{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   920
				if(getLSSIdent(m)==d->lss_transfer.IDNumber)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   921
				{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   922
					/* Current LSS-ID[sub] confirmed correctly */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   923
					MSG_WAR(0x3D3E, "SlaveLSS FastScan IDNumber and LSS-ID match=>", d->lss_transfer.IDNumber);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   924
					if(d->lss_transfer.LSSPos==3)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   925
					{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   926
						/* All LSS-ID[sub] identified correctly, switching to configuration mode */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   927
						MSG_WAR(0x3D3F, "SlaveLSS switching to configuration mode ", 0);
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   928
			   			d->lss_transfer.nodeID=getNodeId(d);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   929
			   			d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   930
			    		d->lss_transfer.FastScan_SM=LSS_FS_RESET;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   931
			    		d->lss_transfer.LSSPos=0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   932
					}		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   933
					else
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   934
					{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   935
						/* Switch to the next LSS-ID[sub] */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   936
						UNS32 errorCode;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   937
  						const indextable *ptrTable;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   938
  						ODCallback_t *Callback;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   939
		
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   940
						d->lss_transfer.LSSPos=getLSSNext(m);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   941
						ptrTable = (*d->scanIndexOD)(0x1018, &errorCode, &Callback);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   942
  						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
   943
						d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;						
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   944
					}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   945
					sendSlaveLSSMessage(d,LSS_IDENT_SLAVE,0,0);
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   946
				}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   947
			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   948
			break;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   949
		}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   950
	}	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   951
	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   952
#endif
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   953
   	default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   954
   		MSG_ERR(0x1D40, "SlaveLSS command not implemented", msg_cs);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   955
  		return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   956
   	}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   957
   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   958
    return 0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   959
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   960
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   961
/*UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2)
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   962
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   963
	return sendMasterLSSMessage(d,command,dat1,dat2);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   964
}*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   965
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   966
UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback)
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   967
{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   968
	//d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   969
	d->lss_transfer.Callback=Callback;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   970
	d->lss_transfer.command=command;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   971
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   972
	StopLSS_MSG_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   973
  	//StartLSS_MSG_TIMER();
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   974
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   975
	return sendMasterLSSMessage(d,command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   976
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   977
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   978
UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   979
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   980
  *dat1=d->lss_transfer.dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   981
  *dat2=d->lss_transfer.dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   982
  return d->lss_transfer.state;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   983
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   984
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   985
//void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error){printf("_lss_StoreConfiguration\n");}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   986
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   987
#endif