RTI.c 8.89 KB
Newer Older
崔立宝's avatar
崔立宝 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 169 170 171 172 173 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538





#include "RTI.h"

/*
uint16_t  RTI25msCounter;
uint16_t  RTI15s;
extern  uint8_t CLEAR_ODO;
extern  uint8_t time_start;

uint8_t  RTI100msCounter;
uint8_t  RTI1sFlag;
uint8_t  flag;
extern uint8_t flag_RADO;
extern uint8_t INIT_cnt;
extern uint8_t InsFuel_clear;
extern  volatile    FuelEco   g_fuelEco;
extern uint8_t  Time_Street_EN;
extern uint8_t  Time_Street_CLOSE;
extern uint8_t  Time_Street_2MIN;
extern uint8_t  Time_Thruway_EN;
extern uint8_t  Time_Thruway_CLOSE;
extern uint8_t  Time_Thruway_2MIN;
uint32_t Relax_cnt;
uint32_t Relax_cnt1;
uint16_t Relax_cnt_street;
uint16_t Relax_cnt_Thruway;
extern  volatile    FuelEco   g_fuelEco1;

uint16_t cntInsFuel;
uint16_t RTIIGNONTimer;
uint16_t RTIIGNOFFTimer;

uint32_t RTITravelTimer;
uint8_t  RTITravelTimerEnable;

uint8_t  RTCSecond;
uint8_t  RTCMinute;
uint8_t  RTCHour;
uint8_t  RTCDate;
uint8_t  RTCMonth;
uint16_t RTCYear;
uint8_t  RTCLeapYear;
uint8_t clear_avaflag2;

volatile uint16_t CallSecond;
volatile uint16_t CallMinute;

uint8_t TickTimer2msFlag1;
uint8_t	TickCnt2ms1;

uint8_t  RTICNT;

extern uint16_t             STOP_2H_FLAG;            //停车2H标志位

uint16_t RTI_Get_IGN_ON_Timer(void)
{
  return RTIIGNONTimer;
}

uint16_t RTI_Get_IGN_OFF_Timer(void)
{
  return RTIIGNOFFTimer;
}

void RTI_Reset_IGN_ON_Timer(void)
{
  RTIIGNONTimer = 0;
}

void RTI_Reset_IGN_OFF_Timer(void)
{
  RTIIGNOFFTimer = 0;
}

void RTI_Reset_Travel_Timer(void)
{
  RTITravelTimer = 0;
}

uint32_t RTI_Get_Travel_Timer(void)
{
  return RTITravelTimer;
}

void RTI_Travel_Timer_Control(uint8_t Status)
{
  RTITravelTimerEnable = Status;
}


uint8_t Get_Tick_Timer_2ms_Flag1(void)
{
  if (TickTimer2msFlag1)
  {
    TickTimer2msFlag1 = 0;
    return 1;
  }
  else
    return 0;
}


void RTI_IGN_ON_Timing_Service(void)
{
  if (RTI1sFlag)
  {
    RTI1sFlag = 0;
    //IGN开启时间
    if (RTIIGNONTimer < 65535) {
      RTIIGNONTimer++;
    }



    //行驶时间
    if (RTITravelTimerEnable)
    {
      RTITravelTimer++;


      if (RTITravelTimer > 359999)       //99时59分59秒
        RTITravelTimer = 0;
      }
  }
}

void RTI_IGN_OFF_Timing_Service(void)
{
  if (RTI1sFlag)
  {
    RTI1sFlag = 0;

    if(STOP_2H_FLAG<7200)
      {
        STOP_2H_FLAG++;
      }
     else
      {
      STOP_2H_FLAG=8000;
      clear_avaflag2=1;
      }

    if (RTIIGNOFFTimer < 65535)
      RTIIGNOFFTimer++;
  }
}

void Set_RTC_Second(uint8_t Second)
{
  RTCSecond = Second;
}

void Set_RTC_Minute(uint8_t Minute)
{
  RTCMinute = Minute;
}

void Set_RTC_Hour(uint8_t Hour)
{
  RTCHour   = Hour;
}

void Set_RTC_Date(uint8_t Date)
{
  RTCDate  = Date;
}

void Set_RTC_Month(uint8_t Month)
{
  RTCMonth = Month;
}

void Set_RTC_Year(uint16_t Year)
{
  RTCYear  = Year;
  RTCLeapYear = Determine_Leap_Year(Year);
}

uint8_t Read_RTC_Second(void)
{
  return RTCSecond;
}

uint8_t Read_RTC_Minute(void)
{
  return RTCMinute;
}

uint8_t Read_RTC_Hour(void)
{
  return RTCHour;
}

uint8_t Read_RTC_Date(void)
{
  return RTCDate;
}

uint8_t Read_RTC_Month(void)
{
  return RTCMonth;
}

uint16_t Read_RTC_Year(void)
{
  return RTCYear;
}

void Power_ON_RTI_Init(void)
{
  PLLCTL_PRE = 1;             //1 RTI continues running during Pseudo Stop Mode.
  PLLCTL_PCE = 1;             //1 COP continues running during Pseudo Stop Mode

  //Real Time 时钟频率设置
  RTICTL = 0x97;      //E1              //Real Time=8M/200000=40HZ  (25MS)           现在改为8M/16000=500HZ   2MS   差了12.5倍
  CRGINT_RTIE = 1;	          //开Real Time 中断

  RTI25msCounter = 0;
  RTI1sFlag      = 0;

  Set_RTC_Second(0);
  Set_RTC_Minute(0);
  Set_RTC_Hour(0);
  Set_RTC_Date(30);
  Set_RTC_Month(9);
  Set_RTC_Year(2016);
}

uint8_t Determine_Leap_Year(uint16_t Year)
{
  uint8_t LeapYear;

  LeapYear = 0;
  if (Year % 4 == 0)
  {
    if (Year % 100 != 0)
      LeapYear = 1;
    else if (Year % 400 == 0)
      LeapYear = 1;
  }

  return LeapYear;
}
*/
#pragma CODE_SEG __NEAR_SEG NON_BANKED   	//置所有中断函数放在FLASH的非分页区

//==================================================
//RTC中断   (周期为25MS)           2015-12-30       500hz  2ms
//==================================================
//void interrupt VectorNumber_Vrti RTC_ISR(void)
void interrupt  RTI_ISR ( void )
{
  /*uint8_t MonthUpdate;
  uint8_t NM_count;
  uint8_t fuelcnt;
  uint8_t contt;

  CRGFLG_RTIF = 1;      //通过写1清0中断标


  TickCnt2ms1++;
  if (TickCnt2ms1 >= 1)
  {
    TickCnt2ms1 = 0;
    TickTimer2msFlag1 = 1;
   }

   if(TaskLock==1)
      	{
       OsekNM_Manage_Main();
      	}

  if(NM_Time.TmaxEnable)
    {
        if(NM_Time.TmaxTime < NM_Time.OverTmaxTime)
        {
            NM_Time.TmaxTime += 2;
        }
     }

    if(NM_Time.TtypEnable)
    {
        if(NM_Time.TtypTime < NM_Time.OverTtypTime)
        {
            NM_Time.TtypTime += 2;
        }
    }
    if(NM_Time.TwbsEnable)
    {
        if(NM_Time.TwbsTime < NM_Time.OverTwbsTime)
        {
            NM_Time.TwbsTime += 2;
        }
    }
    if(NM_Time.SleepEnable)
    {
        if(NM_Time.SleepTime < NM_Time.OverSleepTime)
        {
            NM_Time.SleepTime += 2;
        }
    }

     NM_tSleepRequest_Fun();




    INIT_cnt++;   //25ms加一
    if(INIT_cnt>=1000)   //确定没有雷达数据后2s关闭显示
      {
        flag_RADO=0;   //关闭显示
         INIT_cnt=1200;
      }

   cntInsFuel++;
   if(cntInsFuel>=2500)
    {
      InsFuel_clear =1;
      cntInsFuel=0;
    }*/
  /*
  NM_count++;
  if(NM_count>=40)
  {
    NM_count=0;

  } */
  /*
  if(time_start==1)
  	{
  		  RTI15s++;
  		  if(RTI15s>=7500)
  		  	{
  		  	RTI15s=0;
  		  	CLEAR_ODO=1;
  		  	}

  	}
  	else
  		{
  		   CLEAR_ODO=0;

  		}

  fuelcnt++;
  if(fuelcnt>=50)
  {
    g_fuelEco.FuelEcoTime++;
    g_fuelEco.InstCalTime++;
    g_fuelEco.InstUpTime++;
    if(g_fuelEco.AveTime < 200)
          {
                g_fuelEco.AveTime++;
          }
    g_fuelEco1.FuelEcoTime++;
    g_fuelEco1.InstCalTime++;
    g_fuelEco1.InstUpTime++;
    if(g_fuelEco1.AveTime < 200)
          {
                g_fuelEco1.AveTime++;
          }


    fuelcnt=0;
  }


  RTI25msCounter++;





  if (RTI25msCounter >= 500)
  {
    RTI25msCounter -= 500;
    RTI1sFlag = 1;

   if(Time_Street_EN)
      {
       Relax_cnt++;  //原来一次加25ms  现在一次加2ms
      }
     else
      {
       Relax_cnt=0;
      }

    if(Time_Thruway_EN)
      {
       Relax_cnt1++;
      }
   else
      {
      Relax_cnt1=0;
      }


    if(Time_Thruway_CLOSE)
      {
       Relax_cnt_Thruway++;
       if(Relax_cnt_Thruway>=120)
        {
          Relax_cnt_Thruway=0;
          Time_Thruway_2MIN=1;
        }
      }
     else
      {
        Relax_cnt_Thruway=0;
        Time_Thruway_2MIN=0;
      }

    if(Time_Street_CLOSE)
      {
        Relax_cnt_street++;
        if(Relax_cnt_street>=120)
          {
            Relax_cnt_street=0;
          Time_Street_2MIN=1;
          }

      }
     else
      {
         Relax_cnt_street=0;
         Time_Street_2MIN=0;
      }



    if(TEL_STATUS_HUM==2)
    {

        CallSecond++;
        if(CallSecond>=60)
          {
          CallSecond=0;
          CallMinute++;
          }

    } else if((TEL_STATUS_HUM==1)||(TEL_STATUS_HUM==0))
    {
    CallSecond=0;
    CallMinute=0;
    }



    RTCSecond++;
    if (RTCSecond > 59)
    {
      RTCSecond = 0;

      RTCMinute++;
      if(RTCMinute > 59)
      {
        RTCMinute = 0;

        RTCHour++;
        if (RTCHour > 23)
        {
          RTCHour = 0;

          RTCDate++;
          MonthUpdate = 0;
          switch (RTCMonth)
          {
            case 1  :
            case 3  :
            case 5  :
            case 7  :
            case 8  :
            case 10 :
            case 12 : if (RTCDate > 31)
                      {
                        RTCDate = 1;

                        RTCMonth++;
                        MonthUpdate = 1;
                      }
                      break;

            case 4  :
            case 6  :
            case 9  :
            case 11 : if (RTCDate > 30)
                      {
                        RTCDate = 1;

                        RTCMonth++;
                        MonthUpdate = 1;
                      }
                      break;

            case 2  : if (RTCLeapYear)
                      {
                        if (RTCDate > 29)
                        {
                          RTCDate = 1;

                          RTCMonth++;
                          MonthUpdate = 1;
                        }
                      }
                      else
                      {
                        if (RTCDate > 28)
                        {
                          RTCDate = 1;

                          RTCMonth++;
                          MonthUpdate = 1;
                        }
                      }
                      break;
          }

          if (MonthUpdate)
          {
            if (RTCMonth > 12)
            {
              RTCYear++;
              RTCLeapYear = Determine_Leap_Year(RTCYear);
            }
          }
        }
      }
    }
  }
  */
}

#pragma CODE_SEG DEFAULT
#pragma MESSAGE DISABLE C1825