Branch data MC/DC data Line data Source code
1 : : : #include <app.h>
2 : : : #include <ecu.h>
3 : : : #include <ecu_aux.h>
4 : : : #include <mcal.h>
5 : : : #include <pins.h>
6 : : :
7 : : : uint8_t reb_con = 0;
8 : : :
9 : : : /**
10 : : : * @brief Initializes the application by configuring drivers.
11 : : : * @return SUCCESS(0); FAIL(1).
12 : : : */
13 : : 2 : uint8_t application_init(void)
14 : : : {
15 : : :
16 : : 2 : uint8_t status = SUCCESS;
17 : : 2 : mcal_init();
18 : : :
19 [ + + ]: [ T F ]: 2 : if ((can_init() == FAIL))
20 : : : {
21 : : 1 : show_error("can_init FAIL\n");
22 : : 1 : status = FAIL;
23 : : : }
24 : : :
25 : : 2 : return status;
26 : : : }
27 : : :
28 : : : /**
29 : : : * @brief Handle terminal PIN inputs
30 : : : *
31 : : : * @note This function handle set pins by terminal
32 : : : * ex: "pin 1 0" set the pin number 1 to status 0
33 : : : *
34 : : : */
35 : : 2 : uint8_t read_input(void)
36 : : : {
37 : : : while (1)
38 : : : {
39 [ + + ]: [ T F ]: 4 : if (read_console() == FAIL)
40 : : : {
41 : : 1 : show_error("app.read_console FAIL\n");
42 : : : }
43 : : : }
44 : : : }
45 : : :
46 : : : /**
47 : : : * @brief function that makes hazard lights blink
48 : : : * @return SUCCESS(0); FAIL(1).
49 : : : */
50 : : 5 : uint8_t hazard_lights_blink(void)
51 : : : {
52 : : 5 : uint8_t ret = SUCCESS;
53 [ + + ]: [ T F ]: 12 : while (ret == SUCCESS)
54 : : : {
55 : : 9 : uint8_t status = 0;
56 [ + + ]: [ T F ]: 9 : if (get_hazard_button_status(&status) == FAIL)
57 : : : {
58 : : 1 : show_error("get_hazard_button_status FAIL\n");
59 : : 1 : ret = FAIL;
60 : : : }
61 [ + + ]: [ T F ]: 8 : else if ((status == S_ON))
62 : : : {
63 [ + + ]: [ T F ]: 5 : if ((set_hazard_light(S_ON) == FAIL))
64 : : : {
65 : : 1 : show_error("set_hazard_light FAIL\n");
66 : : 1 : ret = FAIL;
67 : : : };
68 : : 5 : go_sleep(1);
69 [ + + + + ]:[ T F T F ]: 4 : if ((ret == SUCCESS) && (set_hazard_light(S_OFF) == FAIL))
70 : : : {
71 : : 1 : show_error("set_hazard_light FAIL\n");
72 : : 1 : ret = FAIL;
73 : : : };
74 : : 4 : go_sleep(1);
75 : : : }
76 : : : else
77 : : : {
78 : : 3 : go_sleep(2);
79 : : : }
80 : : : }
81 : : 3 : return ret;
82 : : : }
83 : : :
84 : : : /**
85 : : : * @brief Handle messages received from CAN BUS
86 : : : * @return SUCCESS(0); FAIL(1).
87 : : : * @requir{SwHLR_F_6}
88 : : : * @requir{SwHLR_F_10}
89 : : : * @requir{SwHLR_F_15}
90 : : : */
91 : : 7 : uint8_t monitor_read_can(void)
92 : : : {
93 : : : while (1)
94 : : 6 : {
95 : : :
96 : : 13 : struct can_frame frame = {
97 : : : .can_id = 29, .can_dlc = 8, .data = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
98 : : :
99 [ + + ]: [ T F ]: 13 : if (can_read_vcan0(&frame) != FAIL)
100 : : : {
101 : : : // handle message from REB to ECU
102 [ + + ]: [ T F ]: 6 : if (frame.can_id == REB_ECU_ID)
103 : : : {
104 [ + + ]: [ T F ]: 2 : if (handle_ecu_can(frame.data) == FAIL)
105 : : : {
106 : : 1 : show_error("Handle_ecu_can ERROR\n");
107 : : : }
108 : : : }
109 : : :
110 : : : // handle message from REB to IPC
111 [ + + ]: [ T F ]: 6 : if (frame.can_id == REB_IPC_ID)
112 : : : {
113 [ + + ]: [ T F ]: 2 : if (handle_ipc_can(frame.data) == FAIL)
114 : : : {
115 : : 1 : show_error("handle_ipc_can ERROR\n");
116 : : : }
117 : : : }
118 [ + + + + ]:[ T F T F ]: 6 : if ((frame.can_id == 0x015) && (frame.data[0] == 0x10))
119 : : : {
120 : : : // Return as ok the communication between REB x AUX
121 : : 1 : reb_con = 1;
122 : : : }
123 : : : }
124 : : : else
125 : : : {
126 : : 1 : show_error("Error monitor_read_can\n");
127 : : 1 : go_sleep(2);
128 : : : }
129 : : : }
130 : : : return SUCCESS;
131 : : : }
132 : : :
133 : : : /**
134 : : : * @brief Handle the Reb ON and Reb OFF Buttons from GUI
135 : : : * @return SUCCESS(0); FAIL(1).
136 : : : */
137 : : 8 : uint8_t monitor_tcu(void)
138 : : : {
139 : : 8 : uint8_t ret = SUCCESS;
140 [ + + ]: [ T F ]: 11 : while (ret == SUCCESS)
141 : : : {
142 : : 9 : uint8_t status = 0;
143 : : : // get REB ON Button status
144 [ + + ]: [ T F ]: 9 : if (get_tcu_start_reb(&status) == FAIL)
145 : : : {
146 : : 1 : show_error("get_tcu_star_reb FAIL\n");
147 : : 1 : ret = FAIL;
148 : : : }
149 : : : // Activate REB
150 [ + + + + ]:[ T F T F ]: 9 : if ((ret == SUCCESS) && (status == S_ON))
151 : : : {
152 : : : // Toggle OFF Button to not enter in this loop
153 [ + + ]: [ T F ]: 3 : if (set_tcu_start_reb(S_OFF) == FAIL)
154 : : : {
155 : : 1 : show_error("set_tcu_start_reb FAIL\n");
156 : : 1 : ret = FAIL;
157 : : : }
158 : : : // Send frame CAN to REB UNIT to start REB
159 [ + + + + ]:[ T F T F ]: 3 : if ((ret == SUCCESS) && (tcu_can_send_reb(REB_START) == FAIL))
160 : : : {
161 : : 1 : show_error("tcu_can_send_reb FAIL\n");
162 : : 1 : ret = FAIL;
163 : : : }
164 : : : }
165 : : :
166 : : : // get REB OFF Button status
167 [ + + + + ]:[ T F T F ]: 9 : if ((ret == SUCCESS) && (get_tcu_cancel_reb(&status) == FAIL))
168 : : : {
169 : : 1 : show_error("get_tcu_cancel_reb FAIL\n");
170 : : 1 : ret = FAIL;
171 : : : }
172 : : : // Deactivate REB
173 [ + + + + ]:[ T F T F ]: 9 : if ((ret == SUCCESS) && (status == S_ON))
174 : : : {
175 : : : // Toggle OFF Button to not enter in this loop
176 [ + + ]: [ T F ]: 3 : if (set_tcu_cancel_reb(S_OFF) == FAIL)
177 : : : {
178 : : 1 : show_error("set_tcu_cancel_reb FAIL\n");
179 : : 1 : ret = FAIL;
180 : : : }
181 : : : // Send fram CAN to REB UNIT to cancel REB
182 [ + + + + ]:[ T F T F ]: 3 : if ((ret == SUCCESS) && (tcu_can_send_reb(REB_CANCEL) == FAIL))
183 : : : {
184 : : 1 : show_error("tcu_can_send_reb FAIL\n");
185 : : 1 : ret = FAIL;
186 : : : }
187 : : : }
188 : : : else
189 : : : {
190 : : 6 : go_sleep(2);
191 : : : }
192 : : : }
193 : : 2 : return ret;
194 : : : }
195 : : :
196 : : : /**
197 : : : * @brief Check communication CAN between REB e AUX modules sending a frame and receving a response.
198 : : : * @return SUCCESS(0); FAIL(1).
199 : : : * @requir{SwHLR_F_13}
200 : : : * @requir{SwHLR_F_15}
201 : : : */
202 : : 8 : uint8_t check_can_communication(void)
203 : : : {
204 : : : // Frames to check cSommunication CAN between REB e AUX modules
205 : : 8 : struct can_frame test_frame = {0};
206 : : 8 : test_frame.can_id = AUX_COM_ID;
207 : : 8 : test_frame.can_dlc = 1;
208 : : 8 : test_frame.data[0] = AUX_COM_SIG;
209 : : :
210 : : : while (1)
211 : : 4 : {
212 : : 12 : reb_con = 0;
213 : : 12 : int cont_tries = 0;
214 : : :
215 [ + + ]: [ T F ]: 12 : if (can_send_vcan0(&test_frame) == FAIL)
216 : : : {
217 : : 3 : show_error("check_can_communication: Error to send communication test\n");
218 : : : }
219 : : 12 : uint8_t current_ipc_fault_pin_status = 0x00U;
220 : : :
221 [ + + ]: [ T F ]: 74 : while (reb_con == 0x00U)
222 : : : {
223 [ + + ]: [ T F ]: 70 : if (cont_tries >= 10)
224 : : : {
225 : : : // Try 10 times the communication test {SwHLR_F_15}
226 [ + + ]: [ T F ]: 4 : if (read_pin_status(¤t_ipc_fault_pin_status, REB_IPC_FAULT_PIN) == FAIL)
227 : : : {
228 : : 1 : show_error("read_pin_status ERROR\n");
229 : : : }
230 [ + + ]: [ T F ]: 4 : if (current_ipc_fault_pin_status != 0x01U)
231 : : : {
232 [ + + ]: [ T F ]: 3 : if (set_pin_status(1, REB_IPC_FAULT_PIN) == FAIL)
233 : : : {
234 : : 1 : show_error("set_pin_status ERROR\n");
235 : : : }
236 : : : }
237 [ + + ]: [ T F ]: 4 : if (can_send_vcan0(&test_frame) == FAIL)
238 : : : {
239 : : 3 : show_error("check_can_communication: Timeout CAN communication\n");
240 : : : }
241 : : 4 : cont_tries = 0;
242 : : : }
243 : : : // Verify communication each 11 seconds
244 : : 70 : go_sleep(1);
245 : : 62 : cont_tries++;
246 : : : }
247 [ + + ]: [ T F ]: 4 : if (read_pin_status(¤t_ipc_fault_pin_status, REB_IPC_FAULT_PIN) == FAIL)
248 : : : {
249 : : 1 : show_error("read_pin_status ERROR\n");
250 : : : }
251 [ + + ]: [ T F ]: 4 : if (current_ipc_fault_pin_status != 0x00U)
252 : : : {
253 [ + + ]: [ T F ]: 2 : if (set_pin_status(0, REB_IPC_FAULT_PIN) == FAIL)
254 : : : {
255 : : 1 : show_error("set_pin_status ERROR\n");
256 : : : }
257 : : : }
258 : : : }
259 : : : return SUCCESS;
260 : : : }
|