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