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