init.c 4.35 KB
Newer Older
hu's avatar
hu 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
/**************************************************************************//**
  * \file     Init.c
  * \brief    Initializations during work state switching
  * \details
  * \author   Zhang Xuan
  * \version  V1.0.0
  * \date     18-Jan-2019
  * \par      History:
  *           V1.0.0 Initial release
  * \par      Copyright:
  *           (c) Heilongjiang TYW Electronics co., LTD
******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "debugger.h"
#include "r_typedefs.h"
#include "Init.h"
#include "r_dev_clk_types.h"
#include "r_ddb_api.h"

#include "Analog_Signals.h"
#include "Clock.h"
#include "Emulated_EEPROM.h"
#include "GPIO.h"
#include "Internal_Flash.h"
#include "RTC.h"
#include "BU98R10.h"
#include "Watchdog.h"


#include "r_dev_api.h"
#include "r_wm_api.h"
#include "r_tick_api.h"


#include "rh850_macros.h"
#include "cpu.h"
#include "Graphic.h"
#include "Sys_Tick.h"
#include "RSCAN.h"
#include "SDRAM.h"
#include "sflash.h"

#include "sys_scheduler.h"

#include "RTE_ADC.h"
#include "COM_CAN.h"
#include "UDS_Common.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**************************************************************************//**
  * \brief      Initializations during work state switching
  * \attention
  * \retval     None
******************************************************************************/
void Sys_Startup_Pre_Init(void)
{
    /* Release all Modules (except SDRAM controller) */
    Sys_Peripheral_Reset(SYS_PERI_RESETTABLE & (~SYS_PERI_SDRB0));

    /* Prepare device (clear all internal config, prepare interrupts) */
    R_DEV_Prepare();
    Clock_Pre_Init();
    RTC_Pre_Init();
    GPIO_Init(0);



    Mem_SDRAM_Init(MEM_SDRAM_2x_W9812G6KH_120MHz, Mem_SDRAM_DRV_25Ohm);
    //Mem_SDRAM_Init(MEM_SDRAM_2x_IS45S16800F_120MHz, Mem_SDRAM_DRV_25Ohm);

    Sys_Enable_Preload_Buffer();
}

/**************************************************************************//**
  * \brief      Initializations during system power up
  * \attention
  * \retval     None
******************************************************************************/
85 86 87 88 89
uint8_t u8ResetFlag = 0;

extern uint32_t u32ResetFlag;
extern uint32_t TestBackupRam;

hu's avatar
hu committed
90 91 92 93 94 95 96 97 98 99 100
void Sys_Startup_Init(void)
{
    Clock_Init();
    /* Enable interrupts globally */
    enable_interrupt();

    WDT_Init();

    /* init graphic tick driver */
    R_TICK_Init(0);

hu's avatar
hu committed
101
    Gfx_Init(GFX_VO_SINGLE_RGB888 | GFX_VI_ITU656);
hu's avatar
hu committed
102 103 104

    CPU_Init();

105
    //RTC_Init();
hu's avatar
hu committed
106
    Sys_Tick_Timer_Start();
hu's avatar
hu committed
107
    /*COM_CAN_Init(); Ô­CAN³õʼ»¯Î»ÖÃ*/
hu's avatar
hu committed
108 109 110


    RTE_ADC_Init();
hu's avatar
hu committed
111

hu's avatar
hu committed
112 113 114 115 116

    Int_Flash_Init();
    EEPROM_Init();

    BU98R10_Init();
hu's avatar
hu committed
117 118

    /*EOL诊断 配置数据读取 DFLASH*/
hu's avatar
hu committed
119 120
    ReadAllDFlashData();

hu's avatar
hu committed
121 122 123
    /*读取K-LINE*/
    ReadDTCEOLValue_Meter_K_LINE();

hu's avatar
hu committed
124
    d_printf("Init complete!\n");
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
	InitSeriFlashExternReadMode();
    //APP_Startup_Init(Clock_Get_Startup_Mode());
    u8ResetFlag = Clock_Get_Startup_Mode();
	if (u32ResetFlag != 0xA55AA55AUL)
	{
		u8ResetFlag = 0;
	}
	else
	{
		if ((u8ResetFlag == 0) && (TestBackupRam == 0xaabbccddu))
		{
			u8ResetFlag = 1;
			Rtc_Restore_Time();
		}
	}
	
	/*30电初始化*/
	APP_Startup_Init(u8ResetFlag);
	TestBackupRam = 0x11223344UL;
hu's avatar
hu committed
144

hu's avatar
hu committed
145
    /*外发要用到EEP数据,位置移动*/
hu's avatar
hu committed
146
    COM_CAN_Init();
hu's avatar
hu committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    Gfx_Sys_Start();
}

/**************************************************************************//**
  * \brief      Initializations during work state switch to system sleep
  * \attention
  * \retval     None
******************************************************************************/
void Sys_Sleep_Init(void)
{
    Sys_Tick_Timer_Stop();
}

/**************************************************************************//**
  * \brief      Initializations during work state switch to system run
  * \attention
  * \retval     None
******************************************************************************/
void Sys_Wakeup_Init(void)
{

}