Data_Fuel_User.c 8.16 KB
Newer Older
1
#include <stddef.h>
hu's avatar
hu committed
2 3 4 5 6 7
#include "Data_Fuel_User.h"
#include "FuelConfig.h"
#include "Common_Interface.h"
#include "RTE_ADC.h"
#include "GPIO.h"
#include "Services_ODO_User.h"
8
#include "TYW_stdint.h"
hu's avatar
hu committed
9

hu's avatar
hu committed
10 11
static uint16_t Fuel_CurSeg;
static uint16_t Fuel_CyrStep;
hu's avatar
hu committed
12

13 14 15 16 17 18 19 20

#pragma ghs section bss=".myNonInitArea"
uint8_t FuelSaveData[1024]          ;// =  {0};
uint16_t FuelSaveLen                ;// = 0;
uint8_t DrivingRangeSaveData[1024]  ;// =  {0};
uint16_t DrivingRangeSaveLen        ;// = 0;
#pragma ghs section bss=default

hu's avatar
hu committed
21 22
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_User_KL30_Init
hu's avatar
hu committed
23
 * Description    :
hu's avatar
hu committed
24 25 26 27 28 29 30
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
void Fuel_User_KL30_Init(void)
{
hu's avatar
hu committed
31 32
    Fuel_CurSeg = 0u;
    Fuel_CyrStep = 0u;
hu's avatar
hu committed
33 34
    FuelStruct FuelInitPara;
    AFC_INIT AFCInit;
35

hu's avatar
hu committed
36 37 38 39
    uint32_t ODO_Value = 0u;

    ODO_Value = Data_ODO_Read();

hu's avatar
hu committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    FuelInitPara.FuelShortCircuitR = FUEL_R_MIN_VAL;
    FuelInitPara.FuelOpenCircuitR = FUEL_R_MAX_VAL;

    FuelInitPara.DisplayZoneBoundary[0] = DISPLAY_BOUNDARY_ES;  // 1500
    FuelInitPara.DisplayZoneBoundary[1] = DISPLAY_BOUNDARY_1;   // 1500
    FuelInitPara.DisplayZoneBoundary[2] = DISPLAY_BOUNDARY_2;   // 1373
    FuelInitPara.DisplayZoneBoundary[3] = DISPLAY_BOUNDARY_3;   // 1191
    FuelInitPara.DisplayZoneBoundary[4] = DISPLAY_BOUNDARY_4;   // 1009
    FuelInitPara.DisplayZoneBoundary[5] = DISPLAY_BOUNDARY_5;   // 848
    FuelInitPara.DisplayZoneBoundary[6] = DISPLAY_BOUNDARY_6;   // 697
    FuelInitPara.DisplayZoneBoundary[7] = DISPLAY_BOUNDARY_7;   // 545
    FuelInitPara.DisplayZoneBoundary[8] = DISPLAY_BOUNDARY_8;   // 436
    FuelInitPara.DisplayZoneBoundary[9] = DISPLAY_BOUNDARY_9;   // 345
    FuelInitPara.DisplayZoneBoundary[10] = DISPLAY_BOUNDARY_10; // 254
    FuelInitPara.DisplayZoneBoundary[11] = DISPLAY_BOUNDARY_11; // 188
    FuelInitPara.DisplayZoneBoundary[12] = DISPLAY_BOUNDARY_12; // 132
    FuelInitPara.DisplayZoneBoundary[13] = DISPLAY_BOUNDARY_13; //  40
    FuelInitPara.DisplayZoneBoundary[14] = DISPLAY_BOUNDARY_FS; //  30

    AFCInit.CalcAFCMaxNum = 100;      /*50公里或者100公里已更新*/
    AFCInit.AFCMin = 30;              /*油耗最小值十倍*/
    AFCInit.AFCMax = 300;             /*油耗最大值*/
    AFCInit.AFCPreinstall = 80;       /*油耗初始值*/
    AFCInit.CurODO = ODO_Value * 100; /*总共里数100倍*/
    AFCInit.MaxDRMileage = 69900;     /*续航里程最大值*/
hu's avatar
hu committed
65

66 67
    SetFuelSaveData(FuelSaveData, FuelSaveLen);/*新增 ----20220503----*/

hu's avatar
hu committed
68 69 70
    InitFuelParamter(&FuelInitPara);
    InitAFC(&AFCInit);

hu's avatar
hu committed
71
    /*----燃油上涨为下降的0.6----*/
hu's avatar
hu committed
72 73 74 75 76 77 78
    SetIgnOffRefuelThreshold(6);

    SetPowerDnStep(0);

    SetFuelSensorRecoverGroupCnt(10);
    SetFuelSensorOpenCircuitGroupCnt(120);
    SetFuelSensorShortCircuitGroupCnt(120);
79 80

    SetDrivingRangeSaveData(DrivingRangeSaveData, DrivingRangeSaveLen);
hu's avatar
hu committed
81 82 83 84 85 86 87 88 89 90
}
void Fuel_User_KL15_ON_Init(void)
{
}

void Fuel_User_KL15_OFF_Init(void)
{
}
void Fuel_User_Wakeup_Init(void)
{
91 92 93
    /*每次唤醒都要调用 ----20220503----*/
    SetFuelSaveData(FuelSaveData, FuelSaveLen);
    SetDrivingRangeSaveData(DrivingRangeSaveData, DrivingRangeSaveLen);
hu's avatar
hu committed
94
}
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

void *memcpy_new(void *to, void *from, size_t size)
{
    char *tempFrom = NULL;
    char *tempTo   = NULL;
    //assert( to && from );
    /*先转型为字符指针,字符为一个字节*/
    tempFrom = (char*)from;
    tempTo   = (char*)to;
    while (size-- > 0)
    {
        *tempTo++ = *tempFrom++;
    }
    return to;
}

hu's avatar
hu committed
111 112
void Fuel_User_Sleep_Init(void)
{
113 114 115 116 117 118 119 120 121 122 123 124 125
    uint8_t *p;
    p = GetFuelSaveData(&FuelSaveLen);

    if (FuelSaveLen < 1024)
    {
        memcpy_new(FuelSaveData, p, FuelSaveLen);
    }
    p = GetDrivingRangeSaveData(&DrivingRangeSaveLen);

    if (DrivingRangeSaveLen < 1024)
    {
        memcpy_new(DrivingRangeSaveData, p, DrivingRangeSaveLen);
    }
hu's avatar
hu committed
126 127 128
}
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_User_KL15_ON_Processing_Service
hu's avatar
hu committed
129
 * Description    :
hu's avatar
hu committed
130 131 132 133 134 135 136
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 10Ms调用
 --------------------------------------------------------------------------*/
void Fuel_User_KL15_ON_Processing_Service(void)
{
hu's avatar
hu committed
137 138 139 140 141 142 143 144 145 146
    AFC_PARA AFCPara;
    uint8_t FuelR_Valid = 0u;
    uint8_t Vspeed_Valid = 0u;
    uint8_t Espeed_Valid = 0u;
    uint8_t FuelMode = 0u;
    uint8_t Step = 0u;
    uint16_t FuelR = 0u;
    uint16_t Vspeed = 0u;
    uint16_t Espeed = 0u;
    uint16_t FuelResistanceV = 0u;
hu's avatar
hu committed
147
    uint32_t ODO_Value = 0u;
hu's avatar
hu committed
148

hu's avatar
hu committed
149 150 151 152
    FuelR_Valid = RTE_Read_FUEL_R_Valid();
    Vspeed_Valid = Common_Get_Act_V_Speed_Valid();
    Espeed_Valid = Common_Get_Act_E_Speed_Valid();

hu's avatar
hu committed
153
    if ((Common_Get_IG_Sts() == COMMON_POWER_ON) && (Common_Get_IG_Sts_Valid() == COMMON_Valid))
hu's avatar
hu committed
154
    {
hu's avatar
hu committed
155
        if (FuelR_Valid)
hu's avatar
hu committed
156
        {
hu's avatar
hu committed
157 158 159 160 161 162
            FuelR = RTE_Read_FUEL_R();
        }
        else
        {
            FuelR = 0;
        }
hu's avatar
hu committed
163

hu's avatar
hu committed
164 165 166 167 168 169 170 171
        if (Vspeed_Valid)
        {
            Vspeed = Common_Get_Act_V_Speed();
        }
        else
        {
            Vspeed = 0;
        }
hu's avatar
hu committed
172

hu's avatar
hu committed
173 174 175 176 177 178 179 180
        if (Espeed_Valid)
        {
            Espeed = Common_Get_Act_E_Speed();
        }
        else
        {
            Espeed = 0;
        }
hu's avatar
hu committed
181

hu's avatar
hu committed
182 183
        SetPowerSt(1);
        AFCTimerCall();
hu's avatar
hu committed
184

hu's avatar
hu committed
185
        ODO_Value = Data_ODO_Read();
hu's avatar
hu committed
186

hu's avatar
hu committed
187 188 189 190
        AFCPara.CurODO = ODO_Value * 100u;
        AFCPara.FuleConsume = 0u;
        AFCPara.RPM = Espeed;
        AFCPara.Speed = (Vspeed / 10u);
hu's avatar
hu committed
191

hu's avatar
hu committed
192 193
        SetAFCPara((AFC_PARA *)&AFCPara);
        FuelFSM(FuelR); /*新版增加系数*/
hu's avatar
hu committed
194

hu's avatar
hu committed
195 196
        FuelResistanceV = GetFuelResistance(); /*燃油电阻获取*/

hu's avatar
hu committed
197
        FuelMode = GetFuelSensorState(); /*燃油状态获取*/
hu's avatar
hu committed
198

hu's avatar
hu committed
199 200
        if (FuelMode == FuelSensorNormal)
        {
hu's avatar
hu committed
201
            Fuel_CurSeg = (uint16_t)GetFuelSeg();   /*段*/
hu's avatar
hu committed
202 203 204 205 206 207 208
            Fuel_CyrStep = (uint16_t)GetFuelStep(); /*步*/
        }
        else
        {
            Fuel_CurSeg = 0u;
            Fuel_CyrStep = 0u;
        }
hu's avatar
hu committed
209
    }
hu's avatar
hu committed
210 211 212
}
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_User_KL15_OFF_Processing_Service
hu's avatar
hu committed
213
 * Description    :
hu's avatar
hu committed
214 215 216 217 218 219 220
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 嵌入到100Ms中断中
 --------------------------------------------------------------------------*/
void Fuel_User_KL15_OFF_Processing_Service(void)
{
hu's avatar
hu committed
221
    uint8_t i;
hu's avatar
hu committed
222 223
    uint8_t FuelR_Valid = 0;
    uint16_t FuelR = 0;
hu's avatar
hu committed
224 225 226 227 228

    FuelR_Valid = RTE_Read_FUEL_R_Valid();
    FuelR = RTE_Read_FUEL_R();

    if (Common_Get_IG_Sts_Valid() == COMMON_Valid)
hu's avatar
hu committed
229
    {
hu's avatar
hu committed
230
        if (Common_Get_IG_Sts() == COMMON_POWER_OFF)
hu's avatar
hu committed
231
        {
hu's avatar
hu committed
232 233 234 235 236 237 238 239
            SetPowerSt(0);
            for (i = 0; i < 10; i++)
            {
                AFCTimerCall();
            }
            FuelFSM(FuelR);
        }
    }
hu's avatar
hu committed
240
}
hu's avatar
hu committed
241

hu's avatar
hu committed
242 243 244 245 246 247
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_Get_CurSeg
 * Description    : 燃油当前格
 * Input          : None
 * Output         : None
 * Return         : None
hu's avatar
hu committed
248
 * onther         :
hu's avatar
hu committed
249 250 251
 --------------------------------------------------------------------------*/
uint8_t Fuel_Get_CurSeg(void)
{
hu's avatar
hu committed
252
    return Fuel_CurSeg;
hu's avatar
hu committed
253
}
hu's avatar
hu committed
254

hu's avatar
hu committed
255
/*返回燃油库电阻值*/
hu's avatar
hu committed
256 257
uint16_t Fuel_Get_Res(void)
{
hu's avatar
hu committed
258
    return GetFuelResistance();
hu's avatar
hu committed
259
}
hu's avatar
hu committed
260

hu's avatar
hu committed
261 262
uint16_t Fuel_Get_Step(void)
{
hu's avatar
hu committed
263 264 265 266
    uint16_t FuelStep = 0u;

    FuelStep = GetFuelStep();

hu's avatar
hu committed
267
    return FuelStep;
hu's avatar
hu committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
}

uint8_t Fuel_Get_Popup_Sta(void)
{
    uint8_t variable_1 = 0x00u;
    uint8_t variable_2 = 0x00u;
    uint16_t variable_5 = 0x00u;

    uint8_t Popup_Sta = 0u;

    variable_1 = Fuel_Get_CurSeg();/*格*/
    variable_2 = GetFuelSensorState();/*燃油状态*/
    variable_5 = GetFuelResistance(); /*采集的阻值*/

    if ((variable_1 <= 1 ) && (variable_2 == FuelSensorNormal) && (variable_5 != 65535))
    {
        Popup_Sta = 1u;
    }
    else
    {
        Popup_Sta = 0u;
    }
290 291

    return Popup_Sta;
hu's avatar
hu committed
292
}