S32 SDK
lin_commontl_proto.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  */
28 #include "lin_commontl_proto.h"
29 #include "lin_common_api.h"
30 #include "lin_commontl_api.h"
31 #if (SUPPORT_TRANSPORT_LAYER == 1U)
32 
33 /*******************************************************************************
34  * Static function prototypes
35  ******************************************************************************/
36 static void lin_tl_handler_error(l_ifc_handle iii,
37  l_u8 pid);
38 
39 static void lin_tl_get_pdu(l_ifc_handle iii);
40 
41 static void lin_tl_handler_rx_completed(l_ifc_handle iii);
42 
43 static void lin_tl_handler_tx_completed(l_ifc_handle iii);
44 
45 static void lin_process_single_frame(l_ifc_handle iii);
46 
47 static void lin_process_first_frame(l_ifc_handle iii);
48 
49 static void lin_process_consecutive_frame(l_ifc_handle iii);
50 
51 #if (SUPPORT_MASTER_MODE == 1U)
52 static void lin_tl_get_response(l_ifc_handle iii);
53 
54 static void lin_tl_sch_switch(l_ifc_handle iii);
55 
56 static void lin_tl_handle_interleave_mode(l_ifc_handle iii);
57 #endif
58 #if (SUPPORT_SLAVE_MODE == 1U)
59 static void lin_tl_attach_service(l_ifc_handle iii);
60 #endif
61 #if (SUPPORT_PROTOCOL_21 == 1U)
62 static void lin_tl_handle_timeout(l_ifc_handle iii);
63 #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
64 static void lin_process_pdu(l_ifc_handle iii,
65  const lin_tl_pdu_data_t * pdu);
66 
67 static void lin_tl_make_master_request_pdu(l_ifc_handle iii);
68 
69 static void tl_receive_message(l_ifc_handle iii);
70 
71 
72 /*******************************************************************************
73  * Variables
74  ******************************************************************************/
75 /*******************************************************************************
76  * Code
77  ******************************************************************************/
78 
79 /*FUNCTION**********************************************************************
80  *
81  * Function Name : lin_tl_callback_handler
82  * Description : Transport layer callback to process the specified event
83  *
84  * Implements : lin_tl_callback_handler_Activity
85  *END**************************************************************************/
87  lin_tl_event_id_t tl_event_id,
88  l_u8 id)
89 {
90  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
92 
93  switch (tl_event_id)
94  {
95  case TL_RECEIVE_MESSAGE:
96  /* If ld_receive_message is called and first frame in multi PDU is not transmitted */
97  if ((tl_desc_ptr->rx_msg_status == LD_IN_PROGRESS) && (tl_desc_ptr->FF_pdu_received == false))
98  {
99  /* Activate function tl_receive_message() in process_pdu() function to return data to data pointer of ld_receive_message function */
100  tl_desc_ptr->ld_return_data = true;
101  }
102  break;
103  case TL_MAKE_RES_DATA:
104  if (0x3CU == id)
105  {
107  }
108  break;
109  case TL_SLAVE_GET_ACTION:
110  if ((tl_desc_ptr->slave_resp_cnt > 0U) && (tl_desc_ptr->service_status != LD_SERVICE_ERROR))
111  {
112  tl_desc_ptr->slave_resp_cnt--;
113  lin_tl_get_pdu(iii);
114  }
115  else
116  {
117  ret_val = TL_ACTION_ID_IGNORE;
118  }
119  break;
120  case TL_TX_COMPLETED:
122  break;
123  case TL_RX_COMPLETED:
125  break;
126  case TL_ERROR:
127  lin_tl_handler_error(iii, id);
128  break;
129  #if (SUPPORT_PROTOCOL_21 == 1U)
130  case TL_TIMEOUT_SERVICE:
132  break;
133  #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
134  #if (SUPPORT_MASTER_MODE == 1U)
137  break;
138  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
139  default:
140  /* Do nothing */
141  break;
142  }
143 
144  return ret_val;
145 }
146 
147 #if (SUPPORT_PROTOCOL_21 == 1U)
148 /*FUNCTION**********************************************************************
149  *
150  * Function Name : lin_tl_handle_timeout
151  * Description : This function handle when N_CR, N_AS or DIAGNOSTIC INTERLEAVE time out occur
152  *
153  * Implements : lin_tl_handle_timeout_Activity
154  *END**************************************************************************/
155 static void lin_tl_handle_timeout(l_ifc_handle iii)
156 {
157  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
158  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
159  #if (SUPPORT_MASTER_MODE == 1U)
160  const lin_master_data_t * master_data_ptr;
161  const lin_schedule_t * active_schedule_struct_ptr;
162  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
163 
164  if (LD_CHECK_N_CR_TIMEOUT == tl_desc_ptr->check_timeout_type)
165  {
166  if (!(tl_desc_ptr->check_timeout-- > 0U))
167  {
168  /* Update status of transport layer */
169  prot_state_ptr->diagnostic_mode = DIAG_NONE;
170  tl_desc_ptr->service_status = LD_SERVICE_ERROR;
171  tl_desc_ptr->rx_msg_status = LD_N_CR_TIMEOUT;
172  tl_desc_ptr->ld_return_data = false;
173  tl_desc_ptr->FF_pdu_received = false;
175  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
176  }
177  }
178 
179  if (LD_CHECK_N_AS_TIMEOUT == tl_desc_ptr->check_timeout_type)
180  {
181  if (!(tl_desc_ptr->check_timeout-- > 0U))
182  {
183  /* update status of transport layer */
184  prot_state_ptr->diagnostic_mode = DIAG_NONE;
185  tl_desc_ptr->service_status = LD_SERVICE_ERROR;
186  tl_desc_ptr->tx_msg_status = LD_N_AS_TIMEOUT;
188  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
189  }
190  }
191  #if (SUPPORT_MASTER_MODE == 1U)
192  /* process diagnostic interleaved mode */
193  if (prot_state_ptr->diagnostic_mode == DIAG_INTERLEAVE_MODE)
194  {
195  /* To be misra compliant */
198  tl_desc_ptr->interleave_timeout_counter++;
199  if (INTERLEAVE_MAX_TIMEOUT < tl_desc_ptr->interleave_timeout_counter)
200  {
201  active_schedule_struct_ptr = (const lin_schedule_t *)&g_lin_protocol_user_cfg_array[iii].schedule_tbl[master_data_ptr->active_schedule_id];
202  /* Switch back to normal table if active schedule table is diagnostic table */
203  if (LIN_SCH_TBL_DIAG == active_schedule_struct_ptr->sch_tbl_type)
204  {
205  /* Switch to previous normal schedule table*/
206  lin_tl_sch_switch(iii);
207  }
208  /* inform service error */
209  tl_desc_ptr->service_status = LD_SERVICE_ERROR;
210  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
211  prot_state_ptr->diagnostic_mode = DIAG_NONE;
212  tl_desc_ptr->interleave_timeout_counter = 0U;
213  }
214  }
215  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
216 }
217 #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
218 
219 /*FUNCTION**********************************************************************
220  *
221  * Function Name : lin_process_single_frame
222  * Description : Process single frame.
223  *
224  * Implements : lin_process_single_frame_Activity
225  *END**************************************************************************/
226 static void lin_process_single_frame(l_ifc_handle iii)
227 {
228  l_u8 length;
229  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
230  const l_u8 * data = prot_state_ptr->response_buffer_ptr;
231  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
232 
233  #if (SUPPORT_MASTER_MODE == 1U)
234  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
235  lin_master_data_t * master_data_ptr;
236  if (prot_user_config_ptr->function == (bool)LIN_MASTER)
237  {
239  }
240  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
241 
242  length = (l_u8)(data[1] & 0x0FU);
243  /* check length of SF. If not valid, ignore this PDU */
244  if (length <= 6U)
245  {
246  #if (SUPPORT_MASTER_MODE == 1U)
247  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
248  {
249  /* reset queue header and queue tail */
250  tl_desc_ptr->tl_rx_queue.queue_header = 0;
251  tl_desc_ptr->tl_rx_queue.queue_tail = 0;
252  tl_desc_ptr->tl_rx_queue.queue_current_size = 0;
253  tl_desc_ptr->tl_rx_queue.queue_status = LD_NO_DATA;
254  /* put to rx queue */
255  tl_put_raw(iii, data, &(tl_desc_ptr->tl_rx_queue), RECEIVING);
256 
257  /* process diagnostic interleaved mode */
258  if (prot_state_ptr->diagnostic_mode == DIAG_INTERLEAVE_MODE)
259  {
260  tl_desc_ptr->diag_interleave_state = DIAG_NOT_START;
261  tl_desc_ptr->interleave_timeout_counter = 0;
262  prot_state_ptr->diagnostic_mode = DIAG_NONE;
263  }
264 
265  /* set status is IDLE to receive new message */
266  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
267  tl_desc_ptr->service_status = LD_SERVICE_IDLE;
269 
270  /* process response */
271  lin_tl_get_response(iii);
272 
273  /* switch to normal table */
274  /* To be misra compliant */
276  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
277  master_data_ptr->schedule_start_entry_ptr[master_data_ptr->active_schedule_id] = 0;
278  }
279  else
280  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
281  {
282  #if (SUPPORT_SLAVE_MODE == 1U)
283  /* Slave interface */
284  /* put PDU to rx queue */
286  tl_desc_ptr->service_status = LD_REQUEST_FINISHED;
287  /* reset queue header and queue tail */
288  tl_desc_ptr->tl_rx_queue.queue_header = 0;
289  tl_desc_ptr->tl_rx_queue.queue_tail = 0;
290  tl_desc_ptr->tl_rx_queue.queue_current_size = 0;
291  tl_desc_ptr->tl_rx_queue.queue_status = LD_NO_DATA;
292 
293  if (data[0] == LD_FUNCTIONAL_NAD)
294  {
295  tl_desc_ptr->diag_state = LD_DIAG_RX_FUNCTIONAL;
296  }
297  else
298  {
299  tl_desc_ptr->diag_state = LD_DIAG_RX_PHY;
300  }
301 
302  /* put to rx queue */
303  tl_put_raw(iii, data, &(tl_desc_ptr->tl_rx_queue), RECEIVING);
304  tl_desc_ptr->frame_counter = 1;
305  tl_desc_ptr->num_of_pdu = 1;
307  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
308  }
309 
310  /* If ld_receive_message() function is called before SF pdu to be sent */
311  if(tl_desc_ptr->ld_return_data)
312  {
313  tl_receive_message(iii);
314  }
315  tl_desc_ptr->FF_pdu_received = false;
316  }
317 }
318 
319 /*FUNCTION**********************************************************************
320  *
321  * Function Name : lin_process_first_frame
322  * Description : Process first frame.
323  *
324  * Implements : lin_process_first_frame_Activity
325  *END**************************************************************************/
326 static void lin_process_first_frame(l_ifc_handle iii)
327 {
328  l_u16 length;
329  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
331  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
332 
333  /* for both MASTER and SLAVE */
334  length = (l_u16)((((l_u16)data[1] & 0x0FU) << 8U) + (l_u16)data[2]);
335  /* check length of FF. If not valid, ignore this PDU */
336  if ((length >= 7U) && (length <= prot_user_config_ptr->max_message_length))
337  {
338  #if (SUPPORT_SLAVE_MODE == 1U)
339  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
340  {
341  /* For misra compliant rule 9.1 */
342  tl_desc_ptr->diag_state = LD_DIAG_RX_PHY;
343  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
344  {
345  /* Set check N_Cr timeout */
348  }
349  }
350  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
351  /* put PDU to rx queue */
352  /* reset queue header and queue tail */
353  tl_desc_ptr->tl_rx_queue.queue_header = 0;
354  tl_desc_ptr->tl_rx_queue.queue_tail = 0;
355  tl_desc_ptr->tl_rx_queue.queue_current_size = 0;
356  tl_desc_ptr->tl_rx_queue.queue_status = LD_NO_DATA;
357  tl_put_raw(iii, data, &(tl_desc_ptr->tl_rx_queue), RECEIVING);
358 
359  /* calculate number of PDU for this message */
360  if (((length - 5U) % 6U) == 0U)
361  {
362  tl_desc_ptr->num_of_pdu = (l_u8)((length - 5U) / 6U);
363  }
364  else
365  {
366  tl_desc_ptr->num_of_pdu = (l_u8)(((length - 5U) / 6U) + 1U);
367  }
368 
369  /* set frame counter = 1 */
370  tl_desc_ptr->frame_counter = 1U;
371  tl_desc_ptr->service_status = LD_SERVICE_BUSY;
372 
373  /* Mark FF pdu is sent */
374  tl_desc_ptr->FF_pdu_received = true;
375  tl_desc_ptr->interleave_timeout_counter = 0;
376  }
377 }
378 
379 /*FUNCTION**********************************************************************
380  *
381  * Function Name : lin_process_consecutive_frame
382  * Description : Process consecutive frame.
383  *
384  * Implements : lin_process_consecutive_frame_Activity
385  *END**************************************************************************/
386 static void lin_process_consecutive_frame(l_ifc_handle iii)
387 {
388  l_u8 tmp_frame_counter;
389  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
391 
392  #if (SUPPORT_MASTER_MODE == 1U)
393  /* Only for MASTER */
394  lin_master_data_t * master_data_ptr;
395  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
396  if ((bool)LIN_MASTER == g_lin_protocol_user_cfg_array[iii].function)
397  {
398  /* To be misra compliant */
400  /* get frame counter of this PDU */
401  tmp_frame_counter = (l_u8)(data[1] & 0x0FU);
402  /* Check valid frame counter */
403  if (tmp_frame_counter == tl_desc_ptr->frame_counter)
404  {
405  /* increase frame counter */
406  tl_desc_ptr->frame_counter++;
407  if (tl_desc_ptr->frame_counter > 15U)
408  {
409  tl_desc_ptr->frame_counter = 0U;
410  }
411 
412  /* decrease number of PDU to check message is complete */
413  tl_desc_ptr->num_of_pdu--;
414  /* put PDU to rx queue */
415  tl_put_raw(iii, prot_state_ptr->response_buffer_ptr, &(tl_desc_ptr->tl_rx_queue), RECEIVING);
416  }
417  else
418  {
419  /* abort this message */
420  if(tl_desc_ptr->ld_return_data)
421  {
422  tl_desc_ptr->ld_return_data = false;
423  }
424  tl_desc_ptr->FF_pdu_received = false;
425  tl_desc_ptr->rx_msg_status = LD_WRONG_SN;
427  prot_state_ptr->diagnostic_mode = DIAG_NONE;
428  /* switch to normal table */
429  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
430  master_data_ptr->schedule_start_entry_ptr[master_data_ptr->active_schedule_id] = 0U;
431  }
432 
433  if (0U == tl_desc_ptr->num_of_pdu)
434  {
435  /* message is received completely */
436  /* set status is IDLE to receive new message */
438  tl_desc_ptr->service_status = LD_SERVICE_IDLE;
439 
440  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
441  /* process diagnostic interleaved mode */
442  if (prot_state_ptr->diagnostic_mode == DIAG_INTERLEAVE_MODE)
443  {
444  tl_desc_ptr->diag_interleave_state = DIAG_NOT_START;
445  prot_state_ptr->diagnostic_mode = DIAG_NONE;
446  tl_desc_ptr->interleave_timeout_counter = 0;
447  }
448 
449  /* call function to process this response */
450  lin_tl_get_response(iii);
451  /* switch to normal table */
452  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
453  master_data_ptr->schedule_start_entry_ptr[master_data_ptr->active_schedule_id] = 0U;
454 
455  /* If ld_receive_message() function is called before FF pdu to be sent */
456  if(tl_desc_ptr->ld_return_data)
457  {
458  tl_receive_message(iii);
459  }
460  tl_desc_ptr->FF_pdu_received = false;
461  }
462  }
463  else
464  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
465  {
466  #if (SUPPORT_SLAVE_MODE == 1U)
467  /* for SLAVE */
468  /* For misra compliant rule 9.1 */
469 
470  if (g_lin_protocol_user_cfg_array[iii].protocol_version == LIN_PROTOCOL_21)
471  {
472  /* Set check N_Cr timeout */
475  }
476  /* get frame counter of this PDU */
477  tmp_frame_counter = (l_u8)(data[1] & 0x0FU);
478  /* Check valid frame counter */
479  if (tmp_frame_counter == tl_desc_ptr->frame_counter)
480  {
481  /* increase frame counter */
482  tl_desc_ptr->frame_counter++;
483  if (tl_desc_ptr->frame_counter > 15U)
484  {
485  tl_desc_ptr->frame_counter = 0U;
486  }
487 
488  /* decrease number of PDU to check message is complete */
489  tl_desc_ptr->num_of_pdu--;
490  /* put PDU to rx queue */
491  tl_put_raw(iii, data, &(tl_desc_ptr->tl_rx_queue), RECEIVING);
492  tl_desc_ptr->diag_state = LD_DIAG_RX_PHY;
493  }
494  else
495  {
496  /* abort this message */
497  if(tl_desc_ptr->ld_return_data)
498  {
499  tl_desc_ptr->ld_return_data = false;
500  }
501  tl_desc_ptr->FF_pdu_received = false;
502  tl_desc_ptr->rx_msg_status = LD_WRONG_SN;
504  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
505  }
506 
507  if (0U == tl_desc_ptr->num_of_pdu)
508  {
509  /* message is received completely */
510  /* set status is IDLE to receive new message */
512  tl_desc_ptr->service_status = LD_REQUEST_FINISHED;
513 
515  /* If ld_receive_message() function is called before FF pdu to be sent */
516  if(tl_desc_ptr->ld_return_data)
517  {
518  tl_receive_message(iii);
519  }
520  tl_desc_ptr->FF_pdu_received = false;
521  }
522  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
523  }
524 }
525 
526 /*FUNCTION**********************************************************************
527  *
528  * Function Name : lin_process_pdu
529  * Description : Process packet data unit
530  *
531  * Implements : lin_process_pdu_Activity
532  *END**************************************************************************/
533 static void lin_process_pdu(l_ifc_handle iii,
534  const lin_tl_pdu_data_t * pdu)
535 {
536  l_u8 pci_type;
537 #if (SUPPORT_SLAVE_MODE == 1U)
538  if ((bool)LIN_SLAVE == g_lin_protocol_user_cfg_array[iii].function)
539  {
542  }
543 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
544 
545  /* get PCI type */
546  pci_type = (l_u8)(((*pdu)[1] & 0xF0U) >> 4U);
547  switch (pci_type)
548  {
549  case PCI_SF:
551  break;
552  case PCI_FF:
554  break;
555  case PCI_CF:
557  break;
558  default:
559  /* ignore this PDU */
560  break;
561  }
562 }
563 
564 /*FUNCTION**********************************************************************
565  *
566  * Function Name : lin_tl_handler_error
567  * Description : This function handles the diagnostic service and control error in TL
568  * This function is implemented for Slave and Master.
569  *
570  * Implements : lin_tl_handler_error_Activity
571  *END**************************************************************************/
572 static void lin_tl_handler_error(l_ifc_handle iii,
573  l_u8 pid)
574 {
575  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
576  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
577  #if (SUPPORT_MASTER_MODE == 1U)
578  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
579  lin_master_data_t * master_data_ptr;
580 
581  /* for master */
582  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
583  {
585  /* Master request */
586  if (0x3CU == pid)
587  {
588  /* update status of message and queue */
589  tl_desc_ptr->tx_msg_status = LD_FAILED;
590  /* For LIN 2.1 and above*/
591  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
592  {
594  }
595  /* For J2602*/
596  else
597  {
599  }
600  }
601  else
602  {
603  /* Slave Response */
604  /* update status of message and queue */
605  tl_desc_ptr->rx_msg_status = LD_FAILED;
606 
607  /* For LIN 2.1 and above*/
608  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
609  {
611  }
612  /* For J2602*/
613  else
614  {
616  }
617  } /* end of (0x3C == pid) */
618 
620  tl_desc_ptr->service_status = LD_SERVICE_ERROR;
621  if (DIAG_INTERLEAVE_MODE == prot_state_ptr->diagnostic_mode)
622  {
623  /* switch to normal table */
624  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
625  master_data_ptr->schedule_start_entry_ptr[master_data_ptr->active_schedule_id] = 0U;
626  }
627 
628  prot_state_ptr->diagnostic_mode = DIAG_NONE;
629  }
630  else
631  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
632  {
633  /* for slave */
634  /* Master request */
635  if (0x3CU == pid)
636  {
637  /* update status of message and queue */
638  tl_desc_ptr->rx_msg_status = LD_FAILED;
639  tl_desc_ptr->slave_resp_cnt = 0U;
640 
641  /* For LIN 2.1 and above*/
642  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
643  {
645  }
646  /* For J2602*/
647  else
648  {
650  }
651  }
652  else
653  {
654  /* Slave Response */
655  /* update status of message and queue */
656  tl_desc_ptr->tx_msg_status = LD_FAILED;
657  /* For LIN 2.1 and above*/
658  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
659  {
661  }
662  /* For J2602*/
663  else
664  {
666  }
667  } /* end of (0x3C == pid) */
668 
669  tl_desc_ptr->service_status = LD_SERVICE_ERROR;
671  }
672 }
673 
674 /*FUNCTION**********************************************************************
675  *
676  * Function Name : lin_tl_make_master_request_pdu
677  * Description : This function will be called on Master task in LIN protocol.
678  * It create a pointer to PDU data which available for Master request command,
679  * correspond to Diag frame to send
680  * This function is implemented for Master
681  *
682  * Implements : lin_tl_make_master_request_pdu_Activity
683  *END**************************************************************************/
684 static void lin_tl_make_master_request_pdu(l_ifc_handle iii)
685 {
686  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
687 
689  prot_state_ptr->response_length = 8U;
690 }
691 
692 /*FUNCTION**********************************************************************
693  *
694  * Function Name : lin_tl_get_pdu
695  * Description : This function copies the current PDU to Response Buffer in Low-level
696  * This function is implemented for Slave and Master.
697  *
698  * Implements : lin_tl_get_pdu_Activity
699  *END**************************************************************************/
700 static void lin_tl_get_pdu(l_ifc_handle iii)
701 {
702  /* Get data from tx queue */
703  tl_get_raw(iii, g_lin_protocol_state_array[iii].response_buffer_ptr, &(g_lin_tl_descriptor_array[iii].tl_tx_queue), TRANSMITTING);
704 }
705 
706 /*FUNCTION**********************************************************************
707  *
708  * Function Name : lin_tl_handler_rx_completed
709  * Description : This function handles the diag service and control event and data in TL
710  * This function is implemented for Slave and Master.
711  *
712  * Implements : lin_tl_handler_rx_completed_Activity
713  *END**************************************************************************/
714 static void lin_tl_handler_rx_completed(l_ifc_handle iii)
715 {
716  l_u8 pci_type;
717  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
718  const lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
719  const lin_tl_pdu_data_t * lin_tl_pdu = (const lin_tl_pdu_data_t *)prot_state_ptr->response_buffer_ptr;
720  #if (SUPPORT_SLAVE_MODE == 1U)
721  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
722  const lin_node_attribute_t * node_attr_ptr;
723  bool invalid_NAD = false;
724  if (prot_user_config_ptr->function == (bool)LIN_SLAVE)
725  {
726  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
727  invalid_NAD = ((LD_BROADCAST != (*lin_tl_pdu)[0]) && (LD_FUNCTIONAL_NAD != (*lin_tl_pdu)[0]) &&
728  (((*node_attr_ptr->configured_NAD_ptr != (*lin_tl_pdu)[0]) && (SERVICE_ASSIGN_NAD != (*lin_tl_pdu)[2])) ||
729  ((node_attr_ptr->initial_NAD != (*lin_tl_pdu)[0]) && (SERVICE_ASSIGN_NAD == (*lin_tl_pdu)[2]))));
730  }
731  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
732  pci_type = (l_u8)(((*lin_tl_pdu)[1] & 0xF0U) >> 4U);
733  /* check NAD whether or not belongs to this slave node */
734  #if (SUPPORT_SLAVE_MODE == 1U)
735  if (((bool)LIN_SLAVE == prot_user_config_ptr->function) && (invalid_NAD || (pci_type > PCI_CF)))
736  {
737  tl_desc_ptr->slave_resp_cnt = 0;
738  }
739  else
740  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
741  {
742  /* ignore Functional request */
743  if (!(((tl_desc_ptr->diag_state == LD_DIAG_RX_PHY) || (tl_desc_ptr->diag_state == LD_DIAG_TX_PHY)) &&
744  ((*lin_tl_pdu)[0] == LD_FUNCTIONAL_NAD)))
745  {
746  /* check error */
747  if (!((tl_desc_ptr->service_status == LD_SERVICE_ERROR) && (pci_type == PCI_CF)))
748  {
749  /* process received PDU */
750  lin_process_pdu(iii, lin_tl_pdu);
751  }
752  }
753  }
754 }
755 
756 /*FUNCTION**********************************************************************
757  *
758  * Function Name : lin_tl_handler_tx_completed
759  * Description : This function process when interface send diagnostic frame successfully
760  *
761  * Implements : lin_tl_handler_tx_completed_Activity
762  *END**************************************************************************/
763 static void lin_tl_handler_tx_completed(l_ifc_handle iii)
764 {
765  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
766  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
767  #if (SUPPORT_MASTER_MODE == 1U)
768  lin_master_data_t * master_data_ptr;
769  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
770 
771  /* decrease number of PDU for sending message */
772  tl_desc_ptr->tx_msg_size--;
773  /* Check message is sent completely */
774  if (0U == tl_desc_ptr->tx_msg_size)
775  {
777  tl_desc_ptr->tx_msg_status = LD_COMPLETED;
778  tl_desc_ptr->service_status = LD_REQUEST_FINISHED;
779  if (prot_user_config_ptr->function == (bool)LIN_SLAVE)
780  {
781  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
782  }
783  #if (SUPPORT_MASTER_MODE == 1U)
784  else
785  {
787  switch (tl_desc_ptr->diag_state)
788  {
789  case LD_DIAG_TX_PHY:
790  if (master_data_ptr->send_slave_res_flg == (bool)1U)
791  {
792  tl_desc_ptr->diag_state = LD_DIAG_RX_PHY;
793  }
794  else
795  {
796  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
797  master_data_ptr->send_slave_res_flg = (bool)1U;
798  master_data_ptr->send_functional_request_flg = (bool)0U;
799  }
800  break;
802  tl_desc_ptr->diag_state = LD_DIAG_IDLE;
803  master_data_ptr->send_slave_res_flg = (bool)1U;
804  master_data_ptr->send_functional_request_flg = (bool)0U;
805  break;
807  tl_desc_ptr->diag_state = LD_DIAG_RX_PHY;
808  master_data_ptr->send_slave_res_flg = (bool)1U;
809  master_data_ptr->send_functional_request_flg = (bool)0U;
810  break;
811  default:
812  /* DO nothing */
813  break;
814  }
815  }
816  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
817  }
818  else
819  {
820  #if (SUPPORT_SLAVE_MODE == 1U)
821  if ((prot_user_config_ptr->function == (bool)LIN_SLAVE) && (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21))
822  {
825  }
826  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
827  }
828  #if (SUPPORT_MASTER_MODE == 1U)
829  /* For LIN Master switch back to normal schedule from Master Request Schedule */
830  if (prot_user_config_ptr->function == (bool)LIN_MASTER)
831  {
832  /* Switch to previous normal schedule table*/
833  lin_tl_sch_switch(iii);
834  }
835  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
836 }
837 
838 #if (SUPPORT_SLAVE_MODE == 1U)
839 /*FUNCTION**********************************************************************
840  *
841  * Function Name : lin_tl_attach_service
842  * Description : This function makes a connection to Diag service class that support for LIN function
843  * This function is implemented for Slave only.
844  *
845  * Implements : lin_tl_attach_service_Activity
846  *END**************************************************************************/
847 static void lin_tl_attach_service(l_ifc_handle iii)
848 {
849  l_u8 sid;
850  l_u8 frame_type;
851  l_u8 rx_queue_current_status;
852  const lin_transport_layer_queue_t * rx_queue;
853  lin_transport_layer_queue_t * tx_queue;
854  rx_queue = &(g_lin_tl_descriptor_array[iii].tl_rx_queue);
855  tx_queue = &(g_lin_tl_descriptor_array[iii].tl_tx_queue);
856 
857 
858  /* prepare tx queue */
859  tx_queue->queue_current_size = 0;
860  tx_queue->queue_header = 0;
861  tx_queue->queue_tail = 0;
862  tx_queue->queue_status = LD_QUEUE_EMPTY;
863 
864  /* Get rx queue current status */
865  rx_queue_current_status = ld_raw_rx_status(iii);
866  /* Check whether RX Queue contains data */
867  if (((l_u8)LD_DATA_AVAILABLE == rx_queue_current_status) || ((l_u8)LD_QUEUE_FULL == rx_queue_current_status))
868  {
869  /* get frame type */
870  frame_type = (l_u8)((rx_queue->tl_pdu_ptr[rx_queue->queue_header][1] & 0xF0U) >> 4U);
871  /* Get SID information */
872  if (frame_type == PCI_FF)
873  {
874  sid = rx_queue->tl_pdu_ptr[rx_queue->queue_header][3];
875  }
876  else
877  {
878  sid = rx_queue->tl_pdu_ptr[rx_queue->queue_header][2];
879  }
880 
881  /* Callback to diagnostic layer to process SID */
883  }
884 }
885 
886 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
887 
888 #if (SUPPORT_MASTER_MODE == 1U)
889 /*FUNCTION**********************************************************************
890  *
891  * Function Name : lin_tl_get_response
892  * Description : This function checks result of service, it is called when the Slave Response Frame received
893  * This function is implemented for Master only.
894  *
895  * Implements : lin_tl_get_response_Activity
896  *END**************************************************************************/
897 static void lin_tl_get_response(l_ifc_handle iii)
898 {
899  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
901  lin_tl_pdu_data_t lin_tl_pdu;
902  l_u8 sci = 0U;
903  l_u8 i;
904  const lin_transport_layer_queue_t * rx_queue = &(tl_desc_ptr->tl_rx_queue);
905  l_u8 frame_type;
906 
907  for (i = 0; i < 8U; i++)
908  {
909  lin_tl_pdu[i] = rx_queue->tl_pdu_ptr[rx_queue->queue_header][i];
910  }
911 
912  /* get frame type */
913  frame_type = (l_u8)(((lin_tl_pdu)[1] & 0xF0U) >> 4U);
914  /* Set configuration service status */
915  tl_desc_ptr->service_status = LD_SERVICE_IDLE;
916  if (frame_type == PCI_SF)
917  {
918  sci = (lin_tl_pdu)[2];
919  }
920  else
921  {
922  if (frame_type == PCI_FF)
923  {
924  sci = (lin_tl_pdu)[3];
925  }
926  }
927 
928  /* Update last RSID */
929  tl_desc_ptr->last_RSID = sci;
930  /* Get SID information */
931  if (RES_NEGATIVE == sci)
932  {
933  /* set response configuration status to negative response */
934  tl_desc_ptr->last_cfg_result = LD_NEGATIVE;
935  /* update error code */
936  tl_desc_ptr->ld_error_code = (lin_tl_pdu)[4];
937 
938  /* switch to normal schedule table */
939  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
940 
941  tl_desc_ptr->service_status = LD_SERVICE_IDLE;
942  }
943  else
944  {
945  sci = (l_u8)(sci - 0x40U);
946  /* Check the result of service */
947  switch (sci)
948  {
950  /* Assign data received from slave to product_id_ptr */
951  ((l_u8 *)tl_desc_ptr->product_id_ptr)[0] = (lin_tl_pdu)[4];
952  ((l_u8 *)tl_desc_ptr->product_id_ptr)[1] = (lin_tl_pdu)[3];
953  ((l_u8 *)tl_desc_ptr->product_id_ptr)[2] = (lin_tl_pdu)[6];
954  ((l_u8 *)tl_desc_ptr->product_id_ptr)[3] = (lin_tl_pdu)[5];
955  ((l_u8 *)tl_desc_ptr->product_id_ptr)[4] = (lin_tl_pdu)[7];
956 
957  break;
961  case SERVICE_ASSIGN_NAD:
964  break;
965  /* check diagnostic service is belong to class II or class III */
966  default:
967  /* do nothing */
968  break;
969  }
970 
971  /* Set the last configuration result */
972  tl_desc_ptr->last_cfg_result = LD_SUCCESS;
973  tl_desc_ptr->service_status = LD_SERVICE_IDLE;
974  /* switch to normal schedule table */
975  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
976  }
977 }
978 
979 /*FUNCTION**********************************************************************
980  *
981  * Function Name : lin_tl_sch_switch
982  * Description : This function switch value of active schedule table and previous schedule table
983  * and reset entry of active schedule table
984  * This function is implemented for Master only.
985  *
986  * Implements : lin_tl_sch_switch_Activity
987  *END**************************************************************************/
988 static void lin_tl_sch_switch(l_ifc_handle iii)
989 {
990  l_u8 temp;
992 
993  /* Switch to previous normal schedule table*/
994  temp = master_data_ptr->previous_schedule_id;
995  /* current schedule reaches its next schedule entry point */
996  master_data_ptr->previous_schedule_id = master_data_ptr->active_schedule_id;
997  /* Insert new schedule at that point of the current schedule */
998  master_data_ptr->active_schedule_id = temp;
999  /* Assign the start entry of new schedule table by argument entry */
1000  master_data_ptr->schedule_start_entry_ptr[temp] = 0;
1001 }
1002 
1003 /*FUNCTION**********************************************************************
1004  *
1005  * Function Name : lin_tl_handle_interleave_mode
1006  * Description : This function switch value of active schedule table and previous schedule table
1007  * and change diagnostic state of Master
1008  * This function is implemented for Master only.
1009  *
1010  * Implements : lin_tl_handle_interleave_mode_Activity
1011  *END**************************************************************************/
1012 static void lin_tl_handle_interleave_mode(l_ifc_handle iii)
1013 {
1014  l_u8 * active_schedule_id;
1015  l_u8 * previous_schedule_id;
1016  lin_master_data_t * master_data_ptr;
1017  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1018  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
1019  const lin_transport_layer_queue_t * tl_queue;
1020  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1021 
1022  /* Get transmit queue */
1023  tl_queue = &(tl_desc_ptr->tl_tx_queue);
1024 
1025  if (tl_queue->queue_current_size > 0U)
1026  {
1027  prot_state_ptr->diagnostic_mode = DIAG_INTERLEAVE_MODE;
1028  }
1029 
1030  if (DIAG_INTERLEAVE_MODE == prot_state_ptr->diagnostic_mode)
1031  {
1032  /* To be misra compliant */
1034  active_schedule_id = &master_data_ptr->active_schedule_id;
1035  previous_schedule_id = &master_data_ptr->previous_schedule_id;
1036  *previous_schedule_id = *active_schedule_id;
1037 
1038  if (tl_queue->queue_current_size > 0U)
1039  {
1040  switch (tl_desc_ptr->diag_state)
1041  {
1042  case LD_DIAG_IDLE:
1043  if (master_data_ptr->send_functional_request_flg == (bool)0U)
1044  {
1045  tl_desc_ptr->diag_state = LD_DIAG_TX_PHY;
1046  }
1047  else
1048  {
1049  tl_desc_ptr->diag_state = LD_DIAG_TX_FUNCTIONAL;
1050  }
1051  break;
1052  case LD_DIAG_TX_PHY:
1053  if (master_data_ptr->send_functional_request_flg == (bool)1U)
1054  {
1055  tl_desc_ptr->diag_state = LD_DIAG_TX_INTERLEAVED;
1056  }
1057  break;
1058  case LD_DIAG_RX_PHY:
1059  if (master_data_ptr->send_functional_request_flg == (bool)1U)
1060  {
1061  tl_desc_ptr->diag_state = LD_DIAG_RX_INTERLEAVED;
1062  }
1063  break;
1064  default:
1065  /* DO nothing */
1066  break;
1067  }
1068  }
1069 
1070 
1071  if ((tl_desc_ptr->diag_state == LD_DIAG_TX_PHY) || (tl_desc_ptr->diag_state == LD_DIAG_TX_INTERLEAVED) ||
1072  (tl_desc_ptr->diag_state == LD_DIAG_RX_INTERLEAVED) || (tl_desc_ptr->diag_state == LD_DIAG_TX_FUNCTIONAL))
1073  {
1074  *active_schedule_id = (l_u8)(prot_user_config_ptr->schedule_start + 2U);
1075  }
1076  else
1077  {
1078  if (tl_desc_ptr->diag_state == LD_DIAG_RX_PHY)
1079  {
1080  *active_schedule_id = (l_u8)(prot_user_config_ptr->schedule_start + 3U);
1081  }
1082  }
1083  }
1084 }
1085 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
1086 
1087 /*FUNCTION**********************************************************************
1088  *
1089  * Function Name : tl_put_raw
1090  * Description : Copy the specified raw data to the specified queue
1091  *
1092  * Implements : tl_put_raw_Activity
1093  *END**************************************************************************/
1094 void tl_put_raw(l_ifc_handle iii,
1095  const l_u8 * const data,
1097  l_u8 direction)
1098 {
1099  lin_tl_pdu_data_t * queue_data;
1100  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1101  l_u8 i;
1102 
1103 #if (SUPPORT_MASTER_MODE == 1U)
1104  lin_master_data_t * master_data_ptr;
1105 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
1106 
1107  /* Get transmit queue */
1108  queue_data = queue->tl_pdu_ptr;
1109 
1110  /* check status of queue */
1111  if (LD_QUEUE_FULL != queue->queue_status)
1112  {
1113  /* process queue tail */
1114  if ((LD_QUEUE_EMPTY == queue->queue_status) || (LD_NO_DATA == queue->queue_status))
1115  {
1116  /* Set status of queue */
1117  if (TRANSMITTING == direction)
1118  {
1119  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
1120  {
1122  }
1123  }
1124  else
1125  {
1127  }
1128  }
1129  else
1130  {
1131  if ((data[0] == LD_FUNCTIONAL_NAD) && (TRANSMITTING == direction))
1132  {
1133  queue->queue_header--;
1134  if (0U == queue->queue_header)
1135  {
1136  queue->queue_header = queue->queue_max_size;
1137  }
1138  }
1139  else
1140  {
1141  queue->queue_tail++;
1142  /* Check if queue size equal to queue tail */
1143  if (queue->queue_max_size == queue->queue_tail)
1144  {
1145  queue->queue_tail = 0U;
1146  }
1147  }
1148  }
1149 
1150  #if (SUPPORT_MASTER_MODE == 1U)
1151  if ((data[0] == LD_FUNCTIONAL_NAD) && (TRANSMITTING == direction) && (prot_user_config_ptr->function == (bool)LIN_MASTER))
1152  {
1154  for (i = 0U; i < 8U; i++)
1155  {
1156  queue_data[queue->queue_header][i] = data[i];
1157  }
1158 
1159  /* Set Send Functional Request Flag */
1160  master_data_ptr->send_functional_request_flg = (bool)1U;
1161  /* Clear Send slave response flag */
1162  master_data_ptr->send_slave_res_flg = (bool)0U;
1163  }
1164  else
1165  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
1166  {
1167  /* copy data to queue */
1168  for (i = 0U; i < 8U; i++)
1169  {
1170  queue_data[queue->queue_tail][i] = data[i];
1171  }
1172  }
1173 
1174  /* update queue status */
1175  queue->queue_current_size++;
1176  if (queue->queue_current_size >= queue->queue_max_size)
1177  {
1178  queue->queue_status = LD_QUEUE_FULL;
1179  }
1180  }
1181 }
1182 
1183 /*FUNCTION**********************************************************************
1184  *
1185  * Function Name : tl_get_raw
1186  * Description : Get the raw data from the specified queue
1187  *
1188  * Implements : tl_get_raw_Activity
1189  *END**************************************************************************/
1190 void tl_get_raw(l_ifc_handle iii,
1191  l_u8 * const data,
1193  l_u8 direction)
1194 {
1195  const lin_transport_layer_queue_t * tl_queue;
1196  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1197  const lin_tl_pdu_data_t * queue_data;
1198  l_u8 i;
1199  l_u16 queue_header;
1200 
1201  tl_queue = queue;
1202  /* Get queue */
1203  queue_data = (const lin_tl_pdu_data_t *)tl_queue->tl_pdu_ptr;
1204 
1205  /* Check queue status (is the queue contains data? if yes: get data from queue and put them to buffer) */
1206  if ((LD_NO_DATA != tl_queue->queue_status) && (LD_QUEUE_EMPTY != tl_queue->queue_status))
1207  {
1208  /* get data from head queue */
1209  queue_header = tl_queue->queue_header;
1210  for (i = 0U; i < 8U; i++)
1211  {
1212  data[i] = queue_data[queue_header][i];
1213  }
1214 
1215  /* update queue status */
1216  if (0U == (--queue->queue_current_size))
1217  {
1218  if (TRANSMITTING == direction)
1219  {
1220  queue->queue_status = LD_QUEUE_EMPTY;
1221  }
1222  else
1223  {
1224  queue->queue_status = LD_NO_DATA;
1225  }
1226  }
1227  else
1228  {
1229  if (TRANSMITTING == direction)
1230  {
1231  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
1232  {
1234  }
1235  }
1236  else
1237  {
1239  }
1240  }
1241 
1242  /* change queue header */
1243  if (0U != queue->queue_current_size)
1244  {
1245  queue->queue_header++;
1246  if (queue->queue_header == queue->queue_max_size)
1247  {
1248  queue->queue_header = 0U;
1249  }
1250  }
1251  }
1252 }
1253 
1254 /*FUNCTION**********************************************************************
1255  *
1256  * Function Name : tl_receive_message
1257  * Description : Get data from rx_queue and store it in data pointer of
1258  * ld_receive_message() function
1259  *
1260  * Implements : tl_receive_message_Activity
1261  *END**************************************************************************/
1262 static void tl_receive_message(l_ifc_handle iii)
1263 {
1264  lin_tl_descriptor_t * tl_desc_ptr = &g_lin_tl_descriptor_array[iii];
1265  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
1266  lin_tl_pdu_data_t pdu;
1267  l_u16 i;
1268  l_u16 data_index = 0U;
1269  l_u16 tmp_length = 0U;
1270  l_u8 PCI_type;
1271  l_u8* data = tl_desc_ptr->receive_message_ptr;
1272  l_u8* NAD = tl_desc_ptr->receive_NAD_ptr;
1273  l_u16* length = tl_desc_ptr->receive_message_length_ptr;
1274 
1275  if (LD_NO_DATA != tl_desc_ptr->tl_rx_queue.queue_status)
1276  {
1277  /* Message is received completely */
1278  /* get data from receive queue */
1279  /*
1280  * @violates MISRA 2012 Required Rule 1.3 Required
1281  */
1282  ld_get_raw(iii, pdu);
1283  /* Analyze data */
1284  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
1285  {
1286  *NAD = pdu[0];
1287  }
1288 
1289  /* Check type of pdu */
1290  PCI_type = (l_u8)((pdu[1] & 0xF0U) >> 4U);
1291  switch (PCI_type)
1292  {
1293  /* Single frame */
1294  case PCI_SF:
1295  tmp_length = (l_u16)((l_u16)pdu[1] & 0x000FU);
1296  i = *length;
1297  *length = tmp_length;
1298  if (i < tmp_length)
1299  {
1300  tmp_length = i;
1301  }
1302 
1303  data[0] = pdu[2];
1304  for (i = 1U; i < tmp_length; i++)
1305  {
1306  data[i] = pdu[i + 2U];
1307  }
1308  break;
1309  /* Multi frame */
1310  case PCI_FF:
1311  /* First frame */
1312  tmp_length = (l_u16)((((l_u16)pdu[1] & 0x000FU) << 8) + (l_u16)pdu[2]);
1313  i = *length;
1314  *length = tmp_length;
1315  if (i < tmp_length)
1316  {
1317  tmp_length = i;
1318  }
1319  data[0] = pdu[3];
1320  for (i = 1U; i < 5U; i++)
1321  {
1322  data[i] = pdu[i + 3U];
1323  }
1324 
1325  tmp_length -= 5U;
1326  data_index += 5U;
1327 
1328  /* Consecutive frame */
1329  while (tmp_length > 6U)
1330  {
1331  /* get PDU */
1332  /*
1333  * @violates MISRA 2012 Required Rule 1.3 Required
1334  */
1335  ld_get_raw(iii, pdu);
1336  for (i = 2U; i < 8U; i++)
1337  {
1338  data[data_index] = pdu[i];
1339  data_index++;
1340  }
1341 
1342  tmp_length -= 6U;
1343  }
1344 
1345  /* Last frame */
1346  if (tmp_length > 0U)
1347  {
1348  /* get PDU */
1349  /*
1350  * @violates MISRA 2012 Required Rule 1.3 Required
1351  */
1352  ld_get_raw(iii, pdu);
1353  for (i = 0U; i < tmp_length; i++)
1354  {
1355  data[data_index] = pdu[i + 2U];
1356  data_index++;
1357  }
1358  }
1359  break;
1360  default:
1361  /* do nothing */
1362  break;
1363  } /* end of switch */
1364  tl_desc_ptr->ld_return_data = false;
1365  tl_desc_ptr->rx_msg_status = LD_COMPLETED;
1366  }
1367 }
1368 
1369 #endif /*end (SUPPORT_TRANSPORT_LAYER == 1U) */
1370 /*******************************************************************************
1371  * EOF
1372  ******************************************************************************/
#define SERVICE_SAVE_CONFIGURATION
Definition: lin.h:64
static void lin_tl_get_response(l_ifc_handle iii)
lin_sch_tbl_type_t sch_tbl_type
Definition: lin.h:302
static void lin_tl_handle_timeout(l_ifc_handle iii)
lin_tl_event_id_t
Transport layer event IDs Implements : lin_tl_event_id_t_Class.
Definition: lin.h:348
l_ifc_master_handle master_ifc_handle
Definition: lin.h:528
l_u8 num_of_pdu
Definition: lin.h:486
lin_tl_callback_return_t
Transport layer event IDs Implements : lin_tl_callback_return_t_Class.
Definition: lin.h:364
l_u8 ld_error_code
Definition: lin.h:481
#define SERVICE_READ_BY_IDENTIFY
Definition: lin.h:62
static void lin_tl_handler_rx_completed(l_ifc_handle iii)
static void lin_tl_sch_switch(l_ifc_handle iii)
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
static void tl_receive_message(l_ifc_handle iii)
#define SERVICE_ASSIGN_FRAME_ID
Definition: lin.h:61
l_ifc_slave_handle slave_ifc_handle
Definition: lin.h:527
bool FF_pdu_received
Definition: lin.h:495
#define LD_FUNCTIONAL_NAD
lin_master_data_t g_lin_master_data_array[LIN_NUM_OF_MASTER_IFCS]
Definition: lin.c:52
Definition: lin.h:315
#define PCI_SF
static void lin_process_pdu(l_ifc_handle iii, const lin_tl_pdu_data_t *pdu)
l_u8 ld_raw_rx_status(l_ifc_handle iii)
Get the status of the raw frame receive function.
#define DIAG_SERVICE_CALLBACK_HANDLER(iii, sid)
#define LIN_SLAVE
Mode of LIN node (master or slave)
Definition: lin.h:167
l_u16 * receive_message_length_ptr
Definition: lin.h:500
l_diagnostic_mode_t diagnostic_mode
Definition: lin.h:576
l_bool send_slave_res_flg
Definition: lin.h:552
lin_tl_pdu_data_t * tl_pdu_ptr
Definition: lin.h:444
static void lin_tl_handler_error(l_ifc_handle iii, l_u8 pid)
LIN master configuration structure Implements : lin_master_data_t_Class.
Definition: lin.h:541
const lin_node_attribute_t g_lin_node_attribute_array[LIN_NUM_OF_SLAVE_IFCS]
l_u8 previous_schedule_id
Definition: lin.h:544
Schedule table description Implements : lin_schedule_t_Class.
Definition: lin.h:299
static void lin_tl_attach_service(l_ifc_handle iii)
l_u16 interleave_timeout_counter
Definition: lin.h:490
lin_tl_descriptor_t g_lin_tl_descriptor_array[LIN_NUM_OF_IFCS]
Definition: lin.c:49
#define PCI_CF
l_u16 tx_msg_size
Definition: lin.h:477
#define SERVICE_TARGET_RESET
l_u16 check_timeout
Definition: lin.h:484
Configuration structure Implements : lin_protocol_user_config_t_Class.
Definition: lin.h:510
lin_message_status_t rx_msg_status
Definition: lin.h:472
diag_interleaved_state_t diag_interleave_state
Definition: lin.h:489
lin_message_timeout_type_t check_timeout_type
Definition: lin.h:483
l_u8 * response_buffer_ptr
Definition: lin.h:564
l_u8 * receive_NAD_ptr
Definition: lin.h:499
#define LIN_MASTER
Definition: lin.h:168
Definition: lin.h:401
void ld_get_raw(l_ifc_handle iii, l_u8 *const data)
Copy the oldest received diagnostic frame data to the memory specified by data.
LIN protocol status structure Implements : lin_protocol_state_t_Class.
Definition: lin.h:560
static void lin_tl_handler_tx_completed(l_ifc_handle iii)
static void lin_tl_get_pdu(l_ifc_handle iii)
void tl_put_raw(l_ifc_handle iii, const l_u8 *const data, lin_transport_layer_queue_t *queue, l_u8 direction)
l_u16 N_Cr_timeout
Definition: lin.h:205
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
const lin_protocol_user_config_t g_lin_protocol_user_cfg_array[LIN_NUM_OF_IFCS]
static void lin_process_first_frame(l_ifc_handle iii)
ld_queue_status_t queue_status
Definition: lin.h:441
unsigned char l_u8
Unsigned 8 bit integer Implements : l_u8_Class.
Definition: lin_types.h:30
lin_tl_callback_return_t lin_tl_callback_handler(l_ifc_handle iii, lin_tl_event_id_t tl_event_id, l_u8 id)
static void lin_tl_handle_interleave_mode(l_ifc_handle iii)
lin_transport_layer_queue_t tl_tx_queue
Definition: lin.h:467
l_u8 response_length
Definition: lin.h:565
lin_diagnostic_state_t diag_state
Definition: lin.h:488
static void lin_process_single_frame(l_ifc_handle iii)
Definition: lin.h:354
l_u16 N_As_timeout
Definition: lin.h:204
l_bool send_functional_request_flg
Definition: lin.h:553
lin_transport_layer_queue_t tl_rx_queue
Definition: lin.h:468
l_u8 active_schedule_id
Definition: lin.h:543
#define LD_BROADCAST
l_u8 frame_counter
Definition: lin.h:487
#define PCI_FF
#define RES_NEGATIVE
void tl_get_raw(l_ifc_handle iii, l_u8 *const data, lin_transport_layer_queue_t *queue, l_u8 direction)
static void lin_tl_make_master_request_pdu(l_ifc_handle iii)
lin_protocol_handle_t protocol_version
Definition: lin.h:512
lin_message_status_t tx_msg_status
Definition: lin.h:476
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 lin_tl_pdu_data_t[8]
PDU data. Implements : lin_tl_pdu_data_t_Class.
Definition: lin.h:99
#define SERVICE_CONDITIONAL_CHANGE_NAD
Definition: lin.h:63
static void lin_process_consecutive_frame(l_ifc_handle iii)
#define TRANSMITTING
l_u8 last_RSID
Definition: lin.h:480
bool ld_return_data
Definition: lin.h:494
l_u8 initial_NAD
Definition: lin.h:192
l_u8 * schedule_start_entry_ptr
Definition: lin.h:545
l_u8 * receive_message_ptr
Definition: lin.h:498
unsigned short int l_u16
Unsigned 16 bit integer Implements : l_u16_Class.
Definition: lin_types.h:36
#define RECEIVING
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