S32 SDK
lin_common_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  */
18 
19 
20 #include "lin_common_api.h"
21 #include "lin_common_proto.h"
22 #include "lin_lin21_proto.h"
23 #include "lin_j2602_proto.h"
24 
25 
26 /*******************************************************************************
27  * Variables
28  ******************************************************************************/
29 
30 /*******************************************************************************
31  * Static function prototypes
32  ******************************************************************************/
33 /*
34  * @brief Handle the received ID and decide the next action of Stack.
35  *
36  * @param iii Interface name
37  * @param id ID to process
38  * @return void
39  */
40 static void lin_process_id(l_ifc_handle iii,
41  l_u8 id);
42 
43 static void lin_update_rx(l_ifc_handle iii,
44  l_u8 id);
45 
46 static void lin_update_tx(l_ifc_handle iii,
47  l_u8 id);
48 
49 static void lin_handle_error(l_ifc_handle iii,
50  lin_lld_event_id_t event_id,
51  l_u8 id);
52 
53 static void lin_bus_activity_timeout(l_ifc_handle iii);
54 
55 static void lin_update_tx_flags(l_ifc_handle iii,
56  l_u8 frm_id);
57 
58 /*******************************************************************************
59  * Code
60  ******************************************************************************/
61 
62 /*FUNCTION**********************************************************************
63  *
64  * Function Name : lin_pid_resp_callback_handler
65  * Description : Callback handler for LIN low level events.
66  *
67  * Implements : lin_pid_resp_callback_handler_Activity
68  *END**************************************************************************/
69 void lin_pid_resp_callback_handler(l_ifc_handle iii,
70  const lin_lld_event_id_t event_id,
71  l_u8 id)
72 {
73  switch (event_id)
74  {
75  case LIN_LLD_PID_OK:
76  lin_process_id(iii, id);
77  break;
79  lin_update_tx(iii, id);
80  break;
82  lin_update_rx(iii, id);
83  break;
86  break;
87  case LIN_LLD_PID_ERR:
88  case LIN_LLD_FRAME_ERR:
92  lin_handle_error(iii, event_id, id);
93  break;
94  default:
95  /* do nothing */
96  break;
97  }
98 }
99 
100 /*FUNCTION**********************************************************************
101  *
102  * Function Name : lin_process_id
103  * Description : Handle the received ID and decide the next action of Stack.
104  *
105  * Implements : lin_process_id_Activity
106  *END**************************************************************************/
107 static void lin_process_id(l_ifc_handle iii,
108  l_u8 id)
109 {
110  l_u8 action = 0U;
111  const lin_frame_t * lin_frame_ptr;
112  l_u8 frame_index;
113 #if ((SUPPORT_SLAVE_MODE == 1U) && (SUPPORT_PROTOCOL_21 == 1U))
114  l_u8 volatile associate_frame;
115  l_u8 flag_offset;
116  l_u8 flag_size;
117  l_u8 i;
118 #endif
119  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
120  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
121 
122  frame_index = lin_get_frame_index(iii, id);
123  lin_frame_ptr = &(prot_user_config_ptr->frame_tbl_ptr[frame_index]);
124  if (0xFFU != frame_index)
125  {
126  action = 1U;
127  prot_state_ptr->last_pid = lin_process_parity(id,MAKE_PARITY);
128  /* PID belongs to this node, then check type of frame */
129  switch (lin_frame_ptr->frm_type)
130  {
131  /* Unconditional frame */
132  case LIN_FRM_UNCD:
133  if (LIN_RES_PUB == lin_frame_ptr->frm_response)
134  {
136  /* Set response */
137  action = 2U;
138  }
139  break;
140  #if (SUPPORT_PROTOCOL_21 == 1U)
141  /* Event trigger frame */
142  case LIN_FRM_EVNT:
143  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
144  {
145  /* Rx response */
146  action = 1U;
147  }
148  #if (SUPPORT_SLAVE_MODE == 1U)
149  else
150  {
151  /* For each slave node, get the only one associated unconditional frame */
152  associate_frame = (l_u8)(*((lin_frame_ptr->frame_data_ptr)->associated_uncond_frame_ptr));
153  flag_offset = prot_user_config_ptr->frame_tbl_ptr[associate_frame].flag_offset;
154  flag_size = prot_user_config_ptr->frame_tbl_ptr[associate_frame].flag_size;
155  /* Update transmit flags */
156  for (i = 0U; i < flag_size; i++)
157  {
158  if (g_lin_flag_handle_tbl[flag_offset++] != 0xFFU)
159  {
160  /* Frame is updated */
161  lin_make_res_evnt_frame(iii, prot_user_config_ptr->list_identifiers_RAM_ptr[1U + associate_frame - prot_user_config_ptr->frame_start]);
162  /* Set response */
163  action = 2U;
164  break;
165  }
166  }
167  }
168  #endif /* End (SUPPORT_SLAVE_MODE == 1) */
169  break;
170  #endif /* End (SUPPORT_PROTOCOL_21 == 1) */
171 
172  /* Diagnostic frame */
173  case LIN_FRM_DIAG:
174  if (LIN_RES_PUB == lin_frame_ptr->frm_response)
175  {
176  action = 2U;
177  if (0x3CU == id)
178  {
179  if (DIAG_INTERLEAVE_MODE == prot_state_ptr->diagnostic_mode)
180  {
182  }
183  }
184  else
185  {
187  {
188  action = 0U;
189  }
190  }
191  }
192  else
193  {
195  /* Rx response */
196  action = 1U;
197  }
198 
199  break;
200  default:
201  /* do nothing */
202  break;
203  }
204  }
205 
206  switch (action)
207  {
208  case 1U:
209  /* Receive response */
210  (void)lin_lld_rx_response(iii, lin_frame_ptr->frm_len);
211  break;
212  case 2U:
213  /* Set response */
214  (void)lin_lld_set_response(iii, lin_frame_ptr->frm_len);
215  break;
216  default:
217  /* ignore response */
218  (void)lin_lld_ignore_response(iii);
219  break;
220  }
221 }
222 
223 /*FUNCTION**********************************************************************
224  *
225  * Function Name : lin_update_rx
226  * Description : This function update signal, status, and flag after received response.
227  *
228  * Implements : lin_update_rx_Activity
229  *END**************************************************************************/
230 static void lin_update_rx(l_ifc_handle iii,
231  l_u8 id)
232 {
233  l_u8 frame_index, flag_offset, flag_size, i, associate_id;
234  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
235  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
236 #if (SUPPORT_MASTER_MODE == 1U)
237  lin_master_data_t * master_data_ptr;
238 #endif /* End (SUPPORT_MASTER_MODE == 1) */
239 
240  /* Set successful transfer */
241  prot_state_ptr->successful_transfer = 1U;
242  /* if two or more frames are processed since the previous call to l_ifc_read_status, set overrun flag to 1 */
243  if (prot_state_ptr->num_of_processed_frame < 0xFFU)
244  {
245  prot_state_ptr->num_of_processed_frame++;
246  }
247 
248  if ((prot_state_ptr->num_of_processed_frame > 1U) && (prot_state_ptr->overrun_flg == 0U))
249  {
250  prot_state_ptr->overrun_flg = 1U;
251  }
252 
253  frame_index = lin_get_frame_index(iii, id);
254  if (0xFFU != frame_index)
255  {
256  /* This PID doesn't belong to this node */
257  /* PID belongs to this node, then check type of frame */
258  switch (prot_user_config_ptr->frame_tbl_ptr[frame_index].frm_type)
259  {
260  /* Unconditional frame */
261  case LIN_FRM_UNCD:
263  break;
264  /* Event trigger frame */
265  case LIN_FRM_EVNT:
266  lin_update_rx_evnt_frame(iii, id);
267  /* Recalculate frame_index by updating associate PID */
268  associate_id = lin_process_parity(prot_state_ptr->response_buffer_ptr[0], CHECK_PARITY);
269  frame_index = lin_get_frame_index(iii, associate_id);
270  break;
271  /* Diagnostic frame */
272  case LIN_FRM_DIAG:
273  /* If goto sleep signal */
274  if (0U == prot_state_ptr->response_buffer_ptr[0])
275  {
276  /* In a slave node, set go to sleep flag in state structure */
277  prot_state_ptr->go_to_sleep_flg = true;
278  (void)lin_lld_set_low_power_mode(iii);
279  }
280  else
281  {
282  /* Call transport layer callback to process TL_RX_COMPLETED event*/
284  }
285 
286  break;
287  default:
288  /* do nothing */
289  break;
290  }
291 
292  /* Update rx frame flag */
293  g_lin_frame_flag_handle_tbl[frame_index] = true;
294 
295  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
296  {
297  /* Update rx signal flags */
298  flag_offset = prot_user_config_ptr->frame_tbl_ptr[frame_index].flag_offset;
299  flag_size = prot_user_config_ptr->frame_tbl_ptr[frame_index].flag_size;
300  for (i = 0U; i < flag_size; i++)
301  {
302  g_lin_flag_handle_tbl[flag_offset] = 0xFFU;
303  flag_offset++;
304  }
305  }
306  #if (SUPPORT_MASTER_MODE == 1U)
307  else /* If master node */
308  {
310  master_data_ptr->flag_offset = prot_user_config_ptr->frame_tbl_ptr[frame_index].flag_offset;
311  master_data_ptr->flag_size = prot_user_config_ptr->frame_tbl_ptr[frame_index].flag_size;
312  }
313  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
314 
315  #if (SUPPORT_SLAVE_MODE == 1U)
316  /* update word status */
317  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
318  {
319  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
320  {
322  }
323  else
324  {
325  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602)
326  {
328  }
329  }
330  }
331  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
332  }
333 }
334 
335 /*FUNCTION**********************************************************************
336  *
337  * Function Name : lin_update_tx
338  * Description : This function update status and flags after transmit response
339  *
340  * Implements : lin_update_tx_Activity
341  *END**************************************************************************/
342 static void lin_update_tx(l_ifc_handle iii,
343  l_u8 id)
344 {
345  l_u8 frame_index;
346  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
347  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
348 #if (SUPPORT_MASTER_MODE == 1U)
349  const lin_master_data_t * master_data_ptr;
350 #endif
351 #if ((SUPPORT_PROTOCOL_J2602 == 1U) && (SUPPORT_SLAVE_MODE == 1U))
352  l_u8 i;
353  l_u8* bit_offset_temp_ptr;
354  l_u8* byte_offset_temp_ptr;
355  const lin_node_attribute_t * node_attr_ptr;
356 #endif
357 
358  /* Set successful transfer */
359  prot_state_ptr->successful_transfer = 1U;
360  /* if two or more frames are processed since the previous call to l_ifc_read_status, set overrun flag to 1 */
361  if (prot_state_ptr->num_of_processed_frame < 0xFFU)
362  {
363  prot_state_ptr->num_of_processed_frame++;
364  }
365 
366  if ((prot_state_ptr->num_of_processed_frame > 1U) && (prot_state_ptr->overrun_flg == 0U))
367  {
368  prot_state_ptr->overrun_flg = 1U;
369  }
370 
371  if ((bool)1U == prot_state_ptr->transmit_error_resp_sig_flg)
372  {
373  /* Set no error in response */
374  prot_state_ptr->error_in_response = 0U;
375  prot_state_ptr->transmit_error_resp_sig_flg = (bool)0U;
376  }
377 #if (SUPPORT_MASTER_MODE == 1U)
378  /* If the Master node sent go to sleep command successfully, then set go to sleep flag*/
379  if (((bool)LIN_MASTER == prot_user_config_ptr->function) && (0x3CU == id))
380  {
382  /* At this point, the schedule table is LIN_SCH_TBL_NULL */
383  if (prot_user_config_ptr->schedule_tbl[master_data_ptr->active_schedule_id].sch_tbl_type == LIN_SCH_TBL_NULL)
384  {
385  /* Set go to sleep flag in state structure */
386  prot_state_ptr->go_to_sleep_flg = true;
387  (void)lin_lld_set_low_power_mode(iii);
388  }
389  }
390 #endif
391  /* Find frame index by pid */
392  frame_index = lin_get_frame_index(iii, id);
393  lin_update_tx_flags(iii, frame_index);
394  if ((((bool)LIN_MASTER == prot_user_config_ptr->function) && (0x3CU == id) && (DIAG_INTERLEAVE_MODE == prot_state_ptr->diagnostic_mode)) ||
395  (((bool)LIN_SLAVE == prot_user_config_ptr->function) && (0x3DU == id)))
396  {
397  /* Call transport layer callback to process TL_TX_COMPLETED event*/
399  }
400  /* Update tx frame flag */
401  g_lin_frame_flag_handle_tbl[frame_index] = true;
402 
403 #if (SUPPORT_SLAVE_MODE == 1U)
404  /* Update word status */
405  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
406  {
407  #if (SUPPORT_PROTOCOL_21 == 1U)
408  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
409  {
410  lin_update_err_signal(iii, frame_index);
412  }
413 
414  #endif
415  #if (SUPPORT_PROTOCOL_J2602 == 1U)
416  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602)
417  {
418  if (0x3DU != id)
419  {
420  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
421  for (i = 0; i < node_attr_ptr->num_frame_have_esignal; i++)
422  {
423  byte_offset_temp_ptr = node_attr_ptr->response_error_byte_offset_ptr + i;
424  bit_offset_temp_ptr = node_attr_ptr->response_error_bit_offset_ptr + i;
425  /* Clear error signal in frame data buffer */
426  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))));
427  }
428 
429  }
430 
432  }
433 
434  #endif /* if (SUPPORT_PROTOCOL_J2602 == 1U) */
435  }
436 
437 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
438 }
439 
440 /*FUNCTION**********************************************************************
441  *
442  * Function Name : lin_handle_error
443  * Description : This function handle error raised by low-level
444  *
445  * Implements : lin_handle_error_Activity
446  *END**************************************************************************/
447 static void lin_handle_error(l_ifc_handle iii,
448  lin_lld_event_id_t event_id,
449  l_u8 id)
450 {
451 #if ((SUPPORT_PROTOCOL_21 == 1U) || (SUPPORT_SLAVE_MODE == 1U))
452  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
453 #endif
454  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
455 
456 #if ((SUPPORT_MASTER_MODE == 1U) && (SUPPORT_PROTOCOL_21 == 1U))
457  lin_master_data_t * master_data_ptr;
458 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
459 
460 #if (SUPPORT_PROTOCOL_21 == 1U)
461  l_u8 frame_index;
462  frame_index = lin_get_frame_index(iii, id);
463 #endif
464 
465  /* if two or more frames are processed since the previous call to l_ifc_read_status, set overrun flag to 1 */
466  if (prot_state_ptr->num_of_processed_frame < 0xFFU)
467  {
468  prot_state_ptr->num_of_processed_frame++;
469  }
470 
471  if ((prot_state_ptr->num_of_processed_frame > 1U) && (prot_state_ptr->overrun_flg == 0U))
472  {
473  prot_state_ptr->overrun_flg = 1U;
474  }
475 
476  switch (event_id)
477  {
478  /* PID error */
479  case LIN_LLD_PID_ERR:
480  /* do nothing here */
481  break;
482  /* Frame error */
483  case LIN_LLD_FRAME_ERR:
487  #if (SUPPORT_PROTOCOL_21 == 1U)
488  /* Check if frame type is event trigger */
489  /* Find the corresponding frame */
490 
491  if (LIN_FRM_EVNT == prot_user_config_ptr->frame_tbl_ptr[frame_index].frm_type)
492  {
493  #if (SUPPORT_MASTER_MODE == 1U)
494  if (prot_user_config_ptr->function == (bool)LIN_MASTER)
495  {
497  master_data_ptr->event_trigger_collision_flg = true;
498  }
499  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
500  }
501  else
502  #endif /* if (SUPPORT_PROTOCOL_21 == 1U) */
503  {
504  /* Set response error */
505  prot_state_ptr->error_in_response = 1U;
506  /* TL support */
507  if ((0x3CU == id) || (0x3DU == id))
508  {
509  /* Call transport layer callback to handle TL_ERROR */
510  (void)LIN_TL_CALLBACK_HANDLER(iii, TL_ERROR, id);
511  }
512  }
513  break;
514  default:
515  /* do nothing */
516  break;
517  }
518 
519 #if (SUPPORT_SLAVE_MODE == 1U)
520  /* Update word status */
521  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
522  {
523  #if (SUPPORT_PROTOCOL_21 == 1U)
524  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
525  {
526  if (prot_state_ptr->error_in_response == 1U)
527  {
528  lin_update_err_signal(iii, frame_index);
529  }
530  lin_update_word_status_lin21(iii, event_id);
531  }
532  #endif
533  #if (SUPPORT_PROTOCOL_J2602 == 1U)
534  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602)
535  {
536  lin_update_status_byte(iii, event_id);
538  }
539  #endif
540  }
541 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
542 }
543 
544 /*FUNCTION**********************************************************************
545  *
546  * Function Name : lin_bus_activity_timeout
547  * Description : This function set bus activity timeout
548  *
549  * Implements : lin_bus_activity_timeout_Activity
550  *END**************************************************************************/
551 static void lin_bus_activity_timeout(l_ifc_handle iii)
552 {
553  /* Set goto sleep mode */
554 #if (SUPPORT_SLAVE_MODE == 1U)
555  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
556 
557  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
558  {
559  #if (SUPPORT_PROTOCOL_21 == 1U)
560  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_21)
561  {
563  }
564 
565  #endif
566  #if (SUPPORT_PROTOCOL_J2602 == 1U)
567  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602)
568  {
570  }
571 
572  #endif /* End (SUPPORT_PROTOCOL_J2602 ==1) */
573  }
574 
575 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
576 
577  /* Change to low power mode */
578  (void)lin_lld_set_low_power_mode(iii);
579 }
580 
581 #if (SUPPORT_MASTER_MODE == 1U)
582 /*FUNCTION**********************************************************************
583  *
584  * Function Name : lin_switch_sch_table
585  * Description : Check to see if the current schedule table is needed to change
586  * or not. Used in tick callback function.
587  *
588  * Implements : lin_switch_sch_table_Activity
589  *END**************************************************************************/
590 void lin_switch_sch_table(l_ifc_handle iii)
591 {
592  l_u8 * active_schedule_id;
593  const l_u8 * previous_schedule_id;
594  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
596  /* Get current configuration */
597  active_schedule_id = &master_data_ptr->active_schedule_id;
598  previous_schedule_id = &master_data_ptr->previous_schedule_id;
599 
600  /* Get transmit queue */
601  switch (prot_user_config_ptr->schedule_tbl[master_data_ptr->active_schedule_id].sch_tbl_type)
602  {
603  /* Collision */
605  /* Set active table equal to previous table */
606  *active_schedule_id = *previous_schedule_id;
607  break;
608  /* Diagnostic schedule table */
609  case LIN_SCH_TBL_DIAG:
610  /* Set start entry of active schedule table to 0 */
611  master_data_ptr->schedule_start_entry_ptr[*active_schedule_id] = 0U;
612  break;
613  /* Normal schedule table */
614  case LIN_SCH_TBL_NORM:
616  /* Set start entry of active schedule table to 0 */
617  master_data_ptr->schedule_start_entry_ptr[*active_schedule_id] = 0U;
618  break;
619  /* Goto sleep schedule table */
621  /* Switch to NULL_SCHEDULE_TABLE */
622  /* In the lin_sch_table, the NULL_SCHEDULE_TABLE for interface iii */
623  /* is located at shedule_start */
624  *active_schedule_id = prot_user_config_ptr->schedule_start;
625  master_data_ptr->schedule_start_entry_ptr[*active_schedule_id] = 0U;
626  break;
627  case LIN_SCH_TBL_NULL:
628  default:
629  /* do nothing */
630  break;
631  }
632 }
633 
634 /*FUNCTION**********************************************************************
635  *
636  * Function Name : lin_check_sporadic_update
637  * Description : Checks if the associated flags to a sporadic frame have been updated
638  * and a transmission is needed
639  *
640  * Implements : lin_check_sporadic_update_Activity
641  *END**************************************************************************/
643  l_u8 frm_id)
644 {
645  l_u8 flag_offset = 0U;
646  l_u8 flag_size = 0U;
647  l_u8 i = 0U;
648  l_u8 j;
649  l_u8 associate_frame_offset = 0U;
650  const lin_associate_frame_t * ptr;
651  l_u8 retVal = 0xFFU;
652  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
653  ptr = (const lin_associate_frame_t *)(prot_user_config_ptr->frame_tbl_ptr[frm_id].frame_data_ptr);
654 
655  for (j = 0U; j < ptr->num_of_associated_uncond_frames; j++)
656  {
657  associate_frame_offset = (l_u8)ptr->associated_uncond_frame_ptr[j];
658  flag_offset = prot_user_config_ptr->frame_tbl_ptr[associate_frame_offset].flag_offset;
659  flag_size = prot_user_config_ptr->frame_tbl_ptr[associate_frame_offset].flag_size;
660  /* Update transmit flags */
661  for (i = 0U; i < flag_size; i++)
662  {
663  if (g_lin_flag_handle_tbl[flag_offset++] != 0xFFU)
664  {
665  retVal = prot_user_config_ptr->list_identifiers_RAM_ptr[((l_u8)ptr->associated_uncond_frame_ptr[j] - prot_user_config_ptr->frame_start) + 1U];
666  break;
667  }
668  }
669 
670  if (retVal != 0xFFU)
671  {
672  break;
673  }
674  }
675 
676  /* There's no updated frame */
677  return retVal;
678 }
679 
680 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
681 
682 /*FUNCTION**********************************************************************
683  *
684  * Function Name : lin_update_tx_flags
685  * Description : This function updates transmit flags
686  *
687  * Implements : lin_update_tx_flags_Activity
688  *END**************************************************************************/
689 static void lin_update_tx_flags(l_ifc_handle iii,
690  l_u8 frm_id)
691 {
692  l_u8 flag_offset;
693  l_u8 flag_size;
694  l_u8 i;
695  l_u8 associate_frame_offset;
696  const lin_frame_t * lin_frame_ptr;
697  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
698  lin_frame_ptr = &(prot_user_config_ptr->frame_tbl_ptr[frm_id]);
699 
700  if (LIN_FRM_UNCD == lin_frame_ptr->frm_type)
701  {
702  flag_offset = lin_frame_ptr->flag_offset;
703  flag_size = lin_frame_ptr->flag_size;
704  /* Update transmit flags */
705  for (i = 0U; i < flag_size; i++)
706  {
707  g_lin_flag_handle_tbl[flag_offset] = 0xFFU;
708  flag_offset++;
709  }
710  }
711 
712  /* check event trigger frame and clear flag */
713  if (LIN_FRM_EVNT == prot_user_config_ptr->frame_tbl_ptr[frm_id].frm_type)
714  {
715  associate_frame_offset = (l_u8)(*((lin_frame_ptr->frame_data_ptr)->associated_uncond_frame_ptr));
716  flag_offset = prot_user_config_ptr->frame_tbl_ptr[associate_frame_offset].flag_offset;
717  flag_size = prot_user_config_ptr->frame_tbl_ptr[associate_frame_offset].flag_size;
718  /* Update transmit flags */
719  for (i = 0U; i < flag_size; i++)
720  {
721  g_lin_flag_handle_tbl[flag_offset] = 0xFFU;
722  flag_offset++;
723  }
724  }
725 }
726 
727 /*FUNCTION**********************************************************************
728  *
729  * Function Name : lin_get_frame_index
730  * Description : This function returns the index of a frame in frame list
731  * or 0xFF if not found.
732  *
733  * Implements : lin_get_frame_index_Activity
734  *END**************************************************************************/
735 l_u8 lin_get_frame_index(l_ifc_handle iii,
736  l_u8 id)
737 {
738  l_u8 i;
739  l_u8 retVal = 0xFFU;
740  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
741 
742  for (i = prot_user_config_ptr->number_of_configurable_frames; i > 0U; i--)
743  {
744  if (prot_user_config_ptr->list_identifiers_RAM_ptr[i] == id)
745  {
746  retVal = (l_u8)(i + prot_user_config_ptr->frame_start - 1U);
747  break;
748  }
749  }
750 
751  return retVal;
752 }
753 
754 /*FUNCTION**********************************************************************
755  *
756  * Function Name : lin_process_uncd_frame
757  * Description : This function packs signals associated with unconditional frame
758  * into buffer.
759  *
760  * Implements : lin_process_uncd_frame_Activity
761  *END**************************************************************************/
762 void lin_process_uncd_frame(l_ifc_handle iii,
763  l_u8 id,
764  l_u8 type)
765 {
766  l_u8 frame_index;
767  l_u8 * response_buffer_ptr;
768  l_u16 frame_byte_offset;
769  l_u8 i;
770 
771  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
772  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
773 #if (SUPPORT_SLAVE_MODE == 1U)
774  const lin_node_attribute_t * node_attr_ptr;
775 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
776 #if (SUPPORT_MASTER_MODE == 1U)
777  lin_master_data_t * master_data_ptr;
778 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
779  frame_index = lin_get_frame_index(iii, id);
780 
781  if (0xFFU != frame_index)
782  {
783  response_buffer_ptr = prot_state_ptr->response_buffer_ptr;
784 
785  /* Set frame length */
786  prot_state_ptr->response_length = prot_user_config_ptr->frame_tbl_ptr[frame_index].frm_len;
787  frame_byte_offset = prot_user_config_ptr->frame_tbl_ptr[frame_index].frm_offset;
788 
789  /* Make unconditional frame */
790  if (MAKE_UNCONDITIONAL_FRAME == type)
791  {
792  #if (SUPPORT_SLAVE_MODE == 1U)
793  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
794  {
795  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
796 
797  for (i = 0U; i < node_attr_ptr->num_frame_have_esignal; i++)
798  {
799  /* Check if frame contain error signal */
800  if (id == node_attr_ptr->resp_err_frm_id_ptr[i])
801  {
802  prot_state_ptr->transmit_error_resp_sig_flg = (bool)1U;
803  break;
804  }
805  }
806 
807  /* Get data from LIN frame buffer */
808  for (i = 0U; i < prot_state_ptr->response_length; i++)
809  {
810  response_buffer_ptr[i] = g_lin_frame_data_buffer[frame_byte_offset + i];
811  }
812  }
813  else
814  #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
815  {
816  #if (SUPPORT_MASTER_MODE == 1U)
818  /* For Master node, get data from master data buffer */
819  for (i = 0U; i < prot_state_ptr->response_length; i++)
820  {
821  response_buffer_ptr[i] = master_data_ptr->master_data_buffer[i];
822  }
823  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
824  }
825  }
826  /* Update unconditional frame */
827  else
828  {
829  if ((bool)LIN_SLAVE == prot_user_config_ptr->function)
830  {
831  for (i = 0U; i < prot_state_ptr->response_length; i++)
832  {
833  g_lin_frame_data_buffer[frame_byte_offset + i] = response_buffer_ptr[i];
834  }
835  }
836  #if (SUPPORT_MASTER_MODE == 1U)
837  /* If master node save frame */
838  else
839  {
841  master_data_ptr->frm_offset = frame_byte_offset;
842  master_data_ptr->frm_size = prot_state_ptr->response_length;
843  for (i = 0U; i < prot_state_ptr->response_length; i++)
844  {
845  master_data_ptr->master_data_buffer[i] = response_buffer_ptr[i];
846  }
847  }
848  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
849  }
850  }
851 }
852 
853 /*******************************************************************************
854  * EOF
855  ******************************************************************************/
#define UPDATE_UNCONDITIONAL_FRAME
l_u8 overrun_flg
Definition: lin.h:572
l_u16 frm_offset
Definition: lin.h:256
l_u8 * list_identifiers_RAM_ptr
Definition: lin.h:522
lin_sch_tbl_type_t sch_tbl_type
Definition: lin.h:302
static void lin_bus_activity_timeout(l_ifc_handle iii)
l_ifc_master_handle master_ifc_handle
Definition: lin.h:528
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
void lin_make_res_evnt_frame(l_ifc_handle iii, l_u8 pid)
This function packs signals associated with event trigger frame into buffer.
l_u8 frm_size
Definition: lin.h:549
lin_protocol_state_t g_lin_protocol_state_array[LIN_NUM_OF_IFCS]
Definition: lin.c:50
l_ifc_slave_handle slave_ifc_handle
Definition: lin.h:527
lin_master_data_t g_lin_master_data_array[LIN_NUM_OF_MASTER_IFCS]
Definition: lin.c:52
#define LIN_TL_CALLBACK_HANDLER(iii, tl_event_id, id)
Definition: lin.h:374
void lin_update_word_status_lin21(l_ifc_handle iii, lin_lld_event_id_t event_id)
Update node status flags.
#define LIN_SLAVE
Mode of LIN node (master or slave)
Definition: lin.h:167
void lin_update_err_signal(l_ifc_handle iii, l_u8 frm_id)
Update error signal.
l_diagnostic_mode_t diagnostic_mode
Definition: lin.h:576
l_bool go_to_sleep_flg
Definition: lin.h:568
l_u8 flag_offset
Definition: lin.h:550
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
const lin_frame_t * frame_tbl_ptr
Definition: lin.h:519
l_u8 g_lin_frame_data_buffer[LIN_FRAME_BUF_SIZE]
const lin_associate_frame_t * frame_data_ptr
Definition: lin.h:259
l_u8 lin_lld_set_response(l_ifc_handle iii, l_u8 response_length)
This function sends frame data that is contained in LIN_lld_response_buffer[iii]. ...
Definition: lin.c:356
l_u8 flag_offset
Definition: lin.h:257
void lin_update_status_byte(l_ifc_handle iii, lin_lld_event_id_t event_id)
The function is to perform the update of error signal in J2602 system.
void lin_switch_sch_table(l_ifc_handle iii)
l_u8 lin_lld_set_low_power_mode(l_ifc_handle iii)
Let the low level driver go to low power mode.
Definition: lin.c:333
l_u8 num_frame_have_esignal
Definition: lin.h:196
static void lin_handle_error(l_ifc_handle iii, lin_lld_event_id_t event_id, l_u8 id)
l_u8 * resp_err_frm_id_ptr
Definition: lin.h:195
Configuration structure Implements : lin_protocol_user_config_t_Class.
Definition: lin.h:510
l_bool event_trigger_collision_flg
Definition: lin.h:546
l_u8 g_lin_flag_handle_tbl[LIN_FLAG_BUF_SIZE]
static void lin_update_rx(l_ifc_handle iii, l_u8 id)
lin_frame_type_t frm_type
Definition: lin.h:253
l_u8 * response_buffer_ptr
Definition: lin.h:564
l_u8 * response_error_bit_offset_ptr
Definition: lin.h:199
void lin_update_word_status_j2602(l_ifc_handle iii)
Update date word status.
#define LIN_MASTER
Definition: lin.h:168
l_u8 error_in_response
Definition: lin.h:567
void lin_pid_resp_callback_handler(l_ifc_handle iii, const lin_lld_event_id_t event_id, l_u8 id)
Callback handler for low level events.
#define MAKE_UNCONDITIONAL_FRAME
l_u8 lin_check_sporadic_update(l_ifc_handle iii, l_u8 frm_id)
LIN protocol status structure Implements : lin_protocol_state_t_Class.
Definition: lin.h:560
l_u8 flag_size
Definition: lin.h:258
static void lin_update_tx(l_ifc_handle iii, l_u8 id)
static void lin_process_id(l_ifc_handle iii, l_u8 id)
static void lin_update_tx_flags(l_ifc_handle iii, l_u8 frm_id)
l_u8 num_of_processed_frame
Definition: lin.h:571
l_u8 * response_error_byte_offset_ptr
Definition: lin.h:198
l_u8 num_of_associated_uncond_frames
Definition: lin.h:242
const lin_protocol_user_config_t g_lin_protocol_user_cfg_array[LIN_NUM_OF_IFCS]
Informations of associated frame Implements : lin_associate_frame_t_Class.
Definition: lin.h:240
l_u8 lin_get_frame_index(l_ifc_handle iii, l_u8 id)
unsigned char l_u8
Unsigned 8 bit integer Implements : l_u8_Class.
Definition: lin_types.h:30
const lin_schedule_t * schedule_tbl
Definition: lin.h:526
l_u8 response_length
Definition: lin.h:565
Definition: lin.h:354
l_u8 active_schedule_id
Definition: lin.h:543
l_u8 frm_len
Definition: lin.h:254
lin_protocol_handle_t protocol_version
Definition: lin.h:512
Attributes of LIN node Implements : lin_node_attribute_t_Class.
Definition: lin.h:189
l_u8 successful_transfer
Definition: lin.h:566
l_u8 flag_size
Definition: lin.h:551
lin_frame_response_t frm_response
Definition: lin.h:255
l_u8 lin_lld_ignore_response(l_ifc_handle iii)
This function terminates an on-going data transmission/reception.
Definition: lin.c:310
const l_frame_handle * associated_uncond_frame_ptr
Definition: lin.h:243
l_u8 number_of_configurable_frames
Definition: lin.h:517
#define CHECK_PARITY
Definition: lin_driver.h:53
l_bool g_lin_frame_flag_handle_tbl[LIN_NUM_OF_FRMS]
l_u8 lin_lld_rx_response(l_ifc_handle iii, l_u8 response_length)
This function receives frame data into the LIN_lld_response_buffer[iii] buffer.
Definition: lin.c:397
#define MAKE_PARITY
Definition: lin_driver.h:52
l_u16 frm_offset
Definition: lin.h:548
l_u8 master_data_buffer[8]
Definition: lin.h:547
void lin_update_rx_evnt_frame(l_ifc_handle iii, l_u8 pid)
The function updates the receive flags associated with signals/frames in case receive an event trigge...
lin_lld_event_id_t
Event id Implements : lin_lld_event_id_t_Class.
Definition: lin.h:109
Frame description structure Implements : lin_frame_t_Class.
Definition: lin.h:251
void lin_process_uncd_frame(l_ifc_handle iii, l_u8 id, l_u8 type)
l_u8 * schedule_start_entry_ptr
Definition: lin.h:545
unsigned short int l_u16
Unsigned 16 bit integer Implements : l_u16_Class.
Definition: lin_types.h:36
l_bool transmit_error_resp_sig_flg
Definition: lin.h:579