#include "dst_eroum_interface.h" #ifdef DSTAR #include "dsthallocal.h" #include "dsthalerror.h" #include "dsthalPsiProcess.h" #include "dsthalcap.h" #include "dsthalsys.h" #include "dsthaldev.h" #else #include "DHL_SYS_Impl.h" #include "DHL_SYS.h" #include "DHL_PSI.h" #include "DHL_FE.h" #include "DHL_UIO.h" #include "DHL_AVCAP.h" #ifdef __cplusplus extern "C" { #endif #include "DHL_Graphic.h" #ifdef __cplusplus } #endif #endif #include "DST_ISDBT_ChannelTask.h" #include "DST_CommonAPI.h" #include "DST_HostInterface.h" #include "DST_WinManagerTask.h" #include "sqlite3.h" #include "DST_UserInterface.h" static DHL_SignalInfoCallBack g_SignalInfoCallBack = 0; static DHL_VideoStartCallBack g_VideoStartCallBack = 0; static DHL_AudioStartCallBack g_AudioStartCallBack = 0; static DHL_SiCallBack g_SiCallBack = 0; static DHL_CCCallBack g_CCCallBack = 0; static DHL_IrCallBack g_IrCallBack = 0; #ifdef DSTAR DHL_PSI_HANDLE hPsi = 0; #else tDHL_TSD tsd = 0; #endif extern "C" void change_file(int num, int bReadList, int bForce, int bCont); #ifdef DSTAR static void _DHL_SignalInfoCallBack(bool bFocus, DHL_CAP_VIDEO_INPUT vi, DS_U16 hRes, DS_U16 vRes, DS_U16 RefreshRate, bool bInterlaced, DHL_CAP_SRCASPECTRATIO Aspect) { if (g_SignalInfoCallBack == 0) return; DHL_SOURCE_ASEPCT as = DHL_SOURCE_UNKNOWN; switch (Aspect) { case DHL_CAP_SRC_ASPECT_16_9: as = DHL_SOURCE_16x9; break; case DHL_CAP_SRC_ASPECT_SQUARE: case DHL_CAP_SRC_ASPECT_4_3: as = DHL_SOURCE_4x3; break; default: break; } g_SignalInfoCallBack(hRes, vRes, RefreshRate, bInterlaced ? true : false, as); } // 2012.12.04 USER DATA¿¡¼­ CC µ¥ÀÌÅÍ ÃßÃâ static void DHL_UserData_DTVCCPacketBlock(DS_U8 service_number, DS_U8 nSize, DS_U8 *buff) { #if 0 DST_Printf("%s service_number = %d nSize = %d %X\n", __func__, service_number, nSize, buff); for (int i = 0; i>5) & 0x07; if (service_number < 1) return; if (service_number == 7) { if (nSize < 3) return; service_number += (buff[1] & 0x3F); // extended service_number Figure 8 if (block_size > nSize-2) block_size = nSize-2; // block size º¸Á¤ DHL_UserData_DTVCCPacketBlock(service_number, block_size, &buff[2]); } if (block_size > nSize-1) block_size = nSize-1; // block size º¸Á¤ DHL_UserData_DTVCCPacketBlock(service_number, block_size, &buff[1]); } static void DHL_UserData_DTVCC(bool bStart, DS_U8 cc_data_1, DS_U8 cc_data_2) { //DST_Printf("%s %d %02X %02X\n", __func__, bStart, cc_data_1, cc_data_2); static DS_U8 nSeqNumber = 0xFF; static DS_U8 nPacketSize = 0; static DS_U8 data[127]; static DS_U8 nReceiveCount = 0; if (bStart) { DS_U8 seq_number = (cc_data_1 >> 6) & 0x03; nPacketSize = (cc_data_1 & 0x3F); nPacketSize = (nPacketSize == 0) ? 127 : nPacketSize*2-1; // Figure 4 #if 0 DST_Printf("seq_number = %d\n", seq_number); DST_Printf("nPacketSize = %d\n", nPacketSize); DST_Printf("nSeqNumber = %d\n", nSeqNumber); #endif data[0] = cc_data_2; nReceiveCount = 1; if (nSeqNumber != 0xFF && ((nSeqNumber+1)%4) != seq_number) { DST_Printf("Seq Error\n"); if (g_CCCallBack) g_CCCallBack((DS_U8*)0, -1); } nSeqNumber = seq_number; } else { if (nPacketSize == 0) return; if (nPacketSize > nReceiveCount) { data[nReceiveCount] = cc_data_1; nReceiveCount++; } if (nPacketSize > nReceiveCount) { data[nReceiveCount] = cc_data_2; nReceiveCount++; } if (nReceiveCount >= nPacketSize) { DHL_UserData_DTVCCPacket(nReceiveCount, data); nPacketSize = 0; nReceiveCount = 0; } } } static void DHL_UserData_ClosedCaption(DS_U16 nSize, DS_U8 *buff) { #if 0 DST_Printf("%s %d %X\n", __func__, nSize, buff); for (int i = 0; iaspect_ratio_information); DST_Printf("frame_rate_code : %d \n", pSeq->frame_rate_code); DST_Printf("horizontal_size : %d \n", pSeq->horizontal_size); DST_Printf("vertical_size : %d \n", pSeq->vertical_size); DST_Printf("progressive_sequence : %d \n", pSeq->progressive_sequence); g_SignalInfoCallBack(pSeq->horizontal_size, pSeq->vertical_size, pSeq->frame_rate_code, pSeq->progressive_sequence ? false : true, (pSeq->aspect_ratio_information == DAR_9_16) ? DHL_SOURCE_16x9 : DHL_SOURCE_4x3); } if (cb_type == eDHL_CB_FirstVideoShow && g_VideoStartCallBack) { g_VideoStartCallBack(); } } #endif #if 0 ____System___() #endif #ifdef DSTAR static void DSTAR_KeyCallBack(int bRemocon, DS_U32 Code, int bPressed); #endif // SYSTEM ÃʱâÈ­ extern "C" void dbg_print(int val); DHL_ERROR DHL_SYS_Initialize() { #ifdef DSTAR #else dbg_print(1); DHL_SYS_PlatformInit(); #endif return DHL_OK_; } DHL_ERROR DHL_SYS_TV_Open( DHL_SignalInfoCallBack signal, DHL_VideoStartCallBack video, DHL_AudioStartCallBack audio, DHL_SiCallBack si, DHL_CCCallBack cc, DHL_IrCallBack Ir) { // ÄÝ¹é µî·Ï g_SignalInfoCallBack = signal; g_VideoStartCallBack = video; g_AudioStartCallBack = audio; g_SiCallBack = si; g_CCCallBack = cc; g_IrCallBack = Ir; // ÃʱâÈ­ ÀÛ¾÷ #ifdef DSTAR DHL_DISP_PresetVideoOutputFormat(DHL_VIDEO_WXGA); DHL_SYS_Initiate(); DHL_PSI_Init(&hPsi); DHL_FE_Init(TUNER_FAT); DHL_DTV_Init(); DHL_DMX_Init(); DHL_DMX_Start(); DHL_CAP_PresetAudioInput(DHL_CAP_DTV0_AUDIO); DHL_DEV_InitSmartCardInterface((void*)0); // ÀÌ ¶óÀÎÀ» Á¦°ÅÇϸé DSTAR ¼¼¸¶Æ÷¾î ¿¡·¯°¡ ³­´Ù. DHL_CAP_Init(); DHL_CAP_StartVideoEx(DHL_CAP_DTV0_VIDEO, DHL_CAP_VIDEO_NONE, DHL_PIPMODE_NONE, DHL_PIP_NO_PIP); DHL_DTV_StopAudio(); DHL_CAP_ChangeAudioInput(DHL_CAP_DTV0_AUDIO); DHL_CAP_StartAudio(); DHL_DTV_PresetCallback((void *) _DHL_VideoStartCallBack, DHL_CB_NOTIFY_VSTARTING, 1); DHL_CAP_PresetCallback2((DHL_CAP_CBFUNC2_t)_DHL_SignalInfoCallBack); DHL_DTV_PresetCallback((void *) _DHL_CCCallBack, DHL_CB_VDC_CCUDP, 0); DHL_DTV_InitCC(); DHL_DTV_EnableCC(); DHL_IR_Init(DHL_IR_NEC); DHL_IR_SetCbFunc(DSTAR_KeyCallBack); void test_cc(); test_cc(); #else DHL_AV_SetCallback(eDHL_CB_VideoSeqHdr, _DHL_AV_CallBack); DHL_AV_SetCallback(eDHL_CB_FirstVideoShow, _DHL_AV_CallBack); // IR ÃʱâÈ­ // TO DO #endif return DHL_OK_; } DHL_ERROR DHL_SYS_TV_Close() { return DHL_OK_; } #ifdef DSTAR #else #define PSIDataArray_t tDHL_PSI_DataArray #define DHL_TBL_HANDLE tDHL_PSI_ControlHandle #define PSIEvent tDHL_PSI_Event #define psiDataReceived ePSIEVENT_DATARECEIVED #endif typedef struct PSIMultiEventProcData_t { int err; DS_U32 hEvent; DS_U32 id; DS_U32 freq; DS_U16 sID; } PSIMultiEventProcData; static void CT_MultiEventProc(PSIEvent event, DHL_TBL_HANDLE hTblHandle, DS_U32 userParam) { if (!hTblHandle || event != psiDataReceived) return; PSIDataArray_t *desc; if (DHL_PSI_ReadPSIData(hTblHandle, &desc) != DHL_OK) return; PSIMultiEventProcData *procData = (PSIMultiEventProcData *) userParam; if (g_SiCallBack) g_SiCallBack(procData->freq, procData->id, desc->sectPtr, 0); DHL_PSI_FreePSIData(desc); } #if 0 ____Video___() #endif // Video ½ÃÀÛ static bool bVideoStart = false; DHL_ERROR DHL_VID_Start(DS_U16 VideoPID, DS_U16 PcrPID, DHL_VIDEO_TYPE type) { if (bVideoStart == true) DHL_VID_Stop(); bVideoStart = true; #ifdef DSTAR DHL_DTV_StartVideoEx2(VideoPID, PcrPID, type ); #else tDHL_VideoCodingType nType = eDHL_VIDEO_TYPE_H264; switch (type) { case DHL_VIDEO_MPEG1: nType = eDHL_VIDEO_TYPE_MPEG1; break; case DHL_VIDEO_MPEG2: nType = eDHL_VIDEO_TYPE_MPEG2; break; default: break; } DHL_AV_VideoStart(0, VideoPID, PcrPID, nType); #endif return DHL_OK_; } // Video Á¾·á DHL_ERROR DHL_VID_Stop() { if (bVideoStart == false) return DHL_OK_; bVideoStart = false; #ifdef DSTAR DHL_DTV_StopVideo(); #else DHL_AV_VideoStop(0); #endif return DHL_OK_; } // Video Mute ºñµð¿À È­¸éÀ» °ËÀº»öÀ¸·Î º¸ÀÌÁö ¾Êµµ·Ï ÇÔ. CVBS¿¡¼­µµ µ¿ÀÏ // bMute = false --> Video Unmute // bMute = true --> Video Mute DHL_ERROR DHL_VID_Mute(bool bMute) { #ifndef DSTAR DHL_AV_VideoHide(0, bMute ? 1 : 0); #endif return DHL_OK_; } // Video Alive µðÄÚµùµÈ ºñµð¿À°¡ ÀÖ´ÂÁö ¿©ºÎ¸¦ ¾Ë·ÁÁÖ´Â ÇÔ¼ö bool DHL_VID_Alive() { #ifndef DSTAR tDHL_VideoStatus vs; DHL_AV_VideoGetStatus(0, &vs); if (!vs.bOutputExist) return false; #endif return true; } // Video Aspect ¼³Á¤ // ÀÔ·Â ASPECT(4:3 16:9) ¿¡µû¶ó °¢°¢ ³× °¡Áö ¸ðµå°¡ ÀÖÀ½ DHL_ERROR DHL_VID_Aspect(DHL_ASPECT_RATIO ar, DS_U16 w, DS_U16 h) { #ifndef DSTAR tDHL_DispARC adj = eDHL_ARC_FULLSCREEN; switch (ar) { case DHL_ASPECT_4x3_4x3: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_4x3_4x3 eDHL_ARC_FULLSCREEN\n"); break; case DHL_ASPECT_16x9_4x3_WIDE: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_16x9_4x3_WIDE eDHL_ARC_FULLSCREEN\n"); break; case DHL_ASPECT_16x9_4x3_NORMAL: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_16x9_4x3_NORMAL eDHL_ARC_SIDEBAR\n"); break; case DHL_ASPECT_16x9_4x3_ZOOM: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_16x9_4x3_ZOOM eDHL_ARC_ZOOM1\n"); break; case DHL_ASPECT_4x3_16x9_WIDE: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_4x3_16x9_WIDE eDHL_ARC_LETTERBOX\n"); break; case DHL_ASPECT_4x3_16x9_NORMAL: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_4x3_16x9_NORMAL eDHL_ARC_FULLSCREEN\n"); break; case DHL_ASPECT_4x3_16x9_ZOOM: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_4x3_16x9_ZOOM eDHL_ARC_ZOOM2\n"); break; case DHL_ASPECT_16x9_16x9_WIDE: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_16x9_16x9_WIDE eDHL_ARC_FULLSCREEN\n"); break; case DHL_ASPECT_16x9_16x9_NORMAL: adj = eDHL_ARC_FULLSCREEN; printf("DHL_ASPECT_16x9_16x9_NORMAL eDHL_ARC_SIDEBAR\n"); break; default: break; } // DHL_Rect rect; // rect.x = 0; // rect.y = 0; // rect.w = w; // rect.h = h; DHL_AV_VideoSetARC(adj, adj); // tDHL_DispARC nAR = eDHL_ARC_UNKNOWN; // switch (ar) // { // case DHL_ASPECT_16x9_ANAMORPHIC: // 16:9 ÀԷ¼ҽº 16:9 Ãâ·Â // nAR = eDHL_ARC_FULLSCREEN; // break; // case DHL_ASPECT_16x9_16x9: // 16:9 ÀԷ¼ҽº 4:3 Ãâ·Â // nAR = eDHL_ARC_LETTERBOX; // break; // case DHL_ASPECT_16x9_14x9: // 16:9 ÀԷ¼ҽº Zoom1 Ãâ·Â // nAR = eDHL_ARC_SIDEBAR; // break; // case DHL_ASPECT_16x9_ZOOM: // 16:9 ÀԷ¼ҽº Zoom2 Ãâ·Â // nAR = eDHL_ARC_PAN_AND_SCAN; // break; // case DHL_ASPECT_4x3_ANAMORPHIC: // 4:3 ÀԷ¼ҽº 16:9 Ãâ·Â // nAR = eDHL_ARC_TILT_AND_SCAN; // break; // case DHL_ASPECT_4x3_16x9: // 4:3 ÀԷ¼ҽº 4:3 Ãâ·Â // nAR = eDHL_ARC_PARTIAL_LETTERBOX; // break; // case DHL_ASPECT_4x3_14x9: // 4:3 ÀԷ¼ҽº Zoom1 Ãâ·Â // nAR = eDHL_ARC_PARTIAL_SIDEBAR; // break; // case DHL_ASPECT_4x3_ZOOM: // 4:3 ÀԷ¼ҽº Zoom2 Ãâ·Â // nAR = eDHL_ARC_ZOOM1; // break; // default: // break; // } // DHL_AV_VideoSetARC(nAR, nAR); #endif return DHL_OK_; } #if 0 ____Audio___() #endif // Audio ½ÃÀÛ // PcrPID == 0 Àΰæ¿ì Audio Only ä³Î static bool bAudioStart = false; DHL_ERROR DHL_AUD_Start(DS_U16 AudioPid, DS_U16 PcrPID, DHL_AUDIO_TYPE type) { if (bAudioStart == true) DHL_AUD_Stop(); bAudioStart = true; #ifndef DSTAR tDHL_AudioCodingType nType = eDHL_AUDIO_TYPE_AAC_LATM; switch (type) { case DHL_AUDIO_MPEG1: nType = eDHL_AUDIO_TYPE_MPEG_1; break; case DHL_AUDIO_MPEG2: nType = eDHL_AUDIO_TYPE_MPEG_2; break; case DHL_AUDIO_AAC_ADTS: nType = eDHL_AUDIO_TYPE_AAC_ADTS; break; case DHL_AUDIO_AAC_LATM: nType = eDHL_AUDIO_TYPE_AAC_LATM; break; default: break; } DHL_AV_AudioStart(AudioPid, PcrPID, nType); #endif return DHL_OK_; } // Audio Á¾·á DHL_ERROR DHL_AUD_Stop() { if (bAudioStart == false) return DHL_OK_; bAudioStart = false; #ifndef DSTAR DHL_AV_AudioStop(); #endif return DHL_OK_; } // Audio Volume, 0 is mute DHL_ERROR DHL_AUD_Volume(DS_U8 nVal) { #ifndef DSTAR DHL_AV_AudioSetUserVolumeRange(0,100); if (nVal == 0) { DHL_AV_AudioSetVolume(0); DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_GPIO, 1); } else { DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_GPIO, 0); DHL_AV_AudioSetVolume(nVal); } #endif return DHL_OK_; } // Audio Alive µðÄÚµùµÈ ¿Àµð¿À°¡ ÀÖ´ÂÁö ¿©ºÎ¸¦ ¾Ë·ÁÁÖ´Â ÇÔ¼ö bool DHL_AUD_Alive() { #ifndef DSTAR tDHL_AudioStatus as; DHL_AV_AudioGetStatus(&as); if (!as.bOutputExist) return false; #endif return true; } // Play ÁßÀÎ ¿Àµð¿ÀÀÇ ¸ðµå¸¦ ¹ÝȯÇÑ´Ù. DHL_AUDIO_MODE DHL_AUD_GetMode() { return DHL_AUDIO_STEREO; } #if 0 ____SI___() #endif struct DHL_SI_HANDLE { DS_U32 nRequestID; PSIMultiEventProcData *aProcData; void **aPsiCtl; }; #ifdef DSTAR #else #define tableMode ePSIMODE_TABLE #define sectionMode ePSIMODE_SECTION #define PSIMode tDHL_PSI_Mode #endif static DHL_HANDLE DHL_SI_Monitor(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid, DS_U8 tableID, PSIMode psiMode, DS_U16 source_id = 0, bool bETT = false) { DHL_SI_HANDLE *handle = (DHL_SI_HANDLE *)DST_OS_Calloc(1, sizeof(DHL_SI_HANDLE)); handle->nRequestID = nRequestID; handle->aProcData = (PSIMultiEventProcData *)DST_OS_Calloc(1, sizeof(PSIMultiEventProcData)); handle->aProcData->err = noError; handle->aProcData->id = nRequestID; handle->aProcData->freq = RF; handle->aPsiCtl = (void **)DST_OS_Calloc(1, sizeof(void *)); #ifdef DSTAR PSIMask_t *pref = 0; if (source_id) { if (bETT == false) // EIT { DD_PSI_GetEmptyPSIMask(5,&pref); pref->entries[0].value = (tableID == 0xFF) ? 0 : tableID; pref->entries[0].matchMask = (tableID == 0xFF) ? 0 : 0xFF; pref->entries[3].value = (source_id >> 8) & 0xFF; pref->entries[3].matchMask = 0xFF; pref->entries[4].value = source_id & 0xFF; pref->entries[4].matchMask = 0xFF; } else // ETT { DD_PSI_GetEmptyPSIMask(11,&pref); pref->entries[0].value = (tableID == 0xFF) ? 0 : tableID; pref->entries[0].matchMask = (tableID == 0xFF) ? 0 : 0xFF; pref->entries[9].value = (source_id >> 8) & 0xFF; pref->entries[9].matchMask = 0xFF; pref->entries[10].value = source_id & 0xFF; pref->entries[10].matchMask = 0xFF; } T(); } else { DD_PSI_GetEmptyPSIMask(1,&pref); pref->entries[0].value = (tableID == 0xFF) ? 0 : tableID; pref->entries[0].matchMask = (tableID == 0xFF) ? 0 : 0xFF; } if (pref) { DHL_RESULT err = DD_PSI_MonitorPSIPid(hPsi, pid, psiMode, psiCRCChange, pref, 4*1024, 256, CT_MultiEventProc, (DS_U32)handle->aProcData, handle->aPsiCtl); if (err) PSI_Free(pref); if (err) DST_Printf( "\t !! %s err %d \n", __func__, err); } #else tDHL_PSI_Filter *pref = 0; if (source_id) { if (bETT == false) // EIT { DHL_PSI_AllocGenericFilter(&pref); pref->coef[0]= (tableID == 0xFF) ? 0 : tableID; pref->mask[0] = (tableID == 0xFF) ? 0 : 0xFF; pref->coef[3]= (source_id >> 8) & 0xFF; pref->mask[3] = 0xFF; pref->coef[4] = source_id & 0xFF; pref->mask[4] = 0xFF; } else // ETT { DHL_PSI_AllocGenericFilter(&pref); pref->coef[0]= (tableID == 0xFF) ? 0 : tableID; pref->mask[0] = (tableID == 0xFF) ? 0 : 0xFF; pref->coef[9]= (source_id >> 8) & 0xFF; pref->mask[9] = 0xFF; pref->coef[10] = source_id & 0xFF; pref->mask[10] = 0xFF; } T(); } else { DHL_PSI_AllocGenericFilter(&pref); pref->coef[0] = tableID; // Table ID°¡ 0xFFÀ̸é HAL¿¡¼­ MApi_DMX_SectPatternSetÀÇ ±æÀ̸¦ 0À¸·Î ÇÔ pref->mask[0] = (tableID == 0xFF) ? 0 : 0xFF; // pref->mode[0] = 0xFF; } if (pref) { DHL_RESULT err = DHL_PSI_StartMonitor(tsd, pid, psiMode, ePSIUPDATE_CRCCHANGE, pref, 4*1024, 256, CT_MultiEventProc, (DS_U32)handle->aProcData, (tDHL_PSI_ControlHandle *)handle->aPsiCtl); if (err) DST_OS_Free(&pref); } #endif return (DHL_HANDLE)handle; } DHL_HANDLE DHL_SI_MonitorPAT(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0x0000, 0x00, tableMode); } DHL_HANDLE DHL_SI_MonitorPMT(DS_U32 RF, DS_U32 nRequestID, DS_U16 Pid) { DST_Printf("%s nRequestID = %d pid = 0x%X\n", __func__, (int)nRequestID, Pid); return DHL_SI_Monitor(RF, nRequestID, Pid, 0x02, tableMode); } DHL_HANDLE DHL_SI_MonitorTVCT(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xC8, tableMode); } DHL_HANDLE DHL_SI_MonitorCVCT(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xC9, tableMode); } DHL_HANDLE DHL_SI_MonitorMGT(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xC7, tableMode); } DHL_HANDLE DHL_SI_MonitorSTT(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xCD, tableMode); } DHL_HANDLE DHL_SI_MonitorEIT(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid, DS_U16 source_id) { DST_Printf("%s nRequestID = %d pid = 0x%X source_id =0x%X\n", __func__, (int)nRequestID, pid, source_id); return DHL_SI_Monitor(RF, nRequestID, pid, 0xCB, tableMode, source_id); } DHL_HANDLE DHL_SI_MonitorETT(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid, DS_U16 source_id) { DST_Printf("%s nRequestID = %d pid = 0x%X source_id =0x%X\n", __func__, (int)nRequestID, pid, source_id); return DHL_SI_Monitor(RF, nRequestID, pid, 0xCC, tableMode, source_id, true); } DHL_HANDLE DHL_SI_MonitorRFUpdate(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0x1FF5, 0xF5, sectionMode); } DHL_HANDLE DHL_SI_MonitorSCTE_CVT(DS_U32 RF, DS_U32 nRequestID) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, 0xDE1, 0x3C, sectionMode); } DHL_HANDLE DHL_SI_MonitorSCTE_DII(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, pid, 0x3B, tableMode); } DHL_HANDLE DHL_SI_MonitorSCTE_DDB(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid) { DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); return DHL_SI_Monitor(RF, nRequestID, pid, 0x3C, sectionMode); } DHL_ERROR DHL_SI_MonitorStop(DHL_HANDLE* handle) { if (handle == 0 || *handle == 0) return DHL_FAIL_; T(); DHL_SI_HANDLE *h = (DHL_SI_HANDLE *)*handle; PSIMultiEventProcData *aProcData = h->aProcData; void **aPsiCtl = h->aPsiCtl; #ifdef DSTAR DHL_PSI_CancelMonitor(aPsiCtl[0]); #else DHL_PSI_StopMonitor((tDHL_PSI_ControlHandle)aPsiCtl[0]); #endif if (aPsiCtl) DST_OS_Free(&aPsiCtl); if (aProcData) DST_OS_Free(&aProcData); DST_OS_Free(&h); *handle = 0; return DHL_OK_; } #if 0 ____Tuner___() #endif // Æ©³Ê ½ÃÀÛ // Khz ´ÜÀ§ Á֯ļö DHL_ERROR DHL_TUN_Start(int rf, DHL_MODULATION_MODE nMode) { int freqkHz = DST_GetMHzFrequencybyIndex(rf) * 1000; if (DST_g_bUseAirFreq) { if (rf == DST_GetIndexByRFNumber(4)) freqkHz = 69 * 1000; if (rf == DST_GetIndexByRFNumber(18)) freqkHz = 497 * 1000; if (rf == DST_GetIndexByRFNumber(48)) freqkHz = 677 * 1000; } DST_Printf("%s|%d|Tune Freq = %d kHz\n", __func__, __LINE__, freqkHz); #ifdef DSTAR change_file(rf, 0, 0, 1); TunerDemod demod = DEMOD_8VSB; if (nMode == DHL_MODULATION_64QAM) demod = DEMOD_64QAM; if (nMode == DHL_MODULATION_256QAM) demod = DEMOD_256QAM; DHL_FE_Start(TUNER_FAT, freqkHz, demod, FREQ); #else tDHL_Demod demod = eDHL_DEMOD_8VSB; if (nMode == DHL_MODULATION_64QAM) demod = eDHL_DEMOD_64QAM; if (nMode == DHL_MODULATION_256QAM) demod = eDHL_DEMOD_256QAM; DHL_FE_Start(0, freqkHz, demod, 0); #endif return DHL_OK_; } // Æ©³Ê Á¾·á DHL_ERROR DHL_TUN_Stop() { #ifdef DSTAR DHL_FE_Stop(TUNER_FAT); #else DHL_FE_Stop(0); #endif return DHL_OK_; } DHL_ERROR DHL_TUNE_Info(DS_U8 RF, int *SignalStrength, bool *bLock) { #ifdef DSTAR *SignalStrength = rand() % 100; *bLock = true; #else BOOL lock; tDHL_Demod demod; DHL_FE_GetLockStatus(0, &lock, &demod); *bLock = lock ? true : false; UINT32 strength = 0; DHL_FE_GetSignalStrength(0, &strength); *SignalStrength = (int)strength; #endif return DHL_OK_; } #if 0 ____GFX___() #endif #ifdef DSTAR #if OSD_PIXEL_BPP == 16 #define DS_PIXEL_t DS_U16 #define PIXEL_FORMAT 10 //PF_RGB16 #else #define DS_PIXEL_t DS_U32 #define PIXEL_FORMAT 0 //PF_RGB32 #endif extern "C" void DHL_GFX_DrawImage( DS_U32 pBufferId, int offsetX, int offsetY, int w, int h, DS_PIXEL_t *pPixels); extern "C" void DHL_GFX_UpdateScreen(int Plane); static DS_U32 id = 0; static DS_U32 gMsgQ = 0; static void tUpdateScreen() { DS_U32 msg = 0; DS_U32 retLen; while (1) { DST_OS_ReceiveMessage_NoWait(gMsgQ, (DS_U32*)&msg, sizeof(DS_U32), &retLen); DHL_GFX_UpdateScreen(0); // µÎ°³ÀÇ Å½ºÅ©¿¡¼­ µ¿½Ã¿¡ È£ÃâÇÏ¸é ½Ã½ºÅÛ ¸ØÃã... } } static void DHL_UpdateScreen() { DS_U32 msg = 0; if (gMsgQ) DST_OS_SendMessage(gMsgQ, &msg, sizeof(DS_U32)); } void DHL_GFX_Open() { static bool bInit = false; if (bInit == false) { DHL_GFX_Init(0, 0, 0, DST_GetScreenWidth(), DST_GetScreenHeight() + 16, DST_GetScreenWidth(), DST_GetScreenHeight() + 16, PIXEL_FORMAT, &id); bInit = true; /*DS_U32 TaskID = */DST_OS_SpawnTask((void(*)(void *))tUpdateScreen, (char*)"tUpdateScreen", APP_TASK_PRIO_WIN_MGR, WIN_MGR_TASK_STACKSIZE, 0); gMsgQ = DST_OS_CreateMessageQueue("qUpdateScreen", 0, 100, sizeof(DS_U32)); } } void DHL_GFX_Draw(OSD_PIXEL_T *src, int x, int y, int w, int h) { DHL_GFX_DrawImage(id, x, y, w, h, src); DHL_UpdateScreen(); } void DHL_SetLED(bool bRed, bool bGreen) { static bool old_bRed = false; static bool old_bGreen = false; if (bRed == old_bRed && bGreen == old_bGreen) return; old_bRed = bRed; old_bGreen = bGreen; DHL_GFX_Open(); OSD_PIXEL_T *src = (OSD_PIXEL_T *)DST_OS_Calloc(DST_GetScreenWidth() * 16, sizeof(OSD_PIXEL_T)); OSD_PIXEL_T color = 0; if (bRed) { color = bGreen ? CONV32_16(0xFFFFFF00) : CONV32_16(0xFFFF0000); } else { color = bGreen ? CONV32_16(0xFF00FF00) : CONV32_16(0xFF000000); } for (int i = 0; i < DST_GetScreenWidth() * 16; i++) src[i] = color; DHL_GFX_DrawImage(id, 0, DST_GetScreenHeight(), DST_GetScreenWidth(), 16, src); DHL_UpdateScreen(); DST_OS_Free(&src); } #else extern "C" DS_U8 MsOS_Dcache_Flush(DS_U32 u32Start, DS_U32 u32Size); void DHL_GFX_Open() { static bool bInit = false; if (bInit == true) return; bInit = true; DHL_CreatePlane(0, DST_GetScreenWidth(), DST_GetScreenHeight(), eDHL_PIXELTYPE_ARGB8888); DHL_SetDisplayPlane(0); DHL_SetDisplayPlaneSD(0); } void DHL_GFX_Draw(OSD_PIXEL_T *src, int x, int y, int w, int h) { // DHL_RESULT DHL_DrawImage(tDHL_PlaneID id, int x, int y, tDHL_Image *pimg) MsOS_Dcache_Flush((DS_U32)src, w*h*4); tDHL_Image img; img.is_file = 0; img.src.image.buf = src; img.src.image.is_png = 0; img.src.image.width = w; img.src.image.height = h; DHL_DrawImage(0, x, y, &img); } void DHL_SetLED(bool bRed, bool bGreen) { bRed ? DHL_SYS_SetGPIO(41) : DHL_SYS_ResetGPIO(41); bGreen ? DHL_SYS_SetGPIO(40) : DHL_SYS_ResetGPIO(40); } #endif char *DST_GetBoardVersion(void) { char *strVersion = (char*)"R0.1"; #ifndef DSTAR // TO DO GPIO µîÀ» Àо H/W ¹öÀü ¹®ÀÚ¿­ ¹Ýȯ #endif return strVersion; } void DHL_SetCh34(DS_U8 nVal) { #ifndef DSTAR nVal ? DHL_SYS_SetGPIO(15) : DHL_SYS_ResetGPIO(15); #endif } #if 0 ____IR___() #endif static DS_U8 g_KeyPadGPIO = 0; DS_U8 DHL_GetKeyPadGPIO() { #ifndef DSTAR // TO DO // KEY PAD GPIO¸¦ Àоî¿Â´Ù // POWER = 1 UP =2 DN =4 g_KeyPadGPIO = DHL_SYS_ReadGPIO(1) ? 1:0; g_KeyPadGPIO += DHL_SYS_ReadGPIO(2) ? 2: 0; g_KeyPadGPIO += DHL_SYS_ReadGPIO(3) ? 4: 0; #endif return g_KeyPadGPIO; } #ifdef DSTAR // DSTAR¿¡¼­ NEC ۸¦ Èä³»³»±â À§ÇÑ Å½ºÅ© 110ms°£°ÝÀ¸·Î ¸®ÇÍŰ ó¸®ÇÑ´Ù. static DS_U32 DSTAR_KEY_MsgQ = 0; struct DSTAR_KEY { DS_U32 Code; DS_U32 bPressed; DS_U32 tick; }; static void tRepeatKey() { DSTAR_KEY msg ={0,0,0}; DS_U32 retLen = 0; DS_U32 tick = 0; while (1) { DST_OS_Delay(DST_OS_GetTicksPerSecond()/100); // 10ms if (DSTAR_KEY_MsgQ == 0) continue; DSTAR_KEY tmp ={0,0,0}; if (DST_OS_ReceiveMessage_NoWait(DSTAR_KEY_MsgQ, (DS_U32*)&tmp, sizeof(DSTAR_KEY), &retLen) == noError) { msg = tmp; if (msg.bPressed) { if (g_IrCallBack) g_IrCallBack(msg.Code, 0, DST_OS_GetTickCount()); } tick = DST_OS_GetTickCount(); } if (msg.bPressed == 0) continue; if (DST_OS_GetTickCount() - tick < DST_OS_GetTicksPerSecond()/10) continue; if (msg.bPressed) { if (g_IrCallBack) g_IrCallBack(msg.Code, 1, DST_OS_GetTickCount()); } tick = DST_OS_GetTickCount(); } } // DSTAR Ű Äݹé static void DSTAR_KeyCallBack(int bRemocon, DS_U32 Code, int bPressed) { DST_Printf("|%s| code = 0x%02X, bPressed = %d\n", __func__, (int)Code, bPressed); static bool bStart = true; if (bStart == true) { bStart = false; DSTAR_KEY_MsgQ = DST_OS_CreateMessageQueue("DSTAR_KEY", 0, 100, sizeof(DSTAR_KEY)); DST_OS_SpawnTask((void(*)(void *))tRepeatKey, (char*)"DSTAR_KEY", APP_TASK_PRIO_WIN_MGR, WIN_MGR_TASK_STACKSIZE, 0); } // ŰÆÐµå¸¦ Èä³»³»±â À§ÇÑ Å° // Home + - if (Code == 0xCAFE0116 || Code == 0xCAFE010E || Code ==0xCAFE010D) { // DSTAR ŰÆÐµå if (bPressed == 1) { if (Code ==0xCAFE0116) g_KeyPadGPIO = 1;// home key if (Code ==0xCAFE010E) g_KeyPadGPIO = 2;// + if (Code ==0xCAFE010D) g_KeyPadGPIO = 4;// - } else { g_KeyPadGPIO = 0; } } else { DSTAR_KEY msg; msg.Code = Code; msg.bPressed = bPressed; msg.tick = DST_OS_GetTickCount(); DST_OS_SendMessage(DSTAR_KEY_MsgQ, (DS_U32 *)&msg, sizeof(DSTAR_KEY)); } } #endif #if 0 ____OS___() #endif DS_U32 DST_OS_GetTickCount() { #ifdef DSTAR return OS_GetTickCount(); #else return DHL_OS_GetMsCount(); #endif } void DST_OS_Delay(DS_U32 Ticks) { #ifdef DSTAR OS_Delay(Ticks); #else DHL_OS_Delay(Ticks); #endif } DS_U32 DST_OS_GetTicksPerSecond() { #ifdef DSTAR return OS_GetTicksPerSecond(); #else return 1000; #endif } DS_U32 DST_OS_SpawnTask (void (*func)(void* ), char *name, DS_U16 prio, DS_U16 stacksize, DS_U32 arg) { #ifdef DSTAR return OS_SpawnTask((void (*)(DS_U32))func, name, prio, stacksize, arg); #else return DHL_OS_CreateTask(func, name, prio, stacksize, arg); #endif } DS_U32 DST_OS_ReceiveMessage_NoWait(DS_U32 qId, DS_U32 *msgBuf, DS_U32 maxLen, DS_U32 *retLen) { #ifdef DSTAR return OS_ReceiveMessage_NoWait(qId, msgBuf, maxLen, retLen); #else return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)qId, msgBuf, 0); #endif } DS_U32 DST_OS_ReceiveMessage_Wait(DS_U32 qId, DS_U32 *msgBuf, DS_U32 maxLen, DS_U32 *retLen, DS_U32 timeOut) { #ifdef DSTAR return OS_ReceiveMessage_Wait(qId, msgBuf, maxLen, retLen, timeOut); #else return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)qId, msgBuf, timeOut == 0 ? DHL_TIMEOUT_FOREVER : timeOut); #endif } DS_U32 DST_OS_SendMessage (DS_U32 qId, DS_U32 *pBuffer, DS_U32 nBytes) { #ifdef DSTAR return OS_SendMessage(qId, pBuffer, nBytes); #else return DHL_OS_SendMessage((DHL_OS_MSGQ_ID)qId, pBuffer, nBytes); #endif } DS_U32 DST_OS_DeleteMessageQueue(DS_U32 qId) { #ifdef DSTAR return OS_DeleteMessageQueue(qId); #else DHL_OS_DeleteMessageQueue((DHL_OS_MSGQ_ID)qId); return 0; #endif } DS_U32 DST_OS_CreateMessageQueue (const char *name, DS_U32 option, DS_U32 maxMessage, DS_U32 messageLength) { #ifdef DSTAR return OS_CreateMessageQueue (name, option, maxMessage, messageLength); #else return (DS_U32)DHL_OS_CreateMessageQueue (name, option, maxMessage, messageLength); #endif } DS_U32 DST_OS_CreateLock(char *name) { #ifdef DSTAR return OS_CreateMutex(name); #else return (DS_U32)DHL_OS_CreateMutexSemaphore(name); #endif } void DST_OS_Lock(DS_U32 id) { #ifdef DSTAR OS_TakeMutex(id); #else DHL_OS_TakeSemaphore((void*)id, DHL_TIMEOUT_FOREVER); #endif } void DST_OS_Unlock(DS_U32 id) { #ifdef DSTAR OS_GiveMutex(id); #else DHL_OS_GiveSemaphore((void*)id); #endif } #if 0 ____MEMORY___() #endif // LEVEL 0 Æ÷ÆÃ ·¹À̾î // Ç÷§Æû¿¡ µû¶ó Æ÷ÆÃÇØ¾ß ÇÏ´Â ·¹À̾î // malloc°ú free´Â ¿©±â¿¡¼­ Æ÷ÆÃÇÑ´Ù. #ifdef DSTAR static void *_DST_OS_MallocDirect(int size) { return malloc(size); } static void _DST_OS_FreeDirect( void *ptr) { free(ptr); } #else extern "C" void *MsOS_AllocateMemory2(DS_U32 size); extern "C" void MsOS_FreeMemory2(void *ptr); extern "C" void print_heap_status(void); static void *_DST_OS_MallocDirect(int size) { #if 0 return MsOS_AllocateMemory2(size); #else if (size == 0) return 0; void *p = MsOS_AllocateMemory2(size); if (p == 0) { print_heap_status(); DST_OS_PrintMemUnit(); } return p; #endif } static void _DST_OS_FreeDirect( void *ptr) { MsOS_FreeMemory2(ptr); } #endif // LEVEL 1 C Ç¥ÁØÇÔ¼ö ±¸Çö // malloc free calloc realloc À» C ÀÎÅÍÆäÀ̽º¿Í µ¿ÀÏÇÏ°Ô ±¸Çö // freetype sqlite µî Æ÷ÆÃ½Ã¿¡ È£Ãâ // C Ç¥ÁØÇÔ¼ö¿Í ȣȯµÇ´Â ¸Þ¸ð¸® ÇÔ¼ö (¶óÀ̺귯¸® Æ÷ÆÃ¿ë) // C Æ÷ÆÃÀ» À§ÇØ extern "C" ·Î ¼±¾ð extern "C" void *DST_OS_MallocDirect(int size) // malloc { if (size == 0) return 0; int *p = (int*)_DST_OS_MallocDirect(size + sizeof(int)); memset(p, 0, size + sizeof(int)); p[0] = size; return (void *)&p[1]; } extern "C" int DST_OS_MemSize(void *ptr) { if(!ptr) return 0; int *p = (int*)ptr; p--; return p[0]; } extern "C" void *DST_OS_CallocDirect(int num, int size) // calloc { return DST_OS_MallocDirect(num * size); } extern "C" void *DST_OS_ReallocDirect(void *ptr, int size) // realloc { if (!ptr) return DST_OS_MallocDirect(size); // ÀÌÀü¿¡ ÇÒ´çµÈ ¸Þ¸ð¸®°¡ ¾ø´Â °æ¿ì int prev_size = DST_OS_MemSize(ptr); if (prev_size > size) return ptr; // »õ·Î ÇÒ´çµÉ ¸Þ¸ð¸®°¡ ´õ ÀÛÀº °æ¿ì void *p = DST_OS_MallocDirect(size); memcpy(p, ptr, prev_size); DST_OS_FreeDirect(ptr); return p; } extern "C" void DST_OS_FreeDirect( void *ptr) // free { if (!ptr) return; int *p = (int*)ptr; p--; _DST_OS_FreeDirect(p); } // LEVEL 2 APP È£Ãâ ÇÔ¼ö ±¸Çö // ¸Þ¸ð¸® ¸®½ºÆ®¸¦ »ý¼ºÇؼ­ È®ÀÎÇÒ ¼ö ÀÖ´Ù. #define MAX_FUNC_NAME 32 // Çã¿ëÇÒ ÃÖ´ë ÇÔ¼ö À̸§ ±æÀÌ #define MAX_COUNT 2000 // °ü¸®ÇÒ °¹¼ö static struct MEM_LIST { char func[MAX_FUNC_NAME+1]; int nLine; void *p; int nSize; unsigned int tick; } memlist[MAX_COUNT]; void DST_OS_PrintMemUnit(void) { int i = 0, nSum = 0, nCount = 0; DST_Printf("|------------+----------+----------------------------------+------|\n"); DST_Printf("| Address | Size | Function | Line |\n"); DST_Printf("|------------+----------+----------------------------------+------|\n"); for (i = 0; i < MAX_COUNT; i++) { if (memlist[i].p == 0) continue; DST_Printf("| 0x%08X | %8d | %32s | %4d | %4d |\n", (int)memlist[i].p, memlist[i].nSize, memlist[i].func, memlist[i].nLine, (int)(DST_OS_GetTickCount() - memlist[i].tick)/100 ); nSum+=memlist[i].nSize; nCount++; } DST_Printf("|------------+----------+----------------------------------+------|\n"); DST_Printf("| %10d | %8d | |\n", nCount, nSum); DST_Printf("|------------+----------+----------------------------------+------|\n"); } static void Add_MemUint(const char* func, int nLine, void *p, int nSize) { int i = 0; for (i = 0; i < MAX_COUNT; i++) { if (memlist[i].p != 0) continue; if (strlen(func) > MAX_FUNC_NAME) { memcpy(memlist[i].func, func, MAX_FUNC_NAME); memlist[i].func[MAX_FUNC_NAME] = 0; } else { strcpy(memlist[i].func, func); } memlist[i].nLine = nLine; memlist[i].p = p; memlist[i].nSize = nSize; memlist[i].tick = DST_OS_GetTickCount(); break; } //Print_MemUnit(); } static void Del_MemUnit(void *p, const char * func, int nLine) { int i = 0; if (p == 0) return; for (i = 0; i < MAX_COUNT; i++) { if (memlist[i].p != p) continue; memlist[i].p = 0; break; } if (i >= MAX_COUNT) { #if 0 DST_Printf("\n\n\n\nTry to delete unallocated memory 0x%08X. %s %d\n\n\n", (int)p, func, nLine); Print_All_MemUnit(); DST_OS_Delay(5); #endif } //Print_MemUnit(); } void *_DST_OS_Malloc(unsigned int size, const char* func, int nLine) { void *p = 0; if (size == 0) return 0; p = DST_OS_MallocDirect(size); if (p == 0) { DST_Printf("%s|%s|%d|size =%d|Out of memory\n", __func__, func, nLine, size); DST_OS_PrintMemUnit(); } else { Add_MemUint(func, nLine, p, size); } return p; } void *_DST_OS_Calloc(unsigned int count, unsigned int size, const char* func, int nLine) { void *p = _DST_OS_Malloc(count * size, func, nLine); if (!p) return 0; memset(p, 0, count*size); return p; } void _DST_OS_Free(void *where, const char* func, int nLine) { if (where == 0) return; Del_MemUnit(where, func, nLine); DST_OS_FreeDirect(where); where = 0; } #if 0 ____POWER___() #endif void DHL_SYS_Off() { #ifdef DSTAR DHL_SYS_Terminate(); exit(1); #else DHL_SYS_Reset(eDHL_RESET_Standby); #endif } void DHL_SYS_Reboot() { #ifdef DSTAR DHL_SYS_Reset(); exit(1); #else DHL_SYS_Reset(eDHL_RESET_Reboot); #endif } // Video Ãâ·Â On / OFF void DHL_POWER_Display(bool bOn) { T(); DST_Printf("%s %s\n", __func__, bOn ? "On" : "Off"); #ifdef DSTAR #else #endif } // Flash Memory¿¡¼­ Bank ¹øÈ£¸¦ Àоî¿Â´Ù. // Flash ¸Þ¸ð¸®ÀÇ Ã¹¹øÂ° ¹ÙÀÌÆ®°¡ 1ÀÌ ¾Æ´Ï¸é Bank0 1À̸é Bank1ÀÌ´Ù. static DS_U8 g_BankNumber = 0xFF; // Return °ªÀÌ 0À̸é Bank0 1À̸é Bank1 bool DHL_INFO_GetBankNumber() { if (g_BankNumber == 0xFF) { DS_U8* buff = DHL_Flash_Read(FLASH_BANK_SELECT_POS, 1); g_BankNumber = (buff[0]==1) ? 1 : 0; DST_OS_Free(&buff); } return g_BankNumber ==1 ? 1 : 0; } void DHL_INFO_SetBankNumber(DS_U8 data) { if (g_BankNumber == data) return; DHL_Flash_Write(FLASH_BANK_SELECT_POS, 1, & data); DST_Printf("%s %d\n", __func__, data); g_BankNumber = data; } // Flash Memory¿¡¼­ LAST POWER STATE¸¦ Àоî¿Â´Ù. // Flash ¸Þ¸ð¸®ÀÇ Ã¹¹øÂ° ¹ÙÀÌÆ®°¡ 0À̸é OFF »óÅ 0ÀÌ ¾Æ´Ï¸é ONÀÌ´Ù. static DS_U8 g_LastPowerState = 0xFF; bool DHL_INFO_GetLastPowerState() { if (g_LastPowerState == 0xFF) { DS_U8* buff = DHL_Flash_Read(FLASH_LAST_POWER_POS, 1); g_LastPowerState = (buff[0]!=0) ? 1 : 0; DST_OS_Free(&buff); } return g_LastPowerState ? true : false; } void DHL_INFO_SetLastPowerState(bool bOn) { DS_U8 data = bOn ? 1 : 0; if (g_LastPowerState == data) return; DHL_Flash_Write(FLASH_LAST_POWER_POS, 1, & data); DST_Printf("%s %d\n", __func__, data); g_LastPowerState = data; } #if 0 ____Flash_Memory___() #endif static void FlashLock(bool bLock) { static DS_U32 sema4 = 0; if (sema4== 0) sema4 = DST_OS_CreateLock((char*)"flash"); bLock ? DST_OS_Lock(sema4) : DST_OS_Unlock(sema4); } #ifndef DSTAR extern "C" unsigned char MDrv_SERFLASH_Read(unsigned long u32FlashAddr, unsigned long u32FlashSize, unsigned char *user_buffer); extern "C" unsigned char MDrv_SERFLASH_SectorErase(unsigned long u32StartAddr, unsigned long u32EndAddr); extern "C" unsigned char MDrv_SERFLASH_Write(unsigned long u32FlashAddr, unsigned long u32FlashSize, unsigned char *user_buffer); #endif // 4Kbyte ¼½ÅÍ ´ÜÀ§·Î Write 0~1023 ±îÁö ¼½Å͹øÈ£ static void _FlashWrite(DS_U16 nSector, DS_U16 nSize, DS_U8* data) { DS_U8* rdata = DHL_Flash_Read(nSector * 4096, 4096); DS_U8 wdata[4096]; memcpy(wdata, rdata, 4096); memcpy(wdata, data, nSize); // ERASE ÇÒ Çʿ䰡 ÀÖ´ÂÁö °Ë»çÇÑ´Ù. bool bNeedErase = false; for (int i=0; i < 4096; i++) { if (!((~rdata[i]) & wdata[i])) continue; bNeedErase = true; break; } if (bNeedErase == true) { T(); // FLASH ERASE memset(rdata, 0xFF, 4096); #ifdef DSTAR FILE *fp = fopen("flash.bin" , "rb+"); fseek(fp, nSector * 4096, SEEK_SET); fwrite(rdata, 1, 4096, fp); fclose(fp); #else // TO DO Flash Erase if (MDrv_SERFLASH_SectorErase(nSector * 4096, nSector * 4096 + 4096 - 1) != 1) { DST_Printf("|%s|Err|MDrv_SERFLASH_SectorErase(start:0x%x, end:0x%x)\n",__func__, nSector * 4096, nSector * 4096 + 4096 - 1); } #endif } int nStart = -1; for (int i = 0; i < 4096; i++) { if (rdata[i] != wdata[i]) { if (nStart == -1) nStart = i; } if (rdata[i] == wdata[i] || i == 4096-1) { if (nStart != -1) { #ifdef DSTAR FILE *fp = fopen("flash.bin" , "rb+"); fseek(fp, nSector * 4096 + nStart, SEEK_SET); fwrite(&wdata[nStart], 1, i - nStart+1, fp); fclose(fp); #else //__FlashWrite(nSector * 4096 + nStart, i - nStart, &wdata[nStart]); // TO DO Flash Write if (MDrv_SERFLASH_Write(nSector * 4096 + nStart, i - nStart, &wdata[nStart]) != 1) { DST_Printf("|%s|Err|MDrv_SERFLASH_Write(addr:0x%x, len:0x%x)\n",__func__, nSector * 4096 + nStart, i - nStart); } #endif nStart = -1; } } } DST_OS_Free(&rdata); } // address´Â 4Kbyte ´ÜÀ§°ªÀ¸·Î ½ÃÀÛÇØ¾ß ÇÑ´Ù. // nSize´Â °¡´ÉÇÑ ±æÀÌ·Î Á¦ÇÑÀÌ ¾ø´Ù. void DHL_Flash_Write(DS_U32 address, DS_U32 nSize, DS_U8 *data) { if (address%4096 != 0) { DST_Printf("%s|invalid address = %d(0x%X) nSize = %d\n", __func__, (int)address, (int)address, (int)nSize); return; } FlashLock(true); // 4Kbyte ´ÜÀ§·Î ³ª´©¾î¼­ È£ÃâÇÑ´Ù. for (DS_U32 i = 0; i < nSize; i+= 4096) { DS_U32 nSize2 = 4096; if (i+nSize2 > nSize) nSize2 = nSize - i; _FlashWrite((address + i)/4096, nSize2, &data[i]); } FlashLock(false); } // È£ÃâÇÑ ÂÊ¿¡¼­ ¸Þ¸ð¸® ÇØÁ¦ ÇÊ¿ä // Ç×»ó Writeº¸´Ù ¸ÕÀú È£ÃâµÇ¹Ç·Î ÃʱâÈ­ Äڵ嵵 Æ÷ÇÔÇÑ´Ù. DS_U8* DHL_Flash_Read(DS_U32 address, DS_U32 nSize) { FlashLock(true); DS_U8* data = (DS_U8*)DST_OS_Malloc(nSize); #ifdef DSTAR // ÆÄÀÏÀÌ ¾øÀ¸¸é »ý¼ºÇÑ´Ù. FILE *fp = fopen("flash.bin" , "rb"); int nFileLength = 0; if (fp) { fseek(fp, 0, SEEK_END); nFileLength = ftell(fp); fclose(fp); } if (nFileLength != FLASH_TOTAL_SIZE) { fp = fopen("flash.bin", "wb"); DS_U8 *tmp = (DS_U8*)DST_OS_Malloc(FLASH_TOTAL_SIZE); memset(tmp,0xFF, FLASH_TOTAL_SIZE); fwrite(tmp, 1, FLASH_TOTAL_SIZE, fp); DST_OS_Free(&tmp); fclose(fp); } fp = fopen("flash.bin" , "rb"); fseek(fp, address, SEEK_SET); fread(data, 1, nSize, fp); fclose(fp); #else // TO DO Flash Init DHL_SYS_PlatformInit¿¡¼­ ÀÌ¹Ì È£Ãâ // TO DO Flash Read if (MDrv_SERFLASH_Read(address, nSize, data) != 1) { DST_Printf("|%s|Err|MDrv_SERFLASH_Read(addr:0x%x, len:0x%x)\n",__func__, (int)address, (int)nSize); } #endif FlashLock(false); return data; } // ministd¿¡¼­ Áö¿øÇÏÁö ¾Ê´Â stdc ÇÔ¼ö int atoi(char *st) { bool bMinus = false; if (*st == '-' ) { bMinus = true; st++; } int i = 0; while((*st >= '0' && *st <= '9')) { i = i * 10 + (*(st)) - '0'; st++; } return bMinus ? -i : i; } #ifdef DSTAR // CC FeedingÀ» À§ÇÑ Å×½ºÆ® ÇÔ¼ö #include #define SIZE_BUFF (1024*32) static void ttest__cc() { FILE *fp = fopen("/home/megakiss/stream/KBS.tp", "rb"); if (fp == 0) return; while(1) { OS_Delay(OS_GetTicksPerSecond()/100); DS_U8 buff[SIZE_BUFF*2]; int n = fread(buff, 1,SIZE_BUFF, fp); if (n != SIZE_BUFF) { fclose(fp); return; } _DHL_CCCallBack( SIZE_BUFF, buff); } } static void ttest_cc() { while (1) { OS_Delay(OS_GetTicksPerSecond()); ttest__cc(); } } void test_cc() { static int taskID = 0; if (taskID) return; taskID = OS_SpawnTask((void (*)(DS_U32)) ttest_cc, (char*)"ttest_cc", APP_TASK_PRIO_WIN_MGR, WIN_MGR_TASK_STACKSIZE, 0); } #endif // CC FeedingÀ» À§ÇÑ Å×½ºÆ® ÇÔ¼ö