📄 init.c
字号:
// Power on CLKSQ
*PDN_CLR0 = 0x0800;
#endif
// 3. Boost MCU and DSP PLL (MDPLL) to 104MHz (MUST)
*MPLL = 0x0087;
*MPLL = 0x0007;
// 4. Power ou MPLL
*PDN_CLR0 = 0x4000;
// 5. delay until PLL is stable, at least 50us
for (i=0;i<0x100;i++);
// 6. Define ARM(CPU, Data cache, TCM) and MCU PLL
#ifdef MCU_104M
// MCU and BUS clock 2:1
*MCUCLK_CON = 0x0703;
#elif defined MCU_52M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0303;
#elif defined MCU_26M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0101;
#elif defined MCU_13M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0000;
#endif
// 7. Enable MPLL output
*CLK_CON |= 0x0002;
}
#endif /* MT6228 || MT6229 || MT6230 */
#if defined(MT6223) || defined(MT6223P)
{
kal_uint16 i;
#ifdef EXT_26M
// 1. Power on DSP_DIV2, MCU_DIV2, PLL and CLKSQ
*PDN_CLR0 = 0xb800;
// 2. Enable MCU clock divider
*CLK_CON = 0x0002;
#elif defined (EXT_13M)
// Power on PLL and CLKSQ
*PDN_CLR0 = 0x2800;
#endif
// 3. Select PLL input from CLKSQ, set div_ctrl to 6 such that PLL gives 104MHz clock
*PLL = 0xc008;
// 4. Reset PLL
*PLL = 0Xc088;
// 5. Select CLKSQ_DIV2_MCU to provide 13MHz
*CLK_CON = 0x2;
// 6. Define ARM(CPU, Data cache, TCM) and MCU PLL
#ifdef MCU_52M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0303;
#elif defined MCU_26M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0101;
#elif defined MCU_13M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0000;
#endif
// 7. MPLL/2 nad DPLL/2 enable
*CLK_CON = 0x3;
// 8. delay until PLL is stable, at least 50us
for (i=0;i<0x200;i++);
// 9. DPLLSEL = 1'b1, MPLLSEL=2'b10
*PLL = 0xc030; //
}
#endif /* MT6223 || MT6223P*/
#ifdef MT6225
{
kal_uint16 i;
#ifdef EXT_26M
// 1. Power on DSP_DIV2, MCU_DIV2, and CLKSQ
*PDN_CLR0 = 0x9800;
// 2. Enable MCU clock divider
*CLK_CON = 0x0002;
#elif defined (EXT_13M)
// Power on CLKSQ
*PDN_CLR0 = 0x0800;
#endif
// 3. Boost MCU and DSP PLL (MDPLL) to 104MHz (MUST)
*PLL = 0x0080;
*PLL = 0x0000;
// 4. Power ou MPLL
*PDN_CLR0 = 0x2000;
// 5. delay until PLL is stable, at least 50us
for (i=0;i<0x100;i++);
// 6. Define ARM(CPU, Data cache, TCM) and MCU PLL
#ifdef MCU_104M
// MCU and BUS clock 2:1
*MCUCLK_CON = 0x0703;
#elif defined MCU_52M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0303;
#elif defined MCU_26M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0101;
#elif defined MCU_13M
// MCU and BUS clock 1:1
*MCUCLK_CON = 0x0000;
#endif
// 7. Enable MPLL output
*PLL |= 0x0010;
}
#endif /* MT6225 */
}
/*__FUE__ compile option is used for FOTA firmware update engine */
/*add this compile option to avoid compiling other function*/
#ifndef __FUE__
/*************************************************************************
* FUNCTION
* Application_Initialize
*
* DESCRIPTION
* This function implements project protocol stack, hardware depedent
* initialization
*
* CALLS
* Initialize()
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
#if defined(KAL_ON_NUCLEUS)
void Application_Initialize (void *first_available_memory)
#elif defined(KAL_ON_THREADX)
void tx_application_define(void *first_unused_memory)
#endif
{
/* setlocale(LC_CTYPE,"C"); */
__rt_lib_init(0, 0); /* passing 0 since we don't use the heap */
//at this time,the global varibles can be used ,so move the flash id from dma register to global varibles
gManufacture_code=*(volatile kal_uint16*)MANUFACTURE_ID_ADDR;
gDev_code=*(volatile kal_uint16*)DEV_ID_ADDR;;
gExt_dev_code1=*(volatile kal_uint16*)EXT_DEV1_ID_ADDR;
gExt_dev_code2=*(volatile kal_uint16*)EXT_DEV2_ID_ADDR;
emi_dbg=*(volatile kal_uint8*)EMI_LOCATION_ADDR;//
/* Multi-Boot */
*(volatile kal_uint16*)0x80000310=1;//power off dma
#ifdef __MULTI_BOOT__
_boot_mode = *(volatile kal_uint16 *)BOOT_CONFIG_ADDR;
#ifndef L1_NOT_PRESENT
L1D_SetInitMode(_boot_mode);
#endif /* L1_NOT_PRESENT */
#endif /* __MULTI_BOOT__ */
systemIntialization();
#ifdef MTK_PCM
nvrm_init();
#endif
HWDInitialization();
/*here are some code to print the flash driver adaptation information for debug,if verified,it can be delete*/
dbg_print("imanufacture_code=%x,dev_code=%x,ext_dev_code1=%x,ext_dev_code=%x\n\r.",gManufacture_code,gDev_code,gExt_dev_code1,gExt_dev_code2);
dbg_print("ext_sram_size=%x,fat_base=%x,fat_size=%x.\n\r",EMI_EXTSRAM_SIZE,gfat_base_addr,gFatsize);
dbg_print("location of flash in setemi=%d,location of flash initialize_fdd_table=%d.\n\r",emi_dbg,drv_dbg);
switch(flash_driver_dbg)
{
case 0:
PutUARTBytes(0,"common amd without pbp(samsung/toshiba).",30);
break;
case 1:
PutUARTBytes(0,"spansion_pln and wsn with 32 pbp.",30);
break;
case 2:
PutUARTBytes(0,"common amd with pbp(amd/toshiba...)",30);
break;
case 3:
PutUARTBytes(0,"toshiba_tv with pbp",30);
break;
case 4:
PutUARTBytes(0,"toshiba_tv without pbp",30);
break;
case 5:
PutUARTBytes(0,"toshiba_ty with pbp",30);
break;
case 6:
PutUARTBytes(0,"toshiba_ty without pbp",30);
break;
default:
ASSERT(0);
}
//END print debug information
#ifdef _NAND_FLASH_BOOTING_
NFB_InitThirdROM();
NFB_LoadingSecondaryMAUI();
#endif /* _NAND_FLASH_BOOTING_ */
Drv_Init_Phase2();
/* Resource initialization */
systemInitializeResource();
/* check ranges of all message ID */
stack_check_msgid_range();
/* MAUI protocol stack entry routine */
mainp();
#ifdef _MAUI_SOFTWARE_LA_
/* under construction !*/
#endif /* _MAUI_SOFTWARE_LA_ */
#ifdef __PRODUCTION_RELEASE__
#ifdef __MULTI_BOOT__
if ( system_boot_mode!=FACTORY_BOOT )
#endif
WDT_Enable(KAL_FALSE);
#endif /* __PRODUCTION_RELEASE__ */
}
/*************************************************************************
* FUNCTION
* systemIntialization
*
* DESCRIPTION
* This function implements the system specific initialization, including
* interrupt central controller, FDD and KAL.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
static void systemIntialization(void)
{
kal_bool ret_val = KAL_FALSE;
initINTR(); /* initialize the interrupt controller */
IRQ_LISR_Init();
#ifndef _NAND_FLASH_BOOTING_
Initialize_FDD_tables();
#endif /* _NAND_FLASH_BOOTING_ */
/* Register display handler */
kal_register_print_string_function((kal_print_string_func_ptr)stack_print);
/* Register stack fatal error handler */
kal_register_fatal_error_handler((kal_error_func_ptr)fatal_error_handler);
kal_initialize_mem();
/* Initializing the Buffer Pool Information */
stack_init_buff_pool_info();
/* Create buffer pools */
ret_val = stack_resources_init();
/* Initialize KAL resources */
kal_initialize();
}
/*************************************************************************
* FUNCTION
* HWDInitialization
*
* DESCRIPTION
* This function implements hardware dependent initialization and
* management
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
static void HWDInitialization(void)
{
#ifdef MT6208 /* only MT6208 need to do this */
/* Baseband power up control, 32khz oscillator power down mode */
{
kal_uint32 delay=1000000;
REG_WRITE(RTC_base, 0x4316);
while (delay>0) { /* delay for settling 32KHz */
delay--;
}
}
#endif /* MT6208 */
#ifdef MTK_SLEEP_ENABLE
/* Added by Anthony Chin 03/18/2002. For sleep mode management. */
L1SM_Init();
#endif /* MTK_SLEEP_ENABLE */
#ifdef __HW_DIVIDER__
/* Power on Divider.(PDN_CON2) */
*(volatile kal_uint16 *)PDN_CON2 &= 0xF7FF;
#endif /* __HW_DIVIDER__ */
#ifdef IDMA_DOWNLOAD
/* Load DSP via iDMA. */
REG_WRITE(DPRAM_CPU_base, 0);
idma_load();
#endif /* IDMA_DOWNLOAD */
Drv_Init_Phase1();
WDT_Enable(KAL_FALSE);
#ifdef __USB_ENABLE__
if ( INT_USBBoot() )
{
#ifndef __NVRAM_IN_USB_MS__
#if ( !defined(MT6208) )
*(volatile kal_uint16 *)(TDMA_base+0x14) = 0x1000;
#endif /* !MT6208 */
*(volatile kal_uint16 *)PDN_CLR2 = 0x0001;
IRQUnmask(IRQ_CTIRQ1_CODE);
*(volatile kal_uint16 *)(TDMA_base+0x150) = *(volatile kal_uint16 *)(TDMA_base+0x150) | 0x0002;
IRQ_Register_LISR(IRQ_CTIRQ1_CODE, isrCTIRQ1_USBPowerOn,"CTIRQ1");
#endif /* !__NVRAM_IN_USB_MS__ */
}
#endif /*__USB_ENABLE__*/
#ifdef L1_NOT_PRESENT
#if ( !defined(MT6208) )
*(volatile kal_uint16 *)(TDMA_base+0x14) = 0x1000;
#endif /* !MT6208 */
*(volatile kal_uint16 *)PDN_CLR2 = 0x0001;
IRQUnmask(IRQ_CTIRQ1_CODE);
*(volatile kal_uint16 *)(TDMA_base+0x150) = *(volatile kal_uint16 *)(TDMA_base+0x150) | 0x0002;
#endif /* L1_NOT_PRESENT */
}
/*************************************************************************
* FUNCTION
* systemInitializeResource
*
* DESCRIPTION
* This function aims resource initialization, including audio, image,
* font etc.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void systemInitializeResource(void)
{
#if ( (defined(__MTK_TARGET__) || defined (MTK_KAL_MNT)) && !defined(__MAUI_BASIC__) && !defined(__L1_STANDALONE__) && !defined(EMPTY_MMI))
InitializeResourceVariables();
#endif
#ifndef _NAND_FLASH_BOOTING_
#if ( defined(__USB_ENABLE__) && !defined(__MAUI_BASIC__) )
if ( ((BMT.PWRon != CHRPWRON) && (BMT.PWRon != PWRKEYPWRON) && (BMT.PWRon != USBPWRON)) ||
((BMT.PWRon == PWRKEYPWRON) && (Check_NORFlash_Formatted() == 1)) )
#elif ( defined(__MAUI_BASIC__) || defined(_SIMULATION))
if ( (BMT.PWRon != CHRPWRON) && (BMT.PWRon != USBPWRON) )
#else
if ( ((BMT.PWRon != CHRPWRON) && (BMT.PWRon != PWRKEYPWRON)) ||
((BMT.PWRon == PWRKEYPWRON) && (Check_NORFlash_Formatted() == 1)) )
#endif
DRV_POWERON();
#if !defined(__L1_STANDALONE__) && !defined(EMPTY_MMI)
#ifdef __MULTI_BOOT__
if ( (BMT.PWRon == PWRKEYPWRON) && (Check_NORFlash_Formatted()==1 || MTK_FACTORY_MODE==INT_BootMode()) )
#else
if ( (BMT.PWRon == PWRKEYPWRON) && (Check_NORFlash_Formatted() == 1) )
#endif /*__MULTI_BOOT__*/
MMICheckDiskDisplay();
#endif
#endif /* !_NAND_FLASH_BOOTING_ */
srand(rand_num_seed);
}
/*************************************************************************
* FUNCTION
* INT_SetChipReg
*
* DESCRIPTION
* This function sets registers on the chip at system initial stage.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void INT_SetChipReg()
{
#if defined(MT6218B)
if (INT_ecoVersion() <= EN)
{
/* Changing the output driving capability on both digital and analog die to solve the bug at BBRX comb filter */
*(ACIF_CON1) = 0x0600;
*(AC_ODS_CON) = 0x0004;
}
#elif defined(MT6219) /* MT6218B */
if (INT_ecoVersion() <= BV)
{
/* Changing the output driving capability on both digital and analog die to solve the bug at BBRX comb filter */
*(ACIF_CON1) = 0x0600;
*(AC_ODS_CON) = 0x0004;
}
#elif defined(MT6217) /* MT6218B */
/* change DSP ROM rm value */
*((volatile kal_uint32 *)0x80000800) = 0x1505;
*((volatile kal_uint32 *)0x80000804) = 0x1717;
*((volatile kal_uint32 *)0x80000808) = 0x1517;
#elif defined(MT6228_S00) /* MT6218B */
/*
* To fix the bug of RX/TX, apply the setting for reworked MT6228.
*/
*(volatile kal_uint32 *)0x80010068 |= 0x00008a80;
#elif defined(MT6229_S00) /* MT6218B */
/*
* To fix the hardware bug of IRDMA,
* set the IRWIN register such that IRDMA does not always have the first priority.
*/
*(volatile kal_uint32 *)0x80000500 = 0;
#elif defined(MT6226M)
if ((*HW_CODE == 0x6219) && ((*HW_VER & 0xff00) == 0x8b00))
*ACIF_CON0 |= 0x0001;
#elif defined(MT6223) || defined(MT6223P)
*ACIF_CON0 = 0x1;
#endif /* MT6218B */
}
/*************************************************************************
* FUNCTION
* INT_Version_Check
*
* DESCRIPTION
* This function implements HW ID check with software load version
*
* CALLS
* U_PutUARTByte
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
#ifdef __CHIP_VERSION_CHECK__
void INT_Version_Check(void)
{
#ifndef _NAND_FLASH_BOOTING_
volatile register kal_uint16 HwCode;
register kal_uint8 HExtra = ' ';
register kal_uint16 BuildCode;
register kal_int32 i;
HwCode = *HW_CODE;
BuildCode = *HW_VER;
// MT6217AT/AN
if ((HwCode == 0x6218) && (BuildCode == 0x8B03))
{
HwCode = 0x6217;
}
// MT6223P
else if ((HwCode == 0x6223) && (*((volatile kal_uint16 *)(CONFIG_base+0xf010)) & 0x8000))
{
HExtra = 'P';
}
// MT6226M
else if ((HwCode == 0x6219) && ((BuildCode & 0xFF00) == 0x8B00))
{
HwCode = 0x6226;
HExtra = 'M';
}
// MT6226D
else if ((HwCode == 0x6226) && ((BuildCode & 0xFF00) == 0x8D00))
{
HExtra = 'D';
}
// MT6227D
else if ((HwCode == 0x6227) && ((BuildCode & 0xFF00) == 0x8D00))
{
HExtra = 'D';
}
#if defined(MT6205B)
BuildCode = 0x6205;
#elif defined(MT6217)
BuildCode = 0x6217;
#elif defined(MT6219)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -