📄 init.c
字号:
BuildCode = 0x6219;
#elif defined(MT6223)
BuildCode = 0x6223;
#elif defined (MT6223P)
BuildCode = 0x6223;
#define ExtraVer 'P'
#elif defined(MT6225)
BuildCode = 0x6225;
#elif defined(MT6226)
BuildCode = 0x6226;
#elif defined(MT6226D)
BuildCode = 0x6226;
#define ExtraVer 'D'
#elif defined(MT6226M)
BuildCode = 0x6226;
#define ExtraVer 'M'
#elif defined(MT6227)
BuildCode = 0x6227;
#elif defined(MT6227D)
BuildCode = 0x6227;
#define ExtraVer 'D'
#elif defined(MT6228)
BuildCode = 0x6228;
#elif defined(MT6229)
BuildCode = 0x6229;
#elif defined(MT6230)
BuildCode = 0x6230;
#else
BuildCode = 0;
#endif
#ifndef ExtraVer
#define ExtraVer ' '
#endif
if ((HwCode != BuildCode) || (HExtra != ExtraVer))
{
U_PutUARTByte(uart_port1, '@');
while(1)
{
U_PutUARTByte(uart_port1, ' ');
U_PutUARTByte(uart_port1, 'H');
U_PutUARTByte(uart_port1, 'W');
U_PutUARTByte(uart_port1, '=');
U_PutUARTByte(uart_port1, 'M');
U_PutUARTByte(uart_port1, 'T');
for(i = 12; i >= 0; i -= 4)
{
U_PutUARTByte(uart_port1, '0' + ((HwCode >> i) & 0x0F));
}
U_PutUARTByte(uart_port1, HExtra);
U_PutUARTByte(uart_port1, ',');
U_PutUARTByte(uart_port1, ' ');
U_PutUARTByte(uart_port1, 'S');
U_PutUARTByte(uart_port1, 'W');
U_PutUARTByte(uart_port1, '=');
U_PutUARTByte(uart_port1, 'M');
U_PutUARTByte(uart_port1, 'T');
for(i = 12; i >= 0; i -= 4)
{
U_PutUARTByte(uart_port1, '0' + ((BuildCode >> i) & 0x0F));
}
U_PutUARTByte(uart_port1, ExtraVer);
U_PutUARTByte(uart_port1, ' ');
U_PutUARTByte(uart_port1, '\r');
U_PutUARTByte(uart_port1, '\n');
for(i = 0xFFFFF; i > 0; i--) ;
U_PutUARTByte(uart_port1, '#');
}
}
#endif /* _NAND_FLASH_BOOTING_ */
}
#endif /* __CHIP_VERSION_CHECK__ */
/*************************************************************************
* FUNCTION
* INT_Config
*
* DESCRIPTION
* This function implements adjusting Memory Block 0 (EMI_CON0) Wait
* State's setting
*
* CALLS
* INT_Decrypt, INT_SetPLL, INT_SetChipReg
*
* PARAMETERS
*
* RETURNS
* the seed value for random number
*
* GLOBALS AFFECTED
*
*************************************************************************/
int INT_Config(void)
{
kal_uint32 i, seed;
kal_uint16 result_low, result_high;
#if defined(__MULTI_BOOT__) && !defined(L1D_TEST_COSIM)
/* Check BOOT_CONFIG_ADDR */
if ( 0 != (*(volatile kal_uint16 *)BOOT_CONFIG_ADDR) )
{
/* Enter FT_MODE, delay for waiting UART flush TX buffer */
#if defined(MCU_26M)
kal_uint32 delay;
for (delay = 0; delay < 10000; delay++)
; /* nop */
#elif defined(MCU_52M)
kal_uint32 delay;
for (delay = 0; delay < 25000; delay++)
; /* nop */
#endif
}
#endif /* __MULTI_BOOT__ & !L1D_TEST_COSIM */
#ifdef MT6218B
if (INT_ecoVersion() == BN)
*(volatile kal_uint16 *)0x80000500 = 0x0001 ;
#endif /* MT6218B */
#if defined(MT6226) || defined(MT6227) || defined(MT6226M)
if (INT_ecoVersion() == ECO_E1)
*(volatile kal_uint16 *)0x80500108 = 0x1000;
#endif /* MT6226 || MT6227 || MT6226M */
#if defined(_SIMULATION)
/*
* For co-sim load,
* EMI on both bank 0 and bank 1 are assigned with 0x4102.
* And Register 0x80010044 (EMI General Control Register) reserves the default value.
*/
#if (!defined(MT6205B) && !defined(MT6208))
*EMI_CONA = 0x00004102;
*EMI_CONB = 0x00004102;
#else /* !MT6205B && !MT6208 */
*EMI_CON0 = 0x4102;
*EMI_CON1 = 0x4102;
#endif /* !MT6205B && MT6208 */
INT_SetPLL();
#else /* _SIMULATION */
#ifndef _NAND_FLASH_BOOTING_
custom_setEMI();
INT_SetPLL();
#endif /* _NAND_FLASH_BOOTING_ */
#ifdef MT6225
*(volatile kal_uint32 *)(0x80010078) = 0;
#endif /* MT6225 */
#endif /* _SIMULATION */
INT_SetChipReg();
#if defined(_SIMULATION)
/* no need to generate a real random number seed in co-sim */
seed = 0;
#else /* _SIMULATION */
/* generate a random number via reading internal SRAM or 32K-clock calibration */
for (seed = 0, i = 0; i < (1024 / 4); i++) {
/* XOR memory data */
seed = seed ^ *((kal_uint32 *)RAND_GEN_START_ADDR + i);
}
/* check if the seed is zero */
if (seed == 0) {
/* try to find another seed */
/* try 32K clock */
*(volatile kal_uint16 *)DRVPDN_CON2_CLR = DRVPDN_CON2_TDMA;
DRV_WriteReg(SM_FMDURATION,0);
DRV_Reg(SM_CTRL) |= SM_CTRL_FM_START;
while (!(DRV_Reg(SM_STAT) & SM_STAT_FM_RDY)) ;
result_low = DRV_Reg(SM_FM_RESULT_LOW);
result_high = DRV_Reg(SM_FM_RESULT_HIGH) & SM_FM_RESULT_HIGH_MASK;
seed = (result_low | (result_high << 16));
}
#endif /* _SIMULATION */
/*
* NoteXXX: Seed cannot be store in the global variable rand_num_seed directly.
* This is because that RW-data will be initialized later.
* Just return the seed.
*/
return seed;
}
/*************************************************************************
* FUNCTION
* INT_SwitchMCUClock
*
* DESCRIPTION
* This function intended for switching MCU clock.
* Be very careful that, before this function is called, user must ensure
* that there is very save EMI setting.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool INT_SwitchMCUClock(mcu_clock_enum inputclk)
{
kal_uint32 savedMask;
kal_bool status=KAL_TRUE;
savedMask = SaveAndSetIRQMask();
#if defined(MT6228) || defined(MT6229) || defined(MT6230) || defined(MT6225)
switch (inputclk) {
case MCU_13MHZ:
*MCUCLK_CON = 0x0000;
break;
case MCU_26MHZ:
*MCUCLK_CON = 0x0101;
break;
case MCU_52MHZ:
*MCUCLK_CON = 0x0303;
break;
case MCU_104MHZ:
*MCUCLK_CON = 0x0703;
break;
default:
status = KAL_FALSE;
break;
}
#elif defined(MT6223) || defined(MT6223P)
switch ( inputclk )
{
case MCU_13MHZ: *MCUCLK_CON &= 0x00f0 ;
break;
case MCU_26MHZ: *MCUCLK_CON &= 0x00f0 ;
*MCUCLK_CON |= 0x01f1 ;
break;
case MCU_39MHZ: *MCUCLK_CON &= 0x00f0 ;
*MCUCLK_CON |= 0x02f2 ;
break;
case MCU_52MHZ: *MCUCLK_CON &= 0x00f0 ;
*MCUCLK_CON |= 0x03f3 ;
break;
default : status = KAL_FALSE;
}
#elif defined(MT6217) || defined(MT6226) || defined(MT6227) || defined(MT6226M) || defined(MT6227D) || defined(MT6226D)
switch ( inputclk )
{
case MCU_13MHZ: *(volatile kal_uint16 *)0x80000114 = 0x0000 ;
break;
case MCU_26MHZ: *(volatile kal_uint16 *)0x80000114 = 0x0001 ;
break;
case MCU_39MHZ: *(volatile kal_uint16 *)0x80000114 = 0x0002 ;
break;
case MCU_52MHZ: *(volatile kal_uint16 *)0x80000114 = 0x0003 ;
break;
default : status = KAL_FALSE;
}
#elif defined(MT6218B) || defined(MT6219)
#ifdef EXT_26M
switch ( inputclk )
{
case MCU_13MHZ: /* Bypass MPLL, but retain MCU_DIV2 */
*(volatile kal_uint16 *)0x80000108 |= 0x0008;
*(volatile kal_uint16 *)0x80000108 &= ~(0x0002);
break;
case MCU_26MHZ: /* Bypass MPLL and MCU_DIV2*/
*(volatile kal_uint16 *)0x80000108 &= ~(0x000a);
break;
case MCU_52MHZ: /* Do not bypass both MPLL and MCU_DIV2*/
*(volatile kal_uint16 *)0x80000108 |= 0x000a;
break;
default : status = KAL_FALSE;
}
#elif defined EXT_13M
switch ( inputclk )
{
case MCU_13MHZ: /* Bypass MPLL and MCU_DIV2*/
*(volatile kal_uint16 *)0x80000108 &= ~(0x000a);
break;
case MCU_26MHZ: /* Bypass MPLL and MCU_DIV2*/
*(volatile kal_uint16 *)0x80000108 &= ~(0x000a);
*(volatile kal_uint16 *)0x80000100 = 0x01;
{
kal_uint8 i;
// delay until PLL is stable
for (i=0;i<200;i++);
}
*(volatile kal_uint16 *)0x80000108 |= 0x0002;
break;
case MCU_52MHZ: /* Bypass MPLL and MCU_DIV2*/
*(volatile kal_uint16 *)0x80000108 &= ~(0x000a);
*(volatile kal_uint16 *)0x80000100 = 0x03;
{
kal_uint8 i;
// delay until PLL is stable
for (i=0;i<200;i++);
}
*(volatile kal_uint16 *)0x80000108 |= 0x0002;
break;
default : status = KAL_FALSE;
}
#endif /* EXT_26M */
#endif
RestoreIRQMask(savedMask);
return status;
}
/*************************************************************************
* FUNCTION
* INT_BootMode
*
* DESCRIPTION
* This function implements to return boot mode. Remember the routine muse
* be called after Application_Initialize.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint16 INT_BootMode(void)
{
return _boot_mode;
}
#ifdef __MTK_TARGET__
#pragma arm section code = "SNORCODE"
#endif /* __MTK_TARGET__ */
/*************************************************************************
* FUNCTION
* INT_DisableDataCache
*
* DESCRIPTION
* This is specific function for flash driver only.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 INT_DisableDataCache(void)
{
#if ( !defined(MT6205B) && !defined(MT6208) && !defined(MT6228) && !defined(MT6229) && !defined(MT6230) && !defined(MT6225) )
kal_uint32 restore_value;
restore_value = *(kal_uint32 *)(0x80010050);
*(kal_uint32 *)(0x80010050) &= ~(0x30000);
return restore_value;
#else
return 0;
#endif
}
/*************************************************************************
* FUNCTION
* INT_RestoreDataCache
*
* DESCRIPTION
* This is specific function for flash driver only.
*
* CALLS
*
* PARAMETERS
* Value to be restored.
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void INT_RestoreDataCache(kal_uint32 restore_value)
{
#if ( !defined(MT6205B) && !defined(MT6208) && !defined(MT6228) && !defined(MT6229) && !defined(MT6230) && !defined(MT6225) )
*(kal_uint32 *)(0x80010050) = restore_value;
return;
#else
return;
#endif
}
/*************************************************************************
* FUNCTION
* INT_DisableCodePrefetch
*
* DESCRIPTION
* This is specific function for flash driver only.
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
#ifdef MT6205B
kal_uint32 INT_DisableCodePrefetch(void)
{
kal_uint32 restore_value;
restore_value = *(kal_uint32 *)(0x80010030);
*(kal_uint32 *)(0x80010030) &= ~(0x2);
return restore_value;
}
#endif
/*************************************************************************
* FUNCTION
* INT_RestoreCodePrefetch
*
* DESCRIPTION
* This is specific function for flash driver only.
*
* CALLS
*
* PARAMETERS
* Value to be restored.
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
#ifdef MT6205B
void INT_RestoreCodePrefetch(kal_uint32 restore_value)
{
*(kal_uint32 *)(0x80010030) = restore_value;
}
#endif
#ifdef __MTK_TARGET__
#pragma arm section code
#endif /* __MTK_TARGET__ */
/*************************************************************************
* FUNCTION
* INT_InvokeSSTEngine
*
*************************************************************************/
void INT_InvokeSSTEngine(kal_char *err_msg_ptr, kal_int32 err_code, kal_int32 os_err_code)
{
#ifdef _SST_FUNCTION_ENABLE_
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* _SST_FUNCTION_ENABLE_ */
return;
}
/*************************************************************************
* FUNCTION
* INT_QueryPowerDownStatus
*
* DESCRIPTION
* Used to read-back the 4 power down control registers.
*
* CALLS
*
* PARAMETERS
* Pointer of type CONFIG_PDN_TYPE.
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void INT_QueryPowerDownStatus(CONFIG_PDN_TYPE *PDN_ptr)
{
PDN_ptr->pdn_con0 = *(volatile kal_uint16 *)PDN_CON0;
PDN_ptr->pdn_con1 = *(volatile kal_uint16 *)PDN_CON1;
PDN_ptr->pdn_con2 = *(volatile kal_uint16 *)PDN_CON2;
PDN_ptr->pdn_con3 = *(volatile kal_uint16 *)PDN_CON3;
}
/*************************************************************************
* FUNCTION
* INT_SetPowerDownStatus
*
* DESCRIPTION
* Setting 4 power down control registers.
*
* CALLS
*
* PARAMETERS
* Pointer of type CONFIG_PDN_TYPE.
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void INT_SetPowerDownStatus(CONFIG_PDN_TYPE *PDN_ptr)
{
*(volatile kal_uint16 *)PDN_SET0 = PDN_ptr->pdn_con0;
*(volatile kal_uint16 *)PDN_SET1 = PDN_ptr->pdn_con1;
*(volatile kal_uint16 *)PDN_SET2 = PDN_ptr->pdn_con2;
*(volatile kal_uint16 *)PDN_SET3 = PDN_ptr->pdn_con3;
*(volatile kal_uint16 *)PDN_CLR0 = ~(PDN_ptr->pdn_con0);
*(volatile kal_uint16 *)PDN_CLR1 = ~(PDN_ptr->pdn_con1);
*(volatile kal_uint16 *)PDN_CLR2 = ~(PDN_ptr->pdn_con2);
*(volatile kal_uint16 *)PDN_CLR3 = ~(PDN_ptr->pdn_con3);
}
/*************************************************************************
* FUNCTION
* release_bb_chip
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -