src/lss.c
changeset 517 003679edc437
parent 482 ec49f7132e36
equal deleted inserted replaced
516:19085e93ad21 517:003679edc437
   106 #ifdef CO_ENABLE_LSS_FS
   106 #ifdef CO_ENABLE_LSS_FS
   107 	if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
   107 	if(d->lss_transfer.command==LSS_IDENT_FASTSCAN){
   108 		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
   108 		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
   109    			/* if at least one node had answered before the timer expired, start the FastScan protocol*/
   109    			/* if at least one node had answered before the timer expired, start the FastScan protocol*/
   110    			if(d->lss_transfer.LSSanswer!=0){
   110    			if(d->lss_transfer.LSSanswer!=0){
       
   111    				UNS32 Mask=0xFFFFFFFF;
   111    				d->lss_transfer.LSSanswer=0;
   112    				d->lss_transfer.LSSanswer=0;
   112    				d->lss_transfer.BitChecked=31;
   113    				d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[0];
   113    				d->lss_transfer.IDNumber=0;
   114    				Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
       
   115    				d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[0] & Mask;
   114    				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
   116    				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
       
   117    				//printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
   115    				StartLSS_FS_TIMER();
   118    				StartLSS_FS_TIMER();
   116    				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
   119    				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
   117    				return;
   120    				return;
   118    			}
   121    			}
   119    			else{ 
   122    			else{ 
   124    			}
   127    			}
   125    		}
   128    		}
   126    		else{
   129    		else{
   127 			/* This should not happen, an error ocurred*/
   130 			/* This should not happen, an error ocurred*/
   128 			MSG_ERR(0x1D07, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
   131 			MSG_ERR(0x1D07, "LSS FastScan timeout. FastScan_SM inconsisten state.", d->lss_transfer.FastScan_SM);
       
   132 			d->lss_transfer.state = LSS_ABORTED_INTERNAL;
       
   133 			d->lss_transfer.FastScan_SM=LSS_FS_RESET;
   129    		}
   134    		}
   130 	}
   135 	}
   131 	else
   136 	else
   132 #endif
   137 #endif
   133 	if(d->lss_transfer.command==LSS_IDENT_REMOTE_NON_CONF){
   138 	if(d->lss_transfer.command==LSS_IDENT_REMOTE_NON_CONF){
   138 	else{
   143 	else{
   139 		MSG_ERR(0x1D09, "LSS timeout. LSS response not received.", 0);
   144 		MSG_ERR(0x1D09, "LSS timeout. LSS response not received.", 0);
   140     	MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
   145     	MSG_WAR(0x2D0A, "LSS timeout command specifier : ", d->lss_transfer.command);
   141     	/* Set aborted state */
   146     	/* Set aborted state */
   142     	d->lss_transfer.state = LSS_ABORTED_INTERNAL;
   147     	d->lss_transfer.state = LSS_ABORTED_INTERNAL;
       
   148 #ifdef CO_ENABLE_LSS_FS
       
   149     	d->lss_transfer.FastScan_SM = LSS_FS_RESET;
       
   150 #endif
   143     }
   151     }
   144     	
   152     	
   145     /* Call the user function to inform of the problem.*/
   153     /* Call the user function to inform of the problem.*/
   146     if(d->lss_transfer.Callback){
   154     if(d->lss_transfer.Callback){
   147 	   	/*If there is a callback, it is responsible of the error*/
   155 	   	/*If there is a callback, it is responsible of the error*/
   218 			if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
   226 			if(d->lss_transfer.LSSNext<3)d->lss_transfer.LSSNext++;
   219 		}
   227 		}
   220 		else{
   228 		else{
   221 			d->lss_transfer.BitChecked--;
   229 			d->lss_transfer.BitChecked--;
   222 		}
   230 		}
   223    			
   231 		//printf("BitChecked=%d, IDNumber=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber);
   224    		d->lss_transfer.LSSanswer=0;
   232    		d->lss_transfer.LSSanswer=0;
   225   		StartLSS_FS_TIMER();
   233   		StartLSS_FS_TIMER();
   226    		sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
   234    		sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
   227    		return;
   235    		return;
   228    	}
   236    	}
   243 				/* Inform the application that the FastScan finished correctly */
   251 				/* Inform the application that the FastScan finished correctly */
   244 				d->lss_transfer.state = LSS_FINISHED;
   252 				d->lss_transfer.state = LSS_FINISHED;
   245 				d->lss_transfer.dat1=0;
   253 				d->lss_transfer.dat1=0;
   246 			}
   254 			}
   247 			else{
   255 			else{
       
   256 				UNS32 Mask=0xFFFFFFFF;
   248 				/* Start with the next LSS-ID[sub] */
   257 				/* Start with the next LSS-ID[sub] */
   249 				d->lss_transfer.LSSSub++;
   258 				d->lss_transfer.LSSSub++;
   250 				d->lss_transfer.BitChecked=31;
   259 				d->lss_transfer.BitChecked=d->lss_transfer.lss_fs_transfer.FS_BitChecked[d->lss_transfer.LSSSub];
   251    				d->lss_transfer.IDNumber=0;
   260 				Mask=(UNS32)((UNS64)Mask<<(d->lss_transfer.BitChecked+1));
       
   261    				d->lss_transfer.IDNumber=d->lss_transfer.lss_fs_transfer.FS_LSS_ID[d->lss_transfer.LSSSub] & Mask;
   252    				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
   262    				d->lss_transfer.FastScan_SM=LSS_FS_PROCESSING;
       
   263    				//printf("BitChecked=%d, IDNumber=%x MASK=%x\n",d->lss_transfer.BitChecked,d->lss_transfer.IDNumber,Mask);
   253    				StartLSS_FS_TIMER();
   264    				StartLSS_FS_TIMER();
   254    				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
   265    				sendMasterLSSMessage(d,LSS_IDENT_FASTSCAN,0,0);
   255    				return;
   266    				return;
   256 			}
   267 			}
   257 		}
   268 		}
   258 		else{
   269 		else{
   259 			/* This should not happen, an error ocurred*/
   270 			/* This should not happen, an error ocurred*/
   260 			MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
   271 			MSG_ERR(0x1D0E, "LSS FastScan timeout. FastScan response not received.", 0);
       
   272 			MSG_ERR(0x1D0E, "There is not any node with LSS_ID# =>", d->lss_transfer.LSSSub);
       
   273 			MSG_ERR(0x1D0E, "with the value =>", d->lss_transfer.IDNumber);
   261 			/* Set aborted state */
   274 			/* Set aborted state */
   262     		d->lss_transfer.state = LSS_ABORTED_INTERNAL;
   275     		d->lss_transfer.state = LSS_ABORTED_INTERNAL;
       
   276     		d->lss_transfer.FastScan_SM = LSS_FS_RESET;
   263 		}
   277 		}
   264 	}
   278 	}
   265 	break;
   279 	break;
   266 	}
   280 	}
   267 
   281 
   467   case LSS_INQ_NODE_ID: /* Inquire Node-ID */
   481   case LSS_INQ_NODE_ID: /* Inquire Node-ID */
   468 	 hasResponse=1;
   482 	 hasResponse=1;
   469   	break;
   483   	break;
   470 #ifdef CO_ENABLE_LSS_FS
   484 #ifdef CO_ENABLE_LSS_FS
   471   case LSS_IDENT_FASTSCAN:
   485   case LSS_IDENT_FASTSCAN:
       
   486 	  	if(d->lss_transfer.FastScan_SM==LSS_FS_RESET){
       
   487 	  		UNS8 i;
       
   488 	  		 /* Initialize the lss_fs_transfer FastScan parameters */
       
   489 	  		for(i=0;i<4;i++){
       
   490 	  			d->lss_transfer.lss_fs_transfer.FS_LSS_ID[i]=(*(lss_fs_transfer_t*)dat1).FS_LSS_ID[i];
       
   491 	  			d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]=(*(lss_fs_transfer_t*)dat1).FS_BitChecked[i];
       
   492 	  			/* Adjust BitChecked from 32-1 to 31-0 */
       
   493 	  			if(d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]>0)d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]--;
       
   494 	  		}
       
   495 	  		
       
   496 	  		d->lss_transfer.IDNumber=0;
       
   497 	  		d->lss_transfer.BitChecked=128;
       
   498 	  		d->lss_transfer.LSSSub=0;
       
   499 	  		d->lss_transfer.LSSNext=0;
       
   500 	  				
       
   501 	  		/* it will generate a response only if it is the start of the FastScan protocol*/
       
   502 	  		hasResponse=1;
       
   503 	  	}
   472 		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
   504 		m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
   473 		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
   505 		m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
   474 		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
   506 		m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
   475 		m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
   507 		m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
   476 		m.data[5]=d->lss_transfer.BitChecked;
   508 		m.data[5]=d->lss_transfer.BitChecked;
   477 		m.data[6]=d->lss_transfer.LSSSub;
   509 		m.data[6]=d->lss_transfer.LSSSub;
   478 		m.data[7]=d->lss_transfer.LSSNext;
   510 		m.data[7]=d->lss_transfer.LSSNext;
   479 		/* it will generate a response only if it is the start of the FastScan protocol*/
       
   480 		if(d->lss_transfer.FastScan_SM==LSS_FS_RESET)hasResponse=1;
       
   481 	break;
   511 	break;
   482 #endif
   512 #endif
   483   default:
   513   default:
   484    	MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
   514    	MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
   485   	return 0xFF;
   515   	return 0xFF;
   643 				if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/
   673 				if(getNodeId(d)==0xFF){/* The nodeID was 0xFF; initialize the application*/
   644 					MSG_WAR(0x3D25, "The node Id has changed. Reseting to Initialisation state",0);
   674 					MSG_WAR(0x3D25, "The node Id has changed. Reseting to Initialisation state",0);
   645 					setNodeId(d, d->lss_transfer.nodeID);
   675 					setNodeId(d, d->lss_transfer.nodeID);
   646 					setState(d, Initialisation);
   676 					setState(d, Initialisation);
   647 				}
   677 				}
   648 				else{/* The nodeID will be changed on NMT_Reset Request*/
   678 				else{/* The nodeID will be changed on NMT_Reset_Comunication Request*/
   649 				}
   679 				}
   650 			}
   680 			}
   651 			d->lss_transfer.mode=LSS_WAITING_MODE;
   681 			d->lss_transfer.mode=LSS_WAITING_MODE;
   652 		}
   682 		}
   653 	break;
   683 	break;