src/lss.c
author lbessard
Mon, 21 Apr 2008 16:54:01 +0200
changeset 445 666f2cf93f06
parent 436 77796b3e3428
child 482 ec49f7132e36
permissions -rw-r--r--
Bug on Boolean values parsing while importing EDS fixed
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     1
/*
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     3
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     4
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     5
Copyright (C): Jorge Berzosa
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     6
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     7
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     8
See COPYING file for copyrights details.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
     9
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    10
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    11
This library is free software; you can redistribute it and/or
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    12
modify it under the terms of the GNU Lesser General Public
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    13
License as published by the Free Software Foundation; either
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    14
version 2.1 of the License, or (at your option) any later version.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    15
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    16
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    17
This library is distributed in the hope that it will be useful,
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    18
but WITHOUT ANY WARRANTY; without even the implied warranty of
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    20
Lesser General Public License for more details.
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    21
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    22
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    23
You should have received a copy of the GNU Lesser General Public
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    24
License along with this library; if not, write to the Free Software
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    25
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    26
*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    27
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    28
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    29
/*!
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    30
** @file   lss.c
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    31
** @author Jorge Berzosa
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    32
** @date   Mon Oct  22 05:44:32 2007
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    33
**
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    34
** @brief
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    35
**
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    36
**
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    37
*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    38
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    39
#ifdef CO_ENABLE_LSS
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    40
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    41
#include "data.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    42
#include "lss.h"
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    43
#include "canfestival.h"
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    44
#include "sysdep.h"
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    45
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    46
//#define LSS_TIMEOUT_MS	(TIMEVAL)1000  /* ms */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    47
//#define LSS_FS_TIMEOUT_MS	(TIMEVAL)100  /* ms */
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    48
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    49
/* Returns the LSS ident field from a Message struct */
436
77796b3e3428 Fixed suspicious code in lss.c
etisserant
parents: 399
diff changeset
    50
#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
    51
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    52
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    53
/* Returns the LSS switch delay field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    54
#define getLSSDelay(msg) ((msg->data[2] << 8) | (msg->data[1]))
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    55
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    56
/* Returns the LSS FastScan BitCheck field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    57
#define getLSSBitCheck(msg) msg->data[5]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    58
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    59
/* Returns the LSS FastScan LSSSub field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    60
#define getLSSSub(msg) msg->data[6]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    61
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    62
/* Returns the LSS FastScan LSSNext field from a Message struct */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    63
#define getLSSNext(msg) msg->data[7]
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    64
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    65
/* Prototypes for internals functions */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    66
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    67
void LssAlarmMSG(CO_Data* d, UNS32 id);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    68
void LssAlarmSDELAY(CO_Data* d, UNS32 id);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    69
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    70
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    71
#define StopLSS_MSG_TIMER(){\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    72
 MSG_WAR(0x3D01, "StopLSS_MSG_TIMER", 0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    73
 d->lss_transfer.timerMSG = DelAlarm(d->lss_transfer.timerMSG);}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    74
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    75
#define StartLSS_MSG_TIMER(){\
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    76
 MSG_WAR(0x3D02, "StartLSS_MSG_TIMER",0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    77
 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
    78
 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    79
#define StopLSS_SDELAY_TIMER(){\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    80
 MSG_WAR(0x3D03, "StopLSS_SDELAY_TIMER", 0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    81
 d->lss_transfer.timerSDELAY = DelAlarm(d->lss_transfer.timerSDELAY);}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    82
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    83
#define StartLSS_SDELAY_TIMER(){\
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    84
 MSG_WAR(0x3D04, "StartLSS_SDELAY_TIMER",0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    85
 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
    86
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    87
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    88
#ifdef CO_ENABLE_LSS_FS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    89
/* Prototypes for internals functions */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    90
void LssAlarmFS(CO_Data* d, UNS32 id);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    91
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    92
#define StopLSS_FS_TIMER(){\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    93
 MSG_WAR(0x3D05, "StopLSS_FS_TIMER", id);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    94
 d->lss_transfer.timerFS = DelAlarm(d->lss_transfer.timerFS);}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
    95
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
    96
#define StartLSS_FS_TIMER(){\
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    97
 MSG_WAR(0x3D06, "StartLSS_FS_TIMER",0);\
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    98
 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
    99
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   100
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   101
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   102
void LssAlarmMSG(CO_Data* d, UNS32 id)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   103
{	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   104
 	StopLSS_MSG_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   105
#ifdef CO_ENABLE_LSS_FS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   106
	if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   107
		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   108
   			/* 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
   109
   			if(d->lss_transfer.LSSanswer!=0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   110
   				d->lss_transfer.LSSanswer=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   111
   				d->lss_transfer.BitChecked=31;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   112
   				d->lss_transfer.IDNumber=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   113
   				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   114
   				StartLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   115
   				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   116
   				return;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   117
   			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   118
   			else{ 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   119
   			
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   120
    			d->lss_transfer.state = LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   121
    			/* Inform the application that there aren't not configured nodes in the net  */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   122
    			d->lss_transfer.dat1=1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   123
   			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   124
   		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   125
   		else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   126
			/* This should not happen, an error ocurred*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   127
			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
   128
   		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   129
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   130
	else
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   131
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   132
	if(d->lss_transfer.command==LSS_IDENT_REMOTE_NON_CONF){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   133
			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
   134
			d->lss_transfer.state = LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   135
			d->lss_transfer.dat1=1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   136
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   137
	else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   138
		MSG_ERR(0x1D09, "LSS timeout. LSS response not received.", 0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   139
    	MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   140
    	/* Set aborted state */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   141
    	d->lss_transfer.state = LSS_ABORTED_INTERNAL;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   142
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   143
    	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   144
    /* Call the user function to inform of the problem.*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   145
    if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   146
	   	/*If there is a callback, it is responsible of the error*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   147
    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   148
    }
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
    
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   152
/*!                                                                                                
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   156
** @param id                                                                                       
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   157
**/   
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   158
void LssAlarmSDELAY(CO_Data* d, UNS32 id)
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   159
{	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   160
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   161
	/* The first switch_delay period expired. Store the node state, change it 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   162
 	 * so no CAN messages will be sent or received, call the ChangeBaudRate function*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   163
   	if(d->lss_transfer.switchDelayState==SDELAY_FIRST){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   164
   		MSG_WAR(0x3D0B, "LSS switch delay first period expired",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   165
    	d->lss_transfer.switchDelayState=SDELAY_SECOND;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   166
    	//(*d->lss_ChangeBaudRate)(d,d->lss_transfer.baudRate);
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   167
    	canChangeBaudRate(d->lss_transfer.canHandle_t, d->lss_transfer.baudRate);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   168
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   169
    else{ /* d->lss_transfer.switchDelayState==SDELAY_SECOND */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   170
    	MSG_WAR(0x3D0C, "LSS switch delay second period expired",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   171
    	d->lss_transfer.switchDelayState=SDELAY_OFF;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   172
    	StopLSS_SDELAY_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   173
    		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   174
    	if (*(d->iam_a_slave))
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   175
    		d->canHandle=d->lss_transfer.canHandle_t;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   176
    	else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   177
    		d->lss_transfer.dat1=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   178
    		d->lss_transfer.state=LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   179
    		/* Call the user function */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   180
    		if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   181
	    		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   182
    		}
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
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   187
#ifdef CO_ENABLE_LSS_FS
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   188
/*!                                                                                                
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
** @param d                                                                                        
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   192
** @param id                                                                                       
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   193
**/   
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   194
void LssAlarmFS(CO_Data* d, UNS32 id)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   195
{	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   196
	StopLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   197
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   198
	switch(d->lss_transfer.FastScan_SM){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   199
   	case LSS_FS_RESET:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   200
   	{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   201
   	   	/* This should not happen, an error ocurred*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   202
		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
   203
   	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   204
   	break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   205
	case LSS_FS_PROCESSING:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   206
	{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   207
		/* If there isn't any answer, set the bit */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   208
		if(d->lss_transfer.LSSanswer==0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   209
			UNS32 Mask=0x1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   210
			Mask<<=d->lss_transfer.BitChecked;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   211
			d->lss_transfer.IDNumber|=Mask;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   212
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   213
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   214
		if(d->lss_transfer.BitChecked==0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   215
			/* We finished with the current LSS-ID[sub], confirm it */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   216
			d->lss_transfer.FastScan_SM=LSS_FS_CONFIRMATION;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   217
			if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   218
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   219
		else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   220
			d->lss_transfer.BitChecked--;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   221
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   222
   			
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   223
   		d->lss_transfer.LSSanswer=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   224
  		StartLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   225
   		sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   226
   		return;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   227
   	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   228
	break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   229
	case LSS_FS_CONFIRMATION:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   230
	{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   231
		if(d->lss_transfer.LSSanswer!=0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   232
			d->lss_transfer.LSSanswer=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   233
			
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   234
			if(d->lss_transfer.LSSSub==3){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   235
				/* The LSS FastScan protocol finished correctly. Restore the parameters */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   236
				d->lss_transfer.BitChecked=128;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   237
				d->lss_transfer.FastScan_SM=LSS_FS_RESET;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   238
				d->lss_transfer.LSSSub=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   239
				d->lss_transfer.LSSNext=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   240
   				d->lss_transfer.IDNumber=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   241
				
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   242
				/* Inform the application that the FastScan finished correctly */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   243
				d->lss_transfer.state = LSS_FINISHED;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   244
				d->lss_transfer.dat1=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   245
			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   246
			else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   247
				/* Start with the next LSS-ID[sub] */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   248
				d->lss_transfer.LSSSub++;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   249
				d->lss_transfer.BitChecked=31;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   250
   				d->lss_transfer.IDNumber=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   251
   				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   252
   				StartLSS_FS_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   253
   				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   254
   				return;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   255
			}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   256
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   257
		else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   258
			/* This should not happen, an error ocurred*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   259
			MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   260
			/* Set aborted state */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   261
    		d->lss_transfer.state = LSS_ABORTED_INTERNAL;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   262
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   263
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   264
	break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   265
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   266
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   267
   	/* Call the user function to inform of the problem.*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   268
   	if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   269
    	/*If there is a callback, it is responsible of the error*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   270
   		(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   271
   	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   272
}
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   273
#endif
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   274
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   275
	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   276
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   277
**                                                                                                 
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   280
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   281
void startLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   282
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   283
	/*MSG_WAR(0x3D09, "LSS services started",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   284
}
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   290
**/   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   291
void stopLSS(CO_Data* d)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   292
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   293
	/*MSG_WAR(0x3D09, "LSS services stopped",0);*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   294
}
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   300
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   301
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   302
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   303
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   304
UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   305
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   306
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   307
  UNS8 i;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   308
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   309
  if (!d->CurrentCommunicationState.csLSS){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   310
  	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
   311
  	return 0xFF;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   312
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   313
   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   314
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   315
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   316
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   317
  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
   318
  m.cob_id=UNS16_LE(SLSS_ADRESS);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   319
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   320
  /* Tha data sent with the msg depends on the command */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   321
  switch(command){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   322
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   323
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   324
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   325
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   326
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   327
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   328
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   329
  	m.data[2]=*(UNS8 *)dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   330
  	break; 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   331
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   332
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   333
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   334
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   335
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   336
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   337
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   338
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   339
	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   340
  case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   341
  case LSS_IDENT_SLAVE: /* LSS Identify Slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   342
  case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   343
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   344
  default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   345
  	MSG_ERR(0x1D18, "send Slave LSS command not implemented", command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   346
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   347
  }
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
  return canSend(d->canHandle,&m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   350
}
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   351
			
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   352
/* If a baud rate is not supported just comment the line. */
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   353
static UNS8 CO_TranslateBaudRate(char* optarg){
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   354
	if(!strcmp( optarg, "1M")) return 0x00;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   355
	if(!strcmp( optarg, "800K")) return 0x01;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   356
	if(!strcmp( optarg, "500K")) return 0x02;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   357
	if(!strcmp( optarg, "250K")) return 0x03;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   358
	if(!strcmp( optarg, "125K")) return 0x04;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   359
	if(!strcmp( optarg, "100K")) return 0x05;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   360
	if(!strcmp( optarg, "50K")) return 0x06;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   361
	if(!strcmp( optarg, "20K")) return 0x07;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   362
	if(!strcmp( optarg, "10K")) return 0x08;
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   363
	return 0xFF;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   364
}
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   365
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   370
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   371
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   372
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   373
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   374
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   375
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   376
  Message m;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   377
  UNS8 i;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   378
  UNS8 res;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   379
  UNS8 hasResponse=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   380
   
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   381
  for(i=1;i<8;i++)m.data[i]=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   382
  m.len = 8;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   383
  m.rtr = NOT_A_REQUEST;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   384
  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
   385
  m.cob_id=UNS16_LE(MLSS_ADRESS);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   386
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   387
  /* Tha data sent with the msg depends on the command */	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   388
  switch(command){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   389
  case LSS_CONF_NODE_ID: /* Configure Node-ID */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   390
  	hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   391
  case LSS_SM_GLOBAL: /* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   392
  	m.data[1]=*(UNS8 *)dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   393
  	break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   394
  case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   395
  	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   396
  	m.data[1]=*(UNS8 *)dat1;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   397
  	d->lss_transfer.baudRate=*(char **)dat2;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   398
  	
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   399
  	if((m.data[2]=CO_TranslateBaudRate(d->lss_transfer.baudRate))!=0xFF){
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   400
  		hasResponse=1;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   401
		break;	 
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   402
  	}
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
	MSG_ERR(0x1D19, "Master-> Baud rate not supported",0);
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   405
	d->lss_transfer.dat1=0xFF;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   406
	
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   407
	/* 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
   408
	/*{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   409
		MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   410
		d->lss_transfer.dat1=0x01;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   411
	}*/
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   412
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   413
	d->lss_transfer.dat2=0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   414
 	/* If there is a callback, it is responsible of the error */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   415
	if(d->lss_transfer.Callback)
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   416
	   	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   417
	return 0xFF;
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   418
  	//break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   419
  case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   420
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   421
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   422
	if(d->lss_transfer.baudRate!="none"){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   423
		d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   424
		d->lss_transfer.switchDelayState=SDELAY_FIRST;
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 381
diff changeset
   425
		d->lss_transfer.canHandle_t=d->canHandle;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   426
		res=canSend(d->canHandle,&m);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   427
  		if(res==0){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   428
  			StartLSS_SDELAY_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   429
  			d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   430
  		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   431
  		return res;	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   432
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   433
	else{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   434
		MSG_ERR(0x1D1B, "Master-> Baud rate not specified",0);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   435
		d->lss_transfer.dat1=1;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   436
    	/* If there is a callback, it is responsible of the error */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   437
    	if(d->lss_transfer.Callback){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   438
	    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   439
    	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   440
		return 0xFF;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   441
	}
399
8d22c323fe0f some warning errors fixed
groke6
parents: 384
diff changeset
   442
  	//break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   443
  case LSS_SM_SELECTIVE_SERIAL:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   444
  case LSS_IDENT_REMOTE_SERIAL_HIGH:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   445
  	hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   446
  case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   447
  case LSS_SM_SELECTIVE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   448
  case LSS_SM_SELECTIVE_REVISION:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   449
  case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   450
  case LSS_IDENT_REMOTE_PRODUCT:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   451
  case LSS_IDENT_REMOTE_REV_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   452
  case LSS_IDENT_REMOTE_REV_HIGH:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   453
  case LSS_IDENT_REMOTE_SERIAL_LOW:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   454
	m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   455
	m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   456
	m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   457
	m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   458
	break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   459
	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   460
  case LSS_CONF_STORE: /* Store Configured Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   461
  case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   462
  case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   463
  case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   464
  case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   465
  case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   466
  case LSS_INQ_NODE_ID: /* Inquire Node-ID */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   467
	 hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   468
  	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   469
#ifdef CO_ENABLE_LSS_FS
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   470
  case LSS_IDENT_FASTSCAN:
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   471
		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   472
		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   473
		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   474
		m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   475
		m.data[5]=d->lss_transfer.BitChecked;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   476
		m.data[6]=d->lss_transfer.LSSSub;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   477
		m.data[7]=d->lss_transfer.LSSNext;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   478
		/* 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
   479
		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET)hasResponse=1;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   480
	break;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   481
#endif
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   482
  default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   483
   	MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   484
  	return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   485
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   486
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   487
  res=canSend(d->canHandle,&m);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   488
  if(res==0 && hasResponse==1){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   489
  	StartLSS_MSG_TIMER();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   490
  	d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   491
  }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   492
  return res;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   493
}
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   499
** @param cob_id                                                                                   
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   500
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   501
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   502
**/  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   503
UNS8 sendLSS(CO_Data* d, UNS8 command,void *dat1,void *dat2)
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   504
{
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   505
  UNS8 res=1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   506
  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   507
  /* 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
   508
  if (*(d->iam_a_slave)){ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   509
  	res = sendSlaveLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   510
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   511
  else {/* It is a Master */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   512
  	res = sendMasterLSSMessage(d, command,dat1,dat2);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   513
  }
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   514
  return res ;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   515
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   516
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   517
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   518
/*!                                                                                                
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   519
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   520
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   521
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   522
** @param m                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   523
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   524
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   525
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   526
UNS8 proceedLSS_Master(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   527
{ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   528
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   529
	UNS32 Dat1=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   530
	UNS8 Dat2=0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   531
	
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   532
	if(d->lss_transfer.state!=LSS_TRANS_IN_PROGRESS)
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   533
	{
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   534
		//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
   535
		//return 0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   536
		goto ErrorProcessMaster;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   537
	}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   538
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   539
 	MSG_WAR(0x3D1E, "MasterLSS proceedLSS; command ", m->data[0]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   540
	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   541
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   542
   		case LSS_INQ_NODE_ID: /* Inquire Node-ID */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   543
   			if(d->lss_transfer.command!=LSS_INQ_NODE_ID)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   544
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   545
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   546
   		case LSS_CONF_NODE_ID: /* Configure Node-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   547
   		case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   548
   		case LSS_CONF_STORE: /* Store Configured Parameters */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   549
   			if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   550
   			Dat1=m->data[1];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   551
   			Dat2=m->data[2];
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   552
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   553
   		case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   554
   		case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   555
   		case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   556
   		case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   557
   			if(d->lss_transfer.command!=msg_cs)goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   558
   			Dat1=getLSSIdent(m);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   559
 			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   560
 		case LSS_IDENT_SLAVE: /* LSS Identify Slave */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   561
#ifdef CO_ENABLE_LSS_FS
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   562
   			if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   563
   				/* A message arrived during the timer period */
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   564
   				d->lss_transfer.LSSanswer=1;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   565
   				return 0;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   566
  			}
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   567
  			else
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   568
#endif
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   569
			if(d->lss_transfer.command!=LSS_IDENT_REMOTE_VENDOR && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   570
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_PRODUCT && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   571
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_LOW && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   572
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_REV_HIGH && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   573
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_LOW && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   574
 				d->lss_transfer.command!=LSS_IDENT_REMOTE_SERIAL_HIGH )
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   575
 					goto ErrorProcessMaster;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   576
  		break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   577
 		case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response */
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   578
 			if(d->lss_transfer.command!=LSS_SM_SELECTIVE_VENDOR && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   579
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_PRODUCT && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   580
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_REVISION && \
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   581
 				d->lss_transfer.command!=LSS_SM_SELECTIVE_SERIAL )
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   582
 					goto ErrorProcessMaster;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   583
 			break;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   584
   		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
   585
   			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
   586
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   587
   		default:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   588
   			MSG_ERR(0x1D1F, "Master LSS command not implemented", msg_cs);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   589
  			return 0xFF;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   590
   	}
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   591
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   592
	StopLSS_MSG_TIMER();
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   593
    d->lss_transfer.state = LSS_FINISHED;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   594
    	
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   595
	d->lss_transfer.dat1=Dat1;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   596
	d->lss_transfer.dat2=Dat2;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   597
 	/* If there is a callback, it is responsible of the received response */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   598
	if(d->lss_transfer.Callback)
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   599
    	(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   600
    			
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   601
   return 0;
361
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   602
   
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   603
ErrorProcessMaster:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   604
    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
   605
	return 0xFF;
2220813498f2 Added FastScan support to the LSS services.
groke6
parents: 343
diff changeset
   606
		
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   607
}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   608
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
** @param d                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   613
** @param m                                                                                        
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   614
**                                                                                                 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   615
** @return                                                                                         
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   616
**/ 
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   617
UNS8 proceedLSS_Slave(CO_Data* d, Message* m )
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   618
{  
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   619
	UNS8 msg_cs;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   620
	
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   621
  	MSG_WAR(0x3D21, "SlaveLSS proceedLSS; command ", m->data[0]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   622
  	
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   623
   	switch(msg_cs=m->data[0]){
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   624
   	case LSS_SM_GLOBAL:		/* Switch Mode Global */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   625
   		/* if there is not a mode change break*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   626
   		if(m->data[1] == d->lss_transfer.mode){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   627
   			MSG_WAR(0x3D22, "SlaveLSS already in the mode ", m->data[1]);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   628
   			break;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   629
   		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   630
   		
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   631
		if(m->data[1]==LSS_CONFIGURATION_MODE)	{
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   632
			MSG_WAR(0x3D23, "SlaveLSS switching to configuration mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   633
			/* Store the NodeId in case it will be changed */
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   634
			//d->lss_transfer.nodeID=getNodeId(d);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   635
			d->lss_transfer.mode=LSS_CONFIGURATION_MODE;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   636
		}
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   637
		else if(m->data[1]==LSS_WAITING_MODE){
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   638
			MSG_WAR(0x3D24, "SlaveLSS switching to operational mode ", 0);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   639
			
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   640
			/* 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
   641
			if(d->lss_transfer.nodeID!=getNodeId(d)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   642
				if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   643
					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
   644
					setNodeId(d, d->lss_transfer.nodeID);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   645
					setState(d, Initialisation);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents:
diff changeset
   646
				}
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   647
				else{/* The nodeID will be changed on NMT_Reset Request*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
   648
					setNodeId(d, d->lss_transfer.nodeID);
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