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 : : : #include <unistd.h>
7 : : :
8 : : : #include "dtc_codes_reb.h"
9 : : : #include "dtc_logger.h"
10 : : :
11 : : : /**
12 : : : * @brief Handle TCU signal received from can
13 : : : *
14 : : : * @param data Pointer to frame message receive from TCU Can.
15 : : : * @return SUCCESS(0), FAIL(1)
16 : : : * @requir{SwHLR_F_3}
17 : : : */
18 : : 8 : uint8_t handle_tcu_can(const unsigned char *data)
19 : : : {
20 : : 8 : uint8_t status = SUCCESS;
21 : : :
22 : : : // Get first byte.
23 : : 8 : unsigned char signalREB = data[0];
24 : : : // Signal from TCU to cancel REB
25 [ + + ]: [ T F ]: 8 : if (signalREB == (uint8_t)0x02U)
26 : : : {
27 : : : // Deactivate pin for countdown
28 [ + + ]: [ T F ]: 3 : if (set_pin_status(S_OFF, REB_COUNTDOWN_PIN) == FAIL)
29 : : : {
30 : : 1 : show_error("set_pin_status ERROR\n");
31 : : : }
32 : : :
33 [ + + ]: [ T F ]: 3 : if (cancel_reb() == FAIL)
34 : : : {
35 : : 2 : REPORT_ERROR("tcu_can.cancel_reb FAIL\n", DTC_TCU_CANCEL_REB_FAIL);
36 : : 2 : status = FAIL;
37 : : : }
38 : : : }
39 : : :
40 : : : // Signal from TCU to start REB
41 [ + + ]: [ T F ]: 8 : if (signalREB == (uint8_t)0x01U)
42 : : : {
43 : : : // Activate pin for countdown
44 [ + + ]: [ T F ]: 5 : if (set_pin_status(S_ON, REB_COUNTDOWN_PIN) == FAIL)
45 : : : {
46 : : 1 : show_error("set_pin_status ERROR\n");
47 : : : }
48 : : :
49 [ + + ]: [ T F ]: 5 : if (start_reb() == FAIL)
50 : : : {
51 : : 3 : REPORT_ERROR("tcu_can.start_reb FAIL\n", DTC_TCU_START_REB_FAIL);
52 : : 3 : status = FAIL;
53 : : : }
54 : : : }
55 : : 8 : return status;
56 : : : }
57 : : :
58 : : : /**
59 : : : * @brief Send a can message to ECM to block or unblock engine.
60 : : : *
61 : : : * @param status 1 to send frame data 0x01(Block); 2 to send frame data 0x02(Unblock).
62 : : : * @return SUCCESS(0), FAIL(1)
63 : : : * @requir{SwHLR_F_12}
64 : : : * @requir{SwHLR_F_10}
65 : : : * @requir{SwHLR_F_2}
66 : : : * @requir{SwHLR_F_1}
67 : : : */
68 : : 9 : uint8_t reb_can_send_ecu(uint8_t status)
69 : : : {
70 : : 9 : uint8_t statusReturn = SUCCESS;
71 : : :
72 : : 9 : struct can_frame frame = {.can_id = REB_ECU_ID, .can_dlc = 8, .data = {0}};
73 : : :
74 [ + + ]: [ T F ]: 9 : if (status == ECU_REB_START)
75 : : : {
76 : : 4 : show_log("send can to ECU to stop vehicle");
77 : : : // block engine signal
78 : : 4 : frame.data[0] = 0x01;
79 : : : }
80 : : :
81 [ + + ]: [ T F ]: 9 : if (status == ECU_REB_CANCEL)
82 : : : {
83 : : 5 : show_log("send can to ECU to remove reb blocking");
84 : : : // unblock engine signal
85 : : 5 : frame.data[0] = 0x02;
86 : : : }
87 : : :
88 [ + + ]: [ T F ]: 9 : if (can_send_vcan0(&frame) == FAIL)
89 : : : {
90 : : 4 : statusReturn = FAIL;
91 : : : }
92 : : :
93 : : 9 : return statusReturn;
94 : : : }
95 : : :
96 : : : /**
97 : : : * @brief Send a can message to Instrument Paincel Control status of REB.
98 : : : *
99 : : : * @param status 1 to send frame data 0x01(ON); 2 to send frame data 0x02(OFF).
100 : : : * @return SUCCESS(0), FAIL(1)
101 : : : * @requir{SwHLR_F_8}
102 : : : */
103 : : 16 : uint8_t reb_can_send_ipc(uint8_t status)
104 : : : {
105 : : 16 : uint8_t statusReturn = SUCCESS;
106 : : :
107 : : 16 : struct can_frame frame = {.can_id = REB_IPC_ID, .can_dlc = 8, .data = {0}};
108 : : :
109 [ + + ]: [ T F ]: 16 : if (status == IPC_REB_START)
110 : : : {
111 : : 8 : show_log("Send can to IPC to start reb");
112 : : : // Reb is activated
113 : : 8 : frame.data[0] = 0x01;
114 : : : }
115 : : :
116 [ + + ]: [ T F ]: 16 : if (status == IPC_REB_CANCEL)
117 : : : {
118 : : 8 : show_log("Send can to IPC to stop reb");
119 : : : // Reb is deactivated
120 : : 8 : frame.data[0] = 0x02;
121 : : : }
122 : : :
123 [ + + ]: [ T F ]: 16 : if (can_send_vcan0(&frame) == FAIL)
124 : : : {
125 : : 8 : statusReturn = FAIL;
126 : : : }
127 : : 16 : return statusReturn;
128 : : : }
|