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