LCOV - code coverage report
Current view: top level - aux/src - ecu_aux.c (source / functions) Coverage Total Hit
Test: main_coverage.info Lines: 100.0 % 112 112
Test Date: 2025-05-05 20:12:19 Functions: 100.0 % 12 12
Branches: 100.0 % 60 60
MC/DC: 100.0 % 60 60

             Branch data      MC/DC data    Line data    Source code
       1                 :              :             : #include <ecu.h>
       2                 :              :             : #include <ecu_aux.h>
       3                 :              :             : #include <mcal.h>
       4                 :              :             : #include <pins.h>
       5                 :              :             : #include <unistd.h>
       6                 :              :             : 
       7                 :              :             : /**
       8                 :              :             :  *  @brief function that iniciate engine block
       9                 :              :             :  *
      10                 :              :             :  *  @return SUCCESS(0), FAIL(1)
      11                 :              :             :  *  @requir{SwHLR_F_12}
      12                 :              :             :  */
      13                 :              :             : #ifdef UNIT_TEST
      14                 :              :           8 : uint8_t block_engine(void)
      15                 :              :             : #else
      16                 :              :             : static uint8_t block_engine(void)
      17                 :              :             : #endif
      18                 :              :             : {
      19                 :              :             : 
      20                 :              :           8 :     uint8_t ret = SUCCESS;
      21                 :              :           8 :     show_log("block Engine Started");
      22                 :              :             :     // Send command ON to pin 1 (hazard Light)
      23         [ +  + ]:      [ T  F ]:           8 :     if (set_pin_status(S_ON, HAZARD_BUTTON_PIN) == FAIL)
      24                 :              :             :     {
      25                 :              :           3 :         show_error("ECU.set_pin_status FAIL (hazard Light)\n");
      26                 :              :           3 :         ret = FAIL;
      27                 :              :             :     }
      28                 :              :             : 
      29         [ +  + ]:      [ T  F ]:           8 :     if (ret == SUCCESS)
      30                 :              :             :     {
      31                 :              :             :         // Send command ON to pin 5 (block engine)
      32         [ +  + ]:      [ T  F ]:           5 :         if (set_pin_status(S_ON, ENGINE_REB_MODE) == FAIL)
      33                 :              :             :         {
      34                 :              :           1 :             show_error("ECU.set_pin_status FAIL (engine block)\n");
      35                 :              :           1 :             ret = FAIL;
      36                 :              :             :         }
      37                 :              :             :     }
      38                 :              :             : 
      39         [ +  + ]:      [ T  F ]:           8 :     if (ret == SUCCESS)
      40                 :              :             :     {
      41                 :              :             :         // Send command ON to pin 3 (driver notification)
      42         [ +  + ]:      [ T  F ]:           4 :         if (set_pin_status(S_ON, REB_IPC_WARNING) == FAIL)
      43                 :              :             :         {
      44                 :              :           1 :             show_error("ECU.set_pin_status FAIL (driver notification)\n");
      45                 :              :           1 :             ret = FAIL;
      46                 :              :             :         }
      47                 :              :             :     }
      48                 :              :           8 :     return ret;
      49                 :              :             : }
      50                 :              :             : 
      51                 :              :             : /**
      52                 :              :             :  *  @brief function that iniciate engine unblock
      53                 :              :             :  *
      54                 :              :             :  *  @return SUCCESS(0), FAIL(1)
      55                 :              :             :  *  @requir{SwHLR_F_12}
      56                 :              :             :  */
      57                 :              :             : #ifdef UNIT_TEST
      58                 :              :           6 : uint8_t unblock_engine(void)
      59                 :              :             : #else
      60                 :              :             : static uint8_t unblock_engine(void)
      61                 :              :             : #endif
      62                 :              :             : {
      63                 :              :           6 :     uint8_t ret = SUCCESS;
      64                 :              :           6 :     show_log("unblock engine started");
      65                 :              :             :     // change pin 1 to off
      66         [ +  + ]:      [ T  F ]:           6 :     if (set_pin_status(S_OFF, HAZARD_BUTTON_PIN) == FAIL)
      67                 :              :             :     {
      68                 :              :           2 :         show_error("ECU.set_pin_status FAIL (turn off block request)\n");
      69                 :              :           2 :         ret = FAIL;
      70                 :              :             :     }
      71                 :              :             : 
      72         [ +  + ]:      [ T  F ]:           6 :     if (ret == SUCCESS)
      73                 :              :             :     {
      74                 :              :             :         // Send unblock engine command (pin 5)
      75         [ +  + ]:      [ T  F ]:           4 :         if (set_pin_status(S_OFF, ENGINE_REB_MODE) == FAIL)
      76                 :              :             :         {
      77                 :              :           1 :             show_error("ECU.set_pin_status FAIL (engine unblock)\n");
      78                 :              :           1 :             ret = FAIL;
      79                 :              :             :         }
      80                 :              :             :     }
      81                 :              :             : 
      82         [ +  + ]:      [ T  F ]:           6 :     if (ret == SUCCESS)
      83                 :              :             :     {
      84                 :              :             : 
      85                 :              :             :         // Remove driver notification (pin 3)
      86         [ +  + ]:      [ T  F ]:           3 :         if (set_pin_status(S_OFF, REB_IPC_WARNING) == FAIL)
      87                 :              :             :         {
      88                 :              :           1 :             show_error("ECU.set_pin_status FAIL (remove driver notification)\n");
      89                 :              :           1 :             ret = FAIL;
      90                 :              :             :         }
      91                 :              :             :     }
      92                 :              :           6 :     return ret;
      93                 :              :             : }
      94                 :              :             : 
      95                 :              :             : /**
      96                 :              :             :  * @brief Function check if Hazard button is pressed or not
      97                 :              :             :  * @return SUCCESS(0); FAIL(1).
      98                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
      99                 :              :             :  */
     100                 :              :          10 : uint8_t get_hazard_button_status(uint8_t *status)
     101                 :              :             : {
     102                 :              :          10 :     uint8_t ret = SUCCESS;
     103         [ +  + ]:      [ T  F ]:          10 :     if (read_pin_status(status, HAZARD_BUTTON_PIN) == FAIL)
     104                 :              :             :     {
     105                 :              :           1 :         show_error("ECU.read_pin_status FAIL\n");
     106                 :              :           1 :         ret = FAIL;
     107                 :              :             :     }
     108                 :              :          10 :     return ret;
     109                 :              :             : }
     110                 :              :             : 
     111                 :              :             : /**
     112                 :              :             :  * @brief Function change status of Hazard button
     113                 :              :             :  * @return SUCCESS(0); FAIL(1).
     114                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
     115                 :              :             :  */
     116                 :              :          10 : uint8_t set_hazard_light(uint8_t status)
     117                 :              :             : {
     118                 :              :          10 :     uint8_t ret = SUCCESS;
     119         [ +  + ]:      [ T  F ]:          10 :     if (set_pin_status(status, HAZARD_LIGHTS_PIN) == FAIL)
     120                 :              :             :     {
     121                 :              :           2 :         show_error("ECU.set_pin_status FAIL\n");
     122                 :              :           2 :         ret = FAIL;
     123                 :              :             :     }
     124                 :              :          10 :     return ret;
     125                 :              :             : }
     126                 :              :             : 
     127                 :              :             : /**
     128                 :              :             :  * @brief Function check if REB ON button is pressed or not
     129                 :              :             :  * @return SUCCESS(0); FAIL(1).
     130                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
     131                 :              :             :  */
     132                 :              :          10 : uint8_t get_tcu_start_reb(uint8_t *status)
     133                 :              :             : {
     134                 :              :          10 :     uint8_t ret = SUCCESS;
     135         [ +  + ]:      [ T  F ]:          10 :     if (read_pin_status(status, REB_ACTIVATE_PIN) == FAIL)
     136                 :              :             :     {
     137                 :              :           1 :         show_error("ECU.read_pin_status FAIL\n");
     138                 :              :           1 :         ret = FAIL;
     139                 :              :             :     }
     140                 :              :          10 :     return ret;
     141                 :              :             : }
     142                 :              :             : 
     143                 :              :             : /**
     144                 :              :             :  * @brief Function change status of REB ON Button
     145                 :              :             :  * @return SUCCESS(0); FAIL(1).
     146                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
     147                 :              :             :  */
     148                 :              :           4 : uint8_t set_tcu_start_reb(uint8_t status)
     149                 :              :             : {
     150                 :              :           4 :     uint8_t ret = SUCCESS;
     151         [ +  + ]:      [ T  F ]:           4 :     if (set_pin_status(status, REB_ACTIVATE_PIN) == FAIL)
     152                 :              :             :     {
     153                 :              :           1 :         show_error("ECU.set_pin_status FAIL\n");
     154                 :              :           1 :         ret = FAIL;
     155                 :              :             :     }
     156                 :              :           4 :     return ret;
     157                 :              :             : }
     158                 :              :             : 
     159                 :              :             : /**
     160                 :              :             :  * @brief Function change status of REB OFF Button
     161                 :              :             :  * @return SUCCESS(0); FAIL(1).
     162                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
     163                 :              :             :  */
     164                 :              :           6 : uint8_t set_tcu_cancel_reb(uint8_t status)
     165                 :              :             : {
     166                 :              :           6 :     uint8_t ret = SUCCESS;
     167         [ +  + ]:      [ T  F ]:           6 :     if (set_pin_status(status, REB_DEACTIVATE) == FAIL)
     168                 :              :             :     {
     169                 :              :           2 :         show_error("ECU.set_pin_status FAIL\n");
     170                 :              :           2 :         ret = FAIL;
     171                 :              :             :     }
     172                 :              :           6 :     return ret;
     173                 :              :             : }
     174                 :              :             : 
     175                 :              :             : /**
     176                 :              :             :  * @brief Function check if REB OFF button is pressed or not
     177                 :              :             :  * @return SUCCESS(0); FAIL(1).
     178                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
     179                 :              :             :  */
     180                 :              :           7 : uint8_t get_tcu_cancel_reb(uint8_t *status)
     181                 :              :             : {
     182                 :              :           7 :     uint8_t ret = SUCCESS;
     183         [ +  + ]:      [ T  F ]:           7 :     if (read_pin_status(status, REB_DEACTIVATE) == FAIL)
     184                 :              :             :     {
     185                 :              :           1 :         show_error("ECU.set_pin_status FAIL\n");
     186                 :              :           1 :         ret = FAIL;
     187                 :              :             :     }
     188                 :              :           7 :     return ret;
     189                 :              :             : }
     190                 :              :             : 
     191                 :              :             : /**
     192                 :              :             :  *  @brief Send a can message to REB
     193                 :              :             :  *
     194                 :              :             :  *  @param status 1 to send frame data 0x01(ON);  2 to send frame data 0x02(OFF).
     195                 :              :             :  *  @return SUCCESS(0), FAIL(1)
     196                 :              :             :  *  @requir{SwHLR_F_8}
     197                 :              :             :  */
     198                 :              :           6 : uint8_t tcu_can_send_reb(uint8_t status)
     199                 :              :             : {
     200                 :              :           6 :     uint8_t ret = SUCCESS;
     201                 :              :           6 :     struct can_frame frame = {.can_id = TCU_REB_ID, .can_dlc = 8, .data = {0}};
     202                 :              :             : 
     203         [ +  + ]:      [ T  F ]:           6 :     if (status == REB_START)
     204                 :              :             :     {
     205                 :              :           3 :         show_log("send can to REB to start REB");
     206                 :              :             :         // Activate REB
     207                 :              :           3 :         frame.data[0] = 0x01;
     208                 :              :             :     }
     209                 :              :             : 
     210         [ +  + ]:      [ T  F ]:           6 :     if (status == REB_CANCEL)
     211                 :              :             :     {
     212                 :              :           3 :         show_log("send can to REB to stop REB");
     213                 :              :             :         // Deactivate REB
     214                 :              :           3 :         frame.data[0] = 0x02;
     215                 :              :             :     }
     216                 :              :             : 
     217         [ +  + ]:      [ T  F ]:           6 :     if (can_send_vcan0(&frame) == FAIL)
     218                 :              :             :     {
     219                 :              :           2 :         ret = FAIL;
     220                 :              :             :     }
     221                 :              :           6 :     return ret;
     222                 :              :             : }
     223                 :              :             : 
     224                 :              :             : /**
     225                 :              :             :  *  @brief handle messages received from REB to Egine Control Unit
     226                 :              :             :  *
     227                 :              :             :  *  @param data Pointer to frame message receive from REB Can.
     228                 :              :             :  *  @return SUCCESS(0), FAIL(1)
     229                 :              :             :  *  @requir{SwHLR_F_3}
     230                 :              :             :  */
     231                 :              :           6 : uint8_t handle_ecu_can(const unsigned char *data)
     232                 :              :             : {
     233                 :              :           6 :     uint8_t ret = SUCCESS;
     234                 :              :             :     // Get first byte.
     235                 :              :           6 :     unsigned char signalREB = data[0];
     236                 :              :             :     // Signal from REB to block engine
     237         [ +  + ]:      [ T  F ]:           6 :     if (signalREB == 0x01U)
     238                 :              :             :     {
     239         [ +  + ]:      [ T  F ]:           4 :         if (block_engine() == FAIL)
     240                 :              :             :         {
     241                 :              :           2 :             show_error("block_engine FAIL\n");
     242                 :              :           2 :             ret = FAIL;
     243                 :              :             :         }
     244                 :              :             :     }
     245                 :              :             : 
     246         [ +  + ]:      [ T  F ]:           6 :     if (ret == SUCCESS)
     247                 :              :             :     {
     248                 :              :             :         // Signal from REB to unblock engine
     249         [ +  + ]:      [ T  F ]:           4 :         if (signalREB == 0x02U)
     250                 :              :             :         {
     251         [ +  + ]:      [ T  F ]:           2 :             if (unblock_engine() == FAIL)
     252                 :              :             :             {
     253                 :              :           1 :                 show_error("unblock_engine FAIL\n");
     254                 :              :           1 :                 ret = FAIL;
     255                 :              :             :             }
     256                 :              :             :         }
     257                 :              :             :     }
     258                 :              :             : 
     259                 :              :           6 :     return ret;
     260                 :              :             : }
     261                 :              :             : 
     262                 :              :             : /**
     263                 :              :             :  *  @brief handle messages received from REB to instrument painel control
     264                 :              :             :  *
     265                 :              :             :  *  @param data Pointer to frame message receive from REB Can.
     266                 :              :             :  *  @return SUCCESS(0), FAIL(1)
     267                 :              :             :  */
     268                 :              :           6 : uint8_t handle_ipc_can(const unsigned char *data)
     269                 :              :             : {
     270                 :              :           6 :     uint8_t ret = SUCCESS;
     271                 :              :             :     // Get first byte.
     272                 :              :           6 :     unsigned char signalREB = data[0];
     273                 :              :             : 
     274                 :              :             :     // Signal from REB that REB is ON
     275         [ +  + ]:      [ T  F ]:           6 :     if (signalREB == 0x01U)
     276                 :              :             :     {
     277                 :              :           4 :         show_log("Receive from REB ipc to start");
     278         [ +  + ]:      [ T  F ]:           4 :         if (set_reb_warning(S_ON) == FAIL)
     279                 :              :             :         {
     280                 :              :           2 :             show_error("bloc_engine FAIL\n");
     281                 :              :           2 :             ret = FAIL;
     282                 :              :             :         }
     283                 :              :             :     }
     284                 :              :             : 
     285         [ +  + ]:      [ T  F ]:           6 :     if (ret == SUCCESS)
     286                 :              :             :     {
     287                 :              :             :         // Signal from REB that REB is OFF
     288         [ +  + ]:      [ T  F ]:           4 :         if (signalREB == 0x02U)
     289                 :              :             :         {
     290                 :              :           2 :             show_log("Receive from REB ipc to cancel");
     291         [ +  + ]:      [ T  F ]:           2 :             if (set_reb_warning(S_OFF) == FAIL)
     292                 :              :             :             {
     293                 :              :           1 :                 show_error("bloc_engine FAIL\n");
     294                 :              :           1 :                 ret = FAIL;
     295                 :              :             :             }
     296                 :              :             :         }
     297                 :              :             :     }
     298                 :              :             : 
     299                 :              :           6 :     return ret;
     300                 :              :             : }
     301                 :              :             : 
     302                 :              :             : /**
     303                 :              :             :  * @brief Function change status of REB Warning of IPC
     304                 :              :             :  * @return SUCCESS(0); FAIL(1).
     305                 :              :             :  * @param status Pointer to store the status Button {0 or 1}
     306                 :              :             :  */
     307                 :              :           9 : uint8_t set_reb_warning(uint8_t status)
     308                 :              :             : {
     309                 :              :           9 :     uint8_t ret = SUCCESS;
     310                 :              :             :     // Remove driver notification (pin 3)
     311         [ +  + ]:      [ T  F ]:           9 :     if (set_pin_status(status, REB_IPC_WARNING) == FAIL)
     312                 :              :             :     {
     313                 :              :           4 :         show_error("ECU.set_pin_status FAIL  (driver notification)\n");
     314                 :              :           4 :         ret = FAIL;
     315                 :              :             :     }
     316                 :              :           9 :     return ret;
     317                 :              :             : }
        

Generated by: LCOV version 2.3.1-beta