| 1 | #include "dst_eroum_interface.h" |
|---|
| 2 | |
|---|
| 3 | #ifdef DSTAR |
|---|
| 4 | |
|---|
| 5 | #include "dsthallocal.h" |
|---|
| 6 | #include "dsthalerror.h" |
|---|
| 7 | #include "dsthalPsiProcess.h" |
|---|
| 8 | #include "dsthalcap.h" |
|---|
| 9 | #include "dsthalsys.h" |
|---|
| 10 | #include "dsthaldev.h" |
|---|
| 11 | |
|---|
| 12 | #else |
|---|
| 13 | |
|---|
| 14 | #include "DHL_SYS_Impl.h" |
|---|
| 15 | #include "DHL_SYS.h" |
|---|
| 16 | #include "DHL_PSI.h" |
|---|
| 17 | #include "DHL_FE.h" |
|---|
| 18 | #include "DHL_UIO.h" |
|---|
| 19 | #include "DHL_AVCAP.h" |
|---|
| 20 | |
|---|
| 21 | #ifdef __cplusplus |
|---|
| 22 | extern "C" { |
|---|
| 23 | #endif |
|---|
| 24 | |
|---|
| 25 | #include "DHL_Graphic.h" |
|---|
| 26 | |
|---|
| 27 | #ifdef __cplusplus |
|---|
| 28 | } |
|---|
| 29 | #endif |
|---|
| 30 | |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | #include "DST_ISDBT_ChannelTask.h" |
|---|
| 34 | #include "DST_CommonAPI.h" |
|---|
| 35 | #include "DST_HostInterface.h" |
|---|
| 36 | |
|---|
| 37 | #include "DST_WinManagerTask.h" |
|---|
| 38 | #include "sqlite3.h" |
|---|
| 39 | #include "DST_UserInterface.h" |
|---|
| 40 | |
|---|
| 41 | static DHL_SignalInfoCallBack g_SignalInfoCallBack = 0; |
|---|
| 42 | static DHL_VideoStartCallBack g_VideoStartCallBack = 0; |
|---|
| 43 | static DHL_AudioStartCallBack g_AudioStartCallBack = 0; |
|---|
| 44 | static DHL_SiCallBack g_SiCallBack = 0; |
|---|
| 45 | static DHL_CCCallBack g_CCCallBack = 0; |
|---|
| 46 | static DHL_IrCallBack g_IrCallBack = 0; |
|---|
| 47 | |
|---|
| 48 | #ifdef DSTAR |
|---|
| 49 | DHL_PSI_HANDLE hPsi = 0; |
|---|
| 50 | #else |
|---|
| 51 | tDHL_TSD tsd = 0; |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | /*extern "C" */void change_file(int num, int bReadList, int bForce, int bCont); |
|---|
| 55 | |
|---|
| 56 | #ifdef DSTAR |
|---|
| 57 | 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) |
|---|
| 58 | { |
|---|
| 59 | if (g_SignalInfoCallBack == 0) return; |
|---|
| 60 | DHL_SOURCE_ASEPCT as = DHL_SOURCE_UNKNOWN; |
|---|
| 61 | switch (Aspect) |
|---|
| 62 | { |
|---|
| 63 | case DHL_CAP_SRC_ASPECT_16_9: |
|---|
| 64 | as = DHL_SOURCE_16x9; |
|---|
| 65 | break; |
|---|
| 66 | case DHL_CAP_SRC_ASPECT_SQUARE: |
|---|
| 67 | case DHL_CAP_SRC_ASPECT_4_3: |
|---|
| 68 | as = DHL_SOURCE_4x3; |
|---|
| 69 | break; |
|---|
| 70 | default: |
|---|
| 71 | break; |
|---|
| 72 | } |
|---|
| 73 | g_SignalInfoCallBack(hRes, vRes, RefreshRate, bInterlaced ? true : false, as); |
|---|
| 74 | } |
|---|
| 75 | #endif |
|---|
| 76 | |
|---|
| 77 | // 2012.12.04 USER DATA¿¡¼ CC µ¥ÀÌÅÍ ÃßÃâ |
|---|
| 78 | static void DHL_UserData_DTVCCPacketBlock(DS_U8 service_number, DS_U8 nSize, DS_U8 *buff) |
|---|
| 79 | { |
|---|
| 80 | #if 0 |
|---|
| 81 | DST_Printf("%s service_number = %d nSize = %d %X\n", __func__, service_number, nSize, buff); |
|---|
| 82 | for (int i = 0; i<nSize; i++) DST_Printf("%02X ", buff[i]); |
|---|
| 83 | DST_Printf("\n"); |
|---|
| 84 | #endif |
|---|
| 85 | //ZASÀÇ °æ¿ì 1¹ø ¼ºñ½º¸¸ ó¸®ÇÑ´Ù. |
|---|
| 86 | if (service_number != 1) return; |
|---|
| 87 | if (g_CCCallBack) g_CCCallBack((DS_U8*)buff, (int)nSize); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | static void DHL_UserData_DTVCCPacket(DS_U8 nSize, DS_U8 *buff) |
|---|
| 91 | { |
|---|
| 92 | static DS_U8 nSeqNumber = 0xFF; |
|---|
| 93 | static DS_U8 prev_nSize; |
|---|
| 94 | static DS_U8 prev_buff[256]; |
|---|
| 95 | |
|---|
| 96 | if (nSize == prev_nSize && memcmp(buff, prev_buff, nSize) == 0) return; // ÀÌÀüµ¥ÀÌÅÍ¿Í µ¿ÀÏÇÏ¸é ¹«½Ã |
|---|
| 97 | prev_nSize = nSize; |
|---|
| 98 | memcpy(prev_buff, buff, nSize); |
|---|
| 99 | |
|---|
| 100 | DS_U8 seq_number = (buff[0] >> 6) & 0x03; |
|---|
| 101 | // DST_Printf("seq_number = %d\n", seq_number); |
|---|
| 102 | if (nSeqNumber != 0xFF && ((nSeqNumber+1)%4) != seq_number) |
|---|
| 103 | { |
|---|
| 104 | DST_Printf("Seq Error\n"); |
|---|
| 105 | if (g_CCCallBack) g_CCCallBack((DS_U8*)0, -1); |
|---|
| 106 | } |
|---|
| 107 | nSeqNumber = seq_number; |
|---|
| 108 | if (nSize < 3) return; |
|---|
| 109 | DS_U8 block_size = buff[1] & 0x1F; // Fugure 7 in EIA-708B |
|---|
| 110 | if (block_size < 1) return; |
|---|
| 111 | DS_U8 service_number = (buff[1]>>5) & 0x07; |
|---|
| 112 | if (service_number < 1) return; |
|---|
| 113 | if (service_number == 7) |
|---|
| 114 | { |
|---|
| 115 | if (nSize < 3) return; |
|---|
| 116 | service_number += (buff[2] & 0x3F); // extended service_number Figure 8 |
|---|
| 117 | if (block_size > nSize-2) block_size = nSize-2; // block size º¸Á¤ |
|---|
| 118 | DHL_UserData_DTVCCPacketBlock(service_number, block_size, &buff[3]); |
|---|
| 119 | } |
|---|
| 120 | if (block_size > nSize-1) block_size = nSize-1; // block size º¸Á¤ |
|---|
| 121 | DHL_UserData_DTVCCPacketBlock(service_number, block_size, &buff[2]); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | static void DHL_UserData_DTVCC(bool bStart, DS_U8 cc_data_1, DS_U8 cc_data_2) |
|---|
| 125 | { |
|---|
| 126 | //DST_Printf("%s %d %02X %02X\n", __func__, bStart, cc_data_1, cc_data_2); |
|---|
| 127 | static DS_U8 nPacketSize = 0; |
|---|
| 128 | static DS_U8 data[256]; |
|---|
| 129 | static DS_U8 nReceiveCount = 0; |
|---|
| 130 | if (bStart) |
|---|
| 131 | { |
|---|
| 132 | nPacketSize = (cc_data_1 & 0x3F); |
|---|
| 133 | nPacketSize = (nPacketSize == 0) ? 128 : nPacketSize*2; // Figure 4 |
|---|
| 134 | data[0] = cc_data_1; |
|---|
| 135 | data[1] = cc_data_2; |
|---|
| 136 | nReceiveCount = 2; |
|---|
| 137 | } |
|---|
| 138 | else |
|---|
| 139 | { |
|---|
| 140 | if (nPacketSize == 0) return; |
|---|
| 141 | if (nPacketSize > nReceiveCount) |
|---|
| 142 | { |
|---|
| 143 | data[nReceiveCount] = cc_data_1; |
|---|
| 144 | nReceiveCount++; |
|---|
| 145 | } |
|---|
| 146 | if (nPacketSize > nReceiveCount) |
|---|
| 147 | { |
|---|
| 148 | data[nReceiveCount] = cc_data_2; |
|---|
| 149 | nReceiveCount++; |
|---|
| 150 | } |
|---|
| 151 | if (nReceiveCount >= nPacketSize) |
|---|
| 152 | { |
|---|
| 153 | DHL_UserData_DTVCCPacket(nReceiveCount, data); |
|---|
| 154 | nPacketSize = 0; |
|---|
| 155 | nReceiveCount = 0; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | #ifdef DSTAR |
|---|
| 161 | static void DHL_UserData_ClosedCaption(DS_U16 nSize, DS_U8 *buff) |
|---|
| 162 | { |
|---|
| 163 | #if 0 |
|---|
| 164 | DST_Printf("%s %d %X\n", __func__, nSize, buff); |
|---|
| 165 | for (int i = 0; i<nSize; i++) DST_Printf("%02X ", buff[i]); |
|---|
| 166 | DST_Printf("\n"); |
|---|
| 167 | #endif |
|---|
| 168 | DS_U8 cc_count = buff[0] & 0x1F; |
|---|
| 169 | if (nSize < cc_count * 3 + 2) return; |
|---|
| 170 | int i; |
|---|
| 171 | for ( i = 0; i < cc_count; i++) |
|---|
| 172 | { |
|---|
| 173 | bool cc_valid = (buff[i*3+2] & 0x04) ? true : false; |
|---|
| 174 | DS_U8 cc_type = (buff[i*3+2] & 0x03); |
|---|
| 175 | if (cc_valid == false) continue; |
|---|
| 176 | switch (cc_type) // EIA-708B #7 |
|---|
| 177 | { |
|---|
| 178 | case 0: // line21 field 1 |
|---|
| 179 | break; |
|---|
| 180 | case 1: // line21 field 2 |
|---|
| 181 | break; |
|---|
| 182 | case 2: // dtvcc data |
|---|
| 183 | DHL_UserData_DTVCC(false, buff[i*3+3], buff[i*3+4]); |
|---|
| 184 | break; |
|---|
| 185 | case 3: // dtvcc start |
|---|
| 186 | DHL_UserData_DTVCC(true, buff[i*3+3], buff[i*3+4]); |
|---|
| 187 | break; |
|---|
| 188 | default: |
|---|
| 189 | break; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | #endif |
|---|
| 194 | |
|---|
| 195 | #ifdef DSTAR |
|---|
| 196 | static void DHL_UserData_Callback(DS_U16 nSize, DS_U8 *buff) |
|---|
| 197 | { |
|---|
| 198 | int i; |
|---|
| 199 | #if 0 |
|---|
| 200 | DST_Printf("%s %d %X\n", __func__, nSize, buff); |
|---|
| 201 | for (i = 0; i<nSize; i++) DST_Printf("%02X ", (char*)buff[i]); |
|---|
| 202 | DST_Printf("\n"); |
|---|
| 203 | #endif |
|---|
| 204 | |
|---|
| 205 | #ifdef DSTAR |
|---|
| 206 | for ( i=0; i < nSize - 10; i++) |
|---|
| 207 | { |
|---|
| 208 | // user_data_start_code = 0x000001B2 a_53b 5.2.3 |
|---|
| 209 | if (buff[i] == 0x00 && buff[i+1] == 0x00 && buff[i+2] == 0x01 && buff[i+3] == 0xB2) |
|---|
| 210 | { |
|---|
| 211 | // ATSC_identifier = 0x47413934 |
|---|
| 212 | // user_data_type_code = 0x03 |
|---|
| 213 | if (buff[i+4] == 0x47 && buff[i+5] == 0x41 && buff[i+6] == 0x39 && buff[i+7] == 0x34 && buff[i+8] == 0x03) |
|---|
| 214 | { |
|---|
| 215 | DHL_UserData_ClosedCaption(nSize - i - 9, &buff[i+9]); |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | #else |
|---|
| 220 | for (i=0; i < nSize - 6; i++) |
|---|
| 221 | { |
|---|
| 222 | if (buff[i+0] == 0x47 && buff[i+1] == 0x41 && buff[i+2] == 0x39 && buff[i+3] == 0x34 && buff[i+4] == 0x03) |
|---|
| 223 | { |
|---|
| 224 | DHL_UserData_ClosedCaption(nSize - i - 5, &buff[i+5]); |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | #endif |
|---|
| 228 | } |
|---|
| 229 | #endif |
|---|
| 230 | |
|---|
| 231 | #ifdef DSTAR |
|---|
| 232 | static void _DHL_CCCallBack(DS_U32 nSize, void *buffer) |
|---|
| 233 | { |
|---|
| 234 | DHL_UserData_Callback((DS_U16)nSize, (DS_U8*)buffer); |
|---|
| 235 | } |
|---|
| 236 | #endif |
|---|
| 237 | |
|---|
| 238 | #ifdef DSTAR |
|---|
| 239 | |
|---|
| 240 | static void _DHL_VideoStartCallBack() |
|---|
| 241 | { |
|---|
| 242 | if (g_VideoStartCallBack == 0) return; |
|---|
| 243 | g_VideoStartCallBack(); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | #else |
|---|
| 247 | |
|---|
| 248 | #define USER_DATA_COUNT_MAX 8 |
|---|
| 249 | static int g_UserDataSize[USER_DATA_COUNT_MAX]; |
|---|
| 250 | static DS_U8 g_UserData[USER_DATA_COUNT_MAX][256]; |
|---|
| 251 | static int g_UserDataHead = 0; |
|---|
| 252 | static int g_UserDataTail = 0; |
|---|
| 253 | static void tUserData() |
|---|
| 254 | { |
|---|
| 255 | while (1) |
|---|
| 256 | { |
|---|
| 257 | DST_OS_Delay(10); // 10ms |
|---|
| 258 | if (g_UserDataHead == g_UserDataTail) continue; |
|---|
| 259 | // DST_Printf("g_UserDataTail = %d\n", g_UserDataTail); |
|---|
| 260 | int nLen = g_UserDataSize[g_UserDataTail]; |
|---|
| 261 | DS_U8 *pdata = g_UserData[g_UserDataTail]; |
|---|
| 262 | int i; |
|---|
| 263 | for (i = 0; i < nLen; i+=3) |
|---|
| 264 | { |
|---|
| 265 | switch (pdata[i]) |
|---|
| 266 | { |
|---|
| 267 | case 0: // line21 field 1 |
|---|
| 268 | break; |
|---|
| 269 | case 1: // line21 field 2 |
|---|
| 270 | break; |
|---|
| 271 | case 2: // dtvcc data |
|---|
| 272 | DHL_UserData_DTVCC(false, pdata[i+1], pdata[i+2]); |
|---|
| 273 | break; |
|---|
| 274 | case 3: // dtvcc start |
|---|
| 275 | DHL_UserData_DTVCC(true, pdata[i+1], pdata[i+2]); |
|---|
| 276 | break; |
|---|
| 277 | default: |
|---|
| 278 | break; |
|---|
| 279 | } |
|---|
| 280 | } |
|---|
| 281 | g_UserDataTail = (g_UserDataTail >= USER_DATA_COUNT_MAX-1) ? 0 : g_UserDataTail+1; |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | static void _DHL_AV_CallBack(tDHL_AVCallbackType cb_type, DS_U32 param) |
|---|
| 286 | { |
|---|
| 287 | if (cb_type == eDHL_CB_VideoSeqHdr && g_SignalInfoCallBack) |
|---|
| 288 | { |
|---|
| 289 | if (param == 0) return; |
|---|
| 290 | tDHL_VideoSeqHdr *pSeq = (tDHL_VideoSeqHdr *)param; |
|---|
| 291 | DST_Printf("-- Video Sequence Header info -- \n"); |
|---|
| 292 | DST_Printf("aspect_ratio_information : %d \n", pSeq->aspect_ratio_information); |
|---|
| 293 | DST_Printf("frame_rate_code : %d \n", pSeq->frame_rate_code); |
|---|
| 294 | DST_Printf("horizontal_size : %d \n", pSeq->horizontal_size); |
|---|
| 295 | DST_Printf("vertical_size : %d \n", pSeq->vertical_size); |
|---|
| 296 | DST_Printf("progressive_sequence : %d \n", pSeq->progressive_sequence); |
|---|
| 297 | |
|---|
| 298 | g_SignalInfoCallBack(pSeq->horizontal_size, pSeq->vertical_size, |
|---|
| 299 | pSeq->frame_rate_code, pSeq->progressive_sequence ? false : true, |
|---|
| 300 | (pSeq->aspect_ratio_information == DAR_9_16) ? DHL_SOURCE_16x9 : DHL_SOURCE_4x3); |
|---|
| 301 | } |
|---|
| 302 | if (cb_type == eDHL_CB_FirstVideoShow && g_VideoStartCallBack) |
|---|
| 303 | { |
|---|
| 304 | g_VideoStartCallBack(); |
|---|
| 305 | } |
|---|
| 306 | if (cb_type == eDHL_CB_VideoUserData) |
|---|
| 307 | { |
|---|
| 308 | if (param == 0) return; |
|---|
| 309 | tDHL_UserData *pud=(tDHL_UserData *)param; |
|---|
| 310 | if (pud->pdata == 0) return; |
|---|
| 311 | if (pud->hdr.payload_size > 256) return; |
|---|
| 312 | int nLen = pud->hdr.payload_size; |
|---|
| 313 | nLen = (nLen/3)*3; |
|---|
| 314 | g_UserDataSize[g_UserDataHead] = nLen; |
|---|
| 315 | memcpy(g_UserData[g_UserDataHead], pud->pdata, nLen); |
|---|
| 316 | // DST_Printf("g_UserDataHead = %d\n", g_UserDataHead); |
|---|
| 317 | g_UserDataHead = (g_UserDataHead >= USER_DATA_COUNT_MAX-1) ? 0 : g_UserDataHead+1; |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | #endif |
|---|
| 322 | |
|---|
| 323 | #if 0 |
|---|
| 324 | ____System___() |
|---|
| 325 | #endif |
|---|
| 326 | |
|---|
| 327 | #ifdef DSTAR |
|---|
| 328 | static void DSTAR_KeyCallBack(int bRemocon, DS_U32 Code, int bPressed); |
|---|
| 329 | #endif |
|---|
| 330 | |
|---|
| 331 | // SYSTEM ÃʱâÈ |
|---|
| 332 | /*extern "C" */void dbg_print(int val); |
|---|
| 333 | DHL_ERROR DHL_SYS_Initialize() |
|---|
| 334 | { |
|---|
| 335 | #ifdef DSTAR |
|---|
| 336 | #else |
|---|
| 337 | DHL_SYS_PlatformInit(); // ÃʱâÈ |
|---|
| 338 | int DHL_NVM_FlashGetSize(int flashId); |
|---|
| 339 | FLASH_TOTAL_SIZE = DHL_NVM_FlashGetSize(0); |
|---|
| 340 | if (FLASH_TOTAL_SIZE < 8*1024*1024) FLASH_BANK1_POS = FLASH_BANK0_POS; |
|---|
| 341 | DST_OS_SpawnTask((void(*)(void *))tUserData, (char*)"tUserData", APP_TASK_USER_DATA, WIN_MGR_TASK_STACKSIZE, 0); |
|---|
| 342 | #endif |
|---|
| 343 | return DHL_OK_; |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | typedef void (*irCallback)(unsigned int KeyCode, unsigned int repeat); |
|---|
| 347 | static void IRCallback(unsigned int code, unsigned int repeat); |
|---|
| 348 | extern void IR_Open(irCallback ircallback); |
|---|
| 349 | |
|---|
| 350 | DHL_ERROR DHL_SYS_TV_Open( |
|---|
| 351 | DHL_SignalInfoCallBack signal, |
|---|
| 352 | DHL_VideoStartCallBack video, |
|---|
| 353 | DHL_AudioStartCallBack audio, |
|---|
| 354 | DHL_SiCallBack si, |
|---|
| 355 | DHL_CCCallBack cc, |
|---|
| 356 | DHL_IrCallBack Ir) |
|---|
| 357 | { |
|---|
| 358 | // ÄÝ¹é µî·Ï |
|---|
| 359 | g_SignalInfoCallBack = signal; |
|---|
| 360 | g_VideoStartCallBack = video; |
|---|
| 361 | g_AudioStartCallBack = audio; |
|---|
| 362 | g_SiCallBack = si; |
|---|
| 363 | g_CCCallBack = cc; |
|---|
| 364 | g_IrCallBack = Ir; |
|---|
| 365 | // ÃʱâÈ ÀÛ¾÷ |
|---|
| 366 | #ifdef DSTAR |
|---|
| 367 | DHL_DISP_PresetVideoOutputFormat(DHL_VIDEO_WXGA); |
|---|
| 368 | DHL_SYS_Initiate(); |
|---|
| 369 | DHL_PSI_Init(&hPsi); |
|---|
| 370 | DHL_FE_Init(TUNER_FAT); |
|---|
| 371 | DHL_DTV_Init(); |
|---|
| 372 | DHL_DMX_Init(); |
|---|
| 373 | DHL_DMX_Start(); |
|---|
| 374 | DHL_CAP_PresetAudioInput(DHL_CAP_DTV0_AUDIO); |
|---|
| 375 | DHL_DEV_InitSmartCardInterface((void*)0); // ÀÌ ¶óÀÎÀ» Á¦°ÅÇϸé DSTAR ¼¼¸¶Æ÷¾î ¿¡·¯°¡ ³´Ù. |
|---|
| 376 | DHL_CAP_Init(); |
|---|
| 377 | DHL_CAP_StartVideoEx(DHL_CAP_DTV0_VIDEO, DHL_CAP_VIDEO_NONE, DHL_PIPMODE_NONE, DHL_PIP_NO_PIP); |
|---|
| 378 | DHL_DTV_StopAudio(); |
|---|
| 379 | DHL_CAP_ChangeAudioInput(DHL_CAP_DTV0_AUDIO); |
|---|
| 380 | DHL_CAP_StartAudio(); |
|---|
| 381 | DHL_DTV_PresetCallback((void *) _DHL_VideoStartCallBack, DHL_CB_NOTIFY_VSTARTING, 1); |
|---|
| 382 | DHL_CAP_PresetCallback2((DHL_CAP_CBFUNC2_t)_DHL_SignalInfoCallBack); |
|---|
| 383 | DHL_DTV_PresetCallback((void *) _DHL_CCCallBack, DHL_CB_VDC_CCUDP, 0); |
|---|
| 384 | DHL_DTV_InitCC(); |
|---|
| 385 | DHL_DTV_EnableCC(); |
|---|
| 386 | DHL_IR_Init(DHL_IR_NEC); |
|---|
| 387 | DHL_IR_SetCbFunc(DSTAR_KeyCallBack); |
|---|
| 388 | void test_cc(); |
|---|
| 389 | test_cc(); |
|---|
| 390 | #else |
|---|
| 391 | DHL_AV_SetCallback(eDHL_CB_VideoSeqHdr, _DHL_AV_CallBack); |
|---|
| 392 | DHL_AV_SetCallback(eDHL_CB_FirstVideoShow, _DHL_AV_CallBack); |
|---|
| 393 | DHL_AV_SetCallback(eDHL_CB_VideoUserData, _DHL_AV_CallBack); |
|---|
| 394 | // IR ŽºÅ© »ý¼º |
|---|
| 395 | static void tIRTask(); |
|---|
| 396 | DST_OS_SpawnTask((void(*)(void *))tIRTask, (char*)"tIRTask", APP_TASK_PRIO_IR, WIN_MGR_TASK_STACKSIZE, 0); |
|---|
| 397 | IR_Open(IRCallback); |
|---|
| 398 | #endif |
|---|
| 399 | return DHL_OK_; |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | DHL_ERROR DHL_SYS_TV_Close() |
|---|
| 403 | { |
|---|
| 404 | return DHL_OK_; |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | #ifdef DSTAR |
|---|
| 408 | #else |
|---|
| 409 | #define PSIDataArray_t tDHL_PSI_DataArray |
|---|
| 410 | #define DHL_TBL_HANDLE tDHL_PSI_ControlHandle |
|---|
| 411 | #define PSIEvent tDHL_PSI_Event |
|---|
| 412 | #define psiDataReceived ePSIEVENT_DATARECEIVED |
|---|
| 413 | #endif |
|---|
| 414 | |
|---|
| 415 | typedef struct PSIMultiEventProcData_t |
|---|
| 416 | { |
|---|
| 417 | int err; |
|---|
| 418 | DS_U32 hEvent; |
|---|
| 419 | DS_U32 id; |
|---|
| 420 | DS_U32 freq; |
|---|
| 421 | DS_U16 sID; |
|---|
| 422 | } PSIMultiEventProcData; |
|---|
| 423 | |
|---|
| 424 | static void CT_MultiEventProc(PSIEvent event, DHL_TBL_HANDLE hTblHandle, DS_U32 userParam) |
|---|
| 425 | { |
|---|
| 426 | if (!hTblHandle || event != psiDataReceived) return; |
|---|
| 427 | PSIDataArray_t *desc; |
|---|
| 428 | if (DHL_PSI_ReadPSIData(hTblHandle, &desc) != DHL_OK) return; |
|---|
| 429 | PSIMultiEventProcData *procData = (PSIMultiEventProcData *) userParam; |
|---|
| 430 | if (g_SiCallBack) g_SiCallBack(procData->freq, procData->id, desc->sectPtr, 0); |
|---|
| 431 | DHL_PSI_FreePSIData(desc); |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | #if 0 |
|---|
| 435 | ____Video___() |
|---|
| 436 | #endif |
|---|
| 437 | |
|---|
| 438 | static int prev_lock = 0; // Tuner Lock »óÅÂ |
|---|
| 439 | // Video ½ÃÀÛ |
|---|
| 440 | static bool g_power_display = true; |
|---|
| 441 | static bool bVideoStart = false; |
|---|
| 442 | DHL_ERROR DHL_VID_Start(DS_U16 VideoPID, DS_U16 PcrPID, DHL_VIDEO_TYPE type) |
|---|
| 443 | { |
|---|
| 444 | if (bVideoStart == true) DHL_VID_Stop(); |
|---|
| 445 | if (g_power_display == false) return DHL_FAIL_; |
|---|
| 446 | if (prev_lock == 0) return DHL_FAIL_; |
|---|
| 447 | bVideoStart = true; |
|---|
| 448 | #ifdef DSTAR |
|---|
| 449 | DHL_DTV_StartVideoEx2(VideoPID, PcrPID, type ); |
|---|
| 450 | #else |
|---|
| 451 | tDHL_VideoCodingType nType = eDHL_VIDEO_TYPE_H264; |
|---|
| 452 | switch (type) |
|---|
| 453 | { |
|---|
| 454 | case DHL_VIDEO_MPEG1: |
|---|
| 455 | nType = eDHL_VIDEO_TYPE_MPEG1; |
|---|
| 456 | break; |
|---|
| 457 | case DHL_VIDEO_MPEG2: |
|---|
| 458 | nType = eDHL_VIDEO_TYPE_MPEG2; |
|---|
| 459 | break; |
|---|
| 460 | default: |
|---|
| 461 | break; |
|---|
| 462 | } |
|---|
| 463 | T(); |
|---|
| 464 | DHL_AV_VideoStart(0, VideoPID, PcrPID, nType); |
|---|
| 465 | T(); |
|---|
| 466 | #endif |
|---|
| 467 | return DHL_OK_; |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | // Video Á¾·á |
|---|
| 471 | DHL_ERROR DHL_VID_Stop() |
|---|
| 472 | { |
|---|
| 473 | if (bVideoStart == false) return DHL_OK_; |
|---|
| 474 | bVideoStart = false; |
|---|
| 475 | #ifdef DSTAR |
|---|
| 476 | DHL_DTV_StopVideo(); |
|---|
| 477 | #else |
|---|
| 478 | T(); |
|---|
| 479 | DHL_AV_VideoStop(0); |
|---|
| 480 | #endif |
|---|
| 481 | return DHL_OK_; |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | // Video Mute ºñµð¿À ȸéÀ» °ËÀº»öÀ¸·Î º¸ÀÌÁö ¾Êµµ·Ï ÇÔ. CVBS¿¡¼µµ µ¿ÀÏ |
|---|
| 485 | // bMute = false --> Video Unmute |
|---|
| 486 | // bMute = true --> Video Mute |
|---|
| 487 | DHL_ERROR DHL_VID_Mute(bool bMute) |
|---|
| 488 | { |
|---|
| 489 | #ifndef DSTAR |
|---|
| 490 | DST_Printf("DHL_VID_Mute %d\n", bMute); |
|---|
| 491 | DHL_AV_VideoHide(0, bMute ? 1 : 0); |
|---|
| 492 | #endif |
|---|
| 493 | return DHL_OK_; |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | // Video Alive µðÄÚµùµÈ ºñµð¿À°¡ ÀÖ´ÂÁö ¿©ºÎ¸¦ ¾Ë·ÁÁÖ´Â ÇÔ¼ö |
|---|
| 497 | bool DHL_VID_Alive() |
|---|
| 498 | { |
|---|
| 499 | #ifndef DSTAR |
|---|
| 500 | tDHL_VideoStatus vs; |
|---|
| 501 | DHL_AV_VideoGetStatus(0, &vs); |
|---|
| 502 | if (!vs.bOutputExist) return false; |
|---|
| 503 | #endif |
|---|
| 504 | return true; |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | // Video Aspect ¼³Á¤ |
|---|
| 508 | // ÀÔ·Â ASPECT(4:3 16:9) ¿¡µû¶ó °¢°¢ ³× °¡Áö ¸ðµå°¡ ÀÖÀ½ |
|---|
| 509 | DHL_ERROR DHL_VID_Aspect(DHL_ASPECT_RATIO ar, DS_U16 w, DS_U16 h) |
|---|
| 510 | { |
|---|
| 511 | #ifndef DSTAR |
|---|
| 512 | tDHL_DispARC adj = eDHL_ARC_FULLSCREEN; |
|---|
| 513 | switch (ar) |
|---|
| 514 | { |
|---|
| 515 | case DHL_ASPECT_4x3_4x3: |
|---|
| 516 | adj = eDHL_ARC_FULLSCREEN; |
|---|
| 517 | printf("DHL_ASPECT_4x3_4x3 eDHL_ARC_FULLSCREEN\n"); |
|---|
| 518 | break; |
|---|
| 519 | case DHL_ASPECT_16x9_4x3_WIDE: |
|---|
| 520 | adj = eDHL_ARC_LETTERBOX; |
|---|
| 521 | printf("DHL_ASPECT_16x9_4x3_WIDE eDHL_ARC_FULLSCREEN\n"); |
|---|
| 522 | break; |
|---|
| 523 | case DHL_ASPECT_16x9_4x3_NORMAL: |
|---|
| 524 | adj = eDHL_ARC_FULLSCREEN; |
|---|
| 525 | printf("DHL_ASPECT_16x9_4x3_NORMAL eDHL_ARC_SIDEBAR\n"); |
|---|
| 526 | break; |
|---|
| 527 | case DHL_ASPECT_16x9_4x3_ZOOM: |
|---|
| 528 | adj = eDHL_ARC_ZOOM2; |
|---|
| 529 | printf("DHL_ASPECT_16x9_4x3_ZOOM eDHL_ARC_ZOOM1\n"); |
|---|
| 530 | break; |
|---|
| 531 | default: |
|---|
| 532 | break; |
|---|
| 533 | } |
|---|
| 534 | DHL_AV_VideoSetARC(adj, adj); |
|---|
| 535 | #endif |
|---|
| 536 | return DHL_OK_; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | #if 0 |
|---|
| 540 | ____Audio___() |
|---|
| 541 | #endif |
|---|
| 542 | |
|---|
| 543 | // Audio ½ÃÀÛ |
|---|
| 544 | // PcrPID == 0 Àΰæ¿ì Audio Only ä³Î |
|---|
| 545 | static bool bAudioStart = false; |
|---|
| 546 | DHL_ERROR DHL_AUD_Start(DS_U16 AudioPid, DS_U16 PcrPID, DHL_AUDIO_TYPE type) |
|---|
| 547 | { |
|---|
| 548 | DST_Printf("%s(0x%X, 0x%X, %d)\n", __func__, AudioPid, PcrPID, type); |
|---|
| 549 | if (bAudioStart == true) DHL_AUD_Stop(); |
|---|
| 550 | bAudioStart = true; |
|---|
| 551 | #ifndef DSTAR |
|---|
| 552 | tDHL_AudioCodingType nType = eDHL_AUDIO_TYPE_AAC_LATM; |
|---|
| 553 | switch (type) |
|---|
| 554 | { |
|---|
| 555 | case DHL_AUDIO_MPEG1: |
|---|
| 556 | nType = eDHL_AUDIO_TYPE_MPEG_1; |
|---|
| 557 | break; |
|---|
| 558 | case DHL_AUDIO_MPEG2: |
|---|
| 559 | nType = eDHL_AUDIO_TYPE_MPEG_2; |
|---|
| 560 | break; |
|---|
| 561 | case DHL_AUDIO_AAC_ADTS: |
|---|
| 562 | nType = eDHL_AUDIO_TYPE_AAC_ADTS; |
|---|
| 563 | break; |
|---|
| 564 | case DHL_AUDIO_AAC_LATM: |
|---|
| 565 | nType = eDHL_AUDIO_TYPE_AAC_LATM; |
|---|
| 566 | break; |
|---|
| 567 | case DHL_AUDIO_AC3: |
|---|
| 568 | nType = eDHL_AUDIO_TYPE_AC3; |
|---|
| 569 | break; |
|---|
| 570 | default: |
|---|
| 571 | break; |
|---|
| 572 | } |
|---|
| 573 | DHL_AV_AudioStart(AudioPid, PcrPID, nType); |
|---|
| 574 | #endif |
|---|
| 575 | return DHL_OK_; |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | // Audio Á¾·á |
|---|
| 579 | DHL_ERROR DHL_AUD_Stop() |
|---|
| 580 | { |
|---|
| 581 | if (bAudioStart == false) return DHL_OK_; |
|---|
| 582 | bAudioStart = false; |
|---|
| 583 | #ifndef DSTAR |
|---|
| 584 | T(); |
|---|
| 585 | DHL_AV_AudioStop(); |
|---|
| 586 | #endif |
|---|
| 587 | return DHL_OK_; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | // Audio Volume, 0 is mute |
|---|
| 591 | DHL_ERROR DHL_AUD_Volume(DS_U8 nVal) |
|---|
| 592 | { |
|---|
| 593 | static DS_U8 prev = 200; |
|---|
| 594 | if (prev == nVal) return DHL_OK_; |
|---|
| 595 | prev = nVal; |
|---|
| 596 | // DST_Printf("%s|%d\n", __func__, nVal); |
|---|
| 597 | #ifndef DSTAR |
|---|
| 598 | // T(); |
|---|
| 599 | DHL_AV_AudioSetUserVolumeRange(0,100); |
|---|
| 600 | if (nVal == 0) |
|---|
| 601 | { |
|---|
| 602 | DHL_AV_AudioSetVolume(0); |
|---|
| 603 | DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_GPIO, TRUE); |
|---|
| 604 | } |
|---|
| 605 | else |
|---|
| 606 | { |
|---|
| 607 | DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_GPIO, FALSE); |
|---|
| 608 | DHL_AV_AudioSetVolume(nVal); |
|---|
| 609 | } |
|---|
| 610 | #endif |
|---|
| 611 | return DHL_OK_; |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | // Audio Alive µðÄÚµùµÈ ¿Àµð¿À°¡ ÀÖ´ÂÁö ¿©ºÎ¸¦ ¾Ë·ÁÁÖ´Â ÇÔ¼ö |
|---|
| 615 | bool DHL_AUD_Alive() |
|---|
| 616 | { |
|---|
| 617 | #ifndef DSTAR |
|---|
| 618 | tDHL_AudioStatus as; |
|---|
| 619 | DHL_AV_AudioGetStatus(&as); |
|---|
| 620 | if (!as.bOutputExist) return false; |
|---|
| 621 | #endif |
|---|
| 622 | return true; |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | // Play ÁßÀÎ ¿Àµð¿ÀÀÇ ¸ðµå¸¦ ¹ÝȯÇÑ´Ù. |
|---|
| 626 | DHL_AUDIO_MODE DHL_AUD_GetMode() |
|---|
| 627 | { |
|---|
| 628 | return DHL_AUDIO_STEREO; |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | #if 0 |
|---|
| 632 | ____SI___() |
|---|
| 633 | #endif |
|---|
| 634 | |
|---|
| 635 | typedef struct |
|---|
| 636 | { |
|---|
| 637 | DS_U32 nRequestID; |
|---|
| 638 | PSIMultiEventProcData *aProcData; |
|---|
| 639 | void **aPsiCtl; |
|---|
| 640 | } DHL_SI_HANDLE; |
|---|
| 641 | |
|---|
| 642 | #ifdef DSTAR |
|---|
| 643 | #else |
|---|
| 644 | #define tableMode ePSIMODE_TABLE |
|---|
| 645 | #define sectionMode ePSIMODE_SECTION |
|---|
| 646 | #define PSIMode tDHL_PSI_Mode |
|---|
| 647 | #endif |
|---|
| 648 | |
|---|
| 649 | 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*/) |
|---|
| 650 | { |
|---|
| 651 | DHL_SI_HANDLE *handle = (DHL_SI_HANDLE *)DST_OS_Calloc(1, sizeof(DHL_SI_HANDLE)); |
|---|
| 652 | handle->nRequestID = nRequestID; |
|---|
| 653 | handle->aProcData = (PSIMultiEventProcData *)DST_OS_Calloc(1, sizeof(PSIMultiEventProcData)); |
|---|
| 654 | handle->aProcData->err = noError; |
|---|
| 655 | handle->aProcData->id = nRequestID; |
|---|
| 656 | handle->aProcData->freq = RF; |
|---|
| 657 | handle->aPsiCtl = (void **)DST_OS_Calloc(1, sizeof(void *)); |
|---|
| 658 | #ifdef DSTAR |
|---|
| 659 | PSIMask_t *pref = 0; |
|---|
| 660 | if (source_id) |
|---|
| 661 | { |
|---|
| 662 | if (bETT == false) // EIT |
|---|
| 663 | { |
|---|
| 664 | DD_PSI_GetEmptyPSIMask(5,&pref); |
|---|
| 665 | pref->entries[0].value = (tableID == 0xFF) ? 0 : tableID; |
|---|
| 666 | pref->entries[0].matchMask = (tableID == 0xFF) ? 0 : 0xFF; |
|---|
| 667 | pref->entries[3].value = (source_id >> 8) & 0xFF; |
|---|
| 668 | pref->entries[3].matchMask = 0xFF; |
|---|
| 669 | pref->entries[4].value = source_id & 0xFF; |
|---|
| 670 | pref->entries[4].matchMask = 0xFF; |
|---|
| 671 | } |
|---|
| 672 | else // ETT |
|---|
| 673 | { |
|---|
| 674 | DD_PSI_GetEmptyPSIMask(11,&pref); |
|---|
| 675 | pref->entries[0].value = (tableID == 0xFF) ? 0 : tableID; |
|---|
| 676 | pref->entries[0].matchMask = (tableID == 0xFF) ? 0 : 0xFF; |
|---|
| 677 | pref->entries[9].value = (source_id >> 8) & 0xFF; |
|---|
| 678 | pref->entries[9].matchMask = 0xFF; |
|---|
| 679 | pref->entries[10].value = source_id & 0xFF; |
|---|
| 680 | pref->entries[10].matchMask = 0xFF; |
|---|
| 681 | } |
|---|
| 682 | T(); |
|---|
| 683 | } |
|---|
| 684 | else |
|---|
| 685 | { |
|---|
| 686 | DD_PSI_GetEmptyPSIMask(1,&pref); |
|---|
| 687 | pref->entries[0].value = (tableID == 0xFF) ? 0 : tableID; |
|---|
| 688 | pref->entries[0].matchMask = (tableID == 0xFF) ? 0 : 0xFF; |
|---|
| 689 | } |
|---|
| 690 | if (pref) |
|---|
| 691 | { |
|---|
| 692 | DHL_RESULT err = DD_PSI_MonitorPSIPid(hPsi, pid, psiMode, psiCRCChange, |
|---|
| 693 | pref, 4*1024, 256, CT_MultiEventProc, (DS_U32)handle->aProcData, handle->aPsiCtl); |
|---|
| 694 | if (err) PSI_Free(pref); |
|---|
| 695 | if (err) DST_Printf( "\t !! %s err %d \n", __func__, err); |
|---|
| 696 | } |
|---|
| 697 | #else |
|---|
| 698 | tDHL_PSI_Filter *pref = 0; |
|---|
| 699 | if (source_id) |
|---|
| 700 | { |
|---|
| 701 | if (bETT == false) // EIT |
|---|
| 702 | { |
|---|
| 703 | DHL_PSI_AllocGenericFilter(&pref); |
|---|
| 704 | pref->coef[0]= (tableID == 0xFF) ? 0 : tableID; |
|---|
| 705 | pref->mask[0] = (tableID == 0xFF) ? 0xFF : 0x00; |
|---|
| 706 | pref->coef[3]= (source_id >> 8) & 0xFF; |
|---|
| 707 | pref->mask[3] = 0x00; |
|---|
| 708 | pref->coef[4] = source_id & 0xFF; |
|---|
| 709 | pref->mask[4] = 0x00; |
|---|
| 710 | } |
|---|
| 711 | else // ETT |
|---|
| 712 | { |
|---|
| 713 | DHL_PSI_AllocGenericFilter(&pref); |
|---|
| 714 | pref->coef[0]= (tableID == 0xFF) ? 0 : tableID; |
|---|
| 715 | pref->mask[0] = (tableID == 0xFF) ? 0xFF : 0x00; |
|---|
| 716 | pref->coef[9]= (source_id >> 8) & 0xFF; |
|---|
| 717 | pref->mask[9] = 0x00; |
|---|
| 718 | pref->coef[10] = source_id & 0xFF; |
|---|
| 719 | pref->mask[10] = 0x00; |
|---|
| 720 | } |
|---|
| 721 | } |
|---|
| 722 | else |
|---|
| 723 | { |
|---|
| 724 | DHL_PSI_AllocGenericFilter(&pref); |
|---|
| 725 | pref->coef[0] = tableID; // Table ID°¡ 0xFFÀ̸é HAL¿¡¼ MApi_DMX_SectPatternSetÀÇ ±æÀ̸¦ 0À¸·Î ÇÔ |
|---|
| 726 | pref->mask[0] = (tableID == 0xFF) ? 0xFF : 0x00; |
|---|
| 727 | // pref->mode[0] = 0xFF; |
|---|
| 728 | } |
|---|
| 729 | if (pref) |
|---|
| 730 | { |
|---|
| 731 | DHL_RESULT err = DHL_PSI_StartMonitor(tsd, pid, psiMode, ePSIUPDATE_CRCCHANGE, |
|---|
| 732 | pref, 4*1024, 256, CT_MultiEventProc, (DS_U32)handle->aProcData, (tDHL_PSI_ControlHandle *)handle->aPsiCtl); |
|---|
| 733 | if (err) DST_OS_Free(&pref); |
|---|
| 734 | } |
|---|
| 735 | #endif |
|---|
| 736 | return (DHL_HANDLE)handle; |
|---|
| 737 | } |
|---|
| 738 | |
|---|
| 739 | DHL_HANDLE DHL_SI_MonitorPAT(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 740 | { |
|---|
| 741 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 742 | return DHL_SI_Monitor(RF, nRequestID, 0x0000, 0x00, tableMode, 0, false); |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | DHL_HANDLE DHL_SI_MonitorPMT(DS_U32 RF, DS_U32 nRequestID, DS_U16 Pid, DS_U16 source_id) |
|---|
| 746 | { |
|---|
| 747 | DST_Printf("%s nRequestID = %d pid = 0x%X\n", __func__, (int)nRequestID, Pid); |
|---|
| 748 | return DHL_SI_Monitor(RF, nRequestID, Pid, 0x02, tableMode, source_id, false); |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | DHL_HANDLE DHL_SI_MonitorTVCT(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 752 | { |
|---|
| 753 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 754 | return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xC8, tableMode, 0, false); |
|---|
| 755 | } |
|---|
| 756 | |
|---|
| 757 | #if CVCT_SUPPORT |
|---|
| 758 | DHL_HANDLE DHL_SI_MonitorCVCT(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 759 | { |
|---|
| 760 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 761 | return 0; |
|---|
| 762 | } |
|---|
| 763 | #endif |
|---|
| 764 | |
|---|
| 765 | #if EPG_SUPPORT |
|---|
| 766 | DHL_HANDLE DHL_SI_MonitorMGT(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 767 | { |
|---|
| 768 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 769 | return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xC7, tableMode, 0, false); |
|---|
| 770 | } |
|---|
| 771 | #endif |
|---|
| 772 | |
|---|
| 773 | DHL_HANDLE DHL_SI_MonitorSTT(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 774 | { |
|---|
| 775 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 776 | return DHL_SI_Monitor(RF, nRequestID, 0x1FFB, 0xCD, sectionMode, 0, false); |
|---|
| 777 | } |
|---|
| 778 | |
|---|
| 779 | #if EPG_SUPPORT |
|---|
| 780 | DHL_HANDLE DHL_SI_MonitorEIT(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid, DS_U16 source_id) |
|---|
| 781 | { |
|---|
| 782 | DST_Printf("%s nRequestID = %d pid = 0x%X source_id =0x%X\n", __func__, (int)nRequestID, pid, source_id); |
|---|
| 783 | return DHL_SI_Monitor(RF, nRequestID, pid, 0xCB, tableMode, source_id, false); |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | DHL_HANDLE DHL_SI_MonitorETT(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid, DS_U16 source_id) |
|---|
| 787 | { |
|---|
| 788 | DST_Printf("%s nRequestID = %d pid = 0x%X source_id =0x%X\n", __func__, (int)nRequestID, pid, source_id); |
|---|
| 789 | return DHL_SI_Monitor(RF, nRequestID, pid, 0xCC, tableMode, source_id, true); |
|---|
| 790 | } |
|---|
| 791 | #endif |
|---|
| 792 | |
|---|
| 793 | DHL_HANDLE DHL_SI_MonitorRFUpdate(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 794 | { |
|---|
| 795 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 796 | return DHL_SI_Monitor(RF, nRequestID, 0x1FF5, 0xF5, sectionMode, 0, false); |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | DHL_HANDLE DHL_SI_MonitorSCTE_CVT(DS_U32 RF, DS_U32 nRequestID) |
|---|
| 800 | { |
|---|
| 801 | DST_Printf("%s nRequestID = %d\n", __func__, (int)nRequestID); |
|---|
| 802 | #ifdef DSTAR |
|---|
| 803 | return DHL_SI_Monitor(RF, nRequestID, 8160, 0x3C, sectionMode, 0, false); // ¼°æ¹æ¼Û |
|---|
| 804 | #else // CMB ¿¡¼ PID ÇÒ´ç¹Þ°í Á¤È®ÇÑ °ªÀ¸·Î ¼öÁ¤ÇØ¾ß ÇÔ |
|---|
| 805 | //return DHL_SI_Monitor(RF, nRequestID, 0xDF1, 0x3C, sectionMode, 0, false); |
|---|
| 806 | //return DHL_SI_Monitor(RF, nRequestID, 0x3A2, 0x3C, sectionMode, 0, false); // ±Ý°¹æ¼Û |
|---|
| 807 | //return DHL_SI_Monitor(RF, nRequestID, 0xDF1, 0x3C, sectionMode, 0, false); // CMB¿Í °°°Ô |
|---|
| 808 | return DHL_SI_Monitor(RF, nRequestID, 0x1E5E, 0x3C, sectionMode, 0, false); // Ƽºê·Îµå |
|---|
| 809 | #endif |
|---|
| 810 | } |
|---|
| 811 | |
|---|
| 812 | DHL_HANDLE DHL_SI_MonitorSCTE_DII(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid) |
|---|
| 813 | { |
|---|
| 814 | DST_Printf("%s nRequestID = %d 0x%X\n", __func__, (int)nRequestID, pid); |
|---|
| 815 | return DHL_SI_Monitor(RF, nRequestID, pid, 0x3B, tableMode, 0, false);// CMB¿Í °°°Ô |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | DHL_HANDLE DHL_SI_MonitorSCTE_DDB(DS_U32 RF, DS_U32 nRequestID, DS_U16 pid) |
|---|
| 819 | { |
|---|
| 820 | DST_Printf("%s nRequestID = %d 0x%X\n", __func__, (int)nRequestID, pid); |
|---|
| 821 | return DHL_SI_Monitor(RF, nRequestID, pid, 0x3C, sectionMode, 0, false); // CMB¿Í °°°Ô |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | DHL_ERROR DHL_SI_MonitorStop(DHL_HANDLE* handle) |
|---|
| 825 | { |
|---|
| 826 | if (handle == 0 || *handle == 0) return DHL_FAIL_; |
|---|
| 827 | T(); |
|---|
| 828 | DHL_SI_HANDLE *h = (DHL_SI_HANDLE *)*handle; |
|---|
| 829 | PSIMultiEventProcData *aProcData = h->aProcData; |
|---|
| 830 | void **aPsiCtl = h->aPsiCtl; |
|---|
| 831 | #ifdef DSTAR |
|---|
| 832 | DHL_PSI_CancelMonitor(aPsiCtl[0]); |
|---|
| 833 | #else |
|---|
| 834 | DHL_PSI_StopMonitor((tDHL_PSI_ControlHandle)aPsiCtl[0]); |
|---|
| 835 | #endif |
|---|
| 836 | if (aPsiCtl) DST_OS_Free(&aPsiCtl); |
|---|
| 837 | if (aProcData) DST_OS_Free(&aProcData); |
|---|
| 838 | DST_OS_Free(&h); |
|---|
| 839 | *handle = 0; |
|---|
| 840 | return DHL_OK_; |
|---|
| 841 | } |
|---|
| 842 | |
|---|
| 843 | #if 0 |
|---|
| 844 | ____Tuner___() |
|---|
| 845 | #endif |
|---|
| 846 | |
|---|
| 847 | // Æ©³Ê ½ÃÀÛ |
|---|
| 848 | // Khz ´ÜÀ§ Á֯ļö |
|---|
| 849 | static DS_U32 tuner_start_tick = 0; |
|---|
| 850 | DHL_ERROR DHL_TUN_Start(int rf, DHL_MODULATION_MODE nMode) |
|---|
| 851 | { |
|---|
| 852 | int freqkHz = DST_GetMHzFrequencybyIndex(rf) * 1000; |
|---|
| 853 | if (DST_g_bUseAirFreq) |
|---|
| 854 | { |
|---|
| 855 | if (rf == DST_GetIndexByRFNumber(4)) freqkHz = 69 * 1000; |
|---|
| 856 | if (rf == DST_GetIndexByRFNumber(18)) freqkHz = 497 * 1000; |
|---|
| 857 | if (rf == DST_GetIndexByRFNumber(48)) freqkHz = 677 * 1000; |
|---|
| 858 | } |
|---|
| 859 | DST_Printf("%s|%d|Tune Freq = %d kHz\n", __func__, __LINE__, freqkHz); |
|---|
| 860 | #ifdef DSTAR |
|---|
| 861 | change_file(rf, 0, 0, 1); |
|---|
| 862 | TunerDemod demod = DEMOD_8VSB; |
|---|
| 863 | if (nMode == DHL_MODULATION_64QAM) demod = DEMOD_64QAM; |
|---|
| 864 | if (nMode == DHL_MODULATION_256QAM) demod = DEMOD_256QAM; |
|---|
| 865 | DHL_FE_Start(TUNER_FAT, freqkHz, demod, FREQ); |
|---|
| 866 | #else |
|---|
| 867 | static bool bInit = false; |
|---|
| 868 | if (bInit == false) |
|---|
| 869 | { |
|---|
| 870 | bInit = true; |
|---|
| 871 | T(); |
|---|
| 872 | DHL_FE_Init(); |
|---|
| 873 | T(); |
|---|
| 874 | } |
|---|
| 875 | tDHL_Demod demod = eDHL_DEMOD_8VSB; |
|---|
| 876 | #if 1 // ¼°æ¹æ¼ÛÀº µ¥ÀÌÅÍ Ã¤³Îµµ 8VSBÀ̱⶧¹®¿¡ ¸ðµÎ 8VSB °íÁ¤À¸·Î ÇÔ |
|---|
| 877 | if (nMode == DHL_MODULATION_64QAM) demod = eDHL_DEMOD_64QAM; |
|---|
| 878 | if (nMode == DHL_MODULATION_256QAM) demod = eDHL_DEMOD_256QAM; |
|---|
| 879 | #endif |
|---|
| 880 | T(); |
|---|
| 881 | DHL_FE_Start(0, freqkHz, demod, 0); |
|---|
| 882 | T(); |
|---|
| 883 | #endif |
|---|
| 884 | tuner_start_tick = DST_OS_GetTickCount(); |
|---|
| 885 | return DHL_OK_; |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | // Æ©³Ê Á¾·á |
|---|
| 889 | DHL_ERROR DHL_TUN_Stop() |
|---|
| 890 | { |
|---|
| 891 | #ifdef DSTAR |
|---|
| 892 | DHL_FE_Stop(TUNER_FAT); |
|---|
| 893 | #else |
|---|
| 894 | DHL_FE_Stop(0); |
|---|
| 895 | #endif |
|---|
| 896 | return DHL_OK_; |
|---|
| 897 | } |
|---|
| 898 | |
|---|
| 899 | DHL_ERROR DHL_TUNE_Info(DS_U8 RF, int *SignalStrength, bool *bLock, int *nPower, int *nSNR) |
|---|
| 900 | { |
|---|
| 901 | |
|---|
| 902 | #ifdef DSTAR |
|---|
| 903 | *SignalStrength = rand() % 100; |
|---|
| 904 | *bLock = true; |
|---|
| 905 | *nPower = rand() % 100; |
|---|
| 906 | #else |
|---|
| 907 | int i; |
|---|
| 908 | static int prev_snr[5]; |
|---|
| 909 | // static int prev_lock = 0; |
|---|
| 910 | if (tuner_start_tick > DST_OS_GetTickCount()) tuner_start_tick = DST_OS_GetTickCount(); |
|---|
| 911 | if (DST_OS_GetTickCount() - tuner_start_tick < DST_OS_GetTicksPerSecond()/10) // 100ms À̳»¿¡´Â È£ÃâÇÏÁö ¸»ÀÚ |
|---|
| 912 | { |
|---|
| 913 | *bLock = false; |
|---|
| 914 | *SignalStrength = 0; |
|---|
| 915 | for (i=0; i < 5; i++) prev_snr[i] = -1; |
|---|
| 916 | prev_lock = 0; |
|---|
| 917 | return DHL_OK_; |
|---|
| 918 | } |
|---|
| 919 | |
|---|
| 920 | int lock = 0, snr = 0, power = 0; |
|---|
| 921 | DHL_RESULT dhl_fe_get_sig_info_detail(int *lock, int *snr, int* power); |
|---|
| 922 | dhl_fe_get_sig_info_detail(&lock, &snr, &power); |
|---|
| 923 | if (prev_lock != lock) |
|---|
| 924 | { |
|---|
| 925 | DST_Printf("tuner lock = %d %d0msec\n", lock, DST_OS_GetTickCount() - tuner_start_tick); |
|---|
| 926 | prev_lock = lock; |
|---|
| 927 | } |
|---|
| 928 | // DST_Printf("power = %d %d0msec\n", power, DST_OS_GetTickCount() - tuner_start_tick); |
|---|
| 929 | if (lock == 0 || snr > 20000) snr = 0; // ¿¡·¯°ªÀ¸·Î ¹«½ÃÇÑ´Ù. |
|---|
| 930 | *nSNR = snr; |
|---|
| 931 | for (i=0; i < 4; i++) prev_snr[i] = prev_snr[i+1]; |
|---|
| 932 | prev_snr[4] = snr; |
|---|
| 933 | |
|---|
| 934 | int nValidCount = 0; |
|---|
| 935 | int nSum = 0; |
|---|
| 936 | for (i=0; i < 5; i++) |
|---|
| 937 | { |
|---|
| 938 | if (prev_snr[i] < 0) continue; |
|---|
| 939 | nValidCount++; |
|---|
| 940 | nSum += prev_snr[i]; |
|---|
| 941 | } |
|---|
| 942 | snr = nSum / nValidCount; |
|---|
| 943 | // snrÀÇ °ªÀº 0~12000 »çÀÌÀÇ °ªÀÌ´Ù. |
|---|
| 944 | snr-=2000; |
|---|
| 945 | if (snr > 12000) snr = 12000; |
|---|
| 946 | if (snr < 0) snr = 0; |
|---|
| 947 | snr/=100; |
|---|
| 948 | *bLock = lock ? true : false; |
|---|
| 949 | *SignalStrength = snr; // ¿ÀÅ佺ĵ½Ã LOCKÀÌ ¾Æ´Ñ ÀÌ °ªÀÌ 0º¸´Ù Å©¸é ½ÅÈ£°¡ Àִ°ÍÀ¸·Î °£ÁÖÇÑ´Ù. |
|---|
| 950 | *nPower = power; |
|---|
| 951 | if (*SignalStrength > 100) *SignalStrength = 100; |
|---|
| 952 | // DST_Printf("tick = %d\n", DST_OS_GetTickCount() - tuner_start_tick); |
|---|
| 953 | // DST_Printf("bLock = %d SignalStrength = %d\n", *bLock, *SignalStrength); |
|---|
| 954 | #endif |
|---|
| 955 | return DHL_OK_; |
|---|
| 956 | } |
|---|
| 957 | |
|---|
| 958 | #if 0 |
|---|
| 959 | ____GFX___() |
|---|
| 960 | #endif |
|---|
| 961 | |
|---|
| 962 | #ifdef DSTAR |
|---|
| 963 | |
|---|
| 964 | #if OSD_PIXEL_BPP == 16 |
|---|
| 965 | #define DS_PIXEL_t DS_U16 |
|---|
| 966 | #define PIXEL_FORMAT 10 //PF_RGB16 |
|---|
| 967 | #else |
|---|
| 968 | #define DS_PIXEL_t DS_U32 |
|---|
| 969 | #define PIXEL_FORMAT 0 //PF_RGB32 |
|---|
| 970 | #endif |
|---|
| 971 | |
|---|
| 972 | /*extern "C" */void DHL_GFX_DrawImage( DS_U32 pBufferId, int offsetX, int offsetY, int w, int h, DS_PIXEL_t *pPixels); |
|---|
| 973 | /*extern "C" */void DHL_GFX_UpdateScreen(int Plane); |
|---|
| 974 | static DS_U32 id = 0; |
|---|
| 975 | static DS_U32 gMsgQ = 0; |
|---|
| 976 | |
|---|
| 977 | static void tUpdateScreen() |
|---|
| 978 | { |
|---|
| 979 | DS_U32 msg = 0; |
|---|
| 980 | DS_U32 retLen; |
|---|
| 981 | while (1) |
|---|
| 982 | { |
|---|
| 983 | //T(); |
|---|
| 984 | DST_OS_ReceiveMessage_NoWait(gMsgQ, (DS_U32*)&msg, sizeof(DS_U32), &retLen); |
|---|
| 985 | DHL_GFX_UpdateScreen(0); // µÎ°³ÀÇ Å½ºÅ©¿¡¼ µ¿½Ã¿¡ È£ÃâÇÏ¸é ½Ã½ºÅÛ ¸ØÃã... |
|---|
| 986 | } |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | static void DHL_UpdateScreen() |
|---|
| 990 | { |
|---|
| 991 | DS_U32 msg = 0; |
|---|
| 992 | if (gMsgQ) DST_OS_SendMessage(gMsgQ, &msg, sizeof(DS_U32)); |
|---|
| 993 | } |
|---|
| 994 | |
|---|
| 995 | void DHL_GFX_Open() |
|---|
| 996 | { |
|---|
| 997 | static bool bInit = false; |
|---|
| 998 | if (bInit == false) |
|---|
| 999 | { |
|---|
| 1000 | DHL_GFX_Init(0, |
|---|
| 1001 | 0, 0, DST_GetScreenWidth(), DST_GetScreenHeight() + 16, |
|---|
| 1002 | DST_GetScreenWidth(), DST_GetScreenHeight() + 16, PIXEL_FORMAT, &id); |
|---|
| 1003 | bInit = true; |
|---|
| 1004 | gMsgQ = DST_OS_CreateMessageQueue("qUpdateScreen", 0, 100, sizeof(DS_U32)); |
|---|
| 1005 | /*DS_U32 TaskID = */DST_OS_SpawnTask((void(*)(void *))tUpdateScreen, (char*)"tUpdateScreen", APP_TASK_PRIO_WIN_MGR, WIN_MGR_TASK_STACKSIZE, 0); |
|---|
| 1006 | } |
|---|
| 1007 | } |
|---|
| 1008 | |
|---|
| 1009 | void DHL_GFX_Draw(OSD_PIXEL_T *src, int x, int y, int w, int h) |
|---|
| 1010 | { |
|---|
| 1011 | DHL_GFX_DrawImage(id, x, y, w, h, src); |
|---|
| 1012 | DHL_UpdateScreen(); |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | void DHL_SetLED(bool bRed, bool bGreen) |
|---|
| 1016 | { |
|---|
| 1017 | static bool old_bRed = false; |
|---|
| 1018 | static bool old_bGreen = false; |
|---|
| 1019 | |
|---|
| 1020 | if (bRed == old_bRed && bGreen == old_bGreen) return; |
|---|
| 1021 | old_bRed = bRed; |
|---|
| 1022 | old_bGreen = bGreen; |
|---|
| 1023 | DHL_GFX_Open(); |
|---|
| 1024 | OSD_PIXEL_T *src = (OSD_PIXEL_T *)DST_OS_Calloc(DST_GetScreenWidth() * 16, sizeof(OSD_PIXEL_T)); |
|---|
| 1025 | OSD_PIXEL_T color = 0; |
|---|
| 1026 | if (bRed) |
|---|
| 1027 | { |
|---|
| 1028 | color = bGreen ? CONV32_16(0xFFFFFF00) : CONV32_16(0xFFFF0000); |
|---|
| 1029 | } |
|---|
| 1030 | else |
|---|
| 1031 | { |
|---|
| 1032 | color = bGreen ? CONV32_16(0xFF00FF00) : CONV32_16(0xFF000000); |
|---|
| 1033 | } |
|---|
| 1034 | int i; |
|---|
| 1035 | for ( i = 0; i < DST_GetScreenWidth() * 16; i++) src[i] = color; |
|---|
| 1036 | DHL_GFX_DrawImage(id, 0, DST_GetScreenHeight(), DST_GetScreenWidth(), 16, src); |
|---|
| 1037 | DHL_UpdateScreen(); |
|---|
| 1038 | DST_OS_Free(&src); |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | #else |
|---|
| 1042 | |
|---|
| 1043 | //extern "C" DS_U8 MsOS_Dcache_Flush(DS_U32 u32Start, DS_U32 u32Size); |
|---|
| 1044 | |
|---|
| 1045 | void DHL_GFX_Open() |
|---|
| 1046 | { |
|---|
| 1047 | T(); |
|---|
| 1048 | DHL_RESULT DHL_GrpInit(); |
|---|
| 1049 | DHL_GrpInit(); |
|---|
| 1050 | T(); |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | void DHL_GFX_Draw(OSD_PIXEL_T *src, int x, int y, int w, int h) |
|---|
| 1054 | { |
|---|
| 1055 | void dhl_draw_image2(char* src, int x, int y, int w, int h); |
|---|
| 1056 | dhl_draw_image2((char*)src, x, y, w, h); |
|---|
| 1057 | } |
|---|
| 1058 | |
|---|
| 1059 | void DHL_SetLED(bool bRed, bool bGreen) |
|---|
| 1060 | { |
|---|
| 1061 | static bool bFirst = true; |
|---|
| 1062 | static bool bRedOld = false; |
|---|
| 1063 | static bool bGreenOld = false; |
|---|
| 1064 | if (bFirst == true || bRedOld != bRed || bGreenOld != bGreen) |
|---|
| 1065 | { |
|---|
| 1066 | void dhl_led_control2(DS_U32 onoff); |
|---|
| 1067 | DS_U32 value = (bGreen ? 2 : 0) + (bRed ? 1: 0); |
|---|
| 1068 | { |
|---|
| 1069 | #include "bsettop_rfm.h" |
|---|
| 1070 | extern brfm_t g_sys_rfm; |
|---|
| 1071 | buser_AOV_input_LED(g_sys_rfm, value); |
|---|
| 1072 | } |
|---|
| 1073 | bFirst = false; |
|---|
| 1074 | bRedOld = bRed; |
|---|
| 1075 | bGreenOld = bGreen; |
|---|
| 1076 | } |
|---|
| 1077 | } |
|---|
| 1078 | #endif |
|---|
| 1079 | |
|---|
| 1080 | char *DST_GetBoardVersion(void) |
|---|
| 1081 | { |
|---|
| 1082 | char *strVersion = (char*)"R0.1"; |
|---|
| 1083 | #ifndef DSTAR |
|---|
| 1084 | // TO DO GPIO µîÀ» ÀÐ¾î¼ H/W ¹öÀü ¹®ÀÚ¿ ¹Ýȯ |
|---|
| 1085 | #endif |
|---|
| 1086 | return strVersion; |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | void DHL_SetCh34(DS_U8 nVal) |
|---|
| 1090 | { |
|---|
| 1091 | #ifndef DSTAR |
|---|
| 1092 | DHL_SetRFM34(nVal ? 1 : 0); |
|---|
| 1093 | #endif |
|---|
| 1094 | } |
|---|
| 1095 | |
|---|
| 1096 | #if 0 |
|---|
| 1097 | ____IR___() |
|---|
| 1098 | #endif |
|---|
| 1099 | |
|---|
| 1100 | static DS_U8 g_KeyPadGPIO = 0; |
|---|
| 1101 | DS_U8 DHL_GetKeyPadGPIO() |
|---|
| 1102 | { |
|---|
| 1103 | #ifndef DSTAR |
|---|
| 1104 | // TO DO |
|---|
| 1105 | // KEY PAD GPIO¸¦ Àоî¿Â´Ù |
|---|
| 1106 | // POWER = 1 UP =2 DN =4 |
|---|
| 1107 | // TODO µ¿ÀÛ È®ÀÎ ÇÊ¿ä |
|---|
| 1108 | // g_KeyPadGPIO = DHL_SYS_ReadGPIO(7) ? 1:0; |
|---|
| 1109 | // g_KeyPadGPIO += DHL_SYS_ReadGPIO(GPIO_CH_UP/*6*/) ? 2: 0; |
|---|
| 1110 | // g_KeyPadGPIO += DHL_SYS_ReadGPIO(GPIO_CH_DN/*5*/) ? 4: 0; |
|---|
| 1111 | #endif |
|---|
| 1112 | return g_KeyPadGPIO; |
|---|
| 1113 | } |
|---|
| 1114 | |
|---|
| 1115 | #ifdef DSTAR |
|---|
| 1116 | // DSTAR¿¡¼ NEC ۸¦ Èä³»³»±â À§ÇÑ Å½ºÅ© 110ms°£°ÝÀ¸·Î ¸®ÇÍŰ ó¸®ÇÑ´Ù. |
|---|
| 1117 | static DS_U32 DSTAR_KEY_MsgQ = 0; |
|---|
| 1118 | typedef struct |
|---|
| 1119 | { |
|---|
| 1120 | DS_U32 Code; |
|---|
| 1121 | DS_U32 bPressed; |
|---|
| 1122 | DS_U32 tick; |
|---|
| 1123 | } DSTAR_KEY; |
|---|
| 1124 | |
|---|
| 1125 | static void tRepeatKey() |
|---|
| 1126 | { |
|---|
| 1127 | DSTAR_KEY msg ={0,0,0}; |
|---|
| 1128 | DS_U32 retLen = 0; |
|---|
| 1129 | DS_U32 tick = 0; |
|---|
| 1130 | while (1) |
|---|
| 1131 | { |
|---|
| 1132 | // T(); |
|---|
| 1133 | DST_OS_Delay(10); // 10ms |
|---|
| 1134 | if (DSTAR_KEY_MsgQ == 0) continue; |
|---|
| 1135 | DSTAR_KEY tmp ={0,0,0}; |
|---|
| 1136 | if (DST_OS_ReceiveMessage_NoWait(DSTAR_KEY_MsgQ, (DS_U32*)&tmp, sizeof(DSTAR_KEY), &retLen) == noError) |
|---|
| 1137 | { |
|---|
| 1138 | msg = tmp; |
|---|
| 1139 | if (msg.bPressed) |
|---|
| 1140 | { |
|---|
| 1141 | if (g_IrCallBack) g_IrCallBack(msg.Code, 0, DST_OS_GetTickCount()); |
|---|
| 1142 | } |
|---|
| 1143 | tick = DST_OS_GetTickCount(); |
|---|
| 1144 | } |
|---|
| 1145 | if (msg.bPressed == 0) continue; |
|---|
| 1146 | if (tick > DST_OS_GetTickCount()) tick = DST_OS_GetTickCount(); |
|---|
| 1147 | if (DST_OS_GetTickCount() - tick < DST_OS_GetTicksPerSecond()/10) continue; |
|---|
| 1148 | if (msg.bPressed) |
|---|
| 1149 | { |
|---|
| 1150 | if (g_IrCallBack) g_IrCallBack(msg.Code, 1, DST_OS_GetTickCount()); |
|---|
| 1151 | } |
|---|
| 1152 | tick = DST_OS_GetTickCount(); |
|---|
| 1153 | } |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | // DSTAR Ű Äݹé |
|---|
| 1157 | static void DSTAR_KeyCallBack(int bRemocon, DS_U32 Code, int bPressed) |
|---|
| 1158 | { |
|---|
| 1159 | DST_Printf("|%s| code = 0x%02X, bPressed = %d\n", __func__, (int)Code, bPressed); |
|---|
| 1160 | static bool bStart = true; |
|---|
| 1161 | if (bStart == true) |
|---|
| 1162 | { |
|---|
| 1163 | bStart = false; |
|---|
| 1164 | DSTAR_KEY_MsgQ = DST_OS_CreateMessageQueue("DSTAR_KEY", 0, 100, sizeof(DSTAR_KEY)); |
|---|
| 1165 | DST_OS_SpawnTask((void(*)(void *))tRepeatKey, (char*)"DSTAR_KEY", APP_TASK_PRIO_WIN_MGR, WIN_MGR_TASK_STACKSIZE, 0); |
|---|
| 1166 | } |
|---|
| 1167 | // ŰÆÐµå¸¦ Èä³»³»±â À§ÇÑ Å° |
|---|
| 1168 | // Home + - |
|---|
| 1169 | if (Code == 0xCAFE0116 || Code == 0xCAFE010E || Code ==0xCAFE010D) |
|---|
| 1170 | { |
|---|
| 1171 | // DSTAR ŰÆÐµå |
|---|
| 1172 | if (bPressed == 1) |
|---|
| 1173 | { |
|---|
| 1174 | if (Code ==0xCAFE0116) g_KeyPadGPIO = 1;// home key |
|---|
| 1175 | if (Code ==0xCAFE010E) g_KeyPadGPIO = 2;// + |
|---|
| 1176 | if (Code ==0xCAFE010D) g_KeyPadGPIO = 4;// - |
|---|
| 1177 | } |
|---|
| 1178 | else |
|---|
| 1179 | { |
|---|
| 1180 | g_KeyPadGPIO = 0; |
|---|
| 1181 | } |
|---|
| 1182 | } |
|---|
| 1183 | else |
|---|
| 1184 | { |
|---|
| 1185 | DSTAR_KEY msg; |
|---|
| 1186 | msg.Code = Code; |
|---|
| 1187 | msg.bPressed = bPressed; |
|---|
| 1188 | msg.tick = DST_OS_GetTickCount(); |
|---|
| 1189 | DST_OS_SendMessage(DSTAR_KEY_MsgQ, (DS_U32 *)&msg, sizeof(DSTAR_KEY)); |
|---|
| 1190 | } |
|---|
| 1191 | } |
|---|
| 1192 | #else |
|---|
| 1193 | |
|---|
| 1194 | static DS_U32 g_ir_code = 0; |
|---|
| 1195 | static DS_U32 g_ir_repeat = 0; |
|---|
| 1196 | static void tIRTask() |
|---|
| 1197 | { |
|---|
| 1198 | while (1) |
|---|
| 1199 | { |
|---|
| 1200 | DST_OS_Delay(10); |
|---|
| 1201 | if (g_ir_code == 0) continue; |
|---|
| 1202 | DS_U32 ir_code = g_ir_code; |
|---|
| 1203 | DS_U32 ir_repeat = g_ir_repeat; |
|---|
| 1204 | g_ir_code = 0; |
|---|
| 1205 | g_ir_repeat = 0; |
|---|
| 1206 | DST_g_KeyPressTime = DST_OS_GetTickCount(); |
|---|
| 1207 | if (g_IrCallBack) g_IrCallBack(ir_code, ir_repeat, DST_g_KeyPressTime); |
|---|
| 1208 | } |
|---|
| 1209 | } |
|---|
| 1210 | static void IRCallback(unsigned int code, unsigned int repeat) |
|---|
| 1211 | { |
|---|
| 1212 | int i = 0; |
|---|
| 1213 | unsigned int _code = 0; |
|---|
| 1214 | for (i = 0; i < 32; i++) // ºñÆ® ¹ÝÀü |
|---|
| 1215 | { |
|---|
| 1216 | _code |= ((code >> i) & 0x1) << (31-i); |
|---|
| 1217 | } |
|---|
| 1218 | g_ir_code = _code; |
|---|
| 1219 | g_ir_repeat = (repeat == 85) ? 0 : 1; |
|---|
| 1220 | } |
|---|
| 1221 | |
|---|
| 1222 | #endif |
|---|
| 1223 | |
|---|
| 1224 | |
|---|
| 1225 | #if 0 |
|---|
| 1226 | ____OS___() |
|---|
| 1227 | #endif |
|---|
| 1228 | |
|---|
| 1229 | DS_U32 DST_OS_GetTickCount() |
|---|
| 1230 | { |
|---|
| 1231 | static DS_U32 sema4 = 0; |
|---|
| 1232 | if (sema4== 0) sema4 = DST_OS_CreateLock((char*)"tick"); |
|---|
| 1233 | DST_OS_Lock(sema4); |
|---|
| 1234 | static unsigned int old_tick = 0; |
|---|
| 1235 | static unsigned int loop = 0; |
|---|
| 1236 | #ifdef DSTAR |
|---|
| 1237 | static unsigned start_tick = 0; |
|---|
| 1238 | if (start_tick == 0) start_tick = OS_GetTickCount(); |
|---|
| 1239 | unsigned int tick = (OS_GetTickCount() - start_tick) & 0xFFFF; |
|---|
| 1240 | #else |
|---|
| 1241 | unsigned int tick = (osi_gettickcount() >> 1) & 0xFFFF; |
|---|
| 1242 | #endif |
|---|
| 1243 | if (old_tick > tick) loop += 0x10000; |
|---|
| 1244 | old_tick = tick; |
|---|
| 1245 | unsigned int ret = loop + tick; |
|---|
| 1246 | DST_OS_Unlock(sema4); |
|---|
| 1247 | return ret; |
|---|
| 1248 | } |
|---|
| 1249 | |
|---|
| 1250 | void DST_OS_Delay(DS_U32 ms) |
|---|
| 1251 | { |
|---|
| 1252 | #ifdef DSTAR |
|---|
| 1253 | if (ms < 10) ms = 10; |
|---|
| 1254 | OS_Delay(ms/10); |
|---|
| 1255 | #else |
|---|
| 1256 | DHL_OS_Delay(ms); |
|---|
| 1257 | #endif |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | DS_U32 DST_OS_GetTicksPerSecond() |
|---|
| 1261 | { |
|---|
| 1262 | #ifdef DSTAR |
|---|
| 1263 | return OS_GetTicksPerSecond(); |
|---|
| 1264 | #else |
|---|
| 1265 | return 100; |
|---|
| 1266 | #endif |
|---|
| 1267 | } |
|---|
| 1268 | |
|---|
| 1269 | void DST_OS_GetRunTime(DS_U32 *hour, DS_U32 *min, DS_U32 *sec) |
|---|
| 1270 | { |
|---|
| 1271 | DS_U32 n_sec = DST_OS_GetTickCount() / DST_OS_GetTicksPerSecond(); |
|---|
| 1272 | DS_U32 n_min = n_sec / 60; |
|---|
| 1273 | DS_U32 n_hour = n_min / 60; |
|---|
| 1274 | *sec = n_sec % 60; |
|---|
| 1275 | *min = n_min % 60; |
|---|
| 1276 | *hour = n_hour; |
|---|
| 1277 | } |
|---|
| 1278 | |
|---|
| 1279 | DS_U32 DST_OS_SpawnTask (void (*func)(void* ), char *name, DS_U16 prio, DS_U16 stacksize, DS_U32 arg) |
|---|
| 1280 | { |
|---|
| 1281 | #ifdef DSTAR |
|---|
| 1282 | return OS_SpawnTask((void (*)(DS_U32))func, name, prio, stacksize, arg); |
|---|
| 1283 | #else |
|---|
| 1284 | return DHL_OS_CreateTask(func, name, prio, stacksize, arg); |
|---|
| 1285 | #endif |
|---|
| 1286 | } |
|---|
| 1287 | |
|---|
| 1288 | void DST_OS_SelfDeleteTask() |
|---|
| 1289 | { |
|---|
| 1290 | #ifdef DSTAR |
|---|
| 1291 | #else |
|---|
| 1292 | DHL_OS_SelfDeleteTask(); |
|---|
| 1293 | #endif |
|---|
| 1294 | } |
|---|
| 1295 | |
|---|
| 1296 | DS_U32 DST_OS_ReceiveMessage_NoWait(DS_U32 qId, DS_U32 *msgBuf, DS_U32 maxLen, DS_U32 *retLen) |
|---|
| 1297 | { |
|---|
| 1298 | #ifdef DSTAR |
|---|
| 1299 | return OS_ReceiveMessage_NoWait(qId, msgBuf, maxLen, retLen); |
|---|
| 1300 | #else |
|---|
| 1301 | return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)qId, msgBuf, 0); |
|---|
| 1302 | #endif |
|---|
| 1303 | } |
|---|
| 1304 | |
|---|
| 1305 | DS_U32 DST_OS_ReceiveMessage_Wait(DS_U32 qId, DS_U32 *msgBuf, DS_U32 maxLen, DS_U32 *retLen, DS_U32 timeOut) |
|---|
| 1306 | { |
|---|
| 1307 | #ifdef DSTAR |
|---|
| 1308 | if (timeOut < 10) timeOut = 10; |
|---|
| 1309 | return OS_ReceiveMessage_Wait(qId, msgBuf, maxLen, retLen, timeOut/10); |
|---|
| 1310 | #else |
|---|
| 1311 | return DHL_OS_ReceiveMessage((DHL_OS_MSGQ_ID)qId, msgBuf, timeOut == 0 ? DHL_TIMEOUT_FOREVER : timeOut); |
|---|
| 1312 | #endif |
|---|
| 1313 | } |
|---|
| 1314 | |
|---|
| 1315 | DS_U32 DST_OS_SendMessage (DS_U32 qId, DS_U32 *pBuffer, DS_U32 nBytes) |
|---|
| 1316 | { |
|---|
| 1317 | #ifdef DSTAR |
|---|
| 1318 | return OS_SendMessage(qId, pBuffer, nBytes); |
|---|
| 1319 | #else |
|---|
| 1320 | return DHL_OS_SendMessage((DHL_OS_MSGQ_ID)qId, pBuffer, nBytes); |
|---|
| 1321 | #endif |
|---|
| 1322 | } |
|---|
| 1323 | |
|---|
| 1324 | DS_U32 DST_OS_DeleteMessageQueue(DS_U32 qId) |
|---|
| 1325 | { |
|---|
| 1326 | #ifdef DSTAR |
|---|
| 1327 | return OS_DeleteMessageQueue(qId); |
|---|
| 1328 | #else |
|---|
| 1329 | DHL_OS_DeleteMessageQueue((DHL_OS_MSGQ_ID)qId); |
|---|
| 1330 | return 0; |
|---|
| 1331 | #endif |
|---|
| 1332 | } |
|---|
| 1333 | |
|---|
| 1334 | DS_U32 DST_OS_CreateMessageQueue (const char *name, DS_U32 option, DS_U32 maxMessage, DS_U32 messageLength) |
|---|
| 1335 | { |
|---|
| 1336 | #ifdef DSTAR |
|---|
| 1337 | return OS_CreateMessageQueue (name, option, maxMessage, messageLength); |
|---|
| 1338 | #else |
|---|
| 1339 | return (DS_U32)DHL_OS_CreateMessageQueue (name, option, maxMessage, messageLength); |
|---|
| 1340 | #endif |
|---|
| 1341 | } |
|---|
| 1342 | |
|---|
| 1343 | DS_U32 DST_OS_CreateLock(char *name) |
|---|
| 1344 | { |
|---|
| 1345 | #ifdef DSTAR |
|---|
| 1346 | return OS_CreateMutex(name); |
|---|
| 1347 | #else |
|---|
| 1348 | return (DS_U32)DHL_OS_CreateMutexSemaphore(name); |
|---|
| 1349 | #endif |
|---|
| 1350 | } |
|---|
| 1351 | |
|---|
| 1352 | void DST_OS_Lock(DS_U32 id) |
|---|
| 1353 | { |
|---|
| 1354 | #ifdef DSTAR |
|---|
| 1355 | OS_TakeMutex(id); |
|---|
| 1356 | #else |
|---|
| 1357 | DHL_OS_TakeSemaphore((void*)id, DHL_TIMEOUT_FOREVER); |
|---|
| 1358 | #endif |
|---|
| 1359 | } |
|---|
| 1360 | |
|---|
| 1361 | void DST_OS_Unlock(DS_U32 id) |
|---|
| 1362 | { |
|---|
| 1363 | #ifdef DSTAR |
|---|
| 1364 | OS_GiveMutex(id); |
|---|
| 1365 | #else |
|---|
| 1366 | DHL_OS_GiveSemaphore((void*)id); |
|---|
| 1367 | #endif |
|---|
| 1368 | } |
|---|
| 1369 | |
|---|
| 1370 | #if 0 |
|---|
| 1371 | ____MEMORY___() |
|---|
| 1372 | #endif |
|---|
| 1373 | |
|---|
| 1374 | // LEVEL 0 Æ÷ÆÃ ·¹À̾î |
|---|
| 1375 | // Ç÷§Æû¿¡ µû¶ó Æ÷ÆÃÇØ¾ß ÇÏ´Â ·¹À̾î |
|---|
| 1376 | // malloc°ú free´Â ¿©±â¿¡¼ Æ÷ÆÃÇÑ´Ù. |
|---|
| 1377 | |
|---|
| 1378 | // LEVEL 1 C Ç¥ÁØÇÔ¼ö ±¸Çö |
|---|
| 1379 | // malloc free calloc realloc À» C ÀÎÅÍÆäÀ̽º¿Í µ¿ÀÏÇÏ°Ô ±¸Çö |
|---|
| 1380 | // freetype sqlite µî Æ÷ÆÃ½Ã¿¡ È£Ãâ |
|---|
| 1381 | // C Ç¥ÁØÇÔ¼ö¿Í ȣȯµÇ´Â ¸Þ¸ð¸® ÇÔ¼ö (¶óÀ̺귯¸® Æ÷ÆÃ¿ë) |
|---|
| 1382 | // C Æ÷ÆÃÀ» À§ÇØ extern "C" ·Î ¼±¾ð |
|---|
| 1383 | |
|---|
| 1384 | void *DST_OS_MallocDirect(int size) // malloc |
|---|
| 1385 | { |
|---|
| 1386 | if (size <= 0) return 0; |
|---|
| 1387 | #ifdef DSTAR |
|---|
| 1388 | void *p = malloc(size); |
|---|
| 1389 | #else |
|---|
| 1390 | void *p = OS_Malloc(size); |
|---|
| 1391 | #endif |
|---|
| 1392 | |
|---|
| 1393 | memset(p, 0, size); |
|---|
| 1394 | return p; |
|---|
| 1395 | } |
|---|
| 1396 | |
|---|
| 1397 | void *DST_OS_CallocDirect(int num, int size) // calloc |
|---|
| 1398 | { |
|---|
| 1399 | return DST_OS_MallocDirect(num * size); |
|---|
| 1400 | } |
|---|
| 1401 | |
|---|
| 1402 | void DST_OS_FreeDirect( void *ptr) // free |
|---|
| 1403 | { |
|---|
| 1404 | #ifdef DSTAR |
|---|
| 1405 | free(ptr); |
|---|
| 1406 | #else |
|---|
| 1407 | OS_FreeDirect(ptr); |
|---|
| 1408 | #endif |
|---|
| 1409 | } |
|---|
| 1410 | |
|---|
| 1411 | void *DST_OS_ReallocDirect(void *ptr, int size) // realloc |
|---|
| 1412 | { |
|---|
| 1413 | if (!ptr) return DST_OS_MallocDirect(size); |
|---|
| 1414 | void *nptr = DST_OS_MallocDirect(size); |
|---|
| 1415 | if (!nptr) return NULL; |
|---|
| 1416 | memcpy(nptr,ptr,size); |
|---|
| 1417 | DST_OS_FreeDirect(ptr); |
|---|
| 1418 | return nptr; |
|---|
| 1419 | } |
|---|
| 1420 | |
|---|
| 1421 | |
|---|
| 1422 | |
|---|
| 1423 | // LEVEL 2 APP È£Ãâ ÇÔ¼ö ±¸Çö |
|---|
| 1424 | // ¸Þ¸ð¸® ¸®½ºÆ®¸¦ »ý¼ºÇؼ È®ÀÎÇÒ ¼ö ÀÖ´Ù. |
|---|
| 1425 | |
|---|
| 1426 | #define MAX_FUNC_NAME 32 // Çã¿ëÇÒ ÃÖ´ë ÇÔ¼ö À̸§ ±æÀÌ |
|---|
| 1427 | #define MAX_COUNT 500 // °ü¸®ÇÒ °¹¼ö |
|---|
| 1428 | |
|---|
| 1429 | typedef struct |
|---|
| 1430 | { |
|---|
| 1431 | char func[MAX_FUNC_NAME+1]; |
|---|
| 1432 | int nLine; |
|---|
| 1433 | void *p; |
|---|
| 1434 | int nSize; |
|---|
| 1435 | unsigned int tick; |
|---|
| 1436 | } MEM_LIST; |
|---|
| 1437 | |
|---|
| 1438 | static MEM_LIST memlist[MAX_COUNT]; |
|---|
| 1439 | |
|---|
| 1440 | void DST_OS_PrintMemUnit(void) |
|---|
| 1441 | { |
|---|
| 1442 | int i = 0, nSum = 0, nCount = 0; |
|---|
| 1443 | DST_Printf("|------------+----------+----------------------------------+------|\n"); |
|---|
| 1444 | DST_Printf("| Address | Size | Function | Line |\n"); |
|---|
| 1445 | DST_Printf("|------------+----------+----------------------------------+------|\n"); |
|---|
| 1446 | for (i = 0; i < MAX_COUNT; i++) |
|---|
| 1447 | { |
|---|
| 1448 | if (memlist[i].p == 0) continue; |
|---|
| 1449 | 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 ); |
|---|
| 1450 | nSum+=memlist[i].nSize; |
|---|
| 1451 | nCount++; |
|---|
| 1452 | } |
|---|
| 1453 | DST_Printf("|------------+----------+----------------------------------+------|\n"); |
|---|
| 1454 | DST_Printf("| %10d | %8d | |\n", nCount, nSum); |
|---|
| 1455 | DST_Printf("|------------+----------+----------------------------------+------|\n"); |
|---|
| 1456 | } |
|---|
| 1457 | |
|---|
| 1458 | static void Add_MemUint(const char* func, int nLine, void *p, int nSize) |
|---|
| 1459 | { |
|---|
| 1460 | int i = 0; |
|---|
| 1461 | for (i = 0; i < MAX_COUNT; i++) |
|---|
| 1462 | { |
|---|
| 1463 | if (memlist[i].p != 0) continue; |
|---|
| 1464 | if (strlen(func) > MAX_FUNC_NAME) |
|---|
| 1465 | { |
|---|
| 1466 | memcpy(memlist[i].func, func, MAX_FUNC_NAME); |
|---|
| 1467 | memlist[i].func[MAX_FUNC_NAME] = 0; |
|---|
| 1468 | } |
|---|
| 1469 | else |
|---|
| 1470 | { |
|---|
| 1471 | strcpy(memlist[i].func, func); |
|---|
| 1472 | } |
|---|
| 1473 | memlist[i].nLine = nLine; |
|---|
| 1474 | memlist[i].p = p; |
|---|
| 1475 | memlist[i].nSize = nSize; |
|---|
| 1476 | memlist[i].tick = DST_OS_GetTickCount(); |
|---|
| 1477 | break; |
|---|
| 1478 | } |
|---|
| 1479 | //Print_MemUnit(); |
|---|
| 1480 | } |
|---|
| 1481 | |
|---|
| 1482 | |
|---|
| 1483 | static void Del_MemUnit(void *p, const char * func, int nLine) |
|---|
| 1484 | { |
|---|
| 1485 | int i = 0; |
|---|
| 1486 | if (p == 0) return; |
|---|
| 1487 | for (i = 0; i < MAX_COUNT; i++) |
|---|
| 1488 | { |
|---|
| 1489 | if (memlist[i].p != p) continue; |
|---|
| 1490 | memlist[i].p = 0; |
|---|
| 1491 | break; |
|---|
| 1492 | } |
|---|
| 1493 | if (i >= MAX_COUNT) |
|---|
| 1494 | { |
|---|
| 1495 | #if 0 |
|---|
| 1496 | DST_Printf("\n\n\n\nTry to delete unallocated memory 0x%08X. %s %d\n\n\n", (int)p, func, nLine); |
|---|
| 1497 | Print_All_MemUnit(); |
|---|
| 1498 | DST_OS_Delay(5); |
|---|
| 1499 | #endif |
|---|
| 1500 | } |
|---|
| 1501 | //Print_MemUnit(); |
|---|
| 1502 | } |
|---|
| 1503 | |
|---|
| 1504 | void *_DST_OS_Malloc(unsigned int size, const char* func, int nLine) |
|---|
| 1505 | { |
|---|
| 1506 | void *p = 0; |
|---|
| 1507 | if (size == 0) return 0; |
|---|
| 1508 | p = DST_OS_MallocDirect(size); |
|---|
| 1509 | if (p == 0) |
|---|
| 1510 | { |
|---|
| 1511 | DST_Printf("%s|%s|%d|size =%d|Out of memory\n", __func__, func, nLine, size); |
|---|
| 1512 | DST_OS_PrintMemUnit(); |
|---|
| 1513 | } |
|---|
| 1514 | else |
|---|
| 1515 | { |
|---|
| 1516 | Add_MemUint(func, nLine, p, size); |
|---|
| 1517 | } |
|---|
| 1518 | return p; |
|---|
| 1519 | } |
|---|
| 1520 | |
|---|
| 1521 | void *_DST_OS_Calloc(unsigned int count, unsigned int size, const char* func, int nLine) |
|---|
| 1522 | { |
|---|
| 1523 | void *p = _DST_OS_Malloc(count * size, func, nLine); |
|---|
| 1524 | if (!p) return 0; |
|---|
| 1525 | memset(p, 0, count*size); |
|---|
| 1526 | return p; |
|---|
| 1527 | } |
|---|
| 1528 | |
|---|
| 1529 | void _DST_OS_Free(void *where, const char* func, int nLine) |
|---|
| 1530 | { |
|---|
| 1531 | if (where == 0) return; |
|---|
| 1532 | Del_MemUnit(where, func, nLine); |
|---|
| 1533 | DST_OS_FreeDirect(where); |
|---|
| 1534 | where = 0; |
|---|
| 1535 | } |
|---|
| 1536 | |
|---|
| 1537 | #if 0 |
|---|
| 1538 | ____POWER___() |
|---|
| 1539 | #endif |
|---|
| 1540 | |
|---|
| 1541 | void DHL_SYS_Off() |
|---|
| 1542 | { |
|---|
| 1543 | #ifdef DSTAR |
|---|
| 1544 | DHL_SYS_Terminate(); |
|---|
| 1545 | exit(1); |
|---|
| 1546 | #else |
|---|
| 1547 | int tmbslTDA182I4_SetPowerState(int, int); |
|---|
| 1548 | tmbslTDA182I4_SetPowerState(0,1); // tmPowerStandby |
|---|
| 1549 | DHL_SYS_Reset(eDHL_RESET_Standby); |
|---|
| 1550 | #endif |
|---|
| 1551 | } |
|---|
| 1552 | |
|---|
| 1553 | void DHL_SYS_Reboot() |
|---|
| 1554 | { |
|---|
| 1555 | #ifdef DSTAR |
|---|
| 1556 | DHL_SYS_Reset(); |
|---|
| 1557 | exit(1); |
|---|
| 1558 | #else |
|---|
| 1559 | DHL_SYS_Reset(eDHL_RESET_Reboot); |
|---|
| 1560 | #endif |
|---|
| 1561 | } |
|---|
| 1562 | |
|---|
| 1563 | // Video Ãâ·Â On / OFF |
|---|
| 1564 | void DHL_POWER_Display(bool bOn) |
|---|
| 1565 | { |
|---|
| 1566 | static bool bOn_Old = true; |
|---|
| 1567 | if (bOn == bOn_Old) return; |
|---|
| 1568 | if (bVideoStart == true) return; // ºñµð¿À ½ÃÀ۽ÿ¡´Â µ¿ÀÛÇÏÁö ¾Êµµ·Ï ÇÑ´Ù |
|---|
| 1569 | bOn_Old = bOn; |
|---|
| 1570 | T(); |
|---|
| 1571 | DST_Printf("%s %s\n", __func__, bOn ? "On" : "Off"); |
|---|
| 1572 | #ifdef DSTAR |
|---|
| 1573 | #else |
|---|
| 1574 | void DHL_AV_DispStop(BOOL onoff); |
|---|
| 1575 | DHL_AV_DispStop(bOn ? 0 : 1); |
|---|
| 1576 | DHL_RESULT DHL_SetLTO(BOOL onoff); |
|---|
| 1577 | DHL_SetLTO(bOn ? 0 : 1); |
|---|
| 1578 | #endif |
|---|
| 1579 | g_power_display = bOn; |
|---|
| 1580 | } |
|---|
| 1581 | |
|---|
| 1582 | // Flash Memory¿¡¼ Bank ¹øÈ£¸¦ Àоî¿Â´Ù. |
|---|
| 1583 | // Flash ¸Þ¸ð¸®ÀÇ Ã¹¹øÂ° ¹ÙÀÌÆ®°¡ 1ÀÌ ¾Æ´Ï¸é Bank0 1À̸é Bank1ÀÌ´Ù. |
|---|
| 1584 | static DS_U8 g_BankNumber = 0xFF; |
|---|
| 1585 | // Return °ªÀÌ 0À̸é Bank0 1À̸é Bank1 |
|---|
| 1586 | bool DHL_INFO_GetBankNumber() |
|---|
| 1587 | { |
|---|
| 1588 | if (g_BankNumber == 0xFF) |
|---|
| 1589 | { |
|---|
| 1590 | DS_U8* buff = DHL_Flash_Read(FLASH_BANK_SELECT_POS, 1); |
|---|
| 1591 | g_BankNumber = (buff[0]==1) ? 1 : 0; |
|---|
| 1592 | DST_OS_Free(&buff); |
|---|
| 1593 | } |
|---|
| 1594 | return g_BankNumber ==1 ? 1 : 0; |
|---|
| 1595 | } |
|---|
| 1596 | |
|---|
| 1597 | void DHL_INFO_SetBankNumber(DS_U8 data) |
|---|
| 1598 | { |
|---|
| 1599 | if (FLASH_TOTAL_SIZE < 8*1024*1024) data = 0; // 4MB FlashÀÇ Bank´Â Ç×»ó 0ÀÌ´Ù |
|---|
| 1600 | if (g_BankNumber == data) return; |
|---|
| 1601 | DHL_Flash_Write(FLASH_BANK_SELECT_POS, 1, & data); |
|---|
| 1602 | DST_Printf("%s %d\n", __func__, data); |
|---|
| 1603 | g_BankNumber = data; |
|---|
| 1604 | } |
|---|
| 1605 | |
|---|
| 1606 | // Flash Memory¿¡¼ LAST POWER STATE¸¦ Àоî¿Â´Ù. |
|---|
| 1607 | // Flash ¸Þ¸ð¸®ÀÇ Ã¹¹øÂ° ¹ÙÀÌÆ®°¡ 0À̸é OFF »óÅ 0ÀÌ ¾Æ´Ï¸é ONÀÌ´Ù. |
|---|
| 1608 | static DS_U8 g_LastPowerState = 0xFF; |
|---|
| 1609 | bool DHL_INFO_GetLastPowerState() |
|---|
| 1610 | { |
|---|
| 1611 | if (g_LastPowerState == 0xFF) |
|---|
| 1612 | { |
|---|
| 1613 | DS_U8* buff = DHL_Flash_Read(FLASH_LAST_POWER_POS, 1); |
|---|
| 1614 | g_LastPowerState = (buff[0]!=0) ? 1 : 0; |
|---|
| 1615 | DST_OS_Free(&buff); |
|---|
| 1616 | } |
|---|
| 1617 | return g_LastPowerState ? true : false; |
|---|
| 1618 | } |
|---|
| 1619 | |
|---|
| 1620 | void DHL_INFO_SetLastPowerState(bool bOn) |
|---|
| 1621 | { |
|---|
| 1622 | DS_U8 data = bOn ? 1 : 0; |
|---|
| 1623 | if (g_LastPowerState == data) return; |
|---|
| 1624 | // data = 1; // JUST TEST |
|---|
| 1625 | DHL_Flash_Write(FLASH_LAST_POWER_POS, 1, & data); |
|---|
| 1626 | DST_Printf("%s %d\n", __func__, data); |
|---|
| 1627 | g_LastPowerState = data; |
|---|
| 1628 | } |
|---|
| 1629 | |
|---|
| 1630 | #if 0 |
|---|
| 1631 | ____Flash_Memory___() |
|---|
| 1632 | #endif |
|---|
| 1633 | |
|---|
| 1634 | static void FlashLock(bool bLock) |
|---|
| 1635 | { |
|---|
| 1636 | static DS_U32 sema4 = 0; |
|---|
| 1637 | if (sema4== 0) |
|---|
| 1638 | { |
|---|
| 1639 | #ifndef DSTAR |
|---|
| 1640 | // DHL_NVM_Init(); // DHL_SYS_PlatformInit ¿¡¼ È£ÃâÇϹǷΠÁ¦°Å |
|---|
| 1641 | #endif |
|---|
| 1642 | sema4 = DST_OS_CreateLock((char*)"flash"); |
|---|
| 1643 | } |
|---|
| 1644 | bLock ? DST_OS_Lock(sema4) : DST_OS_Unlock(sema4); |
|---|
| 1645 | } |
|---|
| 1646 | |
|---|
| 1647 | DS_U32 FLASH_TOTAL_SIZE = (8*1024*1024); |
|---|
| 1648 | DS_U32 FLASH_BANK1_POS = (0x400000); |
|---|
| 1649 | |
|---|
| 1650 | // 4Kbyte ¼½ÅÍ ´ÜÀ§·Î Write 0~1023 ±îÁö ¼½Å͹øÈ£ |
|---|
| 1651 | static void _FlashWrite(DS_U16 nSector, DS_U16 nSize, DS_U8* data) |
|---|
| 1652 | { |
|---|
| 1653 | #ifndef DSTAR |
|---|
| 1654 | DHL_RESULT DHL_NVM_FlashWrite(int flashId, UINT32 offset, UINT8 *pBuffer, UINT32 len); |
|---|
| 1655 | if (DHL_NVM_FlashWrite(0, nSector * 4096, data, nSize) != 0) |
|---|
| 1656 | { |
|---|
| 1657 | DST_Printf("|%s|Err|DHL_NVM_FlashWrite(addr:0x%X, len:%d)\n",__func__, nSector * 4096, nSize); |
|---|
| 1658 | } |
|---|
| 1659 | #else |
|---|
| 1660 | if (nSector*4096 + nSize >= FLASH_TOTAL_SIZE) |
|---|
| 1661 | { |
|---|
| 1662 | T(); |
|---|
| 1663 | exit(1); |
|---|
| 1664 | } |
|---|
| 1665 | FILE *fp = fopen("flash.bin" , "rb+"); |
|---|
| 1666 | fseek(fp, nSector * 4096, SEEK_SET); |
|---|
| 1667 | fwrite(data, 1, nSize, fp); |
|---|
| 1668 | fclose(fp); |
|---|
| 1669 | #endif |
|---|
| 1670 | } |
|---|
| 1671 | |
|---|
| 1672 | // address´Â 4Kbyte ´ÜÀ§°ªÀ¸·Î ½ÃÀÛÇØ¾ß ÇÑ´Ù. |
|---|
| 1673 | // nSize´Â °¡´ÉÇÑ ±æÀÌ·Î Á¦ÇÑÀÌ ¾ø´Ù. |
|---|
| 1674 | void DHL_Flash_Write(DS_U32 address, DS_U32 nSize, DS_U8 *data) |
|---|
| 1675 | { |
|---|
| 1676 | if (address%4096 != 0) |
|---|
| 1677 | { |
|---|
| 1678 | DST_Printf("%s|invalid address = %d(0x%X) nSize = %d\n", __func__, (int)address, (int)address, (int)nSize); |
|---|
| 1679 | return; |
|---|
| 1680 | } |
|---|
| 1681 | FlashLock(true); |
|---|
| 1682 | // 4Kbyte ´ÜÀ§·Î ³ª´©¾î¼ È£ÃâÇÑ´Ù. |
|---|
| 1683 | DS_U32 i; |
|---|
| 1684 | for ( i = 0; i < nSize; i+= 4096) |
|---|
| 1685 | { |
|---|
| 1686 | DS_U32 nSize2 = 4096; |
|---|
| 1687 | if (i+nSize2 > nSize) nSize2 = nSize - i; |
|---|
| 1688 | _FlashWrite((address + i)/4096, nSize2, &data[i]); |
|---|
| 1689 | } |
|---|
| 1690 | FlashLock(false); |
|---|
| 1691 | } |
|---|
| 1692 | |
|---|
| 1693 | // È£ÃâÇÑ ÂÊ¿¡¼ ¸Þ¸ð¸® ÇØÁ¦ ÇÊ¿ä |
|---|
| 1694 | // Ç×»ó Writeº¸´Ù ¸ÕÀú È£ÃâµÇ¹Ç·Î ÃʱâÈ Äڵ嵵 Æ÷ÇÔÇÑ´Ù. |
|---|
| 1695 | DS_U8* DHL_Flash_Read(DS_U32 address, DS_U32 nSize) |
|---|
| 1696 | { |
|---|
| 1697 | FlashLock(true); |
|---|
| 1698 | DS_U8* data = (DS_U8*)DST_OS_Malloc(nSize); |
|---|
| 1699 | #ifdef DSTAR |
|---|
| 1700 | if (address + nSize >= FLASH_TOTAL_SIZE) |
|---|
| 1701 | { |
|---|
| 1702 | T(); |
|---|
| 1703 | exit(1); |
|---|
| 1704 | } |
|---|
| 1705 | // ÆÄÀÏÀÌ ¾øÀ¸¸é »ý¼ºÇÑ´Ù. |
|---|
| 1706 | FILE *fp = fopen("flash.bin" , "rb"); |
|---|
| 1707 | int nFileLength = 0; |
|---|
| 1708 | if (fp) |
|---|
| 1709 | { |
|---|
| 1710 | fseek(fp, 0, SEEK_END); |
|---|
| 1711 | nFileLength = ftell(fp); |
|---|
| 1712 | fclose(fp); |
|---|
| 1713 | } |
|---|
| 1714 | if (nFileLength != FLASH_TOTAL_SIZE) |
|---|
| 1715 | { |
|---|
| 1716 | fp = fopen("flash.bin", "wb"); |
|---|
| 1717 | DS_U8 *tmp = (DS_U8*)DST_OS_Malloc(FLASH_TOTAL_SIZE); |
|---|
| 1718 | memset(tmp,0xFF, FLASH_TOTAL_SIZE); |
|---|
| 1719 | fwrite(tmp, 1, FLASH_TOTAL_SIZE, fp); |
|---|
| 1720 | DST_OS_Free(&tmp); |
|---|
| 1721 | fclose(fp); |
|---|
| 1722 | } |
|---|
| 1723 | fp = fopen("flash.bin" , "rb"); |
|---|
| 1724 | fseek(fp, address, SEEK_SET); |
|---|
| 1725 | fread(data, 1, nSize, fp); |
|---|
| 1726 | fclose(fp); |
|---|
| 1727 | #else |
|---|
| 1728 | // TO DO Flash Init DHL_SYS_PlatformInit¿¡¼ ÀÌ¹Ì È£Ãâ |
|---|
| 1729 | // TO DO Flash Read |
|---|
| 1730 | DHL_RESULT DHL_NVM_FlashRead(int flashId, UINT32 offset, UINT8 *pBuffer, UINT32 len); |
|---|
| 1731 | if (DHL_NVM_FlashRead(0, address, data, nSize) != 0) |
|---|
| 1732 | { |
|---|
| 1733 | DST_Printf("|%s|Err|DHL_NVM_FlashRead(addr:0x%x, len:0x%x)\n",__func__, (int)address, (int)nSize); |
|---|
| 1734 | } |
|---|
| 1735 | #endif |
|---|
| 1736 | FlashLock(false); |
|---|
| 1737 | return data; |
|---|
| 1738 | } |
|---|
| 1739 | |
|---|
| 1740 | |
|---|
| 1741 | // ministd¿¡¼ Áö¿øÇÏÁö ¾Ê´Â stdc ÇÔ¼ö |
|---|
| 1742 | |
|---|
| 1743 | int dst_atoi(char *st) |
|---|
| 1744 | { |
|---|
| 1745 | bool bMinus = false; |
|---|
| 1746 | if (*st == '-' ) |
|---|
| 1747 | { |
|---|
| 1748 | bMinus = true; |
|---|
| 1749 | st++; |
|---|
| 1750 | } |
|---|
| 1751 | int i = 0; |
|---|
| 1752 | while((*st >= '0' && *st <= '9')) |
|---|
| 1753 | { |
|---|
| 1754 | i = i * 10 + (*(st)) - '0'; |
|---|
| 1755 | st++; |
|---|
| 1756 | } |
|---|
| 1757 | return bMinus ? -i : i; |
|---|
| 1758 | } |
|---|
| 1759 | |
|---|
| 1760 | #ifndef DSTAR |
|---|
| 1761 | void *memchr(s, c, n) |
|---|
| 1762 | const void *s; |
|---|
| 1763 | register unsigned char c; |
|---|
| 1764 | register size_t n; |
|---|
| 1765 | { |
|---|
| 1766 | if (n != 0) { |
|---|
| 1767 | register const unsigned char *p = s; |
|---|
| 1768 | |
|---|
| 1769 | do { |
|---|
| 1770 | if (*p++ == c) |
|---|
| 1771 | return ((void *)(p - 1)); |
|---|
| 1772 | } while (--n != 0); |
|---|
| 1773 | } |
|---|
| 1774 | return (0); |
|---|
| 1775 | } |
|---|
| 1776 | #include <time.h> |
|---|
| 1777 | struct tm * gmtime(register const time_t *timer) |
|---|
| 1778 | { |
|---|
| 1779 | static struct tm br_time; |
|---|
| 1780 | return &br_time; |
|---|
| 1781 | } |
|---|
| 1782 | |
|---|
| 1783 | size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *t) |
|---|
| 1784 | { |
|---|
| 1785 | s[0] = 0; |
|---|
| 1786 | return 0; |
|---|
| 1787 | } |
|---|
| 1788 | #endif |
|---|
| 1789 | |
|---|
| 1790 | |
|---|
| 1791 | #ifdef DSTAR // CC FeedingÀ» À§ÇÑ Å×½ºÆ® ÇÔ¼ö |
|---|
| 1792 | #include <stdlib.h> |
|---|
| 1793 | #define SIZE_BUFF (1024*32) |
|---|
| 1794 | static void ttest__cc() |
|---|
| 1795 | { |
|---|
| 1796 | FILE *fp = fopen("/home/megakiss/stream/KBS.tp", "rb"); |
|---|
| 1797 | if (fp == 0) return; |
|---|
| 1798 | while(1) |
|---|
| 1799 | { |
|---|
| 1800 | OS_Delay(OS_GetTicksPerSecond()/100); |
|---|
| 1801 | DS_U8 buff[SIZE_BUFF*2]; |
|---|
| 1802 | int n = fread(buff, 1,SIZE_BUFF, fp); |
|---|
| 1803 | if (n != SIZE_BUFF) |
|---|
| 1804 | { |
|---|
| 1805 | fclose(fp); |
|---|
| 1806 | return; |
|---|
| 1807 | } |
|---|
| 1808 | _DHL_CCCallBack( SIZE_BUFF, buff); |
|---|
| 1809 | } |
|---|
| 1810 | } |
|---|
| 1811 | |
|---|
| 1812 | static void ttest_cc() |
|---|
| 1813 | { |
|---|
| 1814 | while (1) |
|---|
| 1815 | { |
|---|
| 1816 | OS_Delay(OS_GetTicksPerSecond()); |
|---|
| 1817 | ttest__cc(); |
|---|
| 1818 | } |
|---|
| 1819 | } |
|---|
| 1820 | |
|---|
| 1821 | void test_cc() |
|---|
| 1822 | { |
|---|
| 1823 | static int taskID = 0; |
|---|
| 1824 | if (taskID) return; |
|---|
| 1825 | taskID = OS_SpawnTask((void (*)(DS_U32)) ttest_cc, (char*)"ttest_cc", APP_TASK_PRIO_WIN_MGR, WIN_MGR_TASK_STACKSIZE, 0); |
|---|
| 1826 | } |
|---|
| 1827 | #endif // CC FeedingÀ» À§ÇÑ Å×½ºÆ® ÇÔ¼ö |
|---|