tDWORD SysDelay(tDWORD dwMs) { //OS_Sleep(dwMs >> 3); if (bInited) { MsOS_DelayTask(dwMs); } else { MsOS_DelayTask(dwMs); } return (0); }
int nmi_tuner_os_chip_enable(void) { #if 0 //hardware reset sar3 high extern void Enable_SAR_GPIO(MS_U8 u8SarNo,MS_BOOL bEnable); extern void mdrv_gpio_set_high(int gpio); extern void mdrv_gpio_init(void); mdrv_gpio_init(); Enable_SAR_GPIO(3,SAR3_GPIO_ENABLE); mdrv_gpio_set_high(20); MsOS_DelayTask(100); #endif return TRUE; }
int eeprom_PageWrite(MS_U16 offset, MS_U8 *pBuf, MS_U16 u16BufLen) { ST_EEPROM_PARA stEtype; MS_U16 u16writeSize=0; if(pBuf==NULL) { UBOOT_ERROR("input parameter 'pBuf' is a null pointer\n"); return -1; } while(u16BufLen>0) { stEtype = getEepeomParameter(stEepromArray[EepromID],offset); UBOOT_DEBUG(fmt, stEtype.u16SlaveIDAddr, stEtype.u8AddrCnt,"write", pBuf,stEtype.pu8Offset, u16BufLen); if(u16BufLen >= stEtype.u8PageSize) { u16writeSize = stEtype.u8PageSize; u16BufLen = u16BufLen - stEtype.u8PageSize; } else { u16writeSize = u16BufLen; u16BufLen = 0; } if(MApi_SWI2C_WriteBytes(stEtype.u16SlaveIDAddr, stEtype.u8AddrCnt,stEtype.pu8Offset,u16writeSize, (MS_U8*)(pBuf)) != TRUE) { UBOOT_ERROR("MApi_SWI2C_WriteBytes FAIL!!\n"); return -1; } MsOS_DelayTask(10); pBuf+=u16writeSize; offset+=u16writeSize; } return 0; }
void tun_rda5880e_init(void) { //soft reset RDA5880e_Write_single(0x30,0x00,0x04); RDA5880e_Write_single(0x30,0x00,0x05); //ldo voltage RDA5880e_Write_single(0x1a,0x14,0x84); RDA5880e_Write_single(0x1b,0x02,0x10); RDA5880e_Write_single(0x1c,0x04,0x44); //ana RDA5880e_Write_single(0x01,0x4a,0x40); RDA5880e_Write_single(0x04,0x02,0xa0); RDA5880e_Write_single(0x05,0xa4,0x45); RDA5880e_Write_single(0x06,0x32,0xff); RDA5880e_Write_single(0x08,0x0f,0xc3); RDA5880e_Write_single(0x09,0xb3,0x24); RDA5880e_Write_single(0x0a,0x22,0xaa); RDA5880e_Write_single(0x0b,0x38,0x20); RDA5880e_Write_single(0x0c,0x38,0x20); RDA5880e_Write_single(0x0d,0x01,0x57); //modify by rda 2011.8.8 RDA5880e_Write_single(0x0e,0x18,0x20); RDA5880e_Write_single(0x10,0x24,0x40); RDA5880e_Write_single(0x3b,0x09,0x27); //rfpll RDA5880e_Write_single(0x11,0x00,0x01); RDA5880e_Write_single(0x12,0x24,0x88); RDA5880e_Write_single(0x13,0x66,0x08); RDA5880e_Write_single(0x14,0x00,0x18); RDA5880e_Write_single(0x15,0xc2,0x8b); RDA5880e_Write_single(0x16,0x20,0x64); RDA5880e_Write_single(0x17,0x01,0x9a); //modify by rda 2011.10.30 // RDA5880e_Write_single(0x17,0x02,0x22); RDA5880e_Write_single(0x31,0x00,0x00); RDA5880e_Write_single(0x3f,0x1a,0x3e); //pd RDA5880e_Write_single(0x2d,0x00,0x00); RDA5880e_Write_single(0x2e,0x00,0xc3); //modify by rda 2011.8.8 MsOS_DelayTask(10); //modify by rda 2011.8.8 RDA5880e_Write_single(0x2e,0x00,0xc2); //rst RDA5880e_Write_single(0x35,0x28,0x07); RDA5880e_Write_single(0x38,0xd1,0x5f); //rfpll sdm RDA5880e_Write_single(0x45,0x00,0xe2); //pllbb_sdm RDA5880e_Write_single(0x46,0x05,0x00); RDA5880e_Write_single(0x47,0x00,0x00); RDA5880e_Write_single(0x48,0x0f,0xde); RDA5880e_Write_single(0x4b,0x30,0x00); RDA5880e_Write_single(0x4d,0x00,0x00); //dsp RDA5880e_Write_single(0x5b,0x00,0x03); RDA5880e_Write_single(0x5d,0x00,0x3f); RDA5880e_Write_single(0x5e,0x10,0x00); RDA5880e_Write_single(0x5f,0x60,0x00); RDA5880e_Write_single(0x60,0x10,0x00); RDA5880e_Write_single(0x61,0xf0,0x00); RDA5880e_Write_single(0x63,0x30,0x00); RDA5880e_Write_single(0x64,0x00,0x00); RDA5880e_Write_single(0x65,0xc1,0x5c); RDA5880e_Write_single(0x68,0xef,0xde); RDA5880e_Write_single(0x79,0x01,0x00); }
void tun_rda5880e_control_if(MS_U32 freq, MS_U32 IF_freq,MS_U32 bandwidth) { MS_U8 cur_band; MS_U16 data_tmp; MS_U32 tmp,tmp1; MS_U32 N; MS_U32 N1; MS_U32 N2; MS_U32 frac1; MS_U32 frac2; MS_U16 data_buf[3]; MS_U8 high; MS_U8 low; //tun_rda5880e_rxon_close_if(); RDA5880e_Write_single(0x30,0x00,0x55); //rxon disable RDA5880e_Write_single(0x16,0x20,0x60); //rfpll_refmulti2_en=0 rfpll_open_en=0 RDA5880e_Write_single(0x50,0x3f,0xfc); //agc_vga_loop_u_ct_slow set fast RDA5880e_Write_single(0x54,0x14,0x88); //agc_vga_update_ct_slow set fast //tun_rda5880e_selband(freq, *cur_band); //ÉèÖÃagc ·Ö¶Î if(freq<=400000) //vhf cur_band=0; else if (freq<=590000) //474~590MHz cur_band=1; else if (freq<=686000) //591~695MHz cur_band=2; else //696~858MHz cur_band=3; //tun_rda5880e_set_crystal(); //{3aH [14:0] } = dec2bin(f_xtal ) f_xtal KHz tmp=(MS_U32)(tuner_crystal); data_buf[0]=RDA5880e_Read(0x3a); data_buf[1]=data_buf[0]&0x8000; //data_tmp=(MS_U32)(tmp&data_buf[1]); ////LGH change 2011_6_2 data_tmp=(MS_U32)((data_buf[1]&0x8000)|(tmp&0x00007fff)); high=(MS_U8)((data_tmp&0xff00)>>8); low=(MS_U8)(data_tmp&0x00ff); RDA5880e_Write_single(0x3a,high,low); //tun_rda5880e_sdm_freq(void); //{46H [11:0] &47H [15:0]}= dec2bin((270*2^23)/f_xtal) //N=(MS_U32)(33750 / tuner_crystal); if(191500==freq) { N=(MS_U32)(280*2000 / tuner_crystal); //modify by rda 2011.6.29 frac1=280*2000-N*tuner_crystal; //modify by rda 2011.6.29 } else { N=(MS_U32)(270*2000 / tuner_crystal); //modify by rda 2011.6.5 frac1=270*2000-N*tuner_crystal; //modify by rda 2011.6.5 } N1=(MS_U32)(frac1*2048/ tuner_crystal); frac2=frac1*2048 -N1*tuner_crystal; N2=(MS_U32)(frac2*2048/ tuner_crystal); tmp=N*4194304+N1*2048+N2; data_buf[0]=RDA5880e_Read(0x46); data_buf[1]=data_buf[0]&0xf000; //data_tmp=(MS_U16)(((tmp>>16)&0x0fff)|data_buf[1]); ////LGH change 2011_6_2/////////////////////////////////////////////////////////////////// tmp=tmp&0xFFFFFFF; tmp1=data_buf[1]; tmp=(MS_U32)(((tmp1<<16)&0xf0000000)|tmp); ////////////////////////////////////////////////////////////////////////////////////// data_tmp=(MS_U16)((tmp>>16)&0xffff); //printf("\n#######2temp:0x%x,0x%x,0x%x,0x%x",tmp,data_buf[0],data_buf[1],data_tmp); high=(MS_U8)((data_tmp&0xff00)>>8); low=(MS_U8)(data_tmp&0x00ff); RDA5880e_Write_single(0x46,high,low); //printf("\n#####control_if46:0x%x",data_tmp); data_tmp=(MS_U16)(tmp&0xffff); high=(MS_U8)((data_tmp&0xff00)>>8); low=(MS_U8)(data_tmp&0x00ff); RDA5880e_Write_single(0x47,high,low); // printf("\n#####control_if47:0x%x",data_tmp); //tun_rda5880e_rf_freq(MS_U32 freq); //{02H [15:0]&03H [15:0] }= dec2bin (f*1000*2^10) if(866000==freq) { RDA5880e_Write_single(0x02,0x34,0xac); RDA5880e_Write_single(0x03,0x60,0x00); RDA5880e_Write_single(0x30,0x00,0x55); //rxon disable MsOS_DelayTask(10); RDA5880e_Write_single(0x30,0x00,0x5d); //rxon able data_buf[2]=RDA5880e_Read(0x18); data_tmp= data_buf[2]+3; high=(MS_U8)(((data_tmp & 0xff00) | 0x0400)>>8); low= (MS_U8) (data_tmp & 0x00ff); RDA5880e_Write_single(0x18,high,low); //fix vco band RDA5880e_Write_single(0x19,0x01,0x90); //fix vco high and rfpll_sel_800m_reg RDA5880e_Write_single(0x32,0x60,0x12); //rf_req=866 RDA5880e_Write_single(0x33,0xf6,0x84); }
int oad_check() { MS_U8 *pu8Buf = NULL; OAD_STATUS_REPORT_TYPE ddbStatus ; MS_U16 blockID=0,msgLen=0,msgType=0 ; MS_U32 msgAddr = 0 ; MS_BOOL Check_FE_Result; MS_U32 u32DsmccTimer=0; DBG_PRINT( printf("%s: at %d\n", __func__, __LINE__) ); u32DsmccTimer = MsOS_GetSystemTime(); while(1) { if( msAPI_Tuner_CheckLock( &Check_FE_Result,FALSE) == FALSE ) { printf("FE Fail!\n"); } else { if(Check_FE_Result==FE_LOCK) { printf("FE Locked.\n"); break; } else { printf("FE Not Locked. Check_FE_Result = %d\n", Check_FE_Result); } } if (MsOS_Timer_DiffTimeFromNow(u32DsmccTimer) > TUNER_LOCK_TIME_OUT) { OAD_DEBUG( printf("Error> Exit DSI\n") ); return 1; //return to do USB download } DBG_PRINT( printf("%s: at %d\n", __func__, __LINE__) ); MsOS_DelayTask(500); } #if(CONFIG_SDTT_OAD) if(!u8IsSDTT_OAD) { #endif if(msAPI_OAD_CreateSectionFilter( MSAPI_DMX_FILTER_TYPE_OAD_MONITOR, OAD_CONTROL_SECTION_TYPE, OAD_DSMCC_MSGID_DSI, wOad_PID, &_u8OADMonitorFID ) == TRUE) { DBG_PRINT( printf("Create filter: OK, pid: 0x%x.\n", wOad_PID) ); } DBG_PRINT( printf("Line: %d\n", __LINE__) ); u32DsmccTimer = MsOS_GetSystemTime(); while(1) { pu8Buf = msAPI_OAD_PollingSectionFilter(_u8OADMonitorFID, au8MonitorSection); if(pu8Buf) { DBG_PRINT( printf("DSI Poll filter: OK.\n") ); if (OAD_SUCCEED==msAPI_OAD_ProcessDSI(pu8Buf)) { u32DsmccTimer = MsOS_GetSystemTime(); versionNum = msAPI_OAD_GetDsiVersionNum() ; if (versionNum!=msAPI_OAD_GetDsiVersionNum()) { printf("versionNum error !!!\n"); } break; } else { printf("process DSI error !!!\n"); } } else { printf("No DSI Data!\n"); } if (MsOS_Timer_DiffTimeFromNow(u32DsmccTimer) > MONITOR_DSI_TIME_OUT) { OAD_DEBUG( printf("Error> Exit DSI\n") ); return 1; } MsOS_DelayTask(100); } #if(CONFIG_SDTT_OAD) } else { printf("===== [%s][%d] =====\n",__FUNCTION__,__LINE__); DBG_PRINT( printf("%s: at %d\n", __func__, __LINE__) ); msAPI_OAD_SetOADMode(OAD_MODE_DATACAR); msAPI_Set_SDTT_OAD(TRUE); } #endif if(msAPI_OAD_CreateSectionFilter( MSAPI_DMX_FILTER_TYPE_OAD_DOWNLOAD,OAD_CONTROL_SECTION_TYPE,OAD_DSMCC_MSGID_DII,wOad_PID, &_u8OADDownloadFID) == TRUE) { DBG_PRINT( printf("\n") ); DBG_PRINT( printf("DII Create filter: OK.\n") ); DBG_PRINT( printf("DII _u8OADDownloadFID = %d\n", _u8OADDownloadFID) ); u32DsmccTimer = MsOS_GetSystemTime(); } else { printf("Error> msAPI_OAD_CreateSectionFilter(OAD_CONTROL_SECTION_TYPE) : Invalid FID=%x\n",_u8OADDownloadFID); return 1; } while(1) { pu8Buf = msAPI_OAD_PollingSectionFilter(_u8OADDownloadFID, au8DownloadSection); if(pu8Buf) { if(OAD_SUCCEED==msAPI_OAD_ProcessDII(pu8Buf)) { msAPI_OAD_DeleteSectionFilter(&_u8OADDownloadFID) ; DBG_PRINT( printf("process DII ok\n") ); break; } if (MsOS_Timer_DiffTimeFromNow(u32DsmccTimer) > MONITOR_DII_TIME_OUT) { printf("Error> Timeout to receive DII\n"); return 1; } } } if(msAPI_OAD_CreateSectionFilter( MSAPI_DMX_FILTER_TYPE_OAD_DOWNLOAD,OAD_DATA_SECTION_TYPE ,OAD_DSMCC_MSGID_DDB, wOad_PID,&_u8OADDownloadFID) == TRUE) { DBG_PRINT( printf("\n") ); DBG_PRINT( printf("DDB Create filter: OK.\n") ); u32DsmccTimer = MsOS_GetSystemTime(); } else { printf("Error> msAPI_OAD_CreateSectionFilter(OAD_DATA_SECTION_TYPE) : Invalid FID\n"); } MApp_BL_DisplaySystem_clear(); //clear screen MApp_BL_DisplaySystem_setStatus((S8*)"DOWNLOAD"); MApp_BL_DisplaySystem(0); while(1) { // msAPI_Timer_ResetWDT(); pu8Buf = msAPI_OAD_PollingSectionFilter(_u8OADDownloadFID, au8DownloadSection); if(pu8Buf) { ddbStatus = msAPI_OAD_ProcessDDB(pu8Buf, &blockID, &msgLen, &msgAddr, &msgType) ; if (ddbStatus != OAD_FAIL) { u32DsmccTimer = MsOS_GetSystemTime(); if(msgLen>0) { if (msgType==OAD_MODE_OBJCAR) { if (blockID==0) { #if defined(CONFIG_URANUS4) || defined(CONFIG_KRONUS) || defined(CONFIG_KAISERIN) || defined(CONFIG_KENYA) memcpy((MS_U8 *)(DOWNLOAD_BUFFER_ADR_OAD),(MS_U8 *)msgAddr,(MS_U32)msgLen) ; #else memcpy((MS_U8 *)MS_PA2KSEG1(MS_VA2PA(DOWNLOAD_BUFFER_ADR_OAD)),(MS_U8 *)msgAddr,(MS_U32)msgLen) ; #endif } else { #if defined(CONFIG_URANUS4) || defined(CONFIG_KRONUS) || defined(CONFIG_KAISERIN) || defined(CONFIG_KENYA) memcpy((MS_U8 *)(DOWNLOAD_BUFFER_ADR_OAD+(blockID*MAX_DDB_MSGSIZE)-BIOP_HEADER_LEN),(MS_U8 *)msgAddr,(MS_U32)msgLen) ; #else memcpy((MS_U8 *)MS_PA2KSEG1(MS_VA2PA(DOWNLOAD_BUFFER_ADR_OAD+(blockID*MAX_DDB_MSGSIZE)-BIOP_HEADER_LEN)),(MS_U8 *)msgAddr,(MS_U32)msgLen) ; #endif } } else if (msgType==OAD_MODE_DATACAR) { MS_U32 u32BlockSize = msAPI_OAD_GetBlockSize(); #if defined(CONFIG_URANUS4) || defined(CONFIG_KRONUS) || defined(CONFIG_KAISERIN) || defined(CONFIG_KENYA) DBG_PRINT( printf("%s: at %d\n", __func__, __LINE__) ); memcpy((MS_U8 *)(DOWNLOAD_BUFFER_ADR_OAD+(blockID*u32BlockSize)),(MS_U8 *)msgAddr,(MS_U32)msgLen) ; #else memcpy((MS_U8 *)MS_PA2KSEG1(MS_VA2PA(DOWNLOAD_BUFFER_ADR_OAD+(blockID*u32BlockSize))),(MS_U8 *)msgAddr,(MS_U32)msgLen) ; #endif } //u32DownloadSize += msgLen ; } } if (ddbStatus == OAD_COMPLETE) { //MS_U32 CRC_result=0; //MS_U32 CRC_value=0; DBG_PRINT( printf("DDB complete.\n") ); //Check CRC32 //CRC_value=*((MS_U32*)(DOWNLOAD_BUFFER_ADR_OAD+u32DownloadSize-4)); //CRC_result=crc32( 0x00, (MS_U8 *)DOWNLOAD_BUFFER_ADR_OAD, u32DownloadSize-4 ); //DBG_PRINT( printf("CRC_result 0x%x, CRC_value 0x%x\n", CRC_result, CRC_value) ); break; } } { static MS_U8 u8PrevPersentage=0; MS_U8 u8Percentage = msAPI_OAD_GetProgress(); if (u8Percentage > 100) u8Percentage = 100; if(u8PrevPersentage != u8Percentage) { u8PrevPersentage = u8Percentage; MApp_BL_DisplaySystem(u8Percentage); DBG_PRINT( printf("u8Percentage: %u, at %d\n", u8Percentage, __LINE__) ); } } if (MsOS_Timer_DiffTimeFromNow(u32DsmccTimer) > MONITOR_DDB_TIME_OUT) { msAPI_OAD_ClearData(); OAD_DEBUG( printf("Error> Exit DDB\n") ); printf("DDB timeout!\n"); return 1; } } MApp_BL_DisplaySystem(100); DBG_PRINT( printf("\nOAD Finished\n") ); msAPI_OAD_GetModuleInfo( &u32ModuleAddr, &u32DownloadSize ); printf("u32ModuleAddr 0x%x, u32DownloadSize 0x%x\n",(unsigned int)u32ModuleAddr,(unsigned int) u32DownloadSize); printf("DOWNLOAD_BUFFER_ADR_OAD 0x%X, DOWNLOAD_BUFFER_LEN_OAD 0x%X\n",(unsigned int) DOWNLOAD_BUFFER_ADR_OAD,(unsigned int) DOWNLOAD_BUFFER_LEN_OAD); MS_U32DOWNLOADSIZE = u32DownloadSize; MApp_BL_DisplaySystem_clear(); MApp_BL_DisplaySystem_setStatus((S8*)"Software Update(OAD)"); MApp_BL_DisplaySystem(0); return 0; }