Common_Interface.c 14.8 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "Common_Interface.h"
#include "CAN_Communication_Matrix.h"
#include "CAN_Lib.h"
#include "Data_VehicleSpeed.h"
#include "Data_EngineSpeed.h"
#include "System_Monitor.h"
#include "GaugesInterface.h"
#include "Gauges.h"
#include "dr7f701441.dvf.h"
#include "GPIO.h"

#include "Line_in.h"

#include "Maintenance.h"
#include "Menu.h"
hu's avatar
hu committed
16
#include "GUI.h"
hu's avatar
hu committed
17 18 19

#include "Emulated_EEPROM.h"
#include "Watchdog.h"
hu's avatar
hu committed
20
#include "UDS_Common.h"
hu's avatar
hu committed
21 22 23 24 25 26 27

/*修饰变量static*/

/*ig on off时间线*/
static uint32_t PowerIgnOnTimeLine;
static uint32_t PowerIgnOffTimeLine;

hu's avatar
hu committed
28 29 30 31 32
static COMMON_PowerStatus_t PowerSts; /*1 ON ;  0 OFF*/
static uint16_t Act_V_Speed;          /*实际值,十倍的*/
static uint16_t Act_E_Speed;          /*实际值*/
static uint16_t Disp_V_Speed;         /*显示值,十倍的*/
static uint16_t Disp_E_Speed;         /*显示值*/
hu's avatar
hu committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

/*数据有效 1 ;数据无效 0 /0xff */
static DataValid_t PowerSts_Valid;
static DataValid_t Act_V_Speed_Valid;
static DataValid_t Act_E_Speed_Valid;
static DataValid_t Disp_V_Speed_Valid;
static DataValid_t Disp_E_Speed_Valid;

static void Common_Set_Act_V_Speed(uint16_t Val);
static void Common_Set_Act_E_Speed(uint16_t Val);
static void Common_Set_Disp_V_Speed(uint16_t Val);
static void Common_Set_Disp_E_Speed(uint16_t Val);

static void Common_Set_Act_V_Speed_Valid(DataValid_t Val);
static void Common_Set_Act_E_Speed_Valid(DataValid_t Val);
static void Common_Set_Disp_V_Speed_Valid(DataValid_t Val);
static void Common_Set_Disp_E_Speed_Valid(DataValid_t Val);

static uint16_t SysRollingCounter;
hu's avatar
hu committed
52
// wangboyu - begin
hu's avatar
hu committed
53
static uint8_t CanFirstEvent[ID_TOTAL_MAX];
hu's avatar
hu committed
54 55
static void Individual_ECU_Communication(void);
// wangboyu - end
hu's avatar
hu committed
56

hu's avatar
hu committed
57
_EOL_K_LINE_SET K_Line_Set;
hu's avatar
hu committed
58

hu's avatar
hu committed
59 60 61 62 63 64 65 66 67 68 69

/**/
static  uint16_t User_FDJYLQQ_Time;
static  uint16_t User_RYLQQ_Time;
static  uint16_t User_BSXY_Time;
static  uint16_t User_CSQY_Time;
static  uint16_t User_LHQY_Time;
static  uint16_t User_KQGZJ_Time;
static  uint16_t User_DLZXY_Time;
static  uint16_t User_LT_Time;

hu's avatar
hu committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/*每次唤醒调用*/
void Common_DataInit(void)
{
    PowerSts = COMMON_POWER_UNKNOW;
    Act_V_Speed = 0xffffu;
    Act_E_Speed = 0xffffu;
    Disp_V_Speed = 0xffffu;
    Disp_E_Speed = 0xffffu;

    PowerSts_Valid = COMMON_Valid_UNKNOW;
    Act_V_Speed_Valid = COMMON_Valid_UNKNOW;
    Act_E_Speed_Valid = COMMON_Valid_UNKNOW;
    Disp_V_Speed_Valid = COMMON_Valid_UNKNOW;
    Disp_E_Speed_Valid = COMMON_Valid_UNKNOW;
    PowerIgnOnTimeLine = 0x0ul;
    PowerIgnOffTimeLine = 0x0ul;
hu's avatar
hu committed
86

hu's avatar
hu committed
87 88 89 90 91 92 93 94 95
    /**/
    User_FDJYLQQ_Time  = 0x00u;
    User_RYLQQ_Time  = 0x00u;
    User_BSXY_Time  = 0x00u;
    User_CSQY_Time  = 0x00u;
    User_LHQY_Time  = 0x00u;
    User_KQGZJ_Time  = 0x00u;
    User_DLZXY_Time  = 0x00u;
    User_LT_Time  = 0x00u;
hu's avatar
hu committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
}

/*以下由各个处理模块按需调用*/
/*使用数据之前,需要先判断数据是否有效,如果无效,则不可以使用*/

COMMON_PowerStatus_t Common_Get_IG_Sts(void)
{
    return PowerSts;
}

uint16_t Common_Get_Act_V_Speed(void)
{
    return Act_V_Speed;
}
uint16_t Common_Get_Act_E_Speed(void)
{
    return Act_E_Speed;
}
uint16_t Common_Get_Disp_V_Speed(void)
{
    return Disp_V_Speed;
}
uint16_t Common_Get_Disp_E_Speed(void)
{
    return Disp_E_Speed;
}

/*获取超速报警状态*/
uint8_t Common_Get_OverSpeed_Status(void)
{
    uint8_t OverSpeedStatus = 0u;
    uint16_t DispVSpeed = 0u;
    DispVSpeed = Common_Get_Disp_V_Speed();

    if (DispVSpeed >= 1000u)
    {
        OverSpeedStatus = 1u;
    }
    else if (DispVSpeed <= 960u)
    {
        OverSpeedStatus = 0u;
    }

    return OverSpeedStatus;
}

static void Common_Set_IG_Sts(COMMON_PowerStatus_t Val)
{
    PowerSts = Val;
}
static void Common_Set_Act_V_Speed(uint16_t Val)
{
    Act_V_Speed = Val;
}
static void Common_Set_Act_E_Speed(uint16_t Val)
{
    Act_E_Speed = Val;
}
static void Common_Set_Disp_V_Speed(uint16_t Val)
{
    Disp_V_Speed = Val;
}
static void Common_Set_Disp_E_Speed(uint16_t Val)
{
    Disp_E_Speed = Val;
}

DataValid_t Common_Get_IG_Sts_Valid(void)
{
    return PowerSts_Valid;
}
DataValid_t Common_Get_Act_V_Speed_Valid(void)
{
hu's avatar
hu committed
169
    return Act_V_Speed_Valid;
hu's avatar
hu committed
170 171 172
}
DataValid_t Common_Get_Act_E_Speed_Valid(void)
{
hu's avatar
hu committed
173
    return Act_E_Speed_Valid;
hu's avatar
hu committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
}
DataValid_t Common_Get_Disp_V_Speed_Valid(void)
{
    return Disp_V_Speed_Valid;
}
DataValid_t Common_Get_Disp_E_Speed_Valid(void)
{
    return Disp_E_Speed_Valid;
}

static void Common_Set_IG_Sts_Valid(DataValid_t Val)
{
    PowerSts_Valid = Val;
}
static void Common_Set_Act_V_Speed_Valid(DataValid_t Val)
{
    Act_V_Speed_Valid = Val;
}
static void Common_Set_Act_E_Speed_Valid(DataValid_t Val)
{
    Act_E_Speed_Valid = Val;
}
static void Common_Set_Disp_V_Speed_Valid(DataValid_t Val)
{
    Disp_V_Speed_Valid = Val;
}
static void Common_Set_Disp_E_Speed_Valid(DataValid_t Val)
{
    Disp_E_Speed_Valid = Val;
}

/*2MS任务*/
hu's avatar
hu committed
206
static uint16_t wbyTest = 0;
hu's avatar
hu committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
void Common_Input_Para(void)
{
    /*    if (SYS_OPR_STAT_IGN_ON)
        {*/
    uint32_t V_Speed_Convert = 0ul;
    uint32_t u32IG_ON_Timer = 0u;
    uint16_t OilValue = 0u; /*机油压力数值*/
    uint32_t EBC2_Speed_Value = 0u;
    uint8_t LineStatus1 = 0u;
    uint8_t LineStatus2 = 0u;

    u32IG_ON_Timer = Common_GetIgnOnTime();

    if (SYS_OPR_STAT_IGN_ON)
    {
        Common_Set_IG_Sts(COMMON_POWER_ON);
        Common_Set_IG_Sts_Valid(COMMON_Valid);

        OilValue = Common_Get_Disp_E_Speed();

        //车速
        wbyTest = Speed_Get_Display_Value();
        Common_Set_Disp_V_Speed(wbyTest);
        Common_Set_Act_V_Speed(Speed_Get_ActualValue());
hu's avatar
hu committed
231

hu's avatar
hu committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        if (Speed_Get_Valid())
        {
            Common_Set_Act_V_Speed_Valid(COMMON_Valid);
            Common_Set_Disp_V_Speed_Valid(COMMON_Valid);
        }
        else
        {
            Common_Set_Act_V_Speed_Valid(COMMON_InValid);
            Common_Set_Disp_V_Speed_Valid(COMMON_InValid);
        }

        Common_Set_Act_E_Speed(RevSpeedManage(Tacho_Get_ActualValue()));

        PowerIgnOffTimeLine = 0ul;
        if (PowerIgnOnTimeLine < 0x7ffffffful)
        {
            PowerIgnOnTimeLine += 2u;
        }
hu's avatar
hu committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332

        /**/
        if ((State_Flag.User_FDJYLQQ_FLAG == 1) || (State_Flag.User_FDJYLQQ_FLAG == 2))
        {
            if (User_FDJYLQQ_Time < 601)
                User_FDJYLQQ_Time++;
        }
        else
        {
            User_FDJYLQQ_Time = 0 ;
        }

        if ((State_Flag.User_RYLQQ_FLAG   == 1) || (State_Flag.User_RYLQQ_FLAG   == 2))
        {
            if (User_RYLQQ_Time < 601)
                User_RYLQQ_Time ++;
        }
        else
        {
            User_RYLQQ_Time  = 0;
        }

        if ((State_Flag.User_BSXY_FLAG    == 1) || (State_Flag.User_BSXY_FLAG    == 2))
        {
            if (User_BSXY_Time < 601)
                User_BSXY_Time ++;
        }
        else
        {
            User_BSXY_Time = 0;
        }

        if ((State_Flag.User_CSQY_FLAG    == 1) || (State_Flag.User_CSQY_FLAG    == 2))
        {
            if (User_CSQY_Time < 601)
                User_CSQY_Time++;
        }
        else
        {
            User_CSQY_Time = 0;
        }

        if ((State_Flag.User_LHQY_FLAG   == 1) || (State_Flag.User_LHQY_FLAG   == 2))
        {
            if (User_LHQY_Time < 601)
                User_LHQY_Time++;
        }
        else
        {
            User_LHQY_Time = 0;
        }

        if ((State_Flag.User_KQGZJ_FLAG   == 1) || (State_Flag.User_KQGZJ_FLAG   == 2))
        {
            if (User_KQGZJ_Time < 601)
                User_KQGZJ_Time++;
        }
        else
        {
            User_KQGZJ_Time = 0;
        }

        if ((State_Flag.User_DLZXY_FLAG   == 1) || (State_Flag.User_DLZXY_FLAG   == 2))
        {
            if (User_DLZXY_Time < 601)
                User_DLZXY_Time ++;
        }
        else
        {
            User_DLZXY_Time = 0;
        }

        if ((State_Flag.User_LT_FLAG      == 1) || (State_Flag.User_LT_FLAG      == 2))
        {
            if (User_LT_Time < 601)
                User_LT_Time ++ ;
        }
        else
        {
            User_LT_Time = 0;
        }

        /**/
hu's avatar
hu committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    }
    else
    {
        PowerIgnOnTimeLine = 0ul;
        if (PowerIgnOffTimeLine < 0x7ffffffful)
        {
            PowerIgnOffTimeLine += 2u;
        }

        Common_Set_IG_Sts(COMMON_POWER_OFF);
        Common_Set_IG_Sts_Valid(COMMON_Valid);

        /*车转真实值OFF为0*/
        Common_Set_Act_V_Speed(0u);
        Common_Set_Act_E_Speed(0u);
        Common_Set_Disp_V_Speed(0u);
        Common_Set_Disp_E_Speed(0u);
hu's avatar
hu committed
350 351 352 353 354 355 356 357 358 359 360 361

        /*----*/
        User_FDJYLQQ_Time = 0u ;
        User_RYLQQ_Time   = 0u ;
        User_BSXY_Time    = 0u ;
        User_CSQY_Time    = 0u ;
        User_LHQY_Time    = 0u ;
        User_KQGZJ_Time   = 0u ;
        User_DLZXY_Time   = 0u ;
        User_LT_Time      = 0u ;
        /*----*/

hu's avatar
hu committed
362 363 364 365 366
    }
}

void Set_Can18FF5510_FirstRecv_Event(void)
{
hu's avatar
hu committed
367
    CanFirstEvent[ID_CanMsg18FF5510_Msg_Count] = 1;
hu's avatar
hu committed
368 369 370 371
}

void Set_Can18FF2300_FirstRecv_Event(void)
{
hu's avatar
hu committed
372
    CanFirstEvent[ID_CanMsg18FF2300_Msg_Count] = 1;
hu's avatar
hu committed
373 374
}

hu's avatar
hu committed
375 376 377
uint8_t Get_CanFirstRecv_Event(uint8_t ID)
{
    return CanFirstEvent[ID];
hu's avatar
hu committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
}

void Common_RollingCounterAdd(void)
{
    SysRollingCounter++;
}

void Common_RollingCounterClear(void)
{
    SysRollingCounter = 0u;
}

uint16_t Common_ReadRollingCounter(void)
{
    return SysRollingCounter;
}

void Common_BlockDelay(uint16_t m_MS)
{
    uint16_t RocBackup;
    uint16_t Counter;
    uint16_t DIMCounter;

    DIMCounter = m_MS * 20u;
    Common_RollingCounterClear();
    RocBackup = Common_ReadRollingCounter();
    do
    {
        Counter = Common_ReadRollingCounter();

        if (Counter >= RocBackup)
        {
            Counter -= RocBackup;
        }
        else
        {
            Counter = 65535u - RocBackup + Counter + 1u;
        }

hu's avatar
hu committed
417 418
    }
    while (Counter < DIMCounter);
hu's avatar
hu committed
419 420 421 422 423 424 425 426 427 428 429 430
}

uint32_t Common_GetIgnOnTime(void)
{
    return PowerIgnOnTimeLine;
}

uint32_t Common_GetIgnOffTime(void)
{
    return PowerIgnOffTimeLine;
}

hu's avatar
hu committed
431 432 433
#pragma diag_suppress = Pm064
int32_t SEGGER_RTT_printf(uint16_t BufferIndex, const char *sFormat, ...);
int32_t SEGGER_RTT_printf(uint16_t BufferIndex, const char *sFormat, ...)
hu's avatar
hu committed
434 435 436
{
    return 0;
}
hu's avatar
hu committed
437

hu's avatar
hu committed
438 439 440 441 442 443
/*EOL诊断配置数据转换为仪表配置数据*/
void ReadDTCEOLValue_Meter_K_LINE(void)
{
    /*获取所有存储数据*/
    ReadDFlashData(EEPROM_BLOCK_EOL_K_LINE, (uint32_t *)&K_Line_Set.Flag, (sizeof(K_Line_Set) / 4u), K_LINE_EOL_InitVal);
}
hu's avatar
hu committed
444 445
void K_LINE_EOL_InitVal(void)
{
hu's avatar
hu committed
446 447
    K_Line_Set.Flag = 0x7AA7A55Au;

hu's avatar
hu committed
448 449 450 451 452 453 454
    K_Line_Set.K_Line_LID20 = 0x00u; /* 00 应对ECE R13      //0:非应对、1:应对 */
    K_Line_Set.K_Line_LID21 = 0x00u; /* 00 EBS/ABS         //0:无、1:EBS、2:ABS(CAN应对) 3:ABS (CAN非应对) */
    K_Line_Set.K_Line_LID22 = 0x00u; /* 00 EVSC            //0:无、1:有 */
    K_Line_Set.K_Line_LID23 = 0x00u; /* 00 驻车锁定         //0:无、1:有 */
    K_Line_Set.K_Line_LID24 = 0x00u; /* 00 HSA             //0:无、1:有 */
    K_Line_Set.K_Line_LID25 = 0x00u; /* 00 AEBS            //0:无、1:有 */
    K_Line_Set.K_Line_LID26 = 0x00u; /* 00 ACC             //0:无、1:有 */
hu's avatar
hu committed
455
    K_Line_Set.K_Line_LID27 = 0x01u; /* 00 LDWS            //0:无、1:有 */
hu's avatar
hu committed
456
    K_Line_Set.K_Line_LID28 = 0x01u; /* 01 车辆间报警        //0:无、1:有 */
hu's avatar
hu committed
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
    K_Line_Set.K_Line_LID29 = 0x01u; /* 01 有无巡航          //0:无、1:有          /*初值1*/
    K_Line_Set.K_Line_LID2A = 0x00u; /* 00 气悬             //0:Reef、1:Rear air、2:Full air */
    K_Line_Set.K_Line_LID2B = 0x00u; /* 00 ISS             //0:无、1: eco stop、 2:Idle Stop */
    K_Line_Set.K_Line_LID2C = 0x00u; /* 00 装货台工作警报蜂鸣 //0:无、1:有             */
    K_Line_Set.K_Line_LID2D = 0x00u; /* 00 ROWS            //0:无、1:ROWS有、2LOCAL警报有 */
    K_Line_Set.K_Line_LID2E = 0x00u; /* 00 行车记录仪        //0:模拟记录仪、1:数字记录仪或行车记录仪 */
    K_Line_Set.K_Line_LID2F = 0x00u; /* 00 车型             //0:单车、1:拖车、2:全拖车 */
    K_Line_Set.K_Line_LID30 = 0x00u; /* 00 缓速器           //0:无、1:有(C&E)、2:有(F) */
    K_Line_Set.K_Line_LID31 = 0x01u; /* -- 定速巡航         //0:无、1:有 */
    K_Line_Set.K_Line_LID32 = 0x00u; /* 00 装货台种类       //0:一般、1:侧翼、2:倾倒 */
    K_Line_Set.K_Line_LID33 = 0x01u; /* 01 SCR?DPD         //0:SCR无/DPD有、1:SCR有/DPD有、2:SCR无/DPD无、3:SCR有/DPD无    /*初值1*/
    K_Line_Set.K_Line_LID34 = 0x00u; /* 00 驻车种类         //0:FULL AIR、1:AOH                     /*初值1*/
    K_Line_Set.K_Line_LID35 = 0x00u; /* -- 气压计           //0:2针式、1:1针式 */
    K_Line_Set.K_Line_LID36 = 0x00u; /* -- 低压警报压       //0:一般输出(539kPa)、1:ADR(588kPa) */
    K_Line_Set.K_Line_LID37 = 0x01u; /* -- 超限警报         //0:无、1:有 */
    K_Line_Set.K_Line_LID38 = 0x01u; /* -- 速度警报         //0:无、1:有 */
    K_Line_Set.K_Line_LID39 = 0x00u; /* 00 可变SLD          //0:无、1:1车速、2:2车速            /*初值1*/
    K_Line_Set.K_Line_LID3A = 0x00u; /* -- OEM             //0:ISZ、1:UDT */
    K_Line_Set.K_Line_LID3B = 0x00u; /* -- 预留 */
    K_Line_Set.K_Line_LID3C = 0x00u; /* -- 预留 */
    K_Line_Set.K_Line_LID3D = 0x00u; /* -- 预留 */
    K_Line_Set.K_Line_LID3E = 0x01u; /* 01 预留             //0:胎压功能未匹配    1:匹配 */
    K_Line_Set.K_Line_LID3F = 0x00u; /* -- 预留 */
    K_Line_Set.K_Line_LID40 = 0x00u; /* 00 发动机种类 */
hu's avatar
hu committed
481
    K_Line_Set.K_Line_LID41 = 0x13u; /* 50 变速器种类&控制                                /*初值50*/
hu's avatar
hu committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
    K_Line_Set.K_Line_LID42 = 0x00u; /* 00 驻车管道                                       /*初值 0*/
    K_Line_Set.K_Line_LID43 = 0x82u; /* 82 车型                                           /*初值44*/
    K_Line_Set.K_Line_LID44 = 0xFFu; /* FF 速度警报                                       /*初值FF*/
    K_Line_Set.K_Line_LID45 = 0xFFu; /* FF 发动机转速                                     /*初值FF*/
    K_Line_Set.K_Line_LID46 = 0xFFu; /* FF 急加速                                         /*初值FF*/
    K_Line_Set.K_Line_LID47 = 0xFFu; /* FF 急减速                                         /*初值FF*/
    K_Line_Set.K_Line_LID48 = 0xFFu; /* FF 长时间怠速                                     /*初值FF*/
    K_Line_Set.K_Line_LID49 = 0xFFu; /* FF 辅助驻车                                       /*初值FF*/
    K_Line_Set.K_Line_LID4A = 0x32u; /* 32 变速箱油              5000 */
    K_Line_Set.K_Line_LID4B = 0x32u; /* 32 差速器油              5000 */
    K_Line_Set.K_Line_LID4C = 0x32u; /* 32 离合器油                     */
    K_Line_Set.K_Line_LID4D = 0x64u; /* 64 动力转向油             10000 */
    K_Line_Set.K_Line_LID4E = 0x78u; /* 78 轮胎                  12000 */
    K_Line_Set.K_Line_LID4F = 0x32u; /* 32 机油&滤清器            5000 */
    K_Line_Set.K_Line_LID50 = 0x00u; /* -- 预留 */
    K_Line_Set.K_Line_LID51 = 0x01u; /* 01 工作模式 */
    K_Line_Set.K_Line_LID52 = 0x00u; /* 00 电子部件设定 */
}