S32 SDK
lin.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  */
42 #include "lin.h"
43 
44 /*******************************************************************************
45  * Variables
46  ******************************************************************************/
47 /* Global variables */
48 /* lin_tl_descriptor_t */
51 #if (SUPPORT_MASTER_MODE == 1U)
52 lin_master_data_t g_lin_master_data_array[LIN_NUM_OF_MASTER_IFCS];
53 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
54 /* Static variables */
55 static lin_state_t s_lin_state_array[LIN_NUM_OF_IFCS];
56 static volatile l_u16 s_lin_max_header_timeout[LIN_NUM_OF_IFCS];
57 static l_u16 s_lin_max_frame_res_timeout_val[LIN_NUM_OF_IFCS][8];
58 static void CallbackHandler(uint32_t instance,
59  void * linState);
60 static l_bool s_baudrate_adjusted_flg[LIN_NUM_OF_IFCS];
61 
62 /*******************************************************************************
63  * Code
64  ******************************************************************************/
65 /*FUNCTION**********************************************************************
66  *
67  * Function Name : lin_process_parity
68  * Description : Makes or checks parity bits. If action is checking parity, the function
69  * returns ID value if parity bits are correct or 0xFF if parity bits are incorrect. If action
70  * is making parity bits, then from input value of ID, the function returns PID.
71  *
72  * Implements : lin_process_parity_Activity
73  *END**************************************************************************/
75  l_u8 typeAction)
76 {
77  return LIN_DRV_ProcessParity(pid, typeAction);
78 }
79 
80 /*FUNCTION**********************************************************************
81  *
82  * Function Name : lin_lld_init
83  * Description : This function initializes a LIN hardware instance for operation.
84  * This function will initialize the run-time state structure to keep track of
85  * the on-going transfers, initialize the module to user defined settings and
86  * default settings, configure the IRQ state structure and enable the module-level
87  * interrupt to the core, and enable the LIN hardware module transmitter and receiver.
88  *
89  * Implements : lin_lld_init_Activity
90  *END**************************************************************************/
91 l_bool lin_lld_init(l_ifc_handle iii)
92 {
93  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
94 
95  l_u32 lin_hardware_instance;
96  l_u8 index;
97  l_u8 ret_val = (l_u8)LIN_LLD_ERROR;
98  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
99  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
100  static l_u8 lin_lld_response_buffer[LIN_NUM_OF_IFCS][10];
101 
102  prot_state_ptr->response_buffer_ptr = lin_lld_response_buffer[iii];
103  /* Get the LIN hardware instance number */
104  lin_hardware_instance = g_lin_virtual_ifc[iii];
105 
106  /* Initialize time out values */
107  /* If autobaud is enabled, set frame response timeout array and header timeout */
108  /* to maximum values in case the Master baudrate is 2400 */
109  if (prot_user_config_ptr->lin_user_config_ptr->autobaudEnable)
110  {
112 
113  for (index = 1U; index < 9U; index++)
114  {
115  s_lin_max_frame_res_timeout_val[iii][index - 1U] = lin_calc_max_res_timeout_cnt(2400, index);
116  }
117  }
118  /* If autobaud is disabled, set frame response timeout array and header timeout */
119  /* to values corresponding to node's configured baudrate */
120  else
121  {
123  for (index = 1U; index < 9U; index++)
124  {
125  s_lin_max_frame_res_timeout_val[iii][index - 1U] = lin_calc_max_res_timeout_cnt(prot_user_config_ptr->lin_user_config_ptr->baudRate, index);
126  }
127  }
128 
129  /* Set frame timeout count */
130  prot_state_ptr->frame_timeout_cnt = s_lin_max_frame_res_timeout_val[iii][7U];
131  /* Set idle timeout count */
132  prot_state_ptr->idle_timeout_cnt = prot_user_config_ptr->max_idle_timeout_cnt;
133 
134  /* Initialize the LIN hardware interface */
135  ret_val = (l_u8)LIN_DRV_Init(lin_hardware_instance, prot_user_config_ptr->lin_user_config_ptr, &s_lin_state_array[iii]);
136 
137  if (ret_val == (l_u8)STATUS_SUCCESS)
138  {
139  /* Install callback function */
140  (void)LIN_DRV_InstallCallback(lin_hardware_instance, CallbackHandler);
141  /* Clear s_baudrate_adjusted_flg[iii] */
142  s_baudrate_adjusted_flg[iii] = false;
143  ret_val = (l_u8)LIN_LLD_OK;
144  }
145 
146  return (ret_val != LIN_LLD_OK) ? true : false;
147 }
148 
149 /*FUNCTION**********************************************************************
150  *
151  * Function Name : lin_lld_deinit
152  * Description : This function shuts down the LIN hardware interface by disabling interrupts and
153  * transmitter/receiver.
154  *
155  * Implements : lin_lld_deinit_Activity
156  *END**************************************************************************/
157 l_u8 lin_lld_deinit(l_ifc_handle iii)
158 {
159  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
160 
161  l_u32 lin_hardware_instance;
162  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
163 
164  /* Get the LIN hardware instance number */
165  lin_hardware_instance = g_lin_virtual_ifc[iii];
166 
167  /* De-initialize the LIN hardware interface */
168  retVal = (l_u8)LIN_DRV_Deinit(lin_hardware_instance);
169 
170  return retVal;
171 }
172 
173 /*FUNCTION**********************************************************************
174  *
175  * Function Name : lin_lld_get_state
176  * Description : This function returns current node's state.
177  *
178  * Implements : lin_lld_get_state_Activity
179  *END**************************************************************************/
180 l_u8 lin_lld_get_state(l_ifc_handle iii)
181 {
182  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
183 
184  l_u32 lin_hardware_instance;
185  l_u8 retVal;
186 
187  /* Get the LIN hardware instance number */
188  lin_hardware_instance = g_lin_virtual_ifc[iii];
189 
190  /* Get current node's state */
191  retVal = (l_u8)LIN_DRV_GetCurrentNodeState(lin_hardware_instance);
192 
193  return retVal;
194 }
195 
196 /*FUNCTION**********************************************************************
197  *
198  * Function Name : lin_lld_tx_header
199  * Description : This function sends frame header for the input ID.
200  *
201  * Implements : lin_lld_tx_header_Activity
202  *END**************************************************************************/
203 l_u8 lin_lld_tx_header(l_ifc_handle iii,
204  l_u8 id)
205 {
206  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
207 
208  l_u32 lin_hardware_instance;
209  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
210  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
211 
212  /* Get the LIN hardware instance number */
213  lin_hardware_instance = g_lin_virtual_ifc[iii];
214 
215  /* Set correct frame timeout */
217 
218  /* Send frame header */
219  retVal = (l_u8)LIN_DRV_MasterSendHeader(lin_hardware_instance, id);
220 
221  if (retVal == (l_u8)STATUS_SUCCESS)
222  {
223  retVal = (l_u8)LIN_LLD_OK;
224  }
225 
226  return retVal;
227 }
228 
229 /*FUNCTION**********************************************************************
230  *
231  * Function Name : lin_lld_tx_wake_up
232  * Description : This function sends a wakeup signal.
233  *
234  * Implements : lin_lld_tx_wake_up_Activity
235  *END**************************************************************************/
236 l_u8 lin_lld_tx_wake_up(l_ifc_handle iii)
237 {
238  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
239 
240  l_u32 lin_hardware_instance;
241  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
242 
243  /* Get the LIN hardware instance number */
244  lin_hardware_instance = g_lin_virtual_ifc[iii];
245 
246  /* Send a wakeup signal */
247  retVal = (l_u8)LIN_DRV_SendWakeupSignal(lin_hardware_instance);
248 
249  if (retVal == (l_u8)STATUS_SUCCESS)
250  {
251  retVal = (l_u8)LIN_LLD_OK;
252  }
253 
254  return retVal;
255 }
256 
257 /*FUNCTION**********************************************************************
258  *
259  * Function Name : lin_lld_int_enable
260  * Description : This function enables LIN hardware interrupt of an interface.
261  *
262  * Implements : lin_lld_int_enable_Activity
263  *END**************************************************************************/
264 l_u8 lin_lld_int_enable(l_ifc_handle iii)
265 {
266  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
267 
268  l_u32 lin_hardware_instance;
269  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
270 
271  /* Get the LIN hardware instance number */
272  lin_hardware_instance = g_lin_virtual_ifc[iii];
273 
274  /* Call function LIN_DRV_DisableIRQ to enable interrupts */
275  retVal = (l_u8)LIN_DRV_EnableIRQ(lin_hardware_instance);
276 
277  return retVal;
278 }
279 
280 /*FUNCTION**********************************************************************
281  *
282  * Function Name : lin_lld_int_disable
283  * Description : This function disables LIN hardware interrupt of an interface.
284  *
285  * Implements : lin_lld_int_disable_Activity
286  *END**************************************************************************/
287 l_u8 lin_lld_int_disable(l_ifc_handle iii)
288 {
289  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
290 
291  l_u32 lin_hardware_instance;
292  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
293 
294  /* Get the LIN hardware instance number */
295  lin_hardware_instance = g_lin_virtual_ifc[iii];
296 
297  /* Call function LIN_DRV_DisableIRQ to disable interrupts */
298  retVal = (l_u8)LIN_DRV_DisableIRQ(lin_hardware_instance);
299 
300  return retVal;
301 }
302 
303 /*FUNCTION**********************************************************************
304  *
305  * Function Name : lin_lld_ignore_response
306  * Description : This function terminates an on-going data transmission/reception.
307  *
308  * Implements : lin_lld_ignore_response_Activity
309  *END**************************************************************************/
310 l_u8 lin_lld_ignore_response(l_ifc_handle iii)
311 {
312  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
313 
314  l_u32 lin_hardware_instance;
315  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
316 
317  /* Get the LIN hardware instance number */
318  lin_hardware_instance = g_lin_virtual_ifc[iii];
319 
320  /* Abort frame data transferring */
321  retVal = (l_u8)LIN_DRV_AbortTransferData(lin_hardware_instance);
322 
323  return retVal;
324 }
325 
326 /*FUNCTION**********************************************************************
327  *
328  * Function Name : lin_lld_set_low_power_mode
329  * Description : This function puts current node to sleep mode.
330  *
331  * Implements : lin_lld_set_low_power_mode_Activity
332  *END**************************************************************************/
334 {
335  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
336 
337  l_u32 lin_hardware_instance;
338  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
339 
340  /* Get the LIN hardware instance number */
341  lin_hardware_instance = g_lin_virtual_ifc[iii];
342 
343  /* Put current node to sleep mode */
344  retVal = (l_u8)LIN_DRV_GoToSleepMode(lin_hardware_instance);
345 
346  return retVal;
347 }
348 
349 /*FUNCTION**********************************************************************
350  *
351  * Function Name : lin_lld_set_response
352  * Description : This function sends frame data that is contained in g_lin_protocol_state_array[iii].response_buffer_ptr.
353  *
354  * Implements : lin_lld_set_response_Activity
355  *END**************************************************************************/
356 l_u8 lin_lld_set_response(l_ifc_handle iii,
357  l_u8 response_length)
358 {
359  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
360 
361  l_u32 lin_hardware_instance;
362  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
363  const l_u8 * buffer;
364 
365  /* Check if response_length is from 1 to 8 */
366  if ((response_length <= 8U) && (response_length != 0U))
367  {
368  buffer = g_lin_protocol_state_array[iii].response_buffer_ptr;
369  /* Get the LIN hardware instance number */
370  lin_hardware_instance = g_lin_virtual_ifc[iii];
371 
372  /* Put response length into buffer */
373  g_lin_protocol_state_array[iii].response_length = response_length;
374 
375  /* Set correct timeout value */
376  LIN_DRV_SetTimeoutCounter(lin_hardware_instance, s_lin_max_frame_res_timeout_val[iii][response_length - 1U]);
377 
378  /* Start sending data from the buffer */
379  retVal = (l_u8)LIN_DRV_SendFrameData(lin_hardware_instance, &buffer[0U], response_length);
380 
381  if (retVal == (l_u8)STATUS_SUCCESS)
382  {
383  retVal = (l_u8)LIN_LLD_OK;
384  }
385  }
386 
387  return retVal;
388 }
389 
390 /*FUNCTION**********************************************************************
391  *
392  * Function Name : lin_lld_rx_response
393  * Description : This function receives frame data into the buffer g_lin_protocol_state_array[iii].response_buffer_ptr.
394  *
395  * Implements : lin_lld_rx_response_Activity
396  *END**************************************************************************/
397 l_u8 lin_lld_rx_response(l_ifc_handle iii,
398  l_u8 response_length)
399 {
400  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
401 
402  l_u32 lin_hardware_instance;
403  l_u8 retVal = (l_u8)LIN_LLD_ERROR;
404 
405  /* Get the LIN hardware instance number */
406  lin_hardware_instance = g_lin_virtual_ifc[iii];
407 
408  /* Check if response_length is from 1 to 8 */
409  if ((response_length <= 8U) && (response_length != 0U))
410  {
411  /* Set correct timeout value */
412  LIN_DRV_SetTimeoutCounter(lin_hardware_instance, s_lin_max_frame_res_timeout_val[iii][response_length - 1U]);
413 
414  /* Start receiving frame data into the buffer */
415  retVal = (l_u8)LIN_DRV_ReceiveFrameData(lin_hardware_instance, g_lin_protocol_state_array[iii].response_buffer_ptr, response_length);
416 
417  if (retVal == (l_u8)STATUS_SUCCESS)
418  {
419  retVal = (l_u8)LIN_LLD_OK;
420  }
421  }
422 
423  return retVal;
424 }
425 
426 /*FUNCTION**********************************************************************
427  *
428  * Function Name : lin_lld_timeout_service
429  * Description : This is a part of Timer Interrupt Handler.
430  *
431  * Implements : lin_lld_timeout_service_Activity
432  *END**************************************************************************/
433 void lin_lld_timeout_service(l_ifc_handle iii)
434 {
435  DEV_ASSERT((l_u8)iii < LIN_NUM_OF_IFCS);
436  l_u32 lin_hardware_instance = g_lin_virtual_ifc[iii];
437  lin_state_t linState = s_lin_state_array[iii];
438  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
439  l_u8 index;
440 
441  LIN_DRV_TimeoutService(lin_hardware_instance);
442 #if (SUPPORT_PROTOCOL_21 == 1U)
443  /* Callback to transport layer to handle N_As and N_Cr timeout for LIN 2.1 and above*/
445 #endif /*(SUPPORT_PROTOCOL_21 == 1)*/
446  switch (linState.currentNodeState)
447  {
448  case LIN_NODE_STATE_IDLE:
449  if (!(prot_state_ptr->idle_timeout_cnt-- > 0U))
450  {
451  /* Callback to handle timeout */
453 
454  /* Put current node to Idle state, reset idle timeout count */
456 
457  /* Put current node to sleep mode */
458  (void)LIN_DRV_GoToSleepMode(lin_hardware_instance);
459  }
460  /* Re-calculate s_lin_max_header_timeout and s_lin_max_frame_res_timeout_val */
461  if (s_baudrate_adjusted_flg[iii])
462  {
463  /* Clear baudrate adjusted flag */
464  s_baudrate_adjusted_flg[iii] = false;
466  for (index = 1U; index < 9U; index++)
467  {
469  }
470  }
471  break;
475  /* timeout send has occurred - change state of the node and inform core */
476  if (!(prot_state_ptr->frame_timeout_cnt-- > 0U))
477  {
478  /* Go to idle state */
479  (void)LIN_DRV_GotoIdleState(lin_hardware_instance);
480 
481  /* Reset frame count timeout */
482  prot_state_ptr->frame_timeout_cnt = s_lin_max_frame_res_timeout_val[iii][7U];
483  }
484  break;
486  /* timeout send has occurred - change state of the node and inform core */
487  if (!(prot_state_ptr->frame_timeout_cnt-- > 0U))
488  {
489  /* Abort frame data transferring */
490  (void)LIN_DRV_AbortTransferData(lin_hardware_instance);
491 
492  /* Reset frame count timeout */
493  prot_state_ptr->frame_timeout_cnt = s_lin_max_frame_res_timeout_val[iii][7U];
494  }
495  break;
502  default:
503  /* do nothing */
504  break;
505  }
506 }
507 
508 /*FUNCTION**********************************************************************
509  *
510  * Function Name : CallbackHandler
511  * Description : This is the callback function for LIN Driver.
512  *
513  * Implements : CallbackHandler_Activity
514  *END**************************************************************************/
515 static void CallbackHandler(uint32_t instance,
516  void * linState)
517 {
518  const lin_state_t * linCurrentState = linState;
519  lin_lld_event_id_t event_id;
520  l_u8 id = linCurrentState->currentId;
521  l_u8 bytesRemaining = 0U;
522  l_ifc_handle iii = g_lin_hardware_ifc[instance];
523  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
524  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
525 #if (SUPPORT_MASTER_MODE == 1U)
526  lin_master_data_t * master_data_ptr;
527 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
528 
529  switch (linCurrentState->currentEventId)
530  {
531  case LIN_PID_OK:
532  event_id = LIN_LLD_PID_OK;
533  CALLBACK_HANDLER(iii, (event_id), (id));
534  break;
535  case LIN_PID_ERROR:
536  event_id = LIN_LLD_PID_ERR;
537  CALLBACK_HANDLER(iii, (event_id), (id));
538  break;
539  case LIN_TX_COMPLETED:
540  event_id = LIN_LLD_TX_COMPLETED;
541  CALLBACK_HANDLER(iii, (event_id), (id));
542  break;
543  case LIN_RX_COMPLETED:
544  event_id = LIN_LLD_RX_COMPLETED;
545  CALLBACK_HANDLER(iii, (event_id), (id));
546  break;
547  case LIN_CHECKSUM_ERROR:
548  event_id = LIN_LLD_CHECKSUM_ERR;
549  CALLBACK_HANDLER(iii, (event_id), (id));
550  break;
551  case LIN_READBACK_ERROR:
552  event_id = LIN_LLD_READBACK_ERR;
553  CALLBACK_HANDLER(iii, (event_id), (id));
554  break;
555  case LIN_FRAME_ERROR:
556  event_id = LIN_LLD_FRAME_ERR;
557  CALLBACK_HANDLER(iii, (event_id), (id));
558  break;
561  break;
562  case LIN_SYNC_ERROR:
563  #if (SUPPORT_PROTOCOL_J2602 == 1U)
564  if (prot_user_config_ptr->protocol_version == LIN_PROTOCOL_J2602)
565  {
566  event_id = LIN_LLD_READBACK_ERR;
567  CALLBACK_HANDLER(iii, (event_id), (id));
568  }
569  #endif /* End of (SUPPORT_PROTOCOL_J2602 == 1U) */
570 
571  prot_state_ptr->frame_timeout_cnt = s_lin_max_frame_res_timeout_val[iii][7U];
572  break;
574  /* Set s_baudrate_adjusted_flg[iii] */
575  s_baudrate_adjusted_flg[iii] = true;
576  break;
577  case LIN_NO_EVENT:
578  if (linCurrentState->timeoutCounterFlag == (bool)1U)
579  {
580  #if (SUPPORT_MASTER_MODE == 1U)
581  if ((prot_state_ptr->diagnostic_mode == DIAG_INTERLEAVE_MODE) && (prot_state_ptr->current_id == 0x3DU))
582  {
583  master_data_ptr = &g_lin_master_data_array[g_lin_protocol_user_cfg_array[iii].master_ifc_handle];
584  master_data_ptr->active_schedule_id = master_data_ptr->previous_schedule_id;
585  master_data_ptr->schedule_start_entry_ptr[master_data_ptr->active_schedule_id] = 0U;
586  }
587  else
588  #endif /* End (SUPPORT_MASTER_MODE == 1U) */
589  {
590  (void)LIN_DRV_GetReceiveStatus(instance, &bytesRemaining);
591  /* Received part of data but not completed */
592  if (linCurrentState->rxSize > bytesRemaining)
593  {
594  event_id = LIN_LLD_NODATA_TIMEOUT;
595  CALLBACK_HANDLER(iii, (event_id), (id));
596  }
597  }
598  }
599  break;
600  default:
601  /* do nothing */
602  break;
603  }
604 
605  prot_state_ptr->idle_timeout_cnt = prot_user_config_ptr->max_idle_timeout_cnt;
606  /*
607  * @violates MISRA 2012 Advisory Rule 8.13 Advisory
608  */
609 }
610 
611 /*******************************************************************************
612  * EOF
613  ******************************************************************************/
const l_ifc_handle g_lin_hardware_ifc[HARDWARE_INSTANCE_COUNT]
volatile bool timeoutCounterFlag
Definition: lin_driver.h:142
static l_u16 lin_calc_max_res_timeout_cnt(l_u32 baudRate, l_u8 size)
Computes the maximum response timeout.
Definition: lin.h:643
status_t LIN_DRV_Init(uint32_t instance, lin_user_config_t *linUserConfig, lin_state_t *linCurrentState)
Initializes an instance LIN Hardware Interface for LIN Network.
Definition: lin_driver.c:62
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
volatile lin_event_id_t currentEventId
Definition: lin_driver.h:139
l_u16 idle_timeout_cnt
Definition: lin.h:578
lin_protocol_state_t g_lin_protocol_state_array[LIN_NUM_OF_IFCS]
Definition: lin.c:50
uint32_t baudRate
Definition: lin_driver.h:67
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
status_t LIN_DRV_ReceiveFrameData(uint32_t instance, uint8_t *rxBuff, uint8_t rxSize)
Receives frame data through the LIN Hardware Interface using non-blocking method. This function will ...
Definition: lin_driver.c:235
status_t LIN_DRV_SendWakeupSignal(uint32_t instance)
Sends a wakeup signal through the LIN Hardware Interface.
Definition: lin_driver.c:336
status_t LIN_DRV_Deinit(uint32_t instance)
Shuts down the LIN Hardware Interface by disabling interrupts and transmitter/receiver.
Definition: lin_driver.c:83
l_u8 lin_lld_tx_header(l_ifc_handle iii, l_u8 id)
This function sends frame header for the input PID.
Definition: lin.c:203
#define LIN_LLD_ERROR
Definition: lin.h:93
l_diagnostic_mode_t diagnostic_mode
Definition: lin.h:576
static void CallbackHandler(uint32_t instance, void *linState)
Definition: lin.c:515
status_t LIN_DRV_DisableIRQ(uint32_t instance)
Disables LIN hardware interrupts.
Definition: lin_driver.c:446
static l_bool s_baudrate_adjusted_flg[LIN_NUM_OF_IFCS]
Definition: lin.c:60
LIN master configuration structure Implements : lin_master_data_t_Class.
Definition: lin.h:541
unsigned long l_u32
Unsigned 32 bit integer Implements : l_u32_Class.
Definition: lin_types.h:42
l_u8 previous_schedule_id
Definition: lin.h:544
volatile lin_node_state_t currentNodeState
Definition: lin_driver.h:140
void LIN_DRV_SetTimeoutCounter(uint32_t instance, uint32_t timeoutValue)
Set Value for Timeout Counter that is used in LIN_DRV_TimeoutService.
Definition: lin_driver.c:389
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
#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
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 lin_lld_int_disable(l_ifc_handle iii)
Disable the interrupt related to the interface.
Definition: lin.c:287
l_bool lin_lld_init(l_ifc_handle iii)
This function initializes a LIN hardware instance for operation. This function will initialize the ru...
Definition: lin.c:91
Configuration structure Implements : lin_protocol_user_config_t_Class.
Definition: lin.h:510
status_t LIN_DRV_MasterSendHeader(uint32_t instance, uint8_t id)
Sends frame header out through the LIN Hardware Interface using a non-blocking method. This function sends LIN Break field, sync field then the ID with correct parity. This function checks if the interface is Master, if not, it will return STATUS_ERROR.This function checks if id is in range from 0 to 0x3F, if not it will return STATUS_ERROR.
Definition: lin_driver.c:409
l_u16 frame_timeout_cnt
Definition: lin.h:577
lin_callback_t LIN_DRV_InstallCallback(uint32_t instance, lin_callback_t function)
Installs callback function that is used for LIN_DRV_IRQHandler.
Definition: lin_driver.c:102
#define CALLBACK_HANDLER(iii, event_id, id)
CALLBACK_HANDLER.
Definition: lin.h:685
volatile uint8_t rxSize
Definition: lin_driver.h:129
uint8_t currentId
Definition: lin_driver.h:137
l_u8 * response_buffer_ptr
Definition: lin.h:564
void lin_lld_timeout_service(l_ifc_handle iii)
Callback function for Timer Interrupt Handler In timer IRQ handler, call this function. Used to check if frame timeout has occurred during frame data transmission and reception, to check for N_As and N_Cr timeout for LIN 2.1 and above. This function also check if there is no LIN bus communication (no headers and no frame data transferring) for Idle timeout (s), then put LIN node to Sleep mode. Users may initialize a timer (for example FTM)with period of Timeout unit (default: 500 micro seconds) to call lin_lld_timeout_service(). For an interface iii, Idle timeout (s) = max_idle_timeout_cnt * Timeout unit (us) frame timeout (us) = frame_timeout_cnt * Timeout unit (us) N_As timeout (us) = N_As_timeout * Timeout unit (us) N_Cr timeout (us) = N_Cr_timeout * Timeout unit (us)
Definition: lin.c:433
static l_u16 lin_calc_max_header_timeout_cnt(l_u32 baudRate)
Computes maximum header timeout.
Definition: lin.h:627
l_u8 lin_lld_tx_wake_up(l_ifc_handle iii)
This function send a wakeup signal.
Definition: lin.c:236
LIN protocol status structure Implements : lin_protocol_state_t_Class.
Definition: lin.h:560
uint8_t LIN_DRV_ProcessParity(uint8_t PID, uint8_t typeAction)
Makes or checks parity bits. If action is checking parity, the function returns ID value if parity bi...
Definition: lin_common.c:58
status_t LIN_DRV_AbortTransferData(uint32_t instance)
Aborts an on-going non-blocking transmission/reception. While performing a non-blocking transferring ...
Definition: lin_driver.c:257
const lin_protocol_user_config_t g_lin_protocol_user_cfg_array[LIN_NUM_OF_IFCS]
void LIN_DRV_TimeoutService(uint32_t instance)
Callback function for Timer Interrupt Handler Users may use (optional, not required) LIN_DRV_TimeoutS...
Definition: lin_driver.c:374
lin_node_state_t LIN_DRV_GetCurrentNodeState(uint32_t instance)
Get the current LIN node state.
Definition: lin_driver.c:354
status_t LIN_DRV_GetReceiveStatus(uint32_t instance, uint8_t *bytesRemaining)
Get status of an on-going non-blocking reception. This function returns whether the data reception is...
Definition: lin_driver.c:280
unsigned char l_u8
Unsigned 8 bit integer Implements : l_u8_Class.
Definition: lin_types.h:30
Runtime state of the LIN driver.
Definition: lin_driver.h:124
status_t LIN_DRV_SendFrameData(uint32_t instance, const uint8_t *txBuff, uint8_t txSize)
Sends frame data out through the LIN Hardware Interface using non-blocking method. This enables an a-sync method for transmitting data. Non-blocking means that the function returns immediately. The application has to get the transmit status to know when the transmit is complete. This function will calculate the checksum byte and send it with the frame data. The function will return immediately after calling this function. If txSize is equal to 0 or greater than 8 or node's current state is in SLEEP mode then the function will return STATUS_ERROR. If isBusBusy is currently true then the function will return LIN_BUS_BUSY.
Definition: lin_driver.c:153
l_u8 response_length
Definition: lin.h:565
lin_user_config_t * lin_user_config_ptr
Definition: lin.h:529
l_u16 max_idle_timeout_cnt
Definition: lin.h:523
l_u8 lin_lld_deinit(l_ifc_handle iii)
This function disconnect the node from the cluster and free all hardware used.
Definition: lin.c:157
l_u8 lin_lld_int_enable(l_ifc_handle iii)
Enable the interrupt related to the interface.
Definition: lin.c:264
l_u8 active_schedule_id
Definition: lin.h:543
status_t LIN_DRV_GoToSleepMode(uint32_t instance)
Puts current LIN node to sleep mode This function changes current node state to LIN_NODE_STATE_SLEEP_...
Definition: lin_driver.c:300
lin_protocol_handle_t protocol_version
Definition: lin.h:512
bool l_bool
0 is false, and non-zero (>0) is true Implements : l_bool_Class
Definition: lin_types.h:48
const l_u32 g_lin_virtual_ifc[LIN_NUM_OF_IFCS]
l_u8 lin_lld_ignore_response(l_ifc_handle iii)
This function terminates an on-going data transmission/reception.
Definition: lin.c:310
#define LIN_LLD_OK
Definition: lin.h:92
static lin_state_t s_lin_state_array[LIN_NUM_OF_IFCS]
Definition: lin.c:55
l_u8 lin_lld_get_state(l_ifc_handle iii)
This function gets current state of an interface.
Definition: lin.c:180
status_t LIN_DRV_GotoIdleState(uint32_t instance)
Puts current LIN node to Idle state This function changes current node state to LIN_NODE_STATE_IDLE.
Definition: lin_driver.c:318
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
lin_lld_event_id_t
Event id Implements : lin_lld_event_id_t_Class.
Definition: lin.h:109
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
status_t LIN_DRV_EnableIRQ(uint32_t instance)
Enables LIN hardware interrupts.
Definition: lin_driver.c:428
Transport layer description Implements : lin_tl_descriptor_t_Class.
Definition: lin.h:464
static volatile l_u16 s_lin_max_header_timeout[LIN_NUM_OF_IFCS]
Definition: lin.c:56
static l_u16 s_lin_max_frame_res_timeout_val[LIN_NUM_OF_IFCS][8]
Definition: lin.c:57