Branch data MC/DC data Line data Source code
1 : : : #include <app.h>
2 : : : #include <ecu.h>
3 : : : #include <ecu_reb.h>
4 : : : #include <mcal.h>
5 : : : #include <pins.h>
6 : : :
7 : : : #include "dtc_codes_reb.h"
8 : : : #include "dtc_logger.h"
9 : : :
10 : : : uint8_t flag_reb_canceled = REB_RUNNING;
11 : : :
12 : : : /**
13 : : : * @brief Initializes the application by configuring drivers.
14 : : : * @return SUCCESS(0); FAIL(1).
15 : : : */
16 : : 2 : uint8_t application_init(void)
17 : : : {
18 : : 2 : uint8_t status = SUCCESS;
19 : : 2 : mcal_init();
20 : : :
21 [ + + ]: [ T F ]: 2 : if (can_init() == FAIL)
22 : : : {
23 : : 1 : REPORT_ERROR("can_init FAIL\n", DTC_CAN_INIT_FAIL);
24 : : 1 : status = FAIL;
25 : : : }
26 : : 2 : return status;
27 : : : }
28 : : :
29 : : : /**
30 : : : * @brief Handle terminal PIN inputs
31 : : : *
32 : : : * @note This function handle set pins by terminal
33 : : : * ex: "pin 1 0" set the pin number 1 to status 0
34 : : : *
35 : : : */
36 : : 2 : uint8_t read_input(void)
37 : : : {
38 : : : while (1)
39 : : : {
40 [ + + ]: [ T F ]: 4 : if (read_console() == FAIL)
41 : : : {
42 : : 1 : REPORT_ERROR("app.read_console FAIL\n", DTC_READ_INPUT_FAIL);
43 : : : }
44 : : : }
45 : : : }
46 : : :
47 : : : /**
48 : : : * @brief Handle messages received from CAN BUS
49 : : : * @return SUCCESS(0); FAIL(1).
50 : : : * @requir{SwHLR_F_1}
51 : : : * @requir{SwHLR_F_3}
52 : : : * @requir{SwHLR_F_6}
53 : : : * @requir{SwHLR_F_10}
54 : : : * @requir{SwHLR_F_13}
55 : : : * @requir{SwHLR_F_15}
56 : : : */
57 : : 7 : uint8_t monitor_read_can(void)
58 : : : {
59 : : 7 : uint8_t status = SUCCESS;
60 [ + + ]: [ T F ]: 12 : while (status == SUCCESS)
61 : : : {
62 : : :
63 : : 11 : struct can_frame frame = {
64 : : : .can_id = 29, .can_dlc = 8, .data = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
65 : : :
66 [ + + ]: [ T F ]: 11 : if (can_read_vcan0(&frame) != FAIL)
67 : : : {
68 : : : // Handle message received from Telematic Control Unit(TCU)
69 [ + + ]: [ T F ]: 5 : if (frame.can_id == TCU_REB_ID)
70 : : : {
71 [ + + ]: [ T F ]: 2 : if (handle_tcu_can(frame.data) == FAIL)
72 : : : {
73 : : 1 : show_error("handle_tcu_can FAIL\n\n");
74 : : : }
75 : : : }
76 [ + + + + ]:[ T F T F ]: 5 : if ((frame.can_id == AUX_COM_ID) && (frame.data[0] == AUX_COM_SIG))
77 : : : {
78 : : : // Check REB x AUX Communication and send response as ok
79 : : : struct can_frame response;
80 : : 2 : response.can_id = REB_COM_ID;
81 : : 2 : response.can_dlc = 1;
82 : : 2 : response.data[0] = REB_COM_SIG;
83 : : :
84 [ + + ]: [ T F ]: 2 : if (can_send_vcan0(&response) == FAIL)
85 : : : {
86 : : 1 : REPORT_ERROR("respond_to_can_test: Error to send response\n",
87 : : : DTC_CAN_RESPONSE_FAIL);
88 : : :
89 : : 1 : status = FAIL;
90 : : : }
91 : : : }
92 : : : }
93 : : : else
94 : : : {
95 : : 2 : REPORT_ERROR("Error monitor_read_can\n", DTC_MONITOR_READ_CAN_FAIL);
96 : : 2 : go_sleep(2);
97 : : : }
98 : : : }
99 : : 1 : return status;
100 : : : }
101 : : :
102 : : : /**
103 : : : * @brief Handle the deactivating REB
104 : : : * @return SUCCESS(0); FAIL(1).
105 : : : * @requir{SwHLR_F_8}
106 : : : */
107 : : 6 : uint8_t cancel_reb(void)
108 : : : {
109 : : 6 : uint8_t status = SUCCESS;
110 : : 6 : flag_reb_canceled = REB_CANCELED;
111 : : : // Send by CAN to IPC the Caceled REB status
112 [ + + ]: [ T F ]: 6 : if (reb_can_send_ipc(IPC_REB_CANCEL) == FAIL)
113 : : : {
114 : : 3 : REPORT_ERROR("cancel_reb.reb_can_send_ipc FAIL\n", DTC_REB_CAN_IPC_CANCEL_FAIL);
115 : : 3 : status = FAIL;
116 : : : }
117 : : :
118 [ + + ]: [ T F ]: 6 : if (status == SUCCESS)
119 : : : {
120 : : : // Send by CAN to Engine Control Unit the Caceled REB status
121 [ + + ]: [ T F ]: 3 : if (reb_can_send_ecu(ECU_REB_CANCEL) == FAIL)
122 : : : {
123 : : 1 : REPORT_ERROR("cancel_reb.reb_can_send_ecu FAIL\n", DTC_REB_CAN_ECU_CANCEL_FAIL);
124 : : 1 : status = FAIL;
125 : : : }
126 : : : }
127 : : 6 : return status;
128 : : : }
129 : : :
130 : : : /**
131 : : : * @brief Handle the activating REB
132 : : : * @return SUCCESS(0); FAIL(1).
133 : : : * @requir{SwHLR_F_8}
134 : : : * @requir{SwHLR_F_12}
135 : : : * @requir{SwHLR_F_14}
136 : : : * @requir{SwHLR_F_2}
137 : : : */
138 : : 7 : uint8_t start_reb(void)
139 : : : {
140 : : 7 : uint8_t status = SUCCESS;
141 : : :
142 : : : // Reset flag when start reb
143 : : 7 : flag_reb_canceled = REB_RUNNING;
144 : : :
145 : : 7 : show_log("Start REB counting and send can to IPC");
146 : : : // send by CAN to IPC the start REB counting
147 [ + + ]: [ T F ]: 7 : if (reb_can_send_ipc(IPC_REB_START) == FAIL)
148 : : : {
149 : : 4 : REPORT_ERROR("start_reb.reb_can_send_ipc FAIL\n", DTC_REB_CAN_IPC_START_FAIL);
150 : : 4 : status = FAIL;
151 : : : }
152 : : :
153 : : 7 : return status;
154 : : : }
155 : : :
156 : : : /**
157 : : : * @brief Handle the activating REB countdown
158 : : : * @requir{SysHLR_3}
159 : : : * @requir{SwHLR_F_12}
160 : : : * @requir{SwHLR_F_14}
161 : : : * @requir{SwHLR_F_1}
162 : : : */
163 : : 4 : uint8_t countdown_reb(void)
164 : : : {
165 : : : while (1)
166 : : 10 : {
167 : : : struct timespec start_time;
168 : : : struct timespec current_time;
169 : : 14 : uint8_t reb_countdown_active = 0;
170 : : :
171 : : 14 : get_time(&start_time);
172 : : :
173 : : : // Verify the status of the pin
174 [ + + ]: [ T F ]: 14 : if (read_pin_status(&reb_countdown_active, REB_COUNTDOWN_PIN) == FAIL)
175 : : : {
176 : : 2 : show_error("read_pin_status ERROR\n");
177 : : : }
178 : : :
179 [ + + ]: [ T F ]: 886251443 : while (reb_countdown_active != 0U)
180 : : : {
181 : : 886251415 : double elapsed_time = 0.0;
182 : : 886251415 : get_time(¤t_time);
183 : : :
184 : : 886251415 : elapsed_time = (current_time.tv_sec - start_time.tv_sec) +
185 : : 886251415 : ((double)(current_time.tv_nsec - start_time.tv_nsec) / 1e9);
186 : : :
187 [ + + ]: [ T F ]: 886251415 : if (elapsed_time >= (double)REB_TIMEOUT)
188 : : : {
189 [ + + ]: [ T F ]: 3 : if (reb_can_send_ecu(ECU_REB_START) == FAIL)
190 : : : {
191 : : 2 : show_error("reb_can_send_ecu ERROR\n");
192 : : : }
193 : : :
194 [ + + ]: [ T F ]: 3 : if (set_pin_status(S_OFF, REB_COUNTDOWN_PIN) == FAIL)
195 : : : {
196 : : 1 : show_error("set_pin_status ERROR\n");
197 : : : }
198 : : : }
199 : : :
200 : : : // Verify the status of the pin again
201 [ + + ]: [ T F ]: 886251415 : if (read_pin_status(&reb_countdown_active, REB_COUNTDOWN_PIN)== FAIL)
202 : : : {
203 : : 1 : show_error("read_pin_status ERROR\n");
204 : : : }
205 : : : }
206 : : :
207 : : 14 : go_sleep(1);
208 : : : }
209 : : : }
|