S32 SDK
lin_diagnostic_service.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
33 #include "lin_commontl_api.h"
34 #include "lin_diagnostic_service.h"
35 
36 #if (SUPPORT_TRANSPORT_LAYER == 1U)
37 #if (SUPPORT_DIAG_SERVICE == 1U)
38 #if (SUPPORT_SLAVE_MODE == 1U)
39 /*******************************************************************************
40  * Static function prototypes
41  ******************************************************************************/
42 #if (SUPPORT_PROTOCOL_21 == 1U)
43 static void lin_diagservice_assign_frame_id_range(l_ifc_handle iii);
44 
45 static void lin_assign_nad(l_ifc_handle iii);
46 
47 static void lin_condittional_change_nad(l_ifc_handle iii);
48 #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
49 
50 static void lin_diagservice_read_by_identifier(l_ifc_handle iii);
51 
52 static void ld_make_slave_response_pdu(l_ifc_handle iii,
53  l_u8 sid,
54  l_u8 res_type,
55  l_u8 error_code);
56 
57 #if (SUPPORT_PROTOCOL_J2602 == 1U)
58 static l_bool ld_change_msg_id(l_ifc_handle iii,
59  l_u8 dnn,
60  l_u8 frame_id_change);
61 
62 static void lin_diagservice_target_reset(l_ifc_handle iii);
63 
64 static void lin_diagservice_assign_frame_id(l_ifc_handle iii);
65 
66 #endif /* End (SUPPORT_PROTOCOL_J2602 == 1U) */
67 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
68 /*******************************************************************************
69  * Code
70  ******************************************************************************/
71 #if (SUPPORT_PROTOCOL_21 == 1U)
72 #if (SUPPORT_MASTER_MODE == 1U)
73 /*FUNCTION**********************************************************************
74  *
75  * Function Name : ld_is_ready
76  * Description : This call returns the status of the last requested configuration service
77  *
78  * Implements : ld_is_ready_Activity
79  *END**************************************************************************/
80 l_u8 ld_is_ready(l_ifc_handle iii)
81 {
82  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
83 
84  l_u8 ret_val;
85  if (g_lin_protocol_user_cfg_array[iii].function == (bool)LIN_MASTER)
86  {
87  ret_val = (l_u8)(g_lin_tl_descriptor_array[iii].service_status);
88  }
89  else
90  {
91  ret_val = 0xFF;
92  }
93 
94  return ret_val;
95 }
96 
97 /*FUNCTION**********************************************************************
98  *
99  * Function Name : ld_check_response
100  * Description : This call returns the result of the last node configuration service, in the
101  * parameters RSID and error_code. A value in RSID is always returned but not always in the
102  * error_code. Default values for RSID and error_code is 0 (zero).
103  *
104  * Implements : ld_check_response_Activity
105  *END**************************************************************************/
106 void ld_check_response(l_ifc_handle iii,
107  l_u8 * const RSID,
108  l_u8 * const error_code)
109 {
110  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
111  DEV_ASSERT(RSID != NULL);
112  DEV_ASSERT(error_code != NULL);
113  const lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
114 
115  if (g_lin_protocol_user_cfg_array[iii].function == (bool)LIN_MASTER)
116  {
117  /* Get last response service identifier */
118  *RSID = tl_desc_ptr->last_RSID;
119  /* Set error_code to the default value - zero */
120  *error_code = 0;
121  /* Get the error code of the last config service if it is negative response */
122  if (LD_NEGATIVE == (tl_desc_ptr->last_cfg_result))
123  {
124  *error_code = tl_desc_ptr->ld_error_code;
125  }
126  }
127 }
128 
129 /*FUNCTION**********************************************************************
130  *
131  * Function Name : ld_assign_frame_id_range
132  * Description : This function assigns the protected identifier of up to four frames
133  *
134  * Implements : ld_assign_frame_id_range_Activity
135  *END**************************************************************************/
136 void ld_assign_frame_id_range(l_ifc_handle iii,
137  l_u8 NAD,
138  l_u8 start_index,
139  const l_u8 * const PIDs)
140 {
141  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
142  DEV_ASSERT(PIDs != NULL);
143  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
144  l_u8 buff[6];
145 
146  /* Check if this interface is a LIN Master */
147  if (g_lin_protocol_user_cfg_array[iii].function == (bool)LIN_MASTER)
148  {
149  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
150  {
151  /* pack data into a single frame */
152  /* Buffer[0] SID of Service Assign Frame ID Range: 0xB7 */
154  buff[1] = start_index;
155  buff[2] = PIDs[0];
156  buff[3] = PIDs[1];
157  buff[4] = PIDs[2];
158  buff[5] = PIDs[3];
159 
160  /* put data into TX_QUEUE */
161  ld_send_message(iii, 6U, NAD, buff);
162 
163  /* set node config status to busy */
164  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
165  } /* End of checking service status */
166  }
167 }
168 
169 /*FUNCTION**********************************************************************
170  *
171  * Function Name : ld_save_configuration
172  * Description : This function is for Master nodes only. This call will make a
173  * save configuration request to a specific slave node with the given
174  * NAD, or to all slave nodes if NAD is set to broadcast.
175  *
176  * Implements : ld_save_configuration_Activity
177  *END**************************************************************************/
178 void ld_save_configuration(l_ifc_handle iii,
179  l_u8 NAD)
180 {
181  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
182 
183  l_u8 data[6];
184  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
185 
186  /* Check if this interface is a LIN Master */
187  if (g_lin_protocol_user_cfg_array[iii].function == (bool)LIN_MASTER)
188  {
189  /* check service is busy? */
190  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
191  {
192  data[0] = SERVICE_SAVE_CONFIGURATION;
193  data[1] = 0xFFU;
194  data[2] = 0xFFU;
195  data[3] = 0xFFU;
196  data[4] = 0xFFU;
197  data[5] = 0xFFU;
198 
199  /* put data into TX_QUEUE */
200  ld_send_message(iii, PCI_SAVE_CONFIGURATION, NAD, data);
201 
202  /* set node config status to busy */
203  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
204  } /* End of checking service status */
205  }
206 }
207 
208 #endif /* End (SUPPORT_MASTER_NODE == 1U) */
209 #if (SUPPORT_SLAVE_MODE == 1U)
210 #if (SUPPORT_PROTOCOL_21 == 1U)
211 /*FUNCTION**********************************************************************
212  *
213  * Function Name : lin_condittional_change_nad
214  * Description : Process Conditional Change NAD request
215  *
216  * Implements : lin_condittional_change_nad_Activity
217  *END**************************************************************************/
218 static void lin_condittional_change_nad(l_ifc_handle iii)
219 {
220  l_u8 id;
221  l_u8 byte;
222  l_u8 mask;
223  l_u8 invert;
224  l_bool give_positive_flg = (bool)0U;
226  const lin_transport_layer_queue_t * rx_queue;
227  lin_product_id_t product_id = node_attr_ptr->product_id;
228  lin_serial_number_t serial_number = node_attr_ptr->serial_number;
229 
230  /* Get receive queue */
231  rx_queue = &(g_lin_tl_descriptor_array[iii].tl_rx_queue);
232  id = rx_queue->tl_pdu_ptr[rx_queue->queue_header][3];
233  byte = rx_queue->tl_pdu_ptr[rx_queue->queue_header][4];
234  mask = rx_queue->tl_pdu_ptr[rx_queue->queue_header][5];
235  invert = rx_queue->tl_pdu_ptr[rx_queue->queue_header][6];
236 
237  switch (id)
238  {
239  case LIN_PRODUCT_ID:
240  if ((byte > 0U) && (byte < 6U))
241  {
242  /*Byte 1: Supplier ID LSB; Byte 2: Supplier ID MSB*/
243  if ((byte > 0U) && (byte < 3U))
244  {
245  byte = (l_u8)(product_id.supplier_id >> ((byte - 1U) * 8U));
246  }
247  /*Byte 3: Function ID LSB; Byte 4: Function ID MSB*/
248  else if ((byte > 2U) && (byte < 5U))
249  {
250  byte = (l_u8)(product_id.function_id >> ((byte - 3U) * 8U));
251  }
252  /* Byte 5: Variant */
253  else
254  {
255  byte = product_id.variant;
256  }
257 
258  /* Do a bitwise XOR with Invert and Do a bitwise AND with Mask */
259  byte = (l_u8)((byte ^ invert) & mask);
260  if (byte == 0U)
261  {
262  give_positive_flg = (l_bool)1U;
263  }
264  }
265 
266  break;
267  case LIN_SERIAL_NUMBER:
268  if ((byte > 0U) && (byte < 5U))
269  {
270  switch (byte)
271  {
272  case 1U:
273  byte = serial_number.serial_0;
274  break;
275  case 2U:
276  byte = serial_number.serial_1;
277  break;
278  case 3U:
279  byte = serial_number.serial_2;
280  break;
281  case 4U:
282  byte = serial_number.serial_3;
283  break;
284  default:
285  /* Do nothing */
286  break;
287  }
288 
289  /* Do a bitwise XOR with Invert and Do a bitwise AND with Mask */
290  byte = (l_u8)((byte ^ invert) & mask);
291  if (byte == 0U)
292  {
293  give_positive_flg = (l_bool)1U;
294  }
295  }
296 
297  break;
298  default:
299  /* Do nothing */
300  break;
301  }
302 
303  if (give_positive_flg == (bool)1U)
304  {
305  /* Make response PDU before change configuration NAD */
307  /* If the final result is zero then change the NAD to New NAD */
308  *node_attr_ptr->configured_NAD_ptr = rx_queue->tl_pdu_ptr[rx_queue->queue_header][7];
309  }
310 }
311 
312 /*FUNCTION**********************************************************************
313  *
314  * Function Name : lin_assign_nad
315  * Description : Process lin assign nad request
316  *
317  * Implements : lin_assign_nad_Activity
318  *END**************************************************************************/
319 static void lin_assign_nad(l_ifc_handle iii)
320 {
321  lin_tl_pdu_data_t lin_tl_pdu;
322  l_u16 supid;
323  l_u16 fid;
324  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
325  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
326  lin_product_id_t product_id = g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle].product_id;
327  const lin_transport_layer_queue_t * rx_queue = &(tl_desc_ptr->tl_rx_queue);
328  l_u8 i;
329  for (i = 0; i < 8U; i++)
330  {
331  lin_tl_pdu[i] = rx_queue->tl_pdu_ptr[rx_queue->queue_header][i];
332  }
333 
334  /* Get supplier and function identification in request */
335  supid = (l_u16)(((l_u16)lin_tl_pdu[4]) << 8U);
336  supid = (l_u16)(supid | ((l_u16)lin_tl_pdu[3]));
337 
338  fid = (l_u16)(((l_u16)lin_tl_pdu[6]) << 8U);
339  fid = (l_u16)(fid | ((l_u16)lin_tl_pdu[5]));
340 
341  /* Check Supplier ID and Function ID */
342  if (((supid != product_id.supplier_id) && (supid != LD_ANY_SUPPLIER)) ||
343  ((fid != product_id.function_id) && (fid != LD_ANY_FUNCTION)))
344  {
345  tl_desc_ptr->slave_resp_cnt = 0U;
346  }
347  else
348  {
350  }
351 }
352 
353 /*FUNCTION**********************************************************************
354  *
355  * Function Name : lin_diagservice_assign_frame_id_range
356  * Description : This function to process assign frame id range request, and also prepare its response data.
357  * This function is only for Slave Node.
358  *
359  * Implements : lin_diagservice_assign_frame_id_range_Activity
360  *END**************************************************************************/
361 static void lin_diagservice_assign_frame_id_range(l_ifc_handle iii)
362 {
363  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
364 
365  l_u8 j;
366  l_u8 i;
367  l_u8 start_index;
368  l_u8 cfg_frame_num = 0U;
369  lin_tl_pdu_data_t lin_tl_pdu;
370  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
372  l_u8 storePID = 1U;
373  for (i = 0; i < 8U; i++)
374  {
375  lin_tl_pdu[i] = rx_queue->tl_pdu_ptr[rx_queue->queue_header][i];
376  }
377 
378  /* Get start index in request */
379  start_index = lin_tl_pdu[3];
380 
381  /* Find the number of configurable frames plus 2, including 0x3C and 0x3D */
382  i = 1U;
383  while (0xFFFFU != (prot_user_config_ptr->list_identifiers_ROM_ptr)[i++])
384  {
385  cfg_frame_num++;
386  }
387 
388  /* Calculate number of configurable frames */
389  cfg_frame_num = (l_u8)(cfg_frame_num - 3U);
390 
391  i = 4U;
392  /* Check request validity */
393  for (j = start_index; j < (start_index + 4U); j++)
394  {
395  if ((0xFFU != lin_tl_pdu[i++]) && (j > cfg_frame_num))
396  {
398  storePID = 0U;
399  break;
400  }
401  }
402 
403  if (storePID == 1U)
404  {
405  /* Store PIDs */
406  for (i = 4U; i < 8U; i++)
407  {
408  switch (lin_tl_pdu[i])
409  {
410  case 0x00U:
411  /* Unassign frame */
412  start_index++;
413  (prot_user_config_ptr->list_identifiers_RAM_ptr)[start_index] = 0xFFU;
414  break;
415  case 0xFFU:
416  /* keep the previous assigned value of this frame */
417  break;
418  default:
419  /* Calculate frame ID and Assign ID to frame */
420  start_index++;
421  (prot_user_config_ptr->list_identifiers_RAM_ptr)[start_index] = lin_process_parity(lin_tl_pdu[i], CHECK_PARITY);
422  break;
423  }
424  } /* End of for statement */
425 
427  }
428 }
429 #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
430 
431 /*FUNCTION**********************************************************************
432  *
433  * Function Name : ld_read_configuration
434  * Description : This function copies current configuration in a reserved area.
435  *
436  * Implements : ld_read_configuration_Activity
437  *END**************************************************************************/
438 l_u8 ld_read_configuration(l_ifc_handle iii,
439  l_u8 * const data,
440  l_u8 * const length)
441 {
442  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
443  DEV_ASSERT(data != NULL);
444  DEV_ASSERT(length != NULL);
445 
446  l_u8 i, temp;
447  const lin_node_attribute_t * node_attr_ptr;
448  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
449  /* Set the default returned value to LD_READ_OK */
450  l_u8 retval = (l_u8)LD_READ_OK;
458  l_u8 expected_length;
459 
460  expected_length = (l_u8)(prot_user_config_ptr->number_of_configurable_frames - 1U);
461  /* Check if slave node */
462  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
463  {
464  temp = *length;
465  /* Get node attribute */
466  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
467  if (temp < expected_length)
468  {
469  /* The 'data' size is not enough to store NAD+PIDs */
470  retval = (l_u8)LD_LENGTH_TOO_SHORT;
471  }
472  else
473  {
474  /* The 'data' size is enough to store NAD+PIDs, so proceed to store them */
475  /* Copy actual NAD to 'data' */
476  data[0] = *node_attr_ptr->configured_NAD_ptr;
477 
478  /* Copy protected IDs to 'data' */
479  for (i = 1U; i < expected_length; i++)
480  {
481  data[i] = prot_user_config_ptr->list_identifiers_RAM_ptr[i];
482  }
483 
484  /* Set the length parameter to the actual size of the configuration */
485  *length = expected_length;
486  }
487  }
488  else
489  {
490  retval = 0xFFU;
491  }
492 
493  return retval;
494 } /* End ld_read_configuration() */
495 
496 /*FUNCTION**********************************************************************
497  *
498  * Function Name : ld_set_configuration
499  * Description : This function configures slave node according to data.
500  *
501  * Implements : ld_set_configuration_Activity
502  *END**************************************************************************/
503 l_u8 ld_set_configuration(l_ifc_handle iii,
504  const l_u8 * const data,
505  l_u16 length)
506 {
507  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
508  DEV_ASSERT(data != NULL);
509 
510  l_u8 i;
511  /* Set the default returned value to LD_DATA_ERROR */
512  l_u8 retval = LD_DATA_ERROR;
513  const lin_node_attribute_t * node_attr_ptr;
514  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
522  l_u16 expected_length;
523 
524  expected_length = (l_u16)((l_u16)prot_user_config_ptr->number_of_configurable_frames - 1U);
525 
526  /* Check if slave node */
527  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
528  {
529  /* Get node attribute */
530  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
531  if (length < expected_length)
532  {
533  /* The 'data' size is not enough to contain NAD+PIDs */
534  retval = LD_LENGTH_NOT_CORRECT;
535  }
536  else
537  {
538  /* The 'data' size is enough to contain NAD+PIDs, so proceed to read from 'data' */
539  /* Read actual NAD from 'data' */
540  *node_attr_ptr->configured_NAD_ptr = data[0];
541 
542  /* Copy protected IDs in 'data' to RAM configuration */
543  for (i = 1U; i < expected_length; ++i)
544  {
545  prot_user_config_ptr->list_identifiers_RAM_ptr[i] = data[i];
546  }
547 
548  /* No error, return OK */
549  retval = LD_SET_OK;
550  }
551  }
552  else
553  {
554  retval = 0xFFU;
555  }
556 
557  return retval;
558 } /* End ld_set_configuration() */
559 
560 #endif /* end (SUPPORT_SLAVE_MODE == 1U) */
561 
562 /* diagnostic services class II */
563 #if (SUPPORT_DIAG_CLASS_II == 1U)
564 /*FUNCTION**********************************************************************
565  *
566  * Function Name : diag_read_data_by_identifier
567  * Description : This function reads data by identifier, Diagnostic Class II service (0x22).
568  *
569  * Implements : diag_read_data_by_identifier_Activity
570  *END**************************************************************************/
571 void diag_read_data_by_identifier(l_ifc_handle iii,
572  const l_u8 NAD,
573  const l_u8 * const data)
574 {
575  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
576  DEV_ASSERT(data != NULL);
577 
578  l_u8 buff[3];
579  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
580  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
581 
582  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
583  {
584  /* check whether service status is idle or not */
585  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
586  {
587  /* check whether input data contains correct data */
588 
589  /* pack data */
590  /* Buffer[0] SID of Service Read Data by Identifier: 0x22 */
592  buff[1] = data[0];
593  buff[2] = data[1];
594 
595  /* send message to transport layer */
596  ld_send_message(iii, 3U, NAD, buff);
597 
598  /* set service status to busy */
599  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
600  }
601  }
602 }
603 
604 /*FUNCTION**********************************************************************
605  *
606  * Function Name : diag_write_data_by_identifier
607  * Description : Write Data by Identifier for a specified node - Diagnostic Class II service (0x2E)
608  *
609  * Implements : diag_write_data_by_identifier_Activity
610  *END**************************************************************************/
611 void diag_write_data_by_identifier(l_ifc_handle iii,
612  const l_u8 NAD,
613  l_u16 data_length,
614  const l_u8 * const data)
615 {
616  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
617  DEV_ASSERT(data != NULL);
618 
619  l_u8 buff[MAX_LENGTH_SERVICE];
620  l_u8 i;
621  l_u16 temp = 0U;
622  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
623  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
625 
626  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
627  {
628  /* Check if length of data is less than length maximum */
629  if (data_length < length)
630  {
631  /* check whether service status is idle or not */
632  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
633  {
634  /* check whether input data contains correct data */
635  temp = data[0];
636  temp <<= 8U;
637  temp |= data[1];
638 
639  /* pack data */
640  /* Buffer[0] SID of Write Data by identifier: 0x2E */
642 
643  if ((temp == 0x0092U) || (temp == 0x0205U))
644  {
645  for (i = 0U; i < data_length; i++)
646  {
647  buff[i + 1U] = data[i];
648  }
649 
650  ld_send_message(iii, data_length + 1U, NAD, buff);
651  /* set service status to busy */
652  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
653  }
654  }
655  }
656  }
657 }
658 
659 #endif /*(SUPPORT_DIAG_CLASS_II == 1U)*/
660 
661 /* Diagnostic services class III */
662 #if (SUPPORT_DIAG_CLASS_III == 1U)
663 /*FUNCTION**********************************************************************
664  *
665  * Function Name : diag_session_control
666  * Description : This function is used for master node only. It will pack data
667  * and send request to slave node with service ID = 0x10: Session control.
668  *
669  * Implements : diag_session_control_Activity
670  *END**************************************************************************/
671 void diag_session_control(l_ifc_handle iii,
672  const l_u8 NAD,
673  l_u16 data_length,
674  const l_u8 * const data)
675 {
676  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
677  DEV_ASSERT(data != NULL);
678 
679  l_u8 buff[MAX_LENGTH_SERVICE];
680  l_u8 i;
681  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
683  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
684 
685  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
686  {
687  /* Check if length of data is less than length maximum */
688  if (data_length < length)
689  {
690  /* check whether service status is idle or not */
691  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
692  {
693  /* pack data */
694  /* Buffer[0] SID of Session Control: 0x10 */
695  buff[0] = SERVICE_SESSION_CONTROL;
696 
697  for (i = 0U; i < data_length; i++)
698  {
699  buff[i + 1U] = data[i];
700  }
701 
702  ld_send_message(iii, data_length + 1U, NAD, buff);
703  /* set service status to busy */
704  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
705  }
706  }
707  }
708 }
709 
710 /*FUNCTION**********************************************************************
711  *
712  * Function Name : diag_fault_memory_read
713  * Description : This function is used for master node only. It will pack data
714  * and send request to slave node with service ID = 0x19: Fault memory read.
715  *
716  * Implements : diag_fault_memory_read_Activity
717  *END**************************************************************************/
718 void diag_fault_memory_read(l_ifc_handle iii,
719  const l_u8 NAD,
720  l_u16 data_length,
721  const l_u8 * const data)
722 {
723  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
724  DEV_ASSERT(data != NULL);
725 
726  l_u8 buff[MAX_LENGTH_SERVICE];
727  l_u8 i;
728  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
730  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
731 
732  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
733  {
734  /* Check if length of data is lower than length maximum */
735  if (data_length < length)
736  {
737  /* check whether service status is idle or not */
738  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
739  {
740  /* pack data */
741  /* Buffer[0] SID of Service fault memory read: 0x19 */
742  buff[0] = SERVICE_FAULT_MEMORY_READ;
743 
744  for (i = 0U; i < data_length; i++)
745  {
746  buff[i + 1U] = data[i];
747  }
748 
749  ld_send_message(iii, data_length + 1U, NAD, buff);
750  /* set service status to busy */
751  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
752  }
753  }
754  }
755 }
756 
757 /*FUNCTION**********************************************************************
758  *
759  * Function Name : diag_fault_memory_clear
760  * Description : This function is used for master node only. It will pack data
761  * and send request to slave node with service ID = 0x14: Fault memory clear.
762  *
763  * Implements : diag_fault_memory_clear_Activity
764  *END**************************************************************************/
765 void diag_fault_memory_clear(l_ifc_handle iii,
766  const l_u8 NAD,
767  l_u16 data_length,
768  const l_u8 * const data)
769 {
770  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
771  DEV_ASSERT(data != NULL);
772 
773  l_u8 buff[MAX_LENGTH_SERVICE];
774  l_u8 i;
775  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
777  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
778  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
779  {
780  /* Check if length of data is lower than length maximum */
781  if (data_length < length)
782  {
783  /* check whether service status is idle or not */
784  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
785  {
786  /* pack data */
787  /* Buffer[0] SID of Service fault memory clear: 0x14 */
788  buff[0] = SERIVCE_FAULT_MEMORY_CLEAR;
789 
790  for (i = 0U; i < data_length; i++)
791  {
792  buff[i + 1U] = data[i];
793  }
794 
795  ld_send_message(iii, data_length + 1U, NAD, buff);
796  /* set service status to busy */
797  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
798  }
799  }
800  }
801 }
802 
803 /*FUNCTION**********************************************************************
804  *
805  * Function Name : diag_IO_control
806  * Description : This function is used for master node only. It will pack data
807  * and send request to slave node with service ID = 0x2F: Input/Output control service.
808  *
809  * Implements : diag_IO_control_Activity
810  *END**************************************************************************/
811 void diag_IO_control(l_ifc_handle iii,
812  const l_u8 NAD,
813  l_u16 data_length,
814  const l_u8 * const data)
815 {
816  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
817  DEV_ASSERT(data != NULL);
818 
819  l_u8 buff[MAX_LENGTH_SERVICE];
820  l_u8 i;
821  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
823  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
824  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
825  {
826  /* Check if length of data is lower than length maximum */
827  if (data_length < length)
828  {
829  /* check whether service status is idle or not */
830  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
831  {
832  /* pack data */
833  /* Buffer[0] SID of IO Control by Identify: 0x2F */
835 
836  for (i = 0U; i < data_length; i++)
837  {
838  buff[i + 1U] = data[i];
839  }
840 
841  ld_send_message(iii, data_length + 1U, NAD, buff);
842  /* set service status to busy */
843  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
844  }
845  }
846  }
847 }
848 
849 #endif /* End (SUPPORT_DIAG_CLASS_III == 1U) */
850 #endif /* End (LIN_PROTOCOL == PROTOCOL_21) */
851 
852 /*FUNCTION**********************************************************************
853  *
854  * Function Name : ld_assign_NAD
855  * Description : This call assigns the NAD (node diagnostic address) of all slave nodes
856  * that matches the initial_NAD, the supplier ID and the function ID.
857  *
858  * Implements : ld_assign_NAD_Activity
859  *END**************************************************************************/
860 void ld_assign_NAD(l_ifc_handle iii,
861  l_u8 initial_NAD,
862  l_u16 supplier_id,
863  l_u16 function_id,
864  l_u8 new_NAD)
865 {
866  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
867 
868  l_u8 data[6];
869  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
870  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
871 
872  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
873  {
874  /* check service is busy? */
875  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
876  {
877  /* data[0] SID of Service assign NAD: 0xB0 */
878  data[0] = SERVICE_ASSIGN_NAD;
879  data[1] = (l_u8)(supplier_id & 0x00FFU);
880  data[2] = (l_u8)((supplier_id >> 8U) & 0x00FFU);
881  data[3] = (l_u8)(function_id & 0x00FFU);
882  data[4] = (l_u8)((function_id >> 8U) & 0x00FFU);
883  data[5] = new_NAD;
884 
885  /* put data into TX_QUEUE */
886  ld_send_message(iii, 6U, initial_NAD, data);
887 
888  /* set node config status to busy */
889  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
890  } /* End of checking service status */
891  }
892 }
893 
894 /*FUNCTION**********************************************************************
895  *
896  * Function Name : ld_conditional_change_NAD
897  * Description : This call changes the NAD
898  * if the node properties fulfill the test specified by id, byte, mask and invert.
899  *
900  * Implements : ld_conditional_change_NAD_Activity
901  *END**************************************************************************/
902 void ld_conditional_change_NAD(l_ifc_handle iii,
903  l_u8 NAD,
904  l_u8 id,
905  l_u8 byte_data,
906  l_u8 mask,
907  l_u8 invert,
908  l_u8 new_NAD)
909 {
910  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
911 
912  l_u8 data[6];
913  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
914  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
915 
916  /* Check input parameters are in accepted range*/
917  if ((id < 32U) && ((0U < byte_data) && (byte_data < 6U)))
918  {
919  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
920  {
921  /* check service is busy? */
922  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
923  {
924  /* data[0] SID of Service Conditional change NAD: 0xB3 */
926  data[1] = id;
927  data[2] = byte_data;
928  data[3] = mask;
929  data[4] = invert;
930  data[5] = new_NAD;
931 
932  /* put data into TX_QUEUE */
933  ld_send_message(iii, 6U, NAD, data);
934 
935  /* set node config status to busy */
936  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
937  } /* End of checking service status */
938  }
939  }
940 }
941 
942 /*FUNCTION**********************************************************************
943  *
944  * Function Name : ld_read_by_id
945  * Description : The call requests the slave node selected with the NAD
946  * to return the property associated with the id parameter.
947  *
948  * Implements : ld_read_by_id_Activity
949  *END**************************************************************************/
950 void ld_read_by_id(l_ifc_handle iii,
951  l_u8 NAD,
952  l_u16 supplier_id,
953  l_u16 function_id,
954  l_u8 id,
955  lin_product_id_t * const data)
956 {
957  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
958  DEV_ASSERT(data != NULL);
959 
960  /* Multi frame support */
961  l_u8 buff[6];
962  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
963  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
964 
965  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
966  {
967  /* Check service is busy? */
968  if (tl_desc_ptr->service_status != LD_SERVICE_BUSY)
969  {
970  /* Create data for Read by Identifier command */
971  /* Buffer[0] SID of Service Read by identifier: 0xB2 */
972  buff[0] = SERVICE_READ_BY_IDENTIFY;
973  buff[1] = id;
974  buff[2] = (l_u8)(supplier_id & 0x00FFU);
975  buff[3] = (l_u8)((supplier_id >> 8U) & 0x00FFU);
976  buff[4] = (l_u8)(function_id & 0x00FFU);
977  buff[5] = (l_u8)((function_id >> 8U) & 0x00FFU);
978 
979  /* Store address of RAM data which contain response info */
980  tl_desc_ptr->product_id_ptr = data;
981 
982  /* put data into TX_QUEUE */
983  ld_send_message(iii, 6U, NAD, buff);
984 
985  /* set node config status to busy */
986  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
987  } /* End of checking service status */
988  }
989 }
990 
991 #if (SUPPORT_SLAVE_MODE == 1U)
992 /*FUNCTION**********************************************************************
993  *
994  * Function Name : diag_get_flag
995  * Description : This function will return flag of diagnostic service,
996  * if LIN node receive master request or slave response.
997  *
998  * Implements : diag_get_flag_Activity
999  *END**************************************************************************/
1000 l_u8 diag_get_flag(l_ifc_handle iii,
1001  l_u8 flag_order)
1002 {
1003  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1004  const l_u8 * service_flag;
1005  l_u8 ret_val = 0xFFU;
1006  const lin_node_attribute_t * node_attr_ptr;
1007  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1008 
1009  if (prot_user_config_ptr->function == (bool)LIN_SLAVE)
1010  {
1011  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
1012  service_flag = node_attr_ptr->service_flags_ptr;
1013 
1014  if (flag_order < node_attr_ptr->number_support_sid)
1015  {
1016  ret_val = (l_u8)service_flag[flag_order];
1017  }
1018  }
1019 
1020  return ret_val;
1021 }
1022 
1023 /*FUNCTION**********************************************************************
1024  *
1025  * Function Name : diag_clear_flag
1026  * Description : This function will clear flag of diagnostic service,
1027  * if lin node receive master request or slave response.
1028  *
1029  * Implements : diag_clear_flag_Activity
1030  *END**************************************************************************/
1031 void diag_clear_flag(l_ifc_handle iii,
1032  l_u8 flag_order)
1033 {
1034  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1035  l_u8 * service_flag;
1036  const lin_node_attribute_t * node_attr_ptr;
1037  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1038 
1039  if (prot_user_config_ptr->function == (bool)LIN_SLAVE)
1040  {
1041  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
1042  /* Get current configuration */
1043  service_flag = node_attr_ptr->service_flags_ptr;
1044 
1045  if (flag_order < node_attr_ptr->number_support_sid)
1046  {
1047  service_flag[flag_order] = 0U;
1048  }
1049  }
1050 }
1051 
1052 /*FUNCTION**********************************************************************
1053  *
1054  * Function Name : lin_diag_service_callback
1055  * Description : Callback handler for dispatching diagnostic services
1056  *
1057  * Implements : lin_diag_service_callback_Activity
1058  *END**************************************************************************/
1059 void lin_diag_service_callback(l_ifc_handle iii,
1060  l_u8 sid)
1061 {
1062  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1063  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1064  const lin_node_attribute_t * node_attr_ptr;
1065  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
1066  l_bool sid_supported_flg = (bool)0U;
1067  l_u8 i;
1068  const l_u8 * service_supported_ptr;
1069  l_u8 * service_flag_ptr;
1070  /* Get support sid */
1071  service_supported_ptr = node_attr_ptr->service_supported_ptr;
1072  /* Get service flag */
1073  service_flag_ptr = node_attr_ptr->service_flags_ptr;
1074 
1075  for (i = 0U; i < node_attr_ptr->number_support_sid; i++)
1076  {
1077  if (service_supported_ptr[i] == sid)
1078  {
1079  service_flag_ptr[i] = 1U;
1080  sid_supported_flg = (bool)1U;
1081  break;
1082  }
1083  }
1084 
1085  if (sid_supported_flg == (bool)1U)
1086  {
1087  /* Check whether or not the Service is supported by the Slave node */
1088  switch (sid)
1089  {
1090  case SERVICE_READ_BY_IDENTIFY: /* Mandatory for TL LIN 2.1 & 2.0, Optional for J2602 */
1092  break;
1093  #if (SUPPORT_PROTOCOL_21 == 1U)
1096  break;
1097  case SERVICE_ASSIGN_NAD:
1098  lin_assign_nad(iii);
1099  break;
1100  case SERVICE_ASSIGN_FRAME_ID_RANGE: /* Mandatory for TL LIN 2.1 */
1101  if (LIN_PROTOCOL_21 == prot_user_config_ptr->protocol_version)
1102  {
1104  }
1105  break;
1107  /* Set save configuration flag */
1108  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
1109  {
1111  }
1112  else
1113  {
1115  }
1116  /* Response to master - RSID */
1118  break;
1119  #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
1120  #if (SUPPORT_PROTOCOL_J2602 == 1U)
1121  case SERVICE_TARGET_RESET:
1122  if (LIN_PROTOCOL_J2602 == prot_user_config_ptr->protocol_version)
1123  {
1125  }
1126  break;
1128  if (LIN_PROTOCOL_J2602 == prot_user_config_ptr->protocol_version)
1129  {
1131  }
1132  break;
1133  #endif /* (End SUPPORT_PROTOCOL_J2602 == 1U) */
1134  default:
1135  /* do nothing */
1136  break;
1137  } /* end of switch */
1138  }
1139  else
1140  {
1142  /* clear queue */
1143  tl_desc_ptr->tl_rx_queue.queue_status = LD_NO_DATA;
1144  tl_desc_ptr->tl_rx_queue.queue_current_size = 0U;
1145  tl_desc_ptr->tl_rx_queue.queue_header = tl_desc_ptr->tl_rx_queue.queue_tail;
1146  }
1147 }
1148 
1149 /*FUNCTION**********************************************************************
1150  *
1151  * Function Name : lin_diagservice_read_by_identifier
1152  * Description : This function to process read by identifier request, and also prepare its response data.
1153  * Only for Slave Nodes.
1154  *
1155  * Implements : lin_diagservice_read_by_identifier_Activity
1156  *END**************************************************************************/
1157 static void lin_diagservice_read_by_identifier(l_ifc_handle iii)
1158 {
1159  lin_product_id_t product_id;
1160  lin_tl_pdu_data_t lin_tl_pdu;
1161  l_u8 id;
1162  l_u16 supid;
1163  l_u16 fid;
1164  const lin_node_attribute_t * node_attr_ptr;
1165  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1166  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1167  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
1168  const lin_transport_layer_queue_t * rx_queue = &(tl_desc_ptr->tl_rx_queue);
1169  l_u8 i;
1170  for (i = 0; i < 8U; i++)
1171  {
1172  lin_tl_pdu[i] = rx_queue->tl_pdu_ptr[rx_queue->queue_header][i];
1173  }
1174 
1175  /* Get the product identification */
1176  product_id = node_attr_ptr->product_id;
1177 
1178  /* Get supplier and function identification in request */
1179  supid = (l_u16)(((l_u16)(lin_tl_pdu[5])) << 8U);
1180  supid = (l_u16)(supid | (l_u16)(lin_tl_pdu[4]));
1181 
1182  fid = (l_u16)(((l_u16)(lin_tl_pdu[7])) << 8U);
1183  fid = (l_u16)(fid | (l_u16)(lin_tl_pdu[6]));
1184 
1185 
1186  /* Check Supplier ID and Function ID */
1187  if (((supid != product_id.supplier_id) && (supid != LD_ANY_SUPPLIER)) ||
1188  ((fid != product_id.function_id) && (fid != LD_ANY_FUNCTION)))
1189  {
1190  tl_desc_ptr->slave_resp_cnt = 0U;
1191  }
1192  else
1193  {
1194  /* Get the identifier of request */
1195  id = lin_tl_pdu[3];
1196 
1197  switch (id)
1198  {
1199  case LIN_PRODUCT_ID:
1201  break;
1202  case LIN_SERIAL_NUMBER:
1204  break;
1205  default:
1206  /* For ID from 32 to 63, call user defined ld_read_by_id_callout */
1207  if ((id >= LIN_READ_USR_DEF_MIN) && (id <= LIN_READ_USR_DEF_MAX))
1208  {
1209  l_u8 data_callout[5] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
1210  l_u8 retval = ld_read_by_id_callout(iii, id, data_callout);
1211  /*If the User ID is supported, make positive response*/
1212  if (retval == LD_POSITIVE_RESPONSE)
1213  {
1214  i = 0U;
1215  while ((i < 5U) && (data_callout[i] == 0xFFU))
1216  {
1217  i++;
1218  }
1219  if (i < 5U)
1220  {
1222  }
1223  else
1224  {
1226  }
1227  }
1228  /*If the User ID is not supported, make negative response*/
1229  else if (retval == LD_NEGATIVE_RESPONSE)
1230  {
1231  /* Make a negative slave response PDU */
1233  }
1234  else
1235  {
1236  if (retval == LD_ID_NO_RESPONSE)
1237  {
1238  /*Do not answer*/
1239  tl_desc_ptr->slave_resp_cnt = 0;
1240  tl_desc_ptr->service_status = LD_SERVICE_IDLE;
1241  }
1242  }
1243  }
1244  /* For ID from 2 to 31 or 64-255, give negative response */
1245  else
1246  {
1247  /* Make a negative slave response PDU */
1249  }
1250 
1251  break;
1252  } /* end of switch */
1253  }
1254 }
1255 
1256 /*FUNCTION**********************************************************************
1257  *
1258  * Function Name : ld_make_slave_response_pdu
1259  *
1260  * Description : Creates PDUs for the transport layer for specified diagnostic service
1261  * and adds them to the transmit queue.
1262  * This function is implemented for Slave only.
1263  *
1264  * Implements : ld_make_slave_response_pdu_Activity
1265  *END**************************************************************************/
1266 static void ld_make_slave_response_pdu(l_ifc_handle iii,
1267  l_u8 sid,
1268  l_u8 res_type,
1269  l_u8 error_code)
1270 {
1271  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1272  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1273  const lin_node_attribute_t * node_attr_ptr;
1274  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
1275  const lin_product_id_t * ident;
1276  const lin_serial_number_t * serial_number;
1277  l_u8 i = 0U;
1278  l_u8 NAD;
1279  lin_tl_pdu_data_t lin_tl_pdu;
1280  const lin_transport_layer_queue_t * rx_queue;
1281 
1282  /* Get receive queue */
1283  rx_queue = &(tl_desc_ptr->tl_rx_queue);
1284  NAD = rx_queue->tl_pdu_ptr[rx_queue->queue_header][0];
1285  if (NAD != LD_FUNCTIONAL_NAD)
1286  {
1287  /* Pack data to response PDU */
1288  lin_tl_pdu[0] = *node_attr_ptr->configured_NAD_ptr;
1289  lin_tl_pdu[1] = 0x03U; /* PCI */
1290  lin_tl_pdu[2] = RES_NEGATIVE; /* SID */
1291  lin_tl_pdu[3] = sid; /* D0 */
1292  lin_tl_pdu[4] = error_code; /* D1 */
1293  lin_tl_pdu[5] = 0xFFU; /* D2 */
1294  lin_tl_pdu[6] = 0xFFU; /* D3 */
1295  lin_tl_pdu[7] = 0xFFU; /* D4 */
1296 
1297  switch (sid)
1298  {
1300  if (POSITIVE == res_type)
1301  {
1302  /* PCI type */
1303  lin_tl_pdu[1] = PCI_RES_READ_BY_IDENTIFY;
1304  /* SID */
1305  lin_tl_pdu[2] = (l_u8)(RES_POSITIVE + sid);
1306 
1307  if (error_code == LIN_PRODUCT_ID)
1308  {
1309  /* Get Identifier info */
1310  ident = (const lin_product_id_t *)(&node_attr_ptr->product_id);
1311  lin_tl_pdu[3] = (l_u8)(ident->supplier_id & 0xFFU);
1312  lin_tl_pdu[4] = (l_u8)(ident->supplier_id >> 8);
1313  lin_tl_pdu[5] = (l_u8)(ident->function_id & 0xFFU);
1314  lin_tl_pdu[6] = (l_u8)(ident->function_id >> 8);
1315  lin_tl_pdu[7] = ident->variant;
1316  }
1317  else if (error_code == LIN_SERIAL_NUMBER)
1318  {
1319  serial_number = (const lin_serial_number_t *)(&node_attr_ptr->serial_number);
1320  lin_tl_pdu[3] = serial_number->serial_0;
1321  lin_tl_pdu[4] = serial_number->serial_1;
1322  lin_tl_pdu[5] = serial_number->serial_2;
1323  lin_tl_pdu[6] = serial_number->serial_3;
1324  /* PCI for Serial Number is 0x05 */
1325  lin_tl_pdu[1] = 0x05U;
1326  }
1327  else
1328  {
1329  if ((error_code >= LIN_READ_USR_DEF_MIN) && (error_code <= LIN_READ_USR_DEF_MAX))
1330  {
1331  l_u8 data_callout[5] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1332  (void)ld_read_by_id_callout(iii, error_code, data_callout);
1333  /* packing user defined pdu */
1334  lin_tl_pdu[3] = data_callout[0];
1335  lin_tl_pdu[4] = data_callout[1];
1336  lin_tl_pdu[5] = data_callout[2];
1337  lin_tl_pdu[6] = data_callout[3];
1338  lin_tl_pdu[7] = data_callout[4];
1339  /* Check for data values*/
1340  for (i = 5U; i > 0U; i--)
1341  {
1342  if (data_callout[i - 1U] != 0xFFU)
1343  {
1344  /* PCI: Data length is 1 (RSID) + all data exclude 0xFF */
1345  lin_tl_pdu[1] = (l_u8)(i + 1U);
1346  break;
1347  }
1348  }
1349  }
1350  }
1351  }
1352  break;
1354  if (POSITIVE == res_type)
1355  {
1356  /* PCI type */
1357  lin_tl_pdu[1] = PCI_RES_SAVE_CONFIGURATION;
1358  /* SID */
1359  lin_tl_pdu[2] = (l_u8)(RES_POSITIVE + sid);
1360  /* Data unused */
1361  lin_tl_pdu[3] = 0xFFU;
1362  lin_tl_pdu[4] = 0xFFU;
1363  }
1364  break;
1365  case SERVICE_ASSIGN_NAD:
1366  if (POSITIVE == res_type)
1367  {
1368  lin_tl_pdu[0] = node_attr_ptr->initial_NAD;
1369  *node_attr_ptr->configured_NAD_ptr = rx_queue->tl_pdu_ptr[rx_queue->queue_header][7];
1370  /* PCI */
1371  lin_tl_pdu[1] = 0x01U;
1372  /* RSID */
1373  lin_tl_pdu[2] = 0xF0U;
1374  lin_tl_pdu[3] = 0xFFU;
1375  lin_tl_pdu[4] = 0xFFU;
1376  }
1377  break;
1379  /* PCI */
1380  lin_tl_pdu[1] = 0x01U;
1381  /* RSID */
1382  lin_tl_pdu[2] = 0xF3U;
1383  lin_tl_pdu[3] = 0xFFU;
1384  lin_tl_pdu[4] = 0xFFU;
1385  break;
1386  #if (SUPPORT_PROTOCOL_21 == 1U)
1387  case SERVICE_ASSIGN_FRAME_ID_RANGE: /* Mandatory for TL LIN 2.1 */
1388  if (POSITIVE == res_type)
1389  {
1390  lin_tl_pdu[1] = PCI_RES_ASSIGN_FRAME_ID_RANGE;
1391  lin_tl_pdu[2] = (l_u8)(RES_POSITIVE + sid);
1392  lin_tl_pdu[3] = 0xFFU;
1393  lin_tl_pdu[4] = 0xFFU;
1394  }
1395  break;
1396  #endif /* End (SUPPORT_PROTOCOL_21 == 1U) */
1397  #if (SUPPORT_PROTOCOL_J2602 == 1U)
1398  case SERVICE_TARGET_RESET:
1399  lin_tl_pdu[1] = 0x06U;
1400  if (POSITIVE == res_type)
1401  {
1402  lin_tl_pdu[2] = (l_u8)(RES_POSITIVE + sid);
1403  }
1404 
1405  ident = (lin_product_id_t *)&node_attr_ptr->product_id;
1406  lin_tl_pdu[3] = (l_u8)(ident->supplier_id & 0xFFU);
1407  lin_tl_pdu[4] = (l_u8)(ident->supplier_id >> 8U);
1408  lin_tl_pdu[5] = (l_u8)(ident->function_id & 0xFFU);
1409  lin_tl_pdu[6] = (l_u8)(ident->function_id >> 8U);
1410  lin_tl_pdu[7] = ident->variant;
1411  break;
1413  lin_tl_pdu[0] = *node_attr_ptr->configured_NAD_ptr;
1414  lin_tl_pdu[1] = 0x01U; /* PCI */
1415  lin_tl_pdu[2] = 0xF1U; /* SID */
1416  lin_tl_pdu[3] = 0xFFU; /* D0 */
1417  lin_tl_pdu[4] = 0xFFU; /* D1 */
1418  break;
1419  #endif /* End (SUPPORT_PROTOCOL_J2602 == 1U) */
1420  default:
1421  /* do nothing */
1422  break;
1423  } /* end of switch statement */
1424 
1425  /* Put lin_tl_pdu data into transmit queue*/
1426  ld_put_raw(iii, lin_tl_pdu);
1427  tl_desc_ptr->diag_state = LD_DIAG_TX_PHY;
1428  }
1429  else
1430  {
1431  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
1432  }
1433 }
1434 
1435 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
1436 
1437 #if (SUPPORT_PROTOCOL_J2602 == 1U)
1438 /*FUNCTION**********************************************************************
1439  *
1440  * Function Name : ld_is_ready_j2602
1441  * Description : Verifies a state of node setting (using for J2602 and LIN 2.0).
1442  *
1443  * Implements : ld_is_ready_j2602_Activity
1444  *END**************************************************************************/
1445 l_bool ld_is_ready_j2602(l_ifc_handle iii)
1446 {
1447  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1448 
1449  l_bool retVal = false;
1450  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1451  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1452 
1453  if (prot_user_config_ptr->function == (bool)LIN_MASTER)
1454  {
1455  /* Check the service status */
1456  if (LD_SERVICE_BUSY != tl_desc_ptr->service_status)
1457  {
1458  retVal = true;
1459  }
1460  }
1461 
1462  return retVal;
1463 }
1464 
1465 /*FUNCTION**********************************************************************
1466  *
1467  * Function Name : ld_check_response_j2602
1468  * Description : Verifies the state of response (using for J2602 and LIN 2.0)
1469  *
1470  * Implements : ld_check_response_j2602_Activity
1471  *END**************************************************************************/
1473  l_u8 * const RSID,
1474  l_u8 * const error_code)
1475 {
1476  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1477 
1478  l_u8 retval = 0xFFU;
1479  lin_last_cfg_result_t temp;
1480  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1481  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1482 
1483  if (prot_user_config_ptr->function == (bool)LIN_MASTER)
1484  {
1485  /* Get the status of the last service */
1486  temp = tl_desc_ptr->last_cfg_result;
1487  /* Check status of last configuration */
1488  switch (temp)
1489  {
1490  case LD_SUCCESS:
1491  *RSID = tl_desc_ptr->last_RSID;
1492  break;
1493  case LD_NEGATIVE:
1494  *RSID = tl_desc_ptr->last_RSID;
1495  *error_code = tl_desc_ptr->ld_error_code;
1496  break;
1497  default:
1498  /* do nothing */
1499  break;
1500  } /* end of switch */
1501 
1502  retval = (l_u8)temp;
1503  }
1504 
1505  return retval;
1506 }
1507 
1508 /*FUNCTION**********************************************************************
1509  *
1510  * Function Name : ld_assign_frame_id
1511  * Description : This function assigns the protected identifier of up to four frames
1512  * in the slave node with the addressed NAD (using for J2602 and LIN 2.0).
1513  *
1514  * Implements : ld_assign_frame_id_Activity
1515  *END**************************************************************************/
1516 void ld_assign_frame_id(l_ifc_handle iii,
1517  l_u8 NAD,
1518  l_u16 supplier_id,
1519  l_u16 message_id,
1520  l_u8 PID)
1521 {
1522  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1523 
1524  l_u8 data[6];
1525  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1526  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1527 
1528  if (prot_user_config_ptr->function == (bool)LIN_MASTER)
1529  {
1530  /* check service is busy? */
1531  if (LD_SERVICE_BUSY != tl_desc_ptr->service_status)
1532  {
1533  /* SID of Service assign frame identifier: 0xB1 */
1534  data[0] = SERVICE_ASSIGN_FRAME_ID;
1535  data[1] = (l_u8)(supplier_id & 0x00FFU);
1536  data[2] = (l_u8)((supplier_id >> 8U) & 0x00FFU);
1537  data[3] = (l_u8)(message_id & 0x00FFU);
1538  data[4] = (l_u8)((message_id >> 8U) & 0x00FFU);
1539  data[5] = PID;
1540 
1541  /* put data into TX_QUEUE */
1542  ld_send_message(iii, 6U, NAD, data);
1543  /* Set state of service is BUSY */
1544  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
1545  } /* End of checking service status */
1546  }
1547 }
1548 
1549 #if (SUPPORT_SLAVE_MODE == 1U)
1550 /*FUNCTION**********************************************************************
1551  *
1552  * Function Name : ld_assign_NAD_j2602
1553  * Description : This function assigns NAD of a J2602 slave device based on input
1554  * dnn. NAD is (0x60 + dnn).
1555  *
1556  * Implements : ld_assign_NAD_j2602_Activity
1557  *END**************************************************************************/
1558 l_bool ld_assign_NAD_j2602(l_ifc_handle iii,
1559  l_u8 dnn)
1560 {
1561  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1562  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1563  const lin_node_attribute_t * node_attr_ptr;
1564  l_bool ret_val = 1U;
1565 
1566  if ((prot_user_config_ptr->function == (bool)LIN_SLAVE) && (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602))
1567  {
1569  if (dnn <= 0xFU)
1570  {
1571  *(node_attr_ptr->configured_NAD_ptr) = (l_u8)(0x60U + dnn);
1572  ret_val = 0U;
1573  }
1574  }
1575 
1576  return ret_val;
1577 }
1578 
1579 /*FUNCTION**********************************************************************
1580  *
1581  * Function Name : ld_reconfig_msg_ID
1582  * Description : This function reconfigures frame identifiers of a J2602 slave node
1583  * based on input dnn. This function is for slave nodes only.
1584  *
1585  * Implements : ld_reconfig_msg_ID_Activity
1586  *END**************************************************************************/
1587 l_bool ld_reconfig_msg_ID(l_ifc_handle iii,
1588  l_u8 dnn)
1589 {
1590  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
1591  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1592  l_bool ret_val = 1U;
1593  /* Get number of configurable_frames not calculate id 0x3C and 0x3D */
1594  l_u8 number_of_configurable_frames = (l_u8)(prot_user_config_ptr->number_of_configurable_frames - 2);
1595 
1596  /* Check if this interface is a LIN Slave and the protocol is J2602 */
1597  if ((prot_user_config_ptr->function == LIN_SLAVE) && (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602))
1598  {
1599  if (dnn <= 0xDU)
1600  {
1601  /* number of configurable frames greater than 16 */
1602  if (number_of_configurable_frames > 16U)
1603  {
1604  /* Only 0x60 is valid NAD */
1605  /* Do nothing */
1606  }
1607  /* number of configurable frames is from 9 - 16 */
1608  else if (number_of_configurable_frames > 8U)
1609  {
1610  /* Only NAD 0x60, 0x64, 0x68 are valid, 0x6C and 0x6D not valid */
1611  if ((dnn == 0U) || (dnn == 4U) || (dnn == 8U))
1612  {
1613  ret_val = ld_change_msg_id(iii, dnn, 16U);
1614  }
1615  }
1616  /* number of configurable frames is from 5 - 8 */
1617  else if (number_of_configurable_frames > 4U)
1618  {
1619  /* Check to verify if dnn is 0x60, 0x62, 0x64, 0x66, 0x68, 0x6A, 0x6C */
1620  if ((dnn % 2U) == 0U)
1621  {
1622  ret_val = ld_change_msg_id(iii, dnn, 8U);
1623  }
1624  }
1625  /* number of configurable frames is from 1 - 4 */
1626  else
1627  {
1628  ret_val = ld_change_msg_id(iii, dnn, 4U);
1629  }
1630  }
1631  }
1632 
1633  return ret_val;
1634 }
1635 
1636 /*FUNCTION**********************************************************************
1637  *
1638  * Function Name : ld_change_msg_id
1639  * Description : This function reconfigures frame identifiers of a J2602 slave node
1640  * based on input dnn and frame_id_change.
1641  *
1642  * Implements : ld_change_msg_id_Activity
1643  *END**************************************************************************/
1644 static l_bool ld_change_msg_id(l_ifc_handle iii,
1645  l_u8 dnn,
1646  l_u8 frame_id_change)
1647 {
1648  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1649  l_u8 number_of_configurable_frames = prot_user_config_ptr->number_of_configurable_frames;
1650  l_u8 i;
1651  l_u8 id_origin;
1652  /* If new DNN is greater than current DNN */
1653  for (i = number_of_configurable_frames; i > 0U; i--)
1654  {
1655  /* For non-broadcast frame identifiers less than or equal to 0x37 */
1656  if (prot_user_config_ptr->list_identifiers_RAM_ptr[i] <= 0x37U)
1657  {
1658  /* get id with dnn equal 0 */
1659  id_origin = (l_u8)(prot_user_config_ptr->list_identifiers_RAM_ptr[i] % frame_id_change);
1660  prot_user_config_ptr->list_identifiers_RAM_ptr[i] = (l_u8)(id_origin + (l_u8)(dnn << 2));
1661  }
1662  }
1663 
1664  /* Check for broadcast message ID */
1665  for (i = number_of_configurable_frames; i > 0U; i--)
1666  {
1667  /* For broad cast message ID */
1668  if ((prot_user_config_ptr->list_identifiers_RAM_ptr[i] <= 0x3BU) && (prot_user_config_ptr->list_identifiers_RAM_ptr[i] >= 0x38U))
1669  {
1670  if ((dnn >= 8U) &&
1671  ((prot_user_config_ptr->list_identifiers_RAM_ptr[i] == 0x38U) || (prot_user_config_ptr->list_identifiers_RAM_ptr[i] == 0x3AU)))
1672  {
1673  prot_user_config_ptr->list_identifiers_RAM_ptr[i] += 1U;
1674  }
1675  else if ((dnn < 8U) &&
1676  ((prot_user_config_ptr->list_identifiers_RAM_ptr[i] == 0x39U) || (prot_user_config_ptr->list_identifiers_RAM_ptr[i] == 0x3BU)))
1677  {
1678  prot_user_config_ptr->list_identifiers_RAM_ptr[i] -= 1U;
1679  }
1680  }
1681  }
1682 
1683  return (l_bool)0U;
1684 }
1685 
1686 /*FUNCTION**********************************************************************
1687  *
1688  * Function Name : lin_diagservice_target_reset
1689  * Description : Process read by identifier request, and also prepare its response data
1690  * and Reset the Slave Node. This function is only for Slave Node
1691  *
1692  * Implements : lin_diagservice_target_reset_Activity
1693  *END**************************************************************************/
1694 static void lin_diagservice_target_reset(l_ifc_handle iii)
1695 {
1696  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1698  l_u8* byte_offset_temp_ptr;
1699  l_u8* bit_offset_temp_ptr;
1700  l_u8 i;
1701  const lin_transport_layer_queue_t * rx_queue = &(tl_desc_ptr->tl_rx_queue);
1702 
1703  for (i = 0; i < node_attr_ptr->num_frame_have_esignal; i++)
1704  {
1705  /* Set the reset flag within the J2602 Status Byte */
1706  byte_offset_temp_ptr = node_attr_ptr->response_error_byte_offset_ptr + i;
1707  bit_offset_temp_ptr = node_attr_ptr->response_error_bit_offset_ptr + i;
1708  /* Set error signal to 0x01 means "Reset" */
1709  g_lin_frame_data_buffer[*byte_offset_temp_ptr] = (l_u8)((g_lin_frame_data_buffer[*byte_offset_temp_ptr] & (~(0x07U << (*bit_offset_temp_ptr)))) |
1710  (0x01U << (*bit_offset_temp_ptr)));
1711  }
1712  /* check if pdu[0] - NAD is different from LD_BROADCAST */
1713  if (LD_BROADCAST != rx_queue->tl_pdu_ptr[(rx_queue->queue_header)][0])
1714  {
1716  }
1717  else
1718  {
1719  tl_desc_ptr->slave_resp_cnt = 0U;
1720  }
1721 }
1722 
1723 /*FUNCTION**********************************************************************
1724  *
1725  * Function Name : lin_diagservice_assign_frame_id
1726  * Description : Process assign frame id request, and also prepare its response data
1727  * and change protected identifier of frame have correct message
1728  * identifier. This function is only for Slave Nodes
1729  *
1730  * Implements : lin_diagservice_assign_frame_id_Activity
1731  *END**************************************************************************/
1732 static void lin_diagservice_assign_frame_id(l_ifc_handle iii)
1733 {
1734  l_u8 i;
1735  l_u8 id;
1736  l_u16 supplier_id;
1737  l_u16 message_id;
1738  lin_tl_pdu_data_t lin_tl_pdu;
1739  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1741  l_u16 slave_supplier_id = g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle].product_id.supplier_id;
1742 
1743  /* Get data from queue */
1744  for (i = 0U; i < 8U; i++)
1745  {
1746  lin_tl_pdu[i] = rx_queue->tl_pdu_ptr[rx_queue->queue_header][i];
1747  }
1748 
1749  supplier_id = (l_u16)((l_u16)lin_tl_pdu[3] | (l_u16)(lin_tl_pdu[4] << 8U));
1750  message_id = (l_u16)((l_u16)lin_tl_pdu[5] | (l_u16)(lin_tl_pdu[6] << 8U));
1751 
1752  if (supplier_id == slave_supplier_id)
1753  {
1754  id = lin_process_parity(lin_tl_pdu[7], CHECK_PARITY);
1755  if (id != 0xFFU)
1756  {
1757  for (i = (l_u8)(prot_user_config_ptr->number_of_configurable_frames - 2U); i > 0U; i--)
1758  {
1759  if (prot_user_config_ptr->list_identifiers_ROM_ptr[i] == message_id)
1760  {
1761  prot_user_config_ptr->list_identifiers_RAM_ptr[i] = id;
1762  /* Send positive response if assign successfully */
1764  break;
1765  }
1766  }
1767  }
1768  }
1769 }
1770 
1771 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
1772 #endif /* End (SUPPORT_PROTOCOL_J2602 == 1U) */
1773 #endif /* End (SUPPORT_DIAG_SERVICE == 1U) */
1774 #endif /* End (SUPPORT_TRANSPORT_LAYER == 1U) */
1775 /*******************************************************************************
1776  * EOF
1777  ******************************************************************************/
#define SERVICE_SAVE_CONFIGURATION
Definition: lin.h:64
#define LD_NEGATIVE_RESPONSE
Definition: lin.h:88
#define LD_LENGTH_NOT_CORRECT
#define LIN_READ_USR_DEF_MAX
Definition: lin.h:84
#define LD_ID_NO_RESPONSE
Definition: lin.h:87
l_u8 * list_identifiers_RAM_ptr
Definition: lin.h:522
l_u8 diag_get_flag(l_ifc_handle iii, l_u8 flag_order)
This function will return flag of diagnostic service, if LIN slave node receive master request of the...
l_u16 function_id
Definition: lin_types.h:60
lin_product_id_t product_id
Definition: lin.h:193
#define SERIVCE_FAULT_MEMORY_CLEAR
Definition: lin.h:72
static void lin_diagservice_assign_frame_id_range(l_ifc_handle iii)
#define PCI_RES_SAVE_CONFIGURATION
Definition: lin.h:79
void diag_IO_control(l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, const l_u8 *const data)
This function is used for master node only. It will pack data and send request to slave node with ser...
#define SUBFUNCTION_NOT_SUPPORTED
lin_serial_number_t serial_number
Definition: lin.h:194
l_u8 lin_process_parity(l_u8 pid, l_u8 typeAction)
Makes or checks parity bits. If action is checking parity, the function returns ID value if parity bi...
Definition: lin.c:74
l_u8 ld_error_code
Definition: lin.h:481
l_u8 * service_flags_ptr
Definition: lin.h:208
l_bool save_config_flg
Definition: lin.h:575
#define SERVICE_READ_BY_IDENTIFY
Definition: lin.h:62
#define SERVICE_NOT_SUPPORTED
#define SERVICE_FAULT_MEMORY_READ
Definition: lin.h:71
lin_product_id_t * product_id_ptr
Definition: lin.h:485
lin_protocol_state_t g_lin_protocol_state_array[LIN_NUM_OF_IFCS]
Definition: lin.c:50
void ld_read_by_id(l_ifc_handle iii, l_u8 NAD, l_u16 supplier_id, l_u16 function_id, l_u8 id, lin_product_id_t *const data)
The call requests the slave node selected with the NAD to return the property associated with the id ...
#define SERVICE_ASSIGN_FRAME_ID
Definition: lin.h:61
#define LD_POSITIVE_RESPONSE
Definition: lin.h:89
l_ifc_slave_handle slave_ifc_handle
Definition: lin.h:527
void diag_fault_memory_read(l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, const l_u8 *const data)
This function is used for master node only. It will pack data and send request to slave node with ser...
void ld_conditional_change_NAD(l_ifc_handle iii, l_u8 NAD, l_u8 id, l_u8 byte_data, l_u8 mask, l_u8 invert, l_u8 new_NAD)
This call changes the NAD if the node properties fulfill the test specified by id, byte, mask and invert. Master node only.
#define LD_FUNCTIONAL_NAD
#define LIN_SERIAL_NUMBER
#define SERVICE_IO_CONTROL_BY_IDENTIFY
Definition: lin.h:70
#define SERVICE_READ_DATA_BY_IDENTIFY
Definition: lin.h:67
const l_u16 * list_identifiers_ROM_ptr
Definition: lin.h:521
#define LIN_SLAVE
Mode of LIN node (master or slave)
Definition: lin.h:167
static void lin_diagservice_target_reset(l_ifc_handle iii)
void ld_save_configuration(l_ifc_handle iii, l_u8 NAD)
This function to issue a save configuration request to a slave node.
static l_bool ld_change_msg_id(l_ifc_handle iii, l_u8 dnn, l_u8 frame_id_change)
lin_tl_pdu_data_t * tl_pdu_ptr
Definition: lin.h:444
void lin_diag_service_callback(l_ifc_handle iii, l_u8 sid)
l_bool ld_is_ready_j2602(l_ifc_handle iii)
Verifies a state of node setting (using for J2602 and LIN 2.0).
l_u8 ld_set_configuration(l_ifc_handle iii, const l_u8 *const data, l_u16 length)
This function configures slave node according to data.
const l_u8 * service_supported_ptr
Definition: lin.h:207
#define LD_SET_OK
const lin_node_attribute_t g_lin_node_attribute_array[LIN_NUM_OF_SLAVE_IFCS]
l_bool ld_assign_NAD_j2602(l_ifc_handle iii, l_u8 dnn)
This function assigns NAD of a J2602 slave device based on input DNN that is Device Node Number...
l_u8 g_lin_frame_data_buffer[LIN_FRAME_BUF_SIZE]
l_u8 ld_check_response_j2602(l_ifc_handle iii, l_u8 *const RSID, l_u8 *const error_code)
Verifies the state of response (using for J2602 and LIN 2.0) Master node only.
#define NEGATIVE
#define DEV_ASSERT(x)
Definition: devassert.h:77
lin_tl_descriptor_t g_lin_tl_descriptor_array[LIN_NUM_OF_IFCS]
Definition: lin.c:49
#define PCI_RES_ASSIGN_FRAME_ID_RANGE
Definition: lin.h:80
#define SERVICE_TARGET_RESET
l_u8 num_frame_have_esignal
Definition: lin.h:196
Configuration structure Implements : lin_protocol_user_config_t_Class.
Definition: lin.h:510
Serial number Implements : lin_serial_number_t_Class.
Definition: lin.h:177
#define PCI_RES_READ_BY_IDENTIFY
Definition: lin.h:78
#define LD_LENGTH_TOO_SHORT
void ld_send_message(l_ifc_handle iii, l_u16 length, l_u8 NAD, const l_u8 *const data)
Pack the information specified by data and length into one or multiple diagnostic frames...
l_u8 * response_error_bit_offset_ptr
Definition: lin.h:199
void ld_check_response(l_ifc_handle iii, l_u8 *const RSID, l_u8 *const error_code)
This call returns the result of the last node configuration service, in the parameters RSID and error...
l_bool ld_reconfig_msg_ID(l_ifc_handle iii, l_u8 dnn)
This function reconfigures frame identifiers of a J2602 slave node based on input dnn...
#define LIN_MASTER
Definition: lin.h:168
Product id structure Implements : lin_product_id_t_Class.
Definition: lin_types.h:57
#define PCI_SAVE_CONFIGURATION
Definition: lin.h:75
#define SERVICE_SESSION_CONTROL
Definition: lin.h:69
void diag_clear_flag(l_ifc_handle iii, l_u8 flag_order)
This function will clear flag of diagnostic service,.
void diag_write_data_by_identifier(l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, const l_u8 *const data)
Write Data by Identifier for a specified node - Diagnostic Class II service (0x2E) ...
Transport layer queue Implements : lin_transport_layer_queue_t_Class.
Definition: lin.h:437
#define SERVICE_ASSIGN_NAD
Definition: lin.h:60
l_u8 * configured_NAD_ptr
Definition: lin.h:191
l_u8 * response_error_byte_offset_ptr
Definition: lin.h:198
const lin_protocol_user_config_t g_lin_protocol_user_cfg_array[LIN_NUM_OF_IFCS]
ld_queue_status_t queue_status
Definition: lin.h:441
void diag_read_data_by_identifier(l_ifc_handle iii, const l_u8 NAD, const l_u8 *const data)
This function reads data by identifier, Diagnostic Class II service (0x22).
#define GENERAL_REJECT
unsigned char l_u8
Unsigned 8 bit integer Implements : l_u8_Class.
Definition: lin_types.h:30
static void lin_diagservice_assign_frame_id(l_ifc_handle iii)
void ld_assign_frame_id_range(l_ifc_handle iii, l_u8 NAD, l_u8 start_index, const l_u8 *const PIDs)
This function assigns the protected identifier of up to four frames.
#define LD_ANY_SUPPLIER
static void lin_assign_nad(l_ifc_handle iii)
l_u8 ld_read_configuration(l_ifc_handle iii, l_u8 *const data, l_u8 *const length)
This function copies current configuration in a reserved area.
lin_last_cfg_result_t
Status of the last configuration call completed Implements : lin_last_cfg_result_t_Class.
Definition: lin.h:336
void ld_put_raw(l_ifc_handle iii, const l_u8 *const data)
Queue the transmission of 8 bytes of data in one frame.
void ld_assign_NAD(l_ifc_handle iii, l_u8 initial_NAD, l_u16 supplier_id, l_u16 function_id, l_u8 new_NAD)
This call assigns the NAD (node diagnostic address) of all slave nodes that matches the initial_NAD...
l_u16 supplier_id
Definition: lin_types.h:59
lin_diagnostic_state_t diag_state
Definition: lin.h:488
#define LD_DATA_ERROR
lin_transport_layer_queue_t tl_rx_queue
Definition: lin.h:468
void ld_assign_frame_id(l_ifc_handle iii, l_u8 NAD, l_u16 supplier_id, l_u16 message_id, l_u8 PID)
This function assigns the protected identifier to a slave node with the address NAD and specified sup...
static void ld_make_slave_response_pdu(l_ifc_handle iii, l_u8 sid, l_u8 res_type, l_u8 error_code)
#define LD_BROADCAST
#define RES_NEGATIVE
lin_protocol_handle_t protocol_version
Definition: lin.h:512
l_u8 slave_resp_cnt
Definition: lin.h:491
lin_service_status_t service_status
Definition: lin.h:492
Attributes of LIN node Implements : lin_node_attribute_t_Class.
Definition: lin.h:189
l_u8 ld_is_ready(l_ifc_handle iii)
This call returns the status of the last requested configuration service.
l_u8 ld_read_by_id_callout(l_ifc_handle iii, l_u8 id, l_u8 *data)
void diag_fault_memory_clear(l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, const l_u8 *const data)
This function is used for master node only. It will pack data and send request to slave node with ser...
l_u8 lin_tl_pdu_data_t[8]
PDU data. Implements : lin_tl_pdu_data_t_Class.
Definition: lin.h:99
bool l_bool
0 is false, and non-zero (>0) is true Implements : l_bool_Class
Definition: lin_types.h:48
#define LD_ANY_FUNCTION
static void lin_condittional_change_nad(l_ifc_handle iii)
#define SERVICE_CONDITIONAL_CHANGE_NAD
Definition: lin.h:63
#define SERVICE_WRITE_DATA_BY_IDENTIFY
Definition: lin.h:68
#define LIN_PRODUCT_ID
l_u8 number_support_sid
Definition: lin.h:206
#define RES_POSITIVE
l_u8 number_of_configurable_frames
Definition: lin.h:517
#define CHECK_PARITY
Definition: lin_driver.h:53
#define LD_READ_OK
l_u8 last_RSID
Definition: lin.h:480
l_u8 initial_NAD
Definition: lin.h:192
#define POSITIVE
#define LIN_READ_USR_DEF_MIN
Definition: lin.h:83
unsigned short int l_u16
Unsigned 16 bit integer Implements : l_u16_Class.
Definition: lin_types.h:36
static void lin_diagservice_read_by_identifier(l_ifc_handle iii)
void diag_session_control(l_ifc_handle iii, const l_u8 NAD, l_u16 data_length, const l_u8 *const data)
This function is used for master node only. It will pack data and send request to slave node with ser...
Transport layer description Implements : lin_tl_descriptor_t_Class.
Definition: lin.h:464
#define SERVICE_ASSIGN_FRAME_ID_RANGE
Definition: lin.h:65
lin_last_cfg_result_t last_cfg_result
Definition: lin.h:479