S32 SDK
lin_lin21_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_lin21_proto.h"
21 #include "lin_common_proto.h"
22 
23 /*******************************************************************************
24  * Variables
25  ******************************************************************************/
26 
27 #if (SUPPORT_MASTER_MODE == 1U)
28 /*FUNCTION**********************************************************************
29  *
30  * Function Name : lin_collision_resolve
31  * Description : Switch to collision resolve table.
32  *
33  * Implements : lin_collision_resolve_Activity
34  *END**************************************************************************/
35 void lin_collision_resolve(l_ifc_handle iii,
36  l_u8 pid)
37 {
38  const lin_associate_frame_t * ptr;
39  l_u8 frame_index;
40  l_u8 active_schedule_id;
41  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
43  frame_index = lin_get_frame_index(iii, pid);
44  /* Check MASTER function */
45  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
46  {
47  /* Find collision resolver table */
48  /* Swap schedule table */
49  /* Get active_schedule_id */
50  active_schedule_id = master_data_ptr->active_schedule_id;
51  master_data_ptr->previous_schedule_id = active_schedule_id;
52 
53  /* Set collision resolver table to active schedule */
54  ptr = prot_user_config_ptr->frame_tbl_ptr[frame_index].frame_data_ptr;
55 
56  master_data_ptr->active_schedule_id = ptr->coll_resolv_schd;
57 
58  master_data_ptr->schedule_start_entry_ptr[master_data_ptr->active_schedule_id] = 0U;
59  }
60 }
61 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
62 
63 /*FUNCTION**********************************************************************
64  *
65  * Function Name : lin_update_word_status_lin21
66  * Description : Update node status flags.
67  *
68  * Implements : lin_update_word_status_lin21_Activity
69  *END**************************************************************************/
70 void lin_update_word_status_lin21(l_ifc_handle iii,
71  lin_lld_event_id_t event_id)
72 {
73  l_u8 err_in_res;
74  l_u8 suc_in_tras;
75  l_u8 save_config;
76  l_u8 overrun_flag;
77  lin_word_status_str_t * word_status_ptr;
78  lin_protocol_state_t * prot_state_ptr = &g_lin_protocol_state_array[iii];
79 #if (SUPPORT_MASTER_MODE == 1U)
80  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
81  const lin_master_data_t * master_data_ptr;
82  l_u8 active_schedule_id;
83 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
84 
85  err_in_res = prot_state_ptr->error_in_response;
86  prot_state_ptr->error_in_response = 0;
87  suc_in_tras = prot_state_ptr->successful_transfer;
88  /* use of ternary operator below is for being MISRA compliant */
89  save_config = (l_u8)(prot_state_ptr->save_config_flg ? 1U : 0U);
90  overrun_flag = prot_state_ptr->overrun_flg;
91 
92  word_status_ptr = &prot_state_ptr->word_status;
93  word_status_ptr->overrun = overrun_flag;
94 
95  /* values for all processed frames */
96  word_status_ptr->error_in_res |= err_in_res;
97  word_status_ptr->successful_transfer |= suc_in_tras;
98  word_status_ptr->last_pid = prot_state_ptr->last_pid;
99 
100  if(prot_state_ptr->go_to_sleep_flg == true)
101  {
102  /* Set go to sleep flag for word status*/
103  word_status_ptr->go_to_sleep_flg = 1;
104  }
105 
106  if(LIN_LLD_BUS_ACTIVITY_TIMEOUT != event_id)
107  {
108  /* Set bus activity timeout */
109  word_status_ptr->bus_activity = 1U;
110  }
111 
112 #if (SUPPORT_MASTER_MODE == 1U)
113  if ((bool)LIN_MASTER == prot_user_config_ptr->function)
114  {
116  /* If is Master node, value always equal 0 */
117  word_status_ptr->save_config_flg = 0U;
118 
119 
120  active_schedule_id = master_data_ptr->active_schedule_id;
121  /* If collision schedule table is executing, set event_trigger_collision_flag bit field*/
122  if (prot_user_config_ptr->schedule_tbl[active_schedule_id].sch_tbl_type == LIN_SCH_TBL_COLL_RESOLV)
123  {
124  word_status_ptr->event_trigger_collision_flg = 1;
125  }
126  else
127  {
128  word_status_ptr->event_trigger_collision_flg = 0;
129  }
130  }
131  else
132 #endif /* End (SUPPORT_MASTER_MODE == 1U) */
133  {
134  /* For Slave node - using ternary operator is a workaround for MISRA */
135  word_status_ptr->event_trigger_collision_flg = 0U;
136  /* Updated save configuration value to word status */
137  word_status_ptr->save_config_flg = save_config;
138  word_status_ptr->reserved = 0U;
139  }
140 }
141 
142 #if (SUPPORT_SLAVE_MODE == 1U)
143 /*FUNCTION**********************************************************************
144  *
145  * Function Name : lin_update_err_signal
146  * Description : Updates error in response flag for frames different than Event Frames
147  *
148  * Implements : lin_update_err_signal_Activity
149  *END**************************************************************************/
150 void lin_update_err_signal(l_ifc_handle iii,
151  l_u8 frm_id)
152 {
153  l_u8 i;
154  const l_u8* byte_offset_temp_ptr;
155  const l_u8* bit_offset_temp_ptr;
157  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
158  const lin_node_attribute_t * node_attr_ptr;
159  node_attr_ptr = &g_lin_node_attribute_array[prot_user_config_ptr->slave_ifc_handle];
160 
161 
162 
163  /* Set error signal equal to error in response */
164  if (LIN_FRM_EVNT != prot_user_config_ptr->frame_tbl_ptr[frm_id].frm_type)
165  {
166  for (i = 0; i < node_attr_ptr->num_frame_have_esignal; i++)
167  {
168  byte_offset_temp_ptr = &node_attr_ptr->response_error_byte_offset_ptr[i];
169  bit_offset_temp_ptr = &node_attr_ptr->response_error_bit_offset_ptr[i];
170  g_lin_frame_data_buffer[*byte_offset_temp_ptr] = (l_u8)((g_lin_frame_data_buffer[*byte_offset_temp_ptr] & (~(1U << (*bit_offset_temp_ptr)))) |
171  (err_in_res << (*bit_offset_temp_ptr)));
172  }
173  }
174 }
175 
176 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
177 
178 /*FUNCTION**********************************************************************
179  *
180  * Function Name : lin_update_rx_evnt_frame
181  * Description : The function updates the receive flags associated with signals/frames
182  * in case receive an event trigger frame.
183  *
184  * Implements : lin_update_rx_evnt_frame_Activity
185  *END**************************************************************************/
186 void lin_update_rx_evnt_frame(l_ifc_handle iii,
187  l_u8 pid)
188 {
189  const lin_associate_frame_t * ptr;
190  l_u8 frame_index, i, associate_id;
191  const lin_protocol_user_config_t * prot_user_config_ptr = &g_lin_protocol_user_cfg_array[iii];
192 
193  /* Get frame index of the event trigger frame */
194  frame_index = lin_get_frame_index(iii, pid);
195 
196  if (0xFFU != frame_index) /* This PID doesn't belong to this node */
197  {
198  /* calculate PID that associated with ETF */
199  associate_id = lin_process_parity(g_lin_protocol_state_array[iii].response_buffer_ptr[0], CHECK_PARITY);
200  ptr = prot_user_config_ptr->frame_tbl_ptr[frame_index].frame_data_ptr;
201 
202  for (i = 0U; i < ptr->num_of_associated_uncond_frames; i++)
203  {
204  /* First byte of response for event trigger is the PID of the associate frame */
205  if (prot_user_config_ptr->list_identifiers_RAM_ptr[((l_u8)ptr->associated_uncond_frame_ptr[i] - prot_user_config_ptr->frame_start) + 1U] == associate_id)
206  {
207  /* Update unconditional frame */
209  break;
210  }
211  }
212  }
213 }
214 
215 #if (SUPPORT_SLAVE_MODE == 1U)
216 /*FUNCTION**********************************************************************
217  *
218  * Function Name : lin_make_res_evnt_frame
219  * Description : This function packs signals associated with event trigger frame into buffer.
220  *
221  * Implements : lin_make_res_evnt_frame_Activity
222  *END**************************************************************************/
223 void lin_make_res_evnt_frame(l_ifc_handle iii,
224  l_u8 pid)
225 {
226  /* Create response */
228  /* Set associate PID */
230 }
231 
232 #endif /* End (SUPPORT_SLAVE_MODE == 1U) */
233 
234 /*******************************************************************************
235  * EOF
236  ******************************************************************************/
#define UPDATE_UNCONDITIONAL_FRAME
l_u8 overrun_flg
Definition: lin.h:572
l_u8 * list_identifiers_RAM_ptr
Definition: lin.h:522
lin_sch_tbl_type_t sch_tbl_type
Definition: lin.h:302
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
unsigned int go_to_sleep_flg
Definition: lin.h:155
lin_word_status_str_t word_status
Definition: lin.h:573
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_bool save_config_flg
Definition: lin.h:575
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
void lin_collision_resolve(l_ifc_handle iii, l_u8 pid)
Switch to collision resolve table.
lin_master_data_t g_lin_master_data_array[LIN_NUM_OF_MASTER_IFCS]
Definition: lin.c:52
void lin_update_word_status_lin21(l_ifc_handle iii, lin_lld_event_id_t event_id)
Update node status flags.
void lin_update_err_signal(l_ifc_handle iii, l_u8 frm_id)
Update error signal.
l_bool go_to_sleep_flg
Definition: lin.h:568
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 num_frame_have_esignal
Definition: lin.h:196
unsigned int reserved
Definition: lin.h:159
Configuration structure Implements : lin_protocol_user_config_t_Class.
Definition: lin.h:510
unsigned int error_in_res
Definition: lin.h:152
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
#define LIN_MASTER
Definition: lin.h:168
l_u8 error_in_response
Definition: lin.h:567
#define MAKE_UNCONDITIONAL_FRAME
LIN protocol status structure Implements : lin_protocol_state_t_Class.
Definition: lin.h:560
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
unsigned int last_pid
Definition: lin.h:160
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 active_schedule_id
Definition: lin.h:543
Attributes of LIN node Implements : lin_node_attribute_t_Class.
Definition: lin.h:189
l_u8 successful_transfer
Definition: lin.h:566
unsigned int event_trigger_collision_flg
Definition: lin.h:157
status of LIN bus Implements : lin_word_status_str_t_Class
Definition: lin.h:150
const l_frame_handle * associated_uncond_frame_ptr
Definition: lin.h:243
#define CHECK_PARITY
Definition: lin_driver.h:53
unsigned int save_config_flg
Definition: lin.h:158
l_u8 coll_resolv_schd
Definition: lin.h:244
#define MAKE_PARITY
Definition: lin_driver.h:52
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...
unsigned int successful_transfer
Definition: lin.h:153
lin_lld_event_id_t
Event id Implements : lin_lld_event_id_t_Class.
Definition: lin.h:109
unsigned int overrun
Definition: lin.h:154
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 int bus_activity
Definition: lin.h:156