src/lss.c
author frdupin
Mon, 29 Jan 2007 14:34:31 +0100
changeset 78 ac05410cc1b8
parent 0 4472ee7c6c3e
child 89 11dda1450e09
permissions -rw-r--r--
compilers compatibility
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
 Author: CANopen Canada (canfestival@canopencanada.ca)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#include <def.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include <can.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
#include <data.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include <objdictdef.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
#include <objacces.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
#include "can_driver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#ifdef LED_ENABLE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include "led.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#define led_set_state(a,b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#include "lss.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
	NOTES
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
	1. since in the LSS protocol all LSS Slave use the same COB, only 1 Slave
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
	must be allowed to communicate with the Master
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
	2. the Master always take the iniative. the Slave is only allowed to transmit
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
	within a confirmed service
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
	3. requesting message (from the Master) using COB-ID 2021 and response messages
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
	(from the Slave) using COB-ID 2020
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
	0 = this slave is not talking to the master
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
	1 = this slave is talking to the master (this slave has been selected via )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
int	slave_selector;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
int	current_mode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
int	lss_table_selector, lss_table_index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
/* slave storing the information sent by the master */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
UNS32 lss_buffer[10];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
	how this buffer is used
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
	for a SLAVE 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
	[0..3]  used to store the LSS Address
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
	[4..9]  use by LSS Identify Remort Slave
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
	for the MASTER
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
	[0..3] hold the answer from the slave regarding its ID
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
void lss_copy(UNS8 *data, UNS32 value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
/* transfert 32 bits value into uns8 data vector */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
	data[0] = value & 0xff;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
	data[1] = (value>>8) & 0xff;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
	data[2] = (value>>16) & 0xff;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
	data[3] = (value>>24) & 0xff;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
UNS32 lss_get_value(UNS8 *data)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
/* build a 'UNS32' value from a 'unsigned char' vector */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
	return data[0] + (data[1]<<8) + (data[2]<<16) + (data[3]<<24);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
void lss_init_msg(Message *msg)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
	msg->cob_id.w = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
	msg->rtr = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
	msg->len = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
	msg->data[0] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
	msg->data[1] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
	msg->data[2] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
	msg->data[3] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
	msg->data[4] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
	msg->data[5] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
	msg->data[6] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
	msg->data[7] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
void lss_SwitchModeGlobal(CO_Data *d, UNS32 mode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
	this service is used to switch all LSS slaves in the network between operation
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
	mode and configuration mode.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
{	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
	/* 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
		sending a COB-ID 2021
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
		[0] = 4 (for switch mode global)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
		[1] = 0 for operation mode, = 1 for configuration mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
		[2..7] = 0 reserved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
	*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
	if (!(d->iam_a_slave))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
		msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
		msg.len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
		msg.data[0] = 4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
		msg.data[1] = (UNS8)mode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
	else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
		/* set mode global */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
		current_mode = mode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
void lss_SwitchModeSelective_master(CO_Data *d, UNS32 *LSSaddr)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
	LSS address : <vendor-id> <product-code> <revision-number> <serial-number>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
	vendor-id : provided by CiA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
	identical to the CANopen identity object
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
	select the slave corresponding to this ADDRESS
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
	if (d->iam_a_slave) /* not the master */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
		return; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
	msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
	msg.len=5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
	msg.data[0] = 64;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
	lss_copy(msg.data+1, LSSaddr[0]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
	/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
	(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
	msg.data[0] = 65;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
	lss_copy(msg.data+1, LSSaddr[1]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
	/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
	(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
	msg.data[0] = 66;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
	lss_copy(msg.data+1, LSSaddr[2]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
	/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
	(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
	msg.data[0] = 67;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
	lss_copy(msg.data+1, LSSaddr[3]); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
	/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
	(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
UNS32 lss_validate_address(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
#if 0 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
	extern s_identity obj1018;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
	/* maybe we should go throught getODentry but those
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
	data are 1) RO and 2) the proper ID of this device */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
#else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
	UNS32  r, vendor_id, product_code, revision_number, serial_number;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
	UNS8   sz = sizeof(UNS32), dt = int32;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
	r = getODentry(d, 0x1018, 1, (void *)&vendor_id, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
	r = getODentry(d, 0x1018, 2, (void *)&product_code, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
	r = getODentry(d, 0x1018, 3, (void *)&revision_number, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
	r = getODentry(d, 0x1018, 4, (void *)&serial_number, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
	/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
		if
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
		lss_buffer[0] == vendor-id
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
		lss_buffer[1] == product code
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
		lss_buffer[2] == revision
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
		lss_buffer[3] == serial
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
		then return 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
		else return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
	*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
	if (lss_buffer[0] == vendor_id  &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
	    lss_buffer[1] == product_code &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
	    lss_buffer[2] == revision_number &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
	    lss_buffer[3] == serial_number)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
		return 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
void lss_SwitchModeSelective_slave(CO_Data *d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
/* 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
	SwitchModeSelective for the SLAVE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
	received the frames from the master and start building 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
	the lss address 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
	/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
		the master broadcast the address of a particular slave
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
		for 64,65 and 66 store the partial address
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
		when 67 arrive process the call and asknowledge if necessary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
	*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
	if (lss_validate_address(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
		/* slave should transmit cob_id 2020  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
		msg.cob_id.w = 0x07E4 /* 2020 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
		msg.len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
		msg.data[0] = 68;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
		msg.data[1] = (UNS8)current_mode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
	/* reset the address */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
	lss_buffer[0] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
	lss_buffer[1] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
	lss_buffer[2] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
	lss_buffer[3] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
void lss_ConfigureNode_ID(CO_Data *d, UNS32 node_id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
	through this service the LSS Master configures the NMT-address
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
	parameter of a LSS slave.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
	if (!(d->iam_a_slave))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
		msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
		msg.len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
		msg.data[0] = 17;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
		msg.data[1] = (UNS8)node_id;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
	else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
		/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
			receiving NODE ID from the master
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
		*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
		/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
			error code 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
			0 = success
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
			1 = node id out of range
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
			2..254 = reserved
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
			255 = implementation specific error occured
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
				spec error = mode detailed error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
		*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
		msg.cob_id.w = 0x07E4 /* 2020 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
		msg.len = 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
		msg.data[0] = 17;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
		/* msg.data[1] = error code */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
		/* msg.data[2] = spec error */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
void lss_ConfigureBitTimingParameters(CO_Data *d, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
                                      UNS32 table_selector,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
                                      UNS32 table_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
	this service allows all LSS slaves in configuration mode.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
	must be followed by an Activate Bit Timing Parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
	if (!(d->iam_a_slave))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
		msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
		msg.len = 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
		msg.data[0] = 19;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
		msg.data[1] = (UNS8)table_selector;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
		msg.data[2] = (UNS8)table_index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
	else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
		UNS8 error_code;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
		/* validate if this baudrate is possible */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
		if (table_selector == 0  &&  baudrate_valid(table_index) == 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
		{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
			lss_table_selector = table_selector;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
			lss_table_index = table_index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
		}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
		else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
			error_code = 1; /* bit timing not supported */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
		msg.cob_id.w = 0x07E4 /* 2020 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
		msg.len = 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
		msg.data[0] = 19;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
		msg.data[1] = error_code;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
		msg.data[2] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
	led_set_state(d, LED_AUTOBITRATE);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
void lss_ActivateBitTimingParameters_master(CO_Data *d, unsigned short switch_delay)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
	switch_delay in ms
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
	switch_delay has to be longer than the longest timeof any node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
	in the network to avoid that a node already switches while another
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
	stills transmist the old bit timing parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
	if (d->iam_a_slave)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
		return;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
	msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
	msg.len = 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
	msg.data[0] = 21;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
	msg.data[1] = (UNS8)(switch_delay &  0xff);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
	msg.data[2] = (UNS8)((switch_delay >> 8) & 0xff);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
#ifdef LED_ENABLE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
	led_set_state(LED_AUTOBITRATE);		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
	/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
	(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
void lss_ActivateBitTimingParameters_slave(UNS8 byte_low, UNS8 byte_high)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
	/* rebuild the delay value (short) from the 2 (UNS8) data */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
	unsigned short switch_delay = byte_low + (((UNS16)byte_high)<<8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
	/* set the baudrate to the value proposed by the master */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
	if (lss_table_selector == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
		baudrate_set(lss_table_index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
	/* wait for switch_delay ms before continuing */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
void lss_StoreConfiguredParameters(CO_Data *d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
	store configured parameters into non-volatile storage
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
	if (!(d->iam_a_slave))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
		msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
		msg.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
		msg.data[0] = 23;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
	else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
		msg.cob_id.w = 0x07E4 /* 2020 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
		msg.data[0] = 23;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
		/* msg.data[1] = error code; */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
		/* msg.data[2] = spec err */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
void lss_InquireLSSAddress_master(CO_Data *d, int flag)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
	this service allows to determine the LSS-address parameters of a LSS-slave in
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
	configuration mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
	request 1 single item of the LSS address
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
	0 = request vendor-id
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
	1 = request product-id
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
	2 = request revision
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
	3 = request serial
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
	if (!(d->iam_a_slave))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
		msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
		msg.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
		msg.data[0] = 90 + flag;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
int lss_InquireLSSAddress_slave(CO_Data *d, int cs)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
	if (!(d->iam_a_slave)) /* not a slave */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
		return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
	UNS32 value = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
	switch(cs)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
		case 90:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
			value = 0; /* = vendor id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
		case 91:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
			value = 0; /* = product code */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
		case 92:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
			value = 0; /* = revision */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
		case 93:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
			value = 0; /* = serial */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
	if (value > 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
		msg.cob_id.w = 0x07E4 /* 2020 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
		msg.len=5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
		msg.data[0] = cs;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
		lss_copy(msg.data+1, value);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
		return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
	return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
void lss_IdentifyRemoteSlaves(CO_Data *d, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
                              UNS32 vendor_id,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
                              UNS32 product_code,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
                              UNS32 rev_low,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
                              UNS32 rev_high,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
                              UNS32 serial_low,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
                              UNS32 serial_high)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
	throught this service, the LSS Master requests all LSS slave whose LSS address
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
	meets the LSSaddr_sel to idenfity themselves through LSS Identify Slave
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
	if (!(d->iam_a_slave))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
		/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
			request answers from all slaves corresponding
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
			to the revision and serial range of values
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
		*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
		msg.cob_id.w = 0x07E5 /* 2021 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
		msg.len=5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
		msg.data[0] = 70;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
		lss_copy(msg.data+1, vendor_id);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
		msg.data[0] = 71;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
		lss_copy(msg.data+1, product_code); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
		msg.data[0] = 72; /* revision number low */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
		lss_copy(msg.data+1, rev_low);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
		msg.data[0] = 73; /* revision number high */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
		lss_copy(msg.data+1, rev_high);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
		msg.data[0] = 74; /* serial number low */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
		lss_copy(msg.data+1, serial_low);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
		msg.data[0] = 75; /* serial number high */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
		lss_copy(msg.data+1, serial_high);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
int lss_validate_range_addr(CO_Data *d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
	/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
		if 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   573
		lss_buffer[4] == vendor_id
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
		lss_buffer[5] == product code
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
		lss_buffer[6] <= revision <= lss_buffer[7]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
		lss_buffer[8] <= serial <= lss_buffer[9]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   578
		then return 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
		else return 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
	*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
	UNS32  r, vendor_id, product_code, revision_number, serial_number;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
	UNS8   sz = sizeof(UNS32), dt = int32;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
	r = getODentry(d, 0x1018, 1, (void *)&vendor_id, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
	r = getODentry(d, 0x1018, 2, (void *)&product_code, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
	r = getODentry(d, 0x1018, 3, (void *)&revision_number, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
	r = getODentry(d, 0x1018, 4, (void *)&serial_number, &sz, &dt, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
	if (lss_buffer[4] == vendor_id  &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
	    lss_buffer[5] == product_code &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
	    lss_buffer[6] <= revision_number &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
	    revision_number <= lss_buffer[7] &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
	    lss_buffer[8] <= serial_number &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
	    serial_number <= lss_buffer[9])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
		return 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
void lss_IdentifySlave(CO_Data *d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   605
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
	through this service, an LSS slave indicates that it is a slave
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
	with LSS address within the LSSaddr_sel
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
	Message msg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   611
	lss_init_msg(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
	if (lss_validate_range_addr(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
		msg.cob_id.w = 0x07E4 /* 2020 */;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
		msg.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
		msg.data[0] = 79;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
		/* transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   621
		(*d->canSend)(&msg);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   623
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
	/* reset */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
	lss_buffer[4] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
	lss_buffer[5] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
	lss_buffer[6] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
	lss_buffer[7] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
	lss_buffer[8] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
	lss_buffer[9] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
int lss_process_msg(CO_Data *d, Message *msg)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
	/* process the incoming message */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
	if (msg->cob_id.w == 0x07E4 /* 2020 */)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
		// should be the master
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
		// a slave just answered
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
		switch(msg->data[0])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
		{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
			/* slave acknowledging the SwitchModeSelective call */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
			case 68: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
				/* msg->data[1] contains the 'mode global' value from the slave*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
			/* a slave had acknowledged the call from LSS Identify Remote Slave */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
			case 79:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
			/* the slave acknowledged and sent the requested data */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
			case 90:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   654
				lss_buffer[0] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
				/* action ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
			case 91:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
				lss_buffer[1] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
				/* action ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
			case 92:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
				lss_buffer[2] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
				/* action ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
			case 93:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
				lss_buffer[3] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
				/* action ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
		}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
	else if (msg->cob_id.w == 0x07E5 /* 2021 */)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
		// should be a slave
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
		// the master sent a request
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
		switch(msg->data[0])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
		{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
			case 4:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
				lss_SwitchModeGlobal(d, msg->data[1]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
			case 17:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
				lss_ConfigureNode_ID(d, msg->data[1]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
			case 19:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
				lss_ConfigureBitTimingParameters(d, msg->data[1], msg->data[2]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
			case 21:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
				lss_ActivateBitTimingParameters_slave(msg->data[1], msg->data[2]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
			/* Switch Mode Selective */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
			case 64:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
				lss_buffer[0] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
			case 65:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
				lss_buffer[1] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
			case 66:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
				lss_buffer[2] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
			case 67:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
				lss_buffer[3] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
				lss_SwitchModeSelective_slave(d);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
			/* Identify Remote Slave */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
			case 70:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
				lss_buffer[4] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
			case 71:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
				lss_buffer[5] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
			case 72:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
				lss_buffer[6] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   718
			case 73:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
				lss_buffer[7] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
			case 74:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
				lss_buffer[8] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
			case 75:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
				lss_buffer[9] = lss_get_value(msg->data+1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
				lss_IdentifySlave(d);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   727
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   728
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
			/* Inquire Identify of Slave */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
			case 90:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
			case 91:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   732
			case 92:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
			case 93:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
				lss_InquireLSSAddress_slave(d, msg->data[0]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
				break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
		}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   739
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
}