source: svn/newcon3bcm2_21bu/dst/app/src/Function/App_Fnc_Sdds.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 51.2 KB
Line 
1/****************************************************************************
2* NAME: App_Fnc_Sdds.c
3*----------------------------------------------------------------------------
4* Copyright (c) DIGITAL STREAM Technology Inc.
5*----------------------------------------------------------------------------
6* CREATED_BY: Do Gon Lee
7* CREATION_DATE: 2009/08/20
8* $Author: foxhunt $
9* $Revision: 1.0 $
10* $Date: 2009/08/20 11:32:07 $
11*----------------------------------------------------------------------------
12* PURPOSE:
13* - EPG Init, update start/cancel, delete wrapping.
14* - program change envent procedure implement.
15*****************************************************************************/
16
17/*_____ I N C L U D E __________________________________________*/
18
19#include "App_Main.h"
20
21#if SUPPORT_SDDS
22
23#include "DHL_Timer.h"
24#include "DHL_NVM.h"
25#include "DHL_UTL.h"
26#include "DHL_UIO.h"
27
28//#include "DMW_CodeConv.h"
29#include "DMW_PsiSdds.h"
30
31#include "App_Fnc_Common.h"
32
33#include "App_Fnc_Time.h"
34#include "App_Fnc_EPG.h"
35#include "App_Fnc_Sdds.h"
36#include "App_Fnc_AutoScan.h"
37//#include "App_Fnc_ChTune.h"
38
39//#include "App_Fnc_Rating.h"
40//#include "App_Fnc_RRT.h"
41//#include "App_Fnc_CC.h"
42
43#include "App_Res_Resources.h"
44
45
46
47
48
49
50/*_____ D E F I N I T I O N ____________________________________*/
51
52#if COMMENT
53____DbgPrint____(){}
54#endif
55
56DHL_MODULE("@f_sds", 0);
57
58
59
60#if COMMENT
61____Overview____(){}
62#endif
63
64
65/*
66        special ¸ðµå ¿¹¿Ü µ¿ÀÛ:
67
68                rf tuner ¼³Á¤À» caller°¡ ¼öÇàÇÑ´Ù.
69                pid µµ ¹Ì¸® caller°¡ ¾Ë¾Æ¼­ Àü´ÞÇÑ´Ù.
70                download delay ¾øÀÌ ¹Ù·Î µ¿ÀÛ ÇÑ´Ù.
71                download ÁøÇà Áß¿¡ LED blinking µ¿ÀÛÇÑ´Ù.
72                download ¿Ï·á ÈÄ¿¡ power on ¸ðµå¿¡¼­ ¹Ù·Î upgrade ½ÃÀÛÇÑ´Ù.
73                upgrade ¿Ï·á ÈÄ¿¡´Â ÀÚµ¿ ´ë±â ¸ðµå ÁøÀÔÇÑ´Ù.
74
75
76        LED blinking ¹æ½Ä Á¤ÀÇ:
77                off, stby (red), full (blue)
78
79                downloading in progress:
80                        normal blue blinking
81
82                flashing ready:
83                        blue on
84
85                flashing in progress:
86                        fast blue blinking
87
88                all completed:
89                        off
90
91                error found
92                        red/blue toggle
93*/
94
95
96
97#if COMMENT
98____Config____(){}
99#endif
100
101
102
103/*
104        1 À̸é flash update¸¦ À§ÇÑ º°µµÀÇ task »ç¿ë.
105        Áö±ÝÀº ±×³É mw sdds task¸¦ Ȱ¿ëÇÑ´Ù.
106
107        ´Ü flash update µµÁß¿¡´Â task ÀÀ´ä¼º
108        ¾îÂ÷ÇÇ flash update´Â ÀÏ´Ü ½ÃÀ۵Ǹé Ãë¼Ò µÉ ¼öµµ ¾øÀ¸¹Ç·Î
109        Àá½Ã blocking µÇ¾îµµ ±¦Âú´Ù.
110*/
111#define USE_FUPDATE_TASK 0
112
113
114/*
115        sdds ¾÷µ¥ÀÌÆ® ÈÄ¿¡ autoscanÀ» ¼öÇàÇÑ´Ù.
116        autoscanÀº ±âÁ¸¿¡ ½ÅÈ£°¡ ÀâÇû´ø rf¿¡ ´ëÇØ¼­¸¸ ¼öÇàÇÑ´Ù.
117*/
118#define USE_AUTOSCAN_AFTER_UPDATE 1
119
120
121
122/*
123        °¢ sdds ½ºÆ®¸²¿¡´Â Á¦Á¶»ç OUI Äڵ尡 Æ÷ÇԵǾî ÀÖ°í,
124        ÇØ´ç OUI ¿Í ÀÏÄ¡ÇÏ´Â °æ¿ì¿¡¸¸ 󸮵ǵµ·Ï µÇ¾î ÀÖ´Ù.
125
126        ÀÌ Á¦Ç°¿¡¼­ »ç¿ëÇØ¾ß ÇÏ´Â OUI°¡ DST OUI°¡ ¾Æ´Ñ °æ¿ì¶ó¸é ¼öÁ¤ ÇÊ¿ä.
127        ¿¹: ¸¸¾à OEM/ODM Á¦Ç°ÀÇ °æ¿ì..
128       
129        ÀÌ ÄÚµå´Â APP_CONFIG µî°ú °°Àº ¾îµò°¡¿¡¼­ Áß¾Ó °ü¸®°¡ ¹Ù¶÷Á÷ÇÏ´Ù.
130*/
131#define APP_SDDS_CFG_MFG_OUI  IEEE_OUI_DST
132
133/*
134        ¾Æ·¡ °ªµéÀº DST SDDS ±Ô°Ý¿¡¼­ Á¤ÇÑ °¢ Á¦Ç°º° ¸ðµ¨ ¹øÈ£ÀÌ´Ù.
135
136*/
137#define APP_SDDS_CFG_MODEL_NEWCON2  0x03
138//#define APP_SDDS_CFG_MODEL_KVCONVERTER 0x02
139
140#define APP_SDDS_CFG_MODEL  APP_SDDS_CFG_MODEL_NEWCON2
141
142
143
144// address & offsets
145
146#define ADDR_FLASHBASE  0xbc000000
147
148#define OFFSET_BOOTLD 0x0
149#define OFFSET_APPIMG 0x10000
150
151#define ADDR_BOOTLD (ADDR_FLASHBASE+OFFSET_BOOTLD)
152#define ADDR_APPIMG (ADDR_FLASHBASE+OFFSET_APPIMG)
153
154#define ADDR_BOOTLD_ID  (ADDR_BOOTLD+0xc0)
155#define ADDR_BOOTLD_VER (ADDR_BOOTLD+0xd0)
156
157#define ADDR_APPIMG_ID  (ADDR_APPIMG+0x00)
158#define ADDR_APPIMG_VER (ADDR_APPIMG+0x10)
159
160
161
162#define APP_FLASH_ID 0
163
164
165
166/*
167        download ¿Ï·á µÈ »óÅ¿¡¼­ standby ¸ðµå ÁøÀÔ ÈÄ
168        ¾ó¸¶ ÈÄ¿¡ flash upgrade°¡ ½ÃÀ۵ǴÂÁö¸¦ ³ªÅ¸³»´Â delay °ª.
169
170        ÃÊ ´ÜÀ§À̸ç, Å×½ºÆ®¸¦ À§Çؼ­ º¯¼ö·Î ¸¸µë.
171*/
172int g_SddsUpgradeDelayInStandbyModeSeconds = 60*10;
173
174/*
175        1À̸é upgrade delay¸¦ 1ȸ¿¡ ÇÑÇÏ¿© skip ÇÏ°í ¹Ù·Î ½ÃÀÛÇÒ ¼ö ÀÖµµ·Ï ÇØÁØ´Ù.
176        Å×½ºÆ® ¸ñÀûÀÓ..
177*/
178BOOL g_SddsUpgradeSkipDelay;
179
180
181
182#if COMMENT
183____Types____(){}
184#endif
185
186
187const char *SddsCbTypeString(E_SDDS_CB_TYPE t)
188{
189        return (\
190        (t)==eSDDS_CB_TYPE_GetOUI          ? "GetOUI" :\
191        (t)==eSDDS_CB_TYPE_CheckCompatDesc ? "CompatDesc" :\
192        (t)==eSDDS_CB_TYPE_NotifySchedules ? "Schedule" :\
193        (t)==eSDDS_CB_TYPE_CheckModuleInfo ? "ModuleInfo" :\
194        (t)==eSDDS_CB_TYPE_DownloadNotRequired ? "NoDownload" :\
195        (t)==eSDDS_CB_TYPE_DownloadStarted ? "DLStart" :\
196        (t)==eSDDS_CB_TYPE_BlockReceived   ? "BlockRx" :\
197        (t)==eSDDS_CB_TYPE_DownloadCompleted ? "DLComplete" :\
198        (t)==eSDDS_CB_TYPE_DownloadStopped ? "DLStop" :\
199        (t)==eSDDS_CB_TYPE_ResetDownload   ? "Reset" :\
200        (t)==eSDDS_CB_TYPE_UserAction      ? "User" :\
201        "?");
202}
203
204const char *SddsStateString(APP_SDDS_STATE s) 
205{
206        return (\
207                (s)==eSDDS_STATE_INIT ? "Init" :\
208                (s)==eSDDS_STATE_DOWNLOADING ? "Downloading" :\
209                (s)==eSDDS_STATE_READY_FOR_FLASHING ? "ReadyForFlasing" :\
210                (s)==eSDDS_STATE_FLASHING ? "Flashing" :\
211                (s)==eSDDS_STATE_FLASH_END ? "FlashEnd" :\
212                (s)==eSDDS_STATE_COMPELTED ? "Completed" :\
213                "?");
214}
215
216
217
218typedef struct
219{
220        APP_SDDS_STATE state; 
221
222        int id; // ¿ø·¡ module id´Â 16 bit ÀÌ´Ù. -1 À̸é invalid¸¦ ÀǹÌÇÔ.
223        UINT32 size;
224        UINT8 *buffer;
225
226        UINT32 crc;
227        //BOOL bCompleted;
228       
229        UINT32 received_blocks;
230
231        int err; // if non-zero, error occurred during operation.
232       
233} APP_SDDS_FILE;
234
235typedef struct
236{
237        UINT32 start_time;
238        UINT32 duration;
239       
240} APP_SDDS_SCHEDULE;
241
242typedef struct
243{
244        //-------
245        // ÀÌ ºÎºÐÀÇ ÇʵåµéÀº ÀÏ¹Ý task¿¡¼­ update µÈ´Ù.
246        // º°µµÀÇ º¸È£¸¦ Çϰí ÀÖÁö ¾ÊÀ¸¹Ç·Î ¹®Á¦°¡ µÉ ¼ÒÁö°¡ ÀÖÀ½.
247        // ÇÏÁö¸¸ º¯°æ µÇ´Â °÷ÀÌ Á¦ÇÑÀûÀ̹ǷÎ, ÀÏ´Ü ÁøÇà.
248
249        // App_SddsServiceFound() ¿¡¼­ update µÇ´Â Çʵå. º¸Åë epg task ¿¡¼­ È£ÃâµÊ.
250        int    chtype;  // 0: air, 1: cable
251        int    rf;       // ÁøÇà ¿¹Á¤ ¶Ç´Â ÁøÇà ÁßÀÎ rf..
252
253        // App_SddsStart() ¿¡¼­ update µÇ´Â Çʵå.
254        //   °øÀå rfupdate Áß¿¡´Â menu task¿¡¼­, ÀÏ¹Ý sddsÀÇ °æ¿ì´Â timer task¿¡¼­ È£ÃâµÈ´Ù.
255        UINT16 pid;
256        UINT32 special; // °øÀå upgrade µîÀÇ special mode
257                // special ¸ðµå ¿¹¿Ü µ¿ÀÛ ºÎºÐ ¼³¸í Âü°í.
258       
259        //-------
260        // ¾Æ·¡ Çʵå´Â sdds mw task callback ¹× fupdate task ¿¡¼­¸¸ º¯°æµÈ´Ù.
261       
262        APP_SDDS_STATE state;  // Àüü state.
263
264        //-------
265        // ¾Æ·¡ ÇʵåµéÀº sdds mw task callback ¿¡¼­¸¸ º¯°æ µÈ´Ù.
266
267        int sched_chtype;
268        int sched_rf;
269        int sched_pid;
270
271        int n_sched;
272        APP_SDDS_SCHEDULE sched[10]; 
273                // 10 À̸é ÃæºÐÇÔ..
274                // »ç½Ç °¡Àå ½Ã°£ÀÌ °¡±î¿î °Í ¸î °³¸¸ ±â¾ïÇØµµ µÊ.
275
276        APP_SDDS_FILE file[2]; // boot loader and app
277        UINT32 total_blocks;
278
279        //-------
280        // ¾Æ·¡ Çʵå´Â fupdate task ¿¡¼­¸¸ º¯°æµÈ´Ù.
281
282        int total_bytes_to_write;
283        int already_done_bytes;
284        int flash_update_progress;     
285
286} APP_SDDS_INFO;
287
288
289#define APP_FW_ID_LEN 16
290#define APP_FW_VER_LEN 8
291
292typedef struct 
293{
294        // ¿ø·¡ Flash¿¡¼­ ÀÐÀº µ¥ÀÌÅÍ´Â null-termÀÌ ¾ÈµÇ¾î ÀÖÀ» ¼öµµ Àִµ¥
295        // ó¸®ÀÇ ÆíÀǸ¦ À§ÇØ nullz °ø°£±îÁö È®º¸ÇÑ´Ù.
296        char name[APP_FW_ID_LEN+1];
297        char ver[APP_FW_VER_LEN+1];
298       
299} APP_FW_VER;
300
301
302
303#define LIGHT_OFF  0
304#define LIGHT_RED  1
305#define LIGHT_BLUE 2
306
307#define LED_SEQ_OFF               0
308#define LED_SEQ_STEADY_BLUE       1
309#define LED_SEQ_BLUE_BLINK_NORMAL 2
310#define LED_SEQ_BLUE_BLINK_FAST   3
311#define LED_SEQ_STEADY_RED        4
312#define LED_SEQ_RED_BLINK_NORMAL  5
313#define LED_SEQ_RED_BLINK_FAST    6
314#define LED_SEQ_RED_BLUE_TOGGLE   7
315
316
317
318typedef struct {
319        int light;
320        UINT32 duration_ms;
321} APP_LED_OPERATION;
322
323
324
325
326
327#if COMMENT
328____Variables____(){}
329#endif
330
331/*
332        ÀÌ Å×½ºÆ® Ç÷¡±× º¯¼ö´Â Å×½ºÆ® ¿ëµµ·Î¸¸ »ç¿ëÇÑ´Ù.
333        Á¦Á¶»ç OUI¸¦ ¹«½ÃÇÏ°í ¸ðµç ±×·ìÀ» ´Ù accept ÇÑ´Ù.
334*/
335BOOL g_bSddsTestAllowAnyOUI;
336
337/*
338        1ÀÌ¸é ÆÄÀÏ id, version Á¤º¸°¡ µ¿ÀÏÇÏ´õ¶óµµ ´Ù½Ã ¹Þ´Â´Ù.
339        Å×½ºÆ® ¸ñÀûÀÌ´Ù.
340*/
341BOOL g_bSddsTestAcceptSameFile = 0;
342
343
344// DHL_SYS_
345UINT16 g_SddsVer2BdRevs[] =
346{
347        eREV_010, // ES board
348        eREV_020, // DS & 1st MP (600) board
349        eREV_030, // DS & 2nd MP board
350        eREV_040, // DS with MICOM
351};
352
353
354APP_SDDS_INFO g_SddsInfo;
355
356
357
358APP_FW_VER g_SddsFwVer[2];
359        // init °úÁ¤¿¡¼­ ä¿öÁø´Ù.
360        // [0] Àº boot loader
361        // [1] Àº app image
362
363
364BOOL g_SddsPowerOnMode;
365        // TRUE À̸é power on ¸ðµåÀÓ.
366
367
368
369APP_LED_OPERATION g_LedSequence[][2] =
370{
371        // 0: off
372        {
373                { LIGHT_OFF, 1000, }, { LIGHT_OFF, 1000, },
374        },
375        // 1: steady blue
376        {
377                { LIGHT_BLUE, 1000, }, { LIGHT_BLUE, 1000, },
378        },
379        // 2: blue blinking, normal
380        {
381                { LIGHT_BLUE, 500, }, { LIGHT_OFF, 500, },
382        },
383        // 3: blue blinking, fast
384        {
385                { LIGHT_BLUE, 150, }, { LIGHT_OFF, 150, },
386        },
387        // 4: steady red
388        {
389                { LIGHT_RED, 1000, }, { LIGHT_RED, 1000, },
390        },
391        // 5: red blinking, normal
392        {
393                { LIGHT_RED, 500, }, { LIGHT_OFF, 500, },
394        },
395        // 6: red blinking, fast
396        {
397                { LIGHT_RED, 150, }, { LIGHT_OFF, 150, },
398        },
399        // 7: red/blue toggle
400        {
401                { LIGHT_RED, 500, }, { LIGHT_BLUE, 500, },
402        },
403};
404
405
406
407#if COMMENT
408____Led____(){}
409#endif
410
411
412#define SDDS_LED_DOWNLOAD_START LED_SEQ_BLUE_BLINK_NORMAL
413#define SDDS_LED_UPGRADE_START LED_SEQ_BLUE_BLINK_FAST
414#define SDDS_LED_ERROR LED_SEQ_RED_BLUE_TOGGLE
415#define SDDS_LED_COMPELTED LED_SEQ_OFF
416
417void SddsLedBlinkTimerProc(UINT32 nIDTimer, UINT32 param)
418{
419        // nIDTimer == TIMER_ID_SDDS_LED
420
421        int type = (param >> 16) & 0x7;
422        int count = param & 1;
423       
424        DHL_UIO_Control(eDHL_UIO_CT_Indicator, eDHL_UIO_IT_Power, g_LedSequence[type][count].light);
425
426        DHL_SYS_StartTimer(eDHL_TIMER_IR_LED, g_LedSequence[type][count].duration_ms,
427                        SddsLedBlinkTimerProc, param ^ 1, TRUE);
428}
429
430void SddsStartLedBlink(int type)
431{
432        // sdds task º¸´Ù´Â priority°¡ ³ô¾Æ¾ß led°¡ µ¿ÀÛÇÑ´Ù.
433        // ¿Ö³Ä¸é flash upgrade Áß¿¡´Â cpu ¸®¼Ò½º¸¦ 100% Á¡À¯ÇϹǷÎ..
434       
435        DHL_SYS_StartTimer(eDHL_TIMER_IR_LED, 0,
436                        SddsLedBlinkTimerProc, type << 16UL, TRUE);
437}
438
439void SddsStopLedBlink(void)
440{
441        DHL_SYS_KillTimer(eDHL_TIMER_IR_LED);
442        DHL_UIO_Control(eDHL_UIO_CT_Indicator, eDHL_UIO_IT_Power, g_SddsPowerOnMode ? 2 : 1);
443}
444
445
446/*_____ F U N C T I O N ________________________________________*/
447
448
449#if COMMENT
450____Function____(){}
451#endif
452
453
454void SddsPrintInfo(void)
455{
456        int i;
457        UINT32 total_blocks = 0;
458       
459        //if (index != 0 && index != 1) return;
460
461        DHL_OS_Printf("-------- app sdds info --------\n");
462        DHL_OS_Printf(" rf %d, pid 0x%04x\n", g_SddsInfo.rf, g_SddsInfo.pid);
463        DHL_OS_Printf(" state: %s \n", SddsStateString(g_SddsInfo.state));
464
465        for (i=0; i<2; i++)
466        {
467                if (g_SddsInfo.file[i].state == eSDDS_STATE_INIT)
468                        DHL_OS_Printf(" file[%d]: %s\n", i, SddsStateString(g_SddsInfo.file[i].state));
469               
470                else
471                        DHL_OS_Printf(" file[%d]: (id 0x%04x, size %d, buf 0x%x) %s \n",
472                                i,
473                                g_SddsInfo.file[i].id,
474                                g_SddsInfo.file[i].size,
475                                g_SddsInfo.file[i].buffer,
476                                SddsStateString(g_SddsInfo.file[i].state));
477
478                if (g_SddsInfo.file[i].state == eSDDS_STATE_DOWNLOADING) {
479                        DHL_OS_Printf("    %u block received\n", g_SddsInfo.file[i].received_blocks);
480                        total_blocks += g_SddsInfo.file[i].received_blocks;
481                }
482                if (g_SddsInfo.file[i].state == eSDDS_STATE_READY_FOR_FLASHING)
483                        memdump(g_SddsInfo.file[i].buffer, 0x20, "");
484        }
485        if (g_SddsInfo.state == eSDDS_STATE_DOWNLOADING)
486                DHL_OS_Printf(" %u of total %u block received\n", total_blocks, g_SddsInfo.total_blocks);
487       
488}
489
490
491/*
492        App_SddsDeleteAll() api ¿¡ ÀÇÇØ¼­µµ callback µÇÁö¸¸,
493        table version ÀÌ º¯°æµÇ¾ú´Ùµç°¡ ÇÏ´Â ¿ÜºÎÀû ¿äÀο¡ ÀÇÇØ¼­µµ
494        reset µÇ±âµµ ÇÑ´Ù.
495
496        ¸ðµç ¸®¼Ò½º Á¾·áÇϰí, eSDDS_STATE_INIT »óÅ·Î..
497*/
498void SddsResetDownloadCallback(void)
499{
500        int i;
501        dprint(1, "sdds reset called\n");
502        for (i=0; i<2; i++) 
503        {
504                if (g_SddsInfo.file[i].buffer) {
505                        dprint(2, "  free file[%d] buffer %x\n", i, g_SddsInfo.file[i].buffer);
506                        DHL_OS_Free((void **)&g_SddsInfo.file[i].buffer);
507                }
508
509                memset(&g_SddsInfo.file[i], 0, sizeof(g_SddsInfo.file[0]));
510
511                g_SddsInfo.file[i].state = eSDDS_STATE_INIT;
512                g_SddsInfo.file[i].id = -1; // module id init value.
513        }
514
515        if (g_SddsInfo.special) {
516                SddsStopLedBlink();
517        }
518
519        g_SddsInfo.sched_chtype = 0;
520        g_SddsInfo.sched_rf = 0;
521        g_SddsInfo.sched_pid = 0;
522
523        g_SddsInfo.state = eSDDS_STATE_INIT;
524}
525
526
527void SddsReadCurrentFwVersion(void)
528{
529        /*
530                ¾Æ·¡ memcpy·Î ÀÎÇØ¼­ flash rom¿¡ Á÷Á¢ Á¢±ÙÇϴµ¥,
531                NVM ±â·Ï ÀÛ¾÷ µî¿¡ ¿µÇâÀÌ ÀÖÀ» ¼öµµ ÀÖ´Ù.
532                NVM ÂÊ mutex·Î º¸È£¸¦ ¹Þ¾Æ¾ß ÇÏ´Â °ÍÀÎÁö üũ ÇÊ¿ä.
533                ¾Æ´Ï¸é ½Ã½ºÅÛ ÃʱâÈ­ Áß¿¡ 1ȸ Àд ¹æ¹ý »ç¿ë.
534        */
535        int i;
536        char *p;
537        memset(g_SddsFwVer, 0, sizeof(g_SddsFwVer));
538
539        for (i=0; i<2; i++)
540        {
541                if (i==0) {
542                        // »ç½Ç loaderÀÇ ver °ø°£Àº 16À̳ª, 8¸¸ ºñ±³ÇÏÀÚ.
543                        memcpy(g_SddsFwVer[i].name, (UINT8 *)ADDR_BOOTLD_ID, 16);
544                        memcpy(g_SddsFwVer[i].ver,  (UINT8 *)ADDR_BOOTLD_VER, 8);
545                }
546                else {
547                        memcpy(g_SddsFwVer[i].name, (UINT8 *)ADDR_APPIMG_ID, 16);
548                        memcpy(g_SddsFwVer[i].ver,  (UINT8 *)ADDR_APPIMG_VER, 8);
549                }
550
551                // name °ú version ¹®ÀÚ¿­À» trim ÇÑ´Ù. ¸Ç µÚÀÇ space µéÀº Á¦°Å..
552                // sdds stream¿¡¼­ µé¾î¿À´Â °ÍµéÀº space°¡ ¾øÀ¸¹Ç·Î..
553               
554                p = g_SddsFwVer[i].name;
555                while (strlen(p) > 0 && p[strlen(p)-1] == ' ')
556                        p[strlen(p)-1] = 0;
557
558                p = g_SddsFwVer[i].ver;
559                while (strlen(p) > 0 && p[strlen(p)-1] == ' ')
560                        p[strlen(p)-1] = 0;
561        }
562}
563
564/*
565        Æß¿þ¾î¸¦ ´Ù¿î·Îµå ÇÒ Çʿ䰡 ÀÖ´Â °ÍÀÎÁö üũÇÑ´Ù.
566        ´Ù¿î·Îµå°¡ ÇÊ¿äÇÏ´Ù°í ÆÇ´ÜµÇ¸é TRUE¸¦ ¸®ÅÏÇÑ´Ù.
567
568        policy:
569                ½ºÆ®¸² ÀÌ»ó --> °¡´ÉÇϸé reject ÇÏ´Â ¹æÇâÀ¸·Î..
570                º¸µå Á¤º¸ ÀÌ»ó --> °¡´ÉÇϸé accept ÇÏ´Â ¹æÇâÀ¸·Î..
571               
572        ÇØ´ç sdds ½ºÆ®¸²¿¡ moduleinfodesc Á¤º¸°¡ ¾ø´Â °æ¿ì,
573        name, versionÀº NULL ÀÏ ¼ö ÀÖ´Ù.
574        ±×·² °æ¿ì Á¦´ë·Î µÈ ½ºÆ®¸²ÀÌ ¾Æ´Ñ °ÍÀ¸·Î ÆÇ´ÜÇϰí reject ÇÑ´Ù.
575
576        ÇöÀç º¸µåÀÇ Á¤º¸¸¦ Àд °úÁ¤¿¡¼­ ¹®Á¦°¡ ÀÖ´Ù°í ÆÇ´ÜµÇ¸é
577        accept ÇÑ´Ù.
578       
579        name, version stringÀÇ trailing space´Â ºñ±³¿¡¼­ Á¦¿ÜÇÑ´Ù.
580*/
581BOOL SddsCheckFirmwareAcceptable(UINT8 type, UINT8 *name, UINT8 *version, UINT32 crc32)
582{
583        BOOL bAccept = FALSE;
584        char *CurName, *CurVer;
585
586        if (!name || !version) {
587                dprint(0, "!! fw info invalid. type %x\n", type);
588                return FALSE; // reject. invalid stream.
589        }
590
591        /*
592                ¾Æ·¡ memcpy·Î ÀÎÇØ¼­ flash rom¿¡ Á÷Á¢ Á¢±ÙÇϴµ¥,
593                NVM ±â·Ï ÀÛ¾÷ µî¿¡ ¿µÇâÀÌ ÀÖÀ» ¼öµµ ÀÖ´Ù.
594                NVM ÂÊ mutex·Î º¸È£¸¦ ¹Þ¾Æ¾ß ÇÏ´Â °ÍÀÎÁö üũ ÇÊ¿ä.
595                ¾Æ´Ï¸é ½Ã½ºÅÛ ÃʱâÈ­ Áß¿¡ 1ȸ Àд ¹æ¹ý »ç¿ë.
596        */
597        if (type == ModuleType_BootLoader) {
598                CurName = (char *)g_SddsFwVer[0].name;
599                CurVer  = (char *)g_SddsFwVer[0].ver;
600        }
601        else if (type == ModuleType_Application) {
602                CurName = (char *)g_SddsFwVer[1].name;
603                CurVer  = (char *)g_SddsFwVer[1].ver;
604        }
605        else {
606                dprint(0, "!! unknown firmware type %x. skip!\n", type);
607                return FALSE; // reject. invalid stream.
608        }
609
610        // name °ú version ¹®ÀÚ¿­À» trim ÇÑ´Ù.
611        while (strlen(CurName) > 0 && CurName[strlen(CurName)-1] == ' ')
612                CurName[strlen(CurName)-1] = 0;
613        while (strlen(CurVer) > 0 && CurVer[strlen(CurVer)-1] == ' ')
614                CurVer[strlen(CurVer)-1] = 0;
615
616        dprint(2, "  check firmware: type %x, crc %08x\n", type, crc32);
617        dprint(2, "  sdds '%s' '%s' vs. cur '%s' '%s'\n", name, version, CurName, CurVer);
618
619        if (strlen(CurName) < 4 || strlen(CurVer) < 2)
620                bAccept = TRUE; // accept. strange board id & version.
621
622        if (strcmp((char *)name, CurName))
623                bAccept = TRUE; // accept. name is different.
624       
625        if (strcmp((char *)version, (char *)CurVer))
626                bAccept = TRUE; // accept. version is different.
627
628        // todo
629        // Á÷Á¢ flash¿¡ ±â·ÏµÈ fwÀÇ crc°ªÀ» °è»êÇÏ¿© ºñ±³Çصµ µÈ´Ù.
630        // ±×·¯³ª flash¿¡ ±â·ÏµÈ fwÀÇ Á¤È®ÇÑ Å©±â´Â ÇöÀç ¾Ë ¹æ¹ýÀº ¾ø´Ù.
631
632        if (bAccept == FALSE && g_bSddsTestAcceptSameFile) {
633                dprint(0, "!! test mode: accept file '%s' although it is same in flash\n", name);
634                bAccept = TRUE;
635        }
636        if (!bAccept)
637                dprint(2, "  no need to download this firmware\n");
638                // exactly same? then reject.
639       
640        return bAccept;
641}
642       
643
644/*
645        ÇöÀç ¿ì¸®ÀÇ º¸µå°¡ SDDS ½ºÆ®¸²ÀÇ firmware¿¡ ÀûÇÕÇÑÁö¸¦ üũÇÑ´Ù.
646
647        SDDS ½ºÆ®¸²¿¡´Â ÇØ´ç firmware°¡ µ¿ÀÛ °¡´ÉÇÑ º¸µå ¹öÀü ¸®½ºÆ®¸¦ Æ÷ÇÔÇϰí ÀÖ´Ù.
648        ±× ¸®½ºÆ®¿¡ ÇöÀç ÀڽŠº¸µåÀÇ ¹öÀü (¸®ºñÀü)ÀÌ Æ÷ÇԵǾî ÀÖ´ÂÁö¸¦ üũÇÏ¸é µÈ´Ù.
649
650        »ç¿ë °¡´ÉÇÏ´Ù¸é TRUE¸¦ ¸®ÅÏÇÑ´Ù. (accept)
651        »ç¿ëÀÌ ºÒ°¡´ÉÇÏ´Ù¸é FALSE¸¦ ¸®ÅÏÇÑ´Ù. (reject)
652*/
653BOOL SddsCheckBoardAcceptable(int NumBoard, UINT8 *BoardList)
654{
655        /*
656                SDDS ¿¡¼­ »ç¿ëµÇ´Â º¸µå ¹öÀü Á¤º¸¸¦ ¾ò´Â´Ù.
657                DHLÀÇ º¸µå ¸®ºñÀü Á¤º¸´Â 16bitÀÇ enum »ó¼öÀÌÁö¸¸,
658                SDDS ¿¡¼­´Â 1¹ÙÀÌÆ® ¹öÀü Á¤º¸¸¦ »ç¿ëÇϹǷÎ,
659                º°µµÀÇ numberingÀ» »ç¿ëÇϰí ÀÖ´Ù.
660                SDDS ¿¡¼­´Â º¸µå Ãâ½Ã ¼ø¼­´ë·Î ¹øÈ£¸¦ ºÎ¿©ÇÑ´Ù.
661        */
662        int i;
663        DHL_BOARD_TYPE dhl_type;
664        DHL_BOARD_REV  dhl_ver;
665        int SddsBdVer = -1; // sdds ½ºÆ®¸²¿¡¼­ »ç¿ëÇÏ´Â º¸µå ¹öÀü.
666       
667        DHL_SYS_GetBoardTypeVersion(&dhl_type, &dhl_ver);
668
669        for (i=0; i<sizeof(g_SddsVer2BdRevs)/sizeof(g_SddsVer2BdRevs[0]); i++) {
670                if (g_SddsVer2BdRevs[i] == dhl_ver)
671                        SddsBdVer = i;
672        }
673
674        // ÇöÀç º¸µå ¸®ºñÀüÀº ¹Ýµå½Ã À§ ¸®½ºÆ® 'g_SddsVer2BdRevs'¿¡ ÀÖ¾î¾ß ÇÑ´Ù.
675        // ¸¸¾à PCB HWBIT Á¤º¸°¡ À߸ø ÀÐÇô¼­ ±×·± °æ¿ì¶ó¸é º¸µå ¼ö¸®°¡ ÇÊ¿äÇÏ´Ù.
676        // ±×·¸Áö ¾Ê´Ù¸é g_SddsVer2BdRevs ¸®½ºÆ®¸¦ À߸ø ¸¸µç °ÍÀÌ´Ù.
677        //
678        /* tip:
679                ¾ç»êµÈ º¸µå¿¡ ¹®Á¦°¡ À־ (¶Ç´Â g_SddsVer2BdRevs ¹× DHL ¿¡ ¹ö±×°¡ À־)
680                ´ë·®À¸·Î update°¡ ¾ÈµÇ´Â °æ¿ì,
681                rfupdate(sdds) ½ºÆ®¸²¿¡¼­ numSupportedHwVersions¸¦ 0À¸·Î ÇÏ¿© ½ºÆ®¸²À» ¸¸µé¸é
682                ÀÌ ÇÔ¼ö¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù.
683        */
684        DHL_ASSERT(SddsBdVer >= 0, "Err! Check BdRev List or Hardware failure!!\n");
685        dprint(2, "  sdds bdver %u, dhl rev 0x%04x\n", SddsBdVer, dhl_ver);
686       
687        for (i=0; i<NumBoard; i++) 
688        {
689                if (BoardList[i] == SddsBdVer) {
690                        dprint(2, "  sdds bdver %u accepted\n", SddsBdVer);
691                        return TRUE; // accept.
692                }
693        }
694        dprint(2, "  this firmware not support this board\n");
695        return FALSE; // sorry. our board cannot use this firmware.
696}
697
698
699
700
701/*
702        °¢ ÆÄÀϺ° »óÅÂ:
703                * --> eSDDS_STATE_DOWNLOADING
704        Àüü »óÅÂ:
705                º¯°æ ¾øÀ½.
706
707        ¸¸¾à ¼º°øÇÏÁö ¸øÇÏ¸é ¿¡·¯ ¸®ÅÏ..
708
709        index´Â 0: loader, 1: app À¸·Î °íÁ¤Çؼ­ »ç¿ëÇÑ´Ù. sdds ¼½¼ÇÀÇ index°¡ ¾Æ´Ï´Ù.
710*/
711int SddsPrepareDownload(int index, UINT16 id, UINT32 size, UINT32 crc)
712{
713        int err = -1;
714        UINT8 *buffer;
715
716        if (index != 0 && index != 1) {
717                //DHL_ASSERT(FALSE, "");
718                dprint(0, "!! invalid fw index %d\n", index);
719                goto end;
720        }
721
722        if (g_SddsInfo.state != eSDDS_STATE_INIT) {
723                // ±×·² ¼ö ÀÖ´ÂÁö Á¶»ç ÇÊ¿ä..
724                // download Áß¿¡ ´Ù½Ã dsi ºÎÅÍ ¶Ç ½ÃÀÛ?
725                dprint(0, "!! prepare download, but not init state, state %d\n", g_SddsInfo.state);
726                SddsPrintInfo();
727                //DHL_ASSERT(FALSE, "");
728
729                SddsResetDownloadCallback(); // reset ÇÏ°í °è¼Ó ÁøÇàÇÏÀÚ.
730                goto end;
731        }
732
733        // check module id overlap..
734        // µÎ°³ÀÇ ÆÄÀÏ Áß¿¡ ´Ù¸¥ Çϳª°¡ ÀÌ¹Ì ÁøÇà ÁßÀε¥,
735        // ±× id ¿Í µ¿ÀÏÇØ ¹ö¸®¸é block ±¸ºÐÀÌ ¾ÈµÇ¾î ÁøÇàÀÌ ºÒ°¡´ÉÇÏ´Ù.
736        // ½ºÆ®¸²ÀÌ À߸ø ¸¸µé¾îÁø °æ¿ìÀÓ..
737        //
738        if (g_SddsInfo.file[1-index].id >= 0 &&
739                g_SddsInfo.file[1-index].id == id) 
740        {
741                dprint(0, "!! module id overap! [0] %d, [1] %d\n",
742                                g_SddsInfo.file[0].id, g_SddsInfo.file[1].id);
743                DMW_SDDS_Reset();
744                goto end;
745        }
746
747        if (g_SddsInfo.file[index].id >= 0) 
748        {
749                // ±âÁ¸¿¡ download ÇÏ´Ù°¡ ÀϽà ÁßÁöµÈ °æ¿ì¶ó¸é
750                // id, size, buffer µîÀÌ ¸ðµÎ Á¸ÀçÇØ¾ß ÇÔ. id´Â >=0 À̸é À¯È¿ÇÑ °ÍÀÓ.
751               
752                if (g_SddsInfo.file[index].id != id ||
753                        g_SddsInfo.file[index].size != size ||
754                        g_SddsInfo.file[index].buffer == NULL)
755                {
756                        dprint(0, "!! previous file info mismatch. %d %u %p\n",
757                                g_SddsInfo.file[index].id, g_SddsInfo.file[index].size, 
758                                g_SddsInfo.file[index].buffer);
759
760                        // id, size µîÀÌ ´Þ¶óÁö¸é MW ³»¿¡¼­ ¸ÕÀú ÀÌ »ç½ÇÀ» ¾Ë°í
761                        // resetÀ» Çϵµ·Ï µÇ¾î ÀÖÀ¸¹Ç·Î, ÀÌ·± °æ¿ì´Â ¹ß»ýÇÏÁö´Â ¾Ê´Â´Ù.
762                        //DHL_ASSERT(FALSE, "");
763                       
764                        // ±×³É reset Çϰí óÀ½ºÎÅÍ ´Ù½Ã ½ÃÀÛÇÏ´Â ¹æ¹ýÀº ÁÁÁö ¾ÊÀ½.
765                        // ¿Ö³Ä¸é DMW ÀÇ ³»ºÎ state¶û sync°¡ ¾È¸ÂÀ¸¹Ç·Î..
766                        // ±×³É ¿¡·¯·Î ¸®ÅÏÇÏÀÚ. ´Ù¿î·Îµå ÇÏÁö ¾Ê´Â´Ù.
767
768                        DMW_SDDS_Reset();
769                        goto end;
770                }
771        }
772       
773        if (g_SddsInfo.file[index].buffer) {
774                buffer = g_SddsInfo.file[index].buffer;
775                dprint(2, "use previous file[%d] buffer 0x%x\n", index, buffer);       
776        }
777        else {
778                buffer = DHL_OS_Malloc(size + 4); // add some safe margin.
779                if (!buffer) {
780                        dprint(0, "!! out of memory for file[%d] blk, size %u\n", index, size);
781                        //DHL_ASSERT(FALSE, "");
782                        DMW_SDDS_Reset();
783                        goto end;
784                }
785        }
786
787        dprint(2, "file[%d] is (size %u) accepted for download.\n", index, size);
788
789        g_SddsInfo.file[index].id = id; // module id.
790        g_SddsInfo.file[index].size = size;
791        g_SddsInfo.file[index].buffer = buffer;
792        g_SddsInfo.file[index].crc = crc;
793        g_SddsInfo.file[index].state = eSDDS_STATE_DOWNLOADING;
794
795        // µû·Î eSDDS_CB_TYPE_DownloadStarted Ãß°¡ ÇÏ¿´À¸¹Ç·Î ±× ¶§ »óÅ Àüȯ.
796#if 0
797        // µÎ ÆÄÀÏ Áß Çϳª¶óµµ download ¸ðµå¶ó¸é Àüüµµ download ¸ðµå¶ó°í º»´Ù.
798        //if (g_SddsInfo.file[1-index].state == eSDDS_STATE_DOWNLOADING)
799        g_SddsInfo.state = eSDDS_STATE_DOWNLOADING;
800#endif
801
802        dprint(0, "******** sdds file[%d] download start ********\n", index);
803        err = 0;
804       
805end:
806        if (dprintable(2))
807                SddsPrintInfo();
808       
809        return err;
810}
811
812/*
813        dii Á¤º¸ ºñ±³ °á°ú, ´Ù¿î·Îµå°¡ ÇÊ¿ä ¾øÀ» ¶§ È£ÃâµÈ´Ù.
814*/
815void SddsDownloadNotRequiredCallback(void)
816{
817        dprint(0, "******** no sdds file download required ********\n");
818
819        g_SddsInfo.file[0].state = eSDDS_STATE_COMPELTED;
820        g_SddsInfo.file[1].state = eSDDS_STATE_COMPELTED;
821        g_SddsInfo.state = eSDDS_STATE_COMPELTED;
822
823        // DMW_SDDS_Reset(); // reset Çϸé led°¡ reset µÇ¾î ¹ö¸²..
824
825        if (dprintable(2)) SddsPrintInfo();
826
827        if (g_SddsInfo.special)
828                SddsStartLedBlink(SDDS_LED_COMPELTED);
829}
830
831/*
832        ÆÄÀÏ ´Ù¿î·Îµå ¿©ºÎ üũ °¡ ³¡³ª°í, ½ÇÁ¦·Î ´Ù¿î·Îµå ¹Þ±â Á÷Àü¿¡ È£ÃâµÈ´Ù.
833        ¾î¶² ÆÄÀÏÀº ´Ù¿î·Îµå ´ë»óÀÌ ¾Æ´Ò ¼ö ÀÖ´Ù.
834        ÀÌ·± ÆÄÀÏÀº ±×³É eSDDS_STATE_COMPELTED »óÅ·ΠÀüȯ½ÃŲ´Ù.
835
836        °¢ ÆÄÀÏ º° »óÅÂ:
837                eSDDS_STATE_DOWNLOADING -> Çö»ó À¯Áö.
838                eSDDS_STATE_INIT -> eSDDS_STATE_COMPELTED
839        Àüü »óÅÂ:
840                ´Ù¿î·Îµå ÇÊ¿äÇϸé.. eSDDS_STATE_DOWNLOADING
841                ´Ù¿î·Îµå ÇÒ °ÍÀÌ ¾øÀ¸¸é.. eSDDS_STATE_COMPELTED
842*/
843void SddsDownloadStartCallback(S_SDDS_CBPARAM_DOWNLOAD_START *param)
844{
845        // µÎ ÆÄÀÏ Áß ¾î¶² °ÍÀº ´Ù¿î·Îµå ´ë»óÀÌ ¾Æ´Ò ¼öµµ ÀÖÀ½.
846       
847        if (g_SddsInfo.file[0].state < eSDDS_STATE_DOWNLOADING) {
848                dprint(0, "  file 0 is not for downloding.\n");
849                g_SddsInfo.file[0].state = eSDDS_STATE_COMPELTED;
850        }
851        if (g_SddsInfo.file[1].state < eSDDS_STATE_DOWNLOADING) {
852                dprint(0, "  file 1 is not for downloding.\n");
853                g_SddsInfo.file[1].state = eSDDS_STATE_COMPELTED;
854        }
855
856        // µÎ ÆÄÀÏ ´Ù download ´ë»óÀÌ ¾Æ´Ò °æ¿ì..
857        // ÀÌ callback ÀÌ ºÒ¸®Áö ¾Ê´Â°Ô Á¤»óÀ̰ÚÁö¸¸ Ȥ½Ã ºÒ¸®´õ¶óµµ nicely Á¾·á ÇÑ´Ù.
858        if (g_SddsInfo.file[0].state == eSDDS_STATE_COMPELTED &&
859                g_SddsInfo.file[1].state == eSDDS_STATE_COMPELTED) {
860                dprint(0, "!! both file not for download.. stop.\n");
861                g_SddsInfo.state = eSDDS_STATE_COMPELTED;
862
863                if (g_SddsInfo.special)
864                        SddsStartLedBlink(SDDS_LED_ERROR);
865               
866                DMW_SDDS_Reset();
867                return;
868        }
869        g_SddsInfo.total_blocks = param->total_blocks;
870
871        if (dprintable(2)) SddsPrintInfo();
872
873        // backup data for later operation.
874        // ³ªÁß¿¡ ´ë±â ¸ðµå ÁøÀÔ ÈÄ¿¡ ÀÚµ¿ update ½Ã¿¡ »ç¿ëµÈ´Ù.
875        //
876        g_SddsInfo.sched_chtype = g_SddsInfo.chtype;
877        g_SddsInfo.sched_rf = g_SddsInfo.rf;
878        g_SddsInfo.sched_pid = g_SddsInfo.pid;
879
880        if (g_SddsInfo.special)
881                SddsStartLedBlink(SDDS_LED_DOWNLOAD_START);
882
883        /* ÀÌ¹Ì ´Ù¿î·Îµå ¿Ï·á µÈ »óÅÂÀε¥µµ, ´Ù¸¥ ä³Î °¬´Ù µÇµ¹¾Æ¿À¸é
884                EpgMw µî¿¡¼­´Â ´Ù½Ã sdds download start¸¦ Çϵµ·Ï ÇÑ´Ù.
885                ±×·² °æ¿ì ´Ù½Ã downloading »óÅ·ΠÀüȯµÈ´Ù. ³í¸®ÀûÀ¸·Î´Â À߸øµÈ °ÍÀÓ.
886                ÇÏÁö¸¸ MW¿¡¼­ ¹Ù·Î download complete¸¦ ¾Ë·ÁÁֹǷÎ, Å« ¹®Á¦°¡ µÇÁö´Â ¾ÊÀ½.
887        */
888        g_SddsInfo.state = eSDDS_STATE_DOWNLOADING;
889       
890}
891
892
893void SddsReceivedOneBlockCallback(S_SDDS_CBPARAM_BLOCK_RECEIVED *cbp)
894{
895        int index;
896       
897        // module id ·ÎºÎÅÍ file index ãÀ½.
898        //
899        // file state´Â INIT »óÅÂÀÏ ¼ö ÀÖÀ½.
900
901        if (g_SddsInfo.state != eSDDS_STATE_DOWNLOADING) {
902                dprint(0, "!! blk received in not-downloading state %d.\n", g_SddsInfo.state);
903                if (dprintable(2)) SddsPrintInfo();
904                return;
905        }
906       
907        if (g_SddsInfo.file[0].id == cbp->ddb->moduleId)
908                index = 0;
909        else if (g_SddsInfo.file[1].id == cbp->ddb->moduleId)
910                index = 1;
911        else {
912                dprint(2, "!! unrecognized module id %x\n", cbp->ddb->moduleId);
913                if (dprintable(2)) SddsPrintInfo();
914                return;
915        }
916       
917        // ÇØ´ç ¸ðµâÀÌ downloading »óŰ¡ ¾Æ´Ò ¼öµµ ÀÖ´Ù.
918        // ¿¹¸¦ µé¾î ÀÌ¹Ì µ¿ÀÏÇÑ ÆÄÀÏÀÎ °æ¿ì ÇØ´ç ¸ðµâÀº upgrade ´ë»óÀÌ ¾Æ´Ò ¼ö ÀÖÀ½.
919        if (g_SddsInfo.file[index].state != eSDDS_STATE_DOWNLOADING) {
920                dprint(0, "!! file[%d] not for download\n", index);
921                return;
922        }
923       
924        if (cbp->offset + cbp->ddb->blockDataLength > g_SddsInfo.file[index].size) {
925                dprint(0, "!! offset %x + len %x exceed buffer limit %x\n",
926                                cbp->offset, cbp->ddb->blockDataLength, g_SddsInfo.file[index].size);
927                return;
928        }
929        if (g_SddsInfo.file[index].buffer == NULL) {
930                dprint(0, "!! no buffer for file[%d]\n", index);
931                return;
932        }
933
934        memcpy(g_SddsInfo.file[index].buffer + cbp->offset, 
935                cbp->ddb->blockDataBytePtr, cbp->ddb->blockDataLength);
936
937        dprint(2, "  file[%d]: #%u, %u/%u blocks rx\n", index, cbp->idxblk,
938                                cbp->received_blocks, cbp->total_blocks);
939
940        g_SddsInfo.file[index].received_blocks = cbp->received_blocks;
941
942        if (cbp->received_blocks == cbp->total_blocks) 
943        {
944                dprint(2, "  file[%d] download completed\n", index);
945
946                g_SddsInfo.file[index].state = eSDDS_STATE_READY_FOR_FLASHING;
947
948                // µÎ ÆÄÀÏ ´Ù ready µÈ °Å¸é Àüü »óŵµ ready.
949                // ´Ù¸¥ ÆÄÀÏÀº skip ÀÏ ¼öµµ ÀÖÀ½. ±×·² °æ¿ì ÀÌ¹Ì eSDDS_STATE_COMPELTED »óÅÂÀÓ.
950                if (g_SddsInfo.file[1-index].state >= eSDDS_STATE_READY_FOR_FLASHING) {
951
952                        dprint(2, "  all files are downloaded\n");
953                        g_SddsInfo.state = eSDDS_STATE_READY_FOR_FLASHING;
954
955                        // SDDS download ´Â ÀÌÁ¦ Áß´ÜÇØµµ µÈ´Ù.
956                        DMW_SDDS_Stop();
957                }
958        }
959}
960
961
962/*
963        MW¿¡¼­ ÆÄÀÏÀÇ download°¡ ¿Ï·áµÇ¸é È£ÃâµÈ´Ù.
964
965        ÁÖÀÇ»çÇ×:
966                stream¿¡ µé¾î ÀÖ´Â ¸ðµç ÆÄÀÏÀ» ´Ù ¹Þ´Â °ÍÀº ¾Æ´Ï´Ù.
967                ¾î¶² ÆÄÀÏÀº ÀÌ¹Ì update µÇ¾î À־ download ¹ÞÀ» Çʿ䰡 ¾øÀ» ¼öµµ ÀÖ´Ù.
968       
969        id´Â module_id ·Î¼­, ¿ì¸®°¡ »ç¿ëÇÏ´Â file index¿Í´Â ´Ù¸£´Ù.
970
971        id °¡ (UINT32)-1 À̸é ÇÊ¿äÇÑ ÆÄÀÏÀ» ´Ù ´Ù¿î·Îµå ¹Þ¾Ò´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù.
972*/
973void SddsDownloadCompletedCallback(int id)
974{
975        int i;
976        UINT32 crc;
977        BOOL bCrcError;
978       
979        if (id == (UINT32)-1) 
980        {
981                // all download completed.
982
983                dprint(0, "******** sdds download completed ********\n");
984
985                // blockÀ» ¹Þ´Â ¸Å ¼ø°£¸¶´Ù download complete üũ¸¦ ÇßÀ¸¹Ç·Î,
986                // MW¿¡¼­ complete callbackÀ» ºÎ¸¥ Çö ½ÃÁ¡¿¡¼­´Â ÀÌ¹Ì flashing Áغñ »óÅ¿¡ ÀÖ¾î¾ß ÇÑ´Ù.
987
988                // ±×·¯³ª download ´ë»óÀÌ ¾Æ´Ñ ÆÄÀϵ鵵 ÀÖÀ½¿¡ À¯ÀÇ.
989                // ÀÌ ÆÄÀϵéÀº ÀÌ¹Ì eSDDS_STATE_COMPELTED »óŰ¡ µÇ¾î ÀÖ´Ù.
990
991        #if 0
992                // ´Ù¿î·Îµå°¡ Á¦´ë·Î ¾ÈµÈ »óŶó¸é ¾îÂ÷ÇÇ crc ¿¡·¯ ¹ß»ýÇÒ °ÍÀ̰í, ÀÚµ¿ reset µÈ´Ù.
993                if (g_SddsInfo.state != eSDDS_STATE_READY_FOR_FLASHING)
994                        ;//DHL_ASSERT(FALSE, "");
995        #else
996                /*      ÀÌ¹Ì ´Ù¿î·Îµå ¿Ï·á µÈ »óÅ¿¡¼­ ä³Î º¯°æ¿¡ ÀÇÇØ ´Ù½Ã download start µÇ´Â °æ¿ì
997                        state°¡ ready_for_flashing ¿¡¼­ ´Ù½Ã downloadingÀ¸·Î º¯°æµÇ¾î ¹ö¸®´Â ¹®Á¦°¡ ÀÖ´Ù.
998                        °¡Àå ¹Ù¶÷Á÷ÇÑ ÇØ°áÃ¥Àº download start ÀÚü¸¦ ÇÏÁö ¾Ê´Â °ÍÀÓ.. À̰ÍÀº ³ªÁß¿¡ õõÈ÷ Çϰí,
999                        ÀÏ´Ü completed callbackÀÌ ¿À´Â °ÍÀ» Ȱ¿ëÇÏ¿© ÀÌ ¹®Á¦¸¦ ÇÇÇØ°£´Ù.
1000                */
1001                g_SddsInfo.state = eSDDS_STATE_READY_FOR_FLASHING;
1002        #endif
1003       
1004                // crc üũ Çѹø ÇØº¸ÀÚ. ¸¸¾à ¿©±â¼­ mismatch ³ª¸é Áß´ÜÇØ¾ß ÇÒ±î? -> yes.
1005                bCrcError = FALSE;
1006                for (i=0; i<2; i++) 
1007                {
1008                        // ´Ù¿î·Îµå ÇÏÁö ¾ÊÀº ÆÄÀÏÀº ´ç¿¬È÷ crc °è»êÇÏ¸é ¾ÈµÊ.
1009                        if (g_SddsInfo.file[i].state > eSDDS_STATE_READY_FOR_FLASHING)
1010                                continue;
1011
1012                        crc = DHL_UTL_CalcCRC32(DHL_CRC_START, g_SddsInfo.file[i].buffer, g_SddsInfo.file[i].size);
1013                        if (crc !=      g_SddsInfo.file[i].crc) {
1014                                dprint(0, "!! file[%d] crc mismatch! calc %x, stream %x\n", i, crc, g_SddsInfo.file[i].crc);
1015                                bCrcError = TRUE;
1016                        }
1017                        else
1018                                dprint(2, "  file[%d] crc ok\n", i);
1019                }
1020                if (bCrcError) {
1021                        DMW_SDDS_Reset();
1022                        return;
1023                }
1024               
1025                /*
1026                        ´ë±â ¸ðµå »óŶó¸é ¹Ù·Î upgrade¸¦ ½ÃÀÛÇØµµ ÁÁ´Ù.
1027
1028                        ÇöÀç ÀÌ task´Â sdds taskÀÌ´Ù.
1029                        ÀÌÁ¦ ÀÌ task´Â Ưº°È÷ ÇÏ´Â ÀÏÀº ¾ø´Ù.                   
1030                */
1031                if (g_SddsPowerOnMode == FALSE) 
1032                {
1033                        App_SddsUpgradeStart(0);
1034                        // µ¿ÀÏÇÑ sdds task·Î command¸¦ º¸³»´Â ÀÛ¾÷ÀÓ..
1035
1036                        // ÀÌ Âû³ª¿¡ power on ۰¡ ´­·Á¼­ ÀÌ¹Ì App_SddsStop() api°¡ ºÒ¸± ¼ö ÀÖ´Ù.
1037                        // ±×·¯¸é SddsDownloadStopped() °¡ ºÒ¸°´Ù.
1038                        //
1039                }
1040                else // power on ¸ðµåÀÎ °æ¿ì..
1041                {
1042                        // ´ë±â »óÅ·Πµé¾î°£ ÈÄ¿¡ ½Ç½Ã..
1043
1044                        // ±×·¯³ª °øÀå ¸ðµå µî Ư¼ö ¸ðµåÀÏ °æ¿ì´Â ¹Ù·Î ½ÃÀÛÇÑ´Ù.
1045                        if (g_SddsInfo.special) {
1046                                dprint(2, "special mode!\n");
1047                                App_SddsUpgradeStart(0);
1048                        }
1049                }
1050               
1051        }
1052        else 
1053        {
1054                // --- ÀϺΠ¸ðµâ ¸¸ ¿Ï·á µÇ¾úÀ½.
1055               
1056                dprint(2, "  module id %x completed\n", id);
1057
1058                // ÀÌ¹Ì ¸Å block ¼ö½Å Çϸ鼭 complete ¿©ºÎ¸¦ üũÇÏ¿© ÆÄÀÏ º° state´Â À̹Ì
1059                // ready for flashing »óŰ¡ µÇ¾î ÀÖ¾î¾ß ÇÑ´Ù.
1060                // double check!
1061                if (g_SddsInfo.file[0].id == id) {
1062                        if (g_SddsInfo.file[0].state != eSDDS_STATE_READY_FOR_FLASHING) {
1063                                //dprint(0, "!! file[%d] all blk download but wrong state\n");
1064                                DHL_ASSERT(FALSE, "");
1065                                g_SddsInfo.file[0].state = eSDDS_STATE_READY_FOR_FLASHING;
1066                        }
1067                }
1068                else if (g_SddsInfo.file[1].id == id) {
1069                        if (g_SddsInfo.file[1].state != eSDDS_STATE_READY_FOR_FLASHING) {
1070                                //dprint(0, "!! file[%d] all blk download but wrong state\n");
1071                                DHL_ASSERT(FALSE, "");
1072                                g_SddsInfo.file[1].state = eSDDS_STATE_READY_FOR_FLASHING;
1073                        }
1074                }
1075                else {
1076                        dprint(0, "!! dn completed cb: wrong id %d\n", id);
1077                }
1078        }
1079}
1080
1081
1082/*
1083        App_SddsStop() api¿¡ ´ëÇÑ callback.
1084       
1085        È£Ã⠵Ǵ °æ¿ì:
1086                - »ç¿ëÀÚ Ã¤³Î º¯°æ½Ã ¸¶´Ù..
1087                - Standby -> Power ON ½Ã¿¡..
1088*/
1089void SddsDownloadStoppedCallback(void)
1090{
1091        dprint(2, "download stopped\n");
1092
1093        // Ưº°È÷ ÇØ ÁÙ ÀÏ ¾øÀ½.
1094}
1095
1096
1097void SddsAllCompleted(void)
1098{
1099        if (g_SddsInfo.state != eSDDS_STATE_FLASH_END) {
1100                dprint(0, "!! not ready for complete !\n");
1101                return;
1102        }
1103       
1104#if USE_AUTOSCAN_AFTER_UPDATE
1105       
1106        App_NVM_SetBootingScan(TRUE);
1107        App_NVM_Sync();
1108        DHL_OS_Delay(3000);
1109                //ÀçºÎÆÃµÇ¸é scanÀ» Çϵµ·Ï ÇÔ.
1110       
1111#endif
1112
1113        g_SddsInfo.file[0].state = eSDDS_STATE_COMPELTED;
1114        g_SddsInfo.file[1].state = eSDDS_STATE_COMPELTED;
1115        g_SddsInfo.state = eSDDS_STATE_COMPELTED;
1116
1117        dprint(0, "******** sdds all update completed ********\n");
1118
1119        if (g_SddsInfo.special) 
1120        {
1121                if (g_SddsInfo.file[0].err || g_SddsInfo.file[1].err) {
1122                        // ¿¡·¯°¡ ¹ß»ýÇÑ °æ¿ì´Â »ý»ê¶óÀÎ ÀÛ¾÷ÀÚ°¡ ÀÌ »óȲÀ» ¾Ë ¼ö ÀÖµµ·Ï led Ãâ·ÂÀ» ÇØ ÁÖ°í,
1123                        // ¸®ºÎÆÃÇÏÁö ¾Ê°í ¹«ÇÑ ´ë±âÇÑ´Ù.
1124                        BOOL bExit = FALSE;
1125                        SddsStartLedBlink(SDDS_LED_ERROR);
1126                        while (!bExit) 
1127                                DHL_OS_Delay(1000);
1128                }
1129                else { //¹«Á¶°Ç ±â´Ù¸®°Ô ÇÏ´Â °Ô ³ªÀ» °Í °°À½
1130                        BOOL bExit = FALSE;
1131                        SddsStartLedBlink(SDDS_LED_COMPELTED);
1132                        while (!bExit) 
1133                                DHL_OS_Delay(1000);
1134                }
1135        }
1136       
1137        /*
1138                ´Ù ¿Ï·á µÇ¸é ¹«¾ùÀ» ÇÏ¸é µÇ´Â°¡?
1139
1140                ´ë±â¸ðµå¶ó¸é ±×³É reboot ÇÏ¸é µÈ´Ù.
1141                PowerOn »óŶó¸é »ç¿ëÀÚ°¡ OSD·Î ÀÌ »óȲÀ» ÁöÄѺ¸°í ÀÖÀ» °ÍÀÌ´Ù.
1142        */
1143
1144#if 0 //neverdai 110104 App_Proc_Standby¿¡¼­ ¾Ë¾Æ¼­ ó¸®ÇÔ..
1145        if (g_SddsPowerOnMode) // ON ¸ðµå
1146        {
1147                BOOL bExit = 0;
1148                /*
1149                        todo..
1150                        power on »óÅ¿¡¼­ upgrade°¡ ÀÌ·ç¾îÁø °æ¿ì´Â SDDS UI°¡ ¶° ÀÖ´Â »óÅÂÀÌ´Ù.
1151                        ±×³É ±â´Ù¸®°í ÀÖÀ¸¸é Proc_Power ÂÊ¿¡¼­ (¶Ç´Â menu task ¾îµð¼±°¡)
1152                        complete ¿Ï·á¸¦ ¾Ë¾Æ³»°í resetÀ» ÇÒ °ÍÀÓ..
1153                */
1154                while (!bExit) {
1155                        dprint(0, "!! wait system reset..\n");
1156                        DHL_OS_Delay(4000);
1157                        DHL_SYS_Reset(eDHL_RESET_Reboot);
1158                }
1159        }
1160        else // ´ë±â ¸ðµå
1161        {
1162                BOOL bExit = 0;
1163               
1164                while (!bExit) {
1165                        dprint(0, "!! reset system...\n");
1166                        DHL_SYS_Reset(eDHL_RESET_Reboot);
1167                        DHL_OS_Delay(4000);                     
1168                }
1169        }       
1170#endif
1171}
1172
1173
1174
1175
1176
1177
1178/*
1179        addrÀº Àý´ë ÁÖ¼Ò°¡ ¾Æ´Ï°í flash start ºÎÅÍÀÇ offset ÀÌ´Ù.
1180*/
1181int SddsFlashUpdateFile(int addr, int size, UINT8 *buf)
1182{
1183        DHL_RESULT dhr;
1184        int offset; // ±â·ÏÇÒ ÁÖ¼Ò ·ÎºÎÅÍÀÇ offset.
1185
1186        #define CHUNK_SZ 65536
1187       
1188        dprint(2, "update flash at addr %x, size %d (0x%x)..\n",
1189                        addr, size, size);
1190
1191        // size°¡ Ȧ¼öÀÎ °æ¿ì 16-bit flash¿¡¼­ ¹®Á¦°¡ µÈ´Ù.
1192        if (size & 1) {
1193                buf[size] = 0xff; // buf´Â marginÀ» °¡Áö°í ÀÖÀ¸¹Ç·Î 1¹ÙÀÌÆ® Á¤µµ´Â ±¦ÂúÀ½.
1194                size ++;
1195        }
1196        /* ÀûÀº Å©±â º°·Î ³ª´©¾î¼­ Ç¥½Ã¸¦ Çϵµ·Ï ÇÏÀÚ. ÁøÇà »óȲµµ Ç¥½Ã.
1197        */
1198        for (offset=0; offset<size; offset+=CHUNK_SZ)
1199        {
1200                int len = min(size-offset, CHUNK_SZ);
1201
1202                dprint(2, "  updating %x, size %x.. %d/100\n", addr+offset, len, offset*100/size);
1203                dhr = DHL_NVM_FlashWrite(APP_FLASH_ID, addr+offset, buf+offset, len);
1204                if (dhr) {
1205                        dprint(0, "!! flash update err %d\n", dhr);
1206                        return -2;
1207                }
1208
1209                g_SddsInfo.flash_update_progress = 
1210                        (g_SddsInfo.already_done_bytes + offset+len)*100 /
1211                        g_SddsInfo.total_bytes_to_write;
1212
1213                dprint(2, "  total update progress: %d\n", g_SddsInfo.flash_update_progress);
1214
1215                // ÀÌ task ¶§¹®¿¡ ³·Àº priority task°¡ ÀüÇô µ¿ÀÛÇÏÁö ¸øÇؼ­
1216                // ¹®Á¦°¡ »ý±ä´Ù.
1217                // ÃÖ¼ÒÇÑ DMW_Timer ´Â µ¿ÀÛÇÒ ¼ö ÀÖµµ·ÏÀÇ delay¸¸ ÁÖµµ·Ï ÇÔ.
1218                DHL_OS_Delay(20);
1219        }
1220        dprint(2, "flash update ok\n");
1221       
1222        return 0;
1223}
1224
1225
1226void SddsFlashUpdateCallback(UINT32 param)
1227{
1228        int i, r;
1229        char *name[2] = { "loader", "app", };
1230        UINT32 flashoffset[2] = { OFFSET_BOOTLD, OFFSET_APPIMG, };
1231
1232        /*
1233                todo..
1234                update ¸¦ Çϱâ Àü¿¡ ´Ù¸¥ task¿¡¼­ NVM ¿¡ Á¢±ÙÇÏÁö ¸øÇϵµ·Ï
1235                ¸·À» ¼ö ÀÖ´Â ¹æ¾È ÇÊ¿ä.
1236        */
1237
1238        for (i=0; i<2; i++) 
1239                g_SddsInfo.total_bytes_to_write += g_SddsInfo.file[i].size;
1240
1241        g_SddsInfo.already_done_bytes = 0;
1242        g_SddsInfo.flash_update_progress = 0;
1243
1244        if (g_SddsInfo.state != eSDDS_STATE_READY_FOR_FLASHING) {
1245                dprint(0, "!! not ready for flashing! state %u\n", g_SddsInfo.state);
1246                return;
1247        }
1248
1249        dprint(0, "******** sdds flash upgrade start ********\n");
1250        g_SddsInfo.state = eSDDS_STATE_FLASHING;
1251
1252        if (g_SddsInfo.special)
1253                SddsStartLedBlink(SDDS_LED_UPGRADE_START);
1254       
1255        /*
1256                task priority ¶§¹®¿¡ ´Ù¸¥ ÀÛ¾÷ÀÌ ¿øÈ° Ä¡ ¾ÊÀ» ¼ö ÀÖ´Ù.
1257                ÇÊ¿äÇϸé priority¸¦ ³·Ãß¾î¾ß ÇÑ´Ù.
1258               
1259                is it possible??
1260                todo..
1261        */
1262
1263        for (i=0; i<2; i++)
1264        {
1265                // skip ÇÏ´Â ÆÄÀÏÀÇ °æ¿ì..
1266                if (g_SddsInfo.file[i].state > eSDDS_STATE_FLASHING)
1267                        continue;
1268               
1269                dprint(2, "  update %s..\n", name[i]);
1270                g_SddsInfo.file[i].state = eSDDS_STATE_FLASHING;
1271
1272                if (dprintable(2))
1273                        memdump(g_SddsInfo.file[i].buffer, 0xe0, name[i]);
1274
1275                r = SddsFlashUpdateFile(flashoffset[i], 
1276                                g_SddsInfo.file[i].size, g_SddsInfo.file[i].buffer);
1277                if (r) {
1278                        dprint(0, "!! update %s err!\n", name[i]);
1279                        g_SddsInfo.file[i].err = 1;
1280                }
1281                //---- state Àüȯ.
1282                g_SddsInfo.file[i].state = eSDDS_STATE_FLASH_END;
1283
1284                //---- ÁøÇà »óȲ update
1285                g_SddsInfo.already_done_bytes += g_SddsInfo.file[i].size;
1286                g_SddsInfo.flash_update_progress = 
1287                        g_SddsInfo.already_done_bytes*100 / g_SddsInfo.total_bytes_to_write;
1288        }
1289
1290        g_SddsInfo.state = eSDDS_STATE_FLASH_END;
1291
1292        SddsAllCompleted();
1293
1294}
1295
1296
1297void SddsUserAction(UINT32 param)
1298{
1299        SddsFlashUpdateCallback(param);
1300}
1301
1302
1303void SddsDownloadStartTimerProc(UINT32 nIDTimer, UINT32 param)
1304{
1305        // nIDTimer == TIMER_ID_SDDS_WAIT_1
1306
1307        // »óÀ§ 16 bit´Â pid, ÇÏÀ§ 16 bit´Â program_number
1308        UINT16 program_number = (param >> 16);
1309        UINT16 pid = param & 0xffff;
1310
1311        // Âü°í: pid°¡ ÀÌ¹Ì È®Á¤µÈ °æ¿ì¶ó¸é program_number Á¤º¸´Â 0ÀÏ ¼öµµ ÀÖÀ½.
1312        dprint(2, "download start timer: pid 0x%x, p#%d\n", pid, program_number);
1313
1314        if (pid) {
1315                App_SddsStart(pid, 0);
1316                return;
1317        }
1318        if (program_number == 0)
1319                return;
1320       
1321        // program_number ·ÎºÎÅÍ pid ¸¦ ã¾Æ³»¾ß ÇÑ´Ù.
1322        // pat, pmtlist°¡ ¾ÆÁ÷ Áغñ°¡ ¾ÈµÇ¾ú´Ù¸é Á» ´õ ±â´Ù¸°´Ù.
1323
1324        if (1) 
1325        {
1326                ProgramAVInfo *av = Dmc_LockAVMutex();
1327                int i, index;
1328                MPEG_PMT *pmt = NULL;
1329
1330                /*
1331                        ¾Æ·¡ÀÇ ¿À·ù ¸Þ½ÃÁö¿¡ ÇØ´çµÇ´Â ¿À·ù´Â ¾ÆÁÖ ½É°¢ÇÑ ¿À·ùÀÌ´Ù.
1332                        ÀÌ ºÎºÐ¿¡ ¿À·ù°¡ ¹ß»ýÇÒ °æ¿ì sdds °¡ Á¦´ë·Î ¼öÇàµÇÁö ¸øÇϱ⠶§¹®ÀÌ´Ù.
1333
1334                        1¹ø ¿À·ùÀÇ °æ¿ì, ÀϽÃÀûÀ¸·Î pat, pmt°¡ ¾ÆÁ÷ ¹Ì¼ö½Å »óÅÂÀÏ ¼ö´Â ÀÖ´Ù.
1335                        ÇÏÁö¸¸ 5Ãʳª ¿©À¯¸¦ µÎ¾ú±â ¶§¹®¿¡ Á¤»ó »óȲÀº ¾Æ´Ï¶ó°í º¼ ¼ö ÀÖ´Ù.
1336
1337                        ¾î·µç ÀÌ sdds ¼­ºñ½º´Â ¸Å¿ì Áß¿äÇϹǷÎ, ¼º°øÇÒ ¶§ ±îÁö °è¼Ó ¹Ýº¹ ½ÃµµÇÑ´Ù.
1338                */
1339                do {
1340                        // 1. pat, pmt °¡ ¼ö½Å µÇ¾ú´ÂÁö È®ÀÎ.
1341                        if (!av->pat || !av->pmtList) {
1342                                dprint(0, "!! av pat/pmtlist not ready!\n");
1343                                break;
1344                        }
1345                        // 2. pat ¿¡¼­ program_number ¿¡ ÇØ´çµÇ´Â program °Ë»ö.
1346                        for (i=0, index=-1; i<av->pat->numPrograms; i++) {
1347                                if (av->pat->programs[i].program_number != program_number) continue;
1348                                index = i;
1349                                break;
1350                        }
1351                        if (index < 0) {
1352                                dprint(0, "!! program number %d not found in pat!\n", program_number);
1353                                break;
1354                        }
1355                        dprint(2, "  #%u of pmt[%d] selected\n", program_number, index);
1356                        // 3. pmt¸¦ ¾ò´Â´Ù.                     
1357                        pmt = av->pmtList[index];
1358                        // ÇöÀç ½Ãû ÇÁ·Î±×·¥ÀÇ pmt ÀÎ °æ¿ì, av->pmtList¿¡ ÀÖ´Â °ÍÀÌ ¾Æ´Ï°í av->pmt ¿¡ ÀÖ´Ù.
1359                        if (pmt == NULL && av->pmt && av->pmt->program_number == program_number) {
1360                                pmt = av->pmt;
1361                        }
1362                        if (pmt == NULL) {
1363                                dprint(0, "!! cannot find pmt of #%d\n", program_number);
1364                                break;
1365                        }
1366                        // 4. pmt ¾È¿¡¼­ sdds streamÀ» ã¾Æ pid Á¤º¸¸¦ ¾ò¾î³½´Ù.
1367                        for (i=0; pmt->streams && i<pmt->numStreams; i++) {
1368                                // ÇöÀç ½Ãû ÁßÀÎ pmtÀÇ °æ¿ì, pmtList¿¡ ¾ø´Ù.
1369                                if (pmt->streams[i].stream_type == StreamType_A97SDDS) {
1370                                        pid = pmt->streams[i].elementary_PID;
1371                                        break;
1372                                }
1373                        }
1374                        if (pid == 0) {
1375                                dprint(0, "!! sdds stream type not found in pmt!\n");
1376                                break;
1377                        }
1378                        dprint(2, "  pid 0x%x found\n", pid);
1379                } while (0);
1380               
1381                Dmc_UnlockAVMutex();
1382               
1383        }
1384
1385        if (pid) {
1386                App_SddsStart(pid, 0);
1387                return;
1388        }
1389        else {
1390                // ´Ù½Ã ´õ ±â´Ù¸².. ¼º°ø ÇÒ ¶§ ±îÁö °è¼Ó ¹Ýº¹ÇÑ´Ù.
1391                dprint(2, "  pat/pmt not ready or sdds stream not found.. wait more..\n");
1392                DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_1, 5000, SddsDownloadStartTimerProc, param, TRUE);         
1393        }
1394
1395       
1396}
1397
1398void SddsUpgradeStartTimerProc(UINT32 nIDTimer, UINT32 count)
1399{
1400        // nIDTimer == TIMER_ID_SDDS_WAIT_2
1401
1402        if (g_SddsUpgradeSkipDelay) {
1403                g_SddsUpgradeSkipDelay = count = 0;
1404        }
1405        dprint(0, "%d seconds left to flash upgrade..\n", count);
1406
1407        if (count == 0) {
1408                App_SddsUpgradeStart(0);
1409        }
1410        else {
1411                DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_2, 1000, 
1412                                SddsUpgradeStartTimerProc, count-1, TRUE);
1413        }
1414}
1415
1416
1417void SddsTunerCheckTimerProc(UINT32 nIDTimer, UINT32 param)
1418{
1419        // nIDTimer == TIMER_ID_SDDS_WAIT_0
1420        BOOL bLock;
1421        tDHL_Demod demod;
1422        DHL_RESULT dhr;
1423       
1424        dhr = DHL_FE_GetLockStatus((tDHL_TunerID)0, &bLock, &demod);
1425        if (dhr != DHL_OK || bLock == FALSE) {
1426                dprint(0, "!! tuner not locked\n");
1427                // wait one more time..
1428                DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_0, 1000, SddsTunerCheckTimerProc, param, TRUE);
1429                return;
1430        }
1431       
1432        // pid Á¤º¸¸¦ ¾Ë°í ÀÖÀ¸¹Ç·Î program_number Á¤º¸´Â ÇÊ¿ä ¾ø´Ù.
1433        DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_1, 5000, SddsDownloadStartTimerProc, 
1434                        g_SddsInfo.sched_pid, TRUE);           
1435}
1436
1437
1438
1439#if COMMENT
1440____UpdateTask____(){}
1441#endif
1442
1443
1444#if USE_FUPDATE_TASK
1445
1446DHL_TMHANDLE g_fupdate_task;
1447
1448#define UPDATE_TASK_CMD_Start 0x10
1449
1450
1451void SddsInitUpdateTask(void)
1452{
1453        DHL_RESULT dhr;
1454        DHL_TIMER_INIT_PARAM param;
1455
1456        memset(&param, 0, sizeof(param));
1457
1458        param.name = "FUpdate";
1459        param.max_timer_entry = 4;
1460        param.task_priority = TASK_PRI_DMW_FLASH;
1461        param.stack_size = 16384;
1462        param.use_mutex_lock = 0;
1463
1464        dhr = DHL_TIMER_Initialize(&param, &g_fupdate_task);
1465
1466        DHL_ASSERT(dhr == DHL_OK, "");
1467}
1468
1469void SddsUpdateTaskDispatcher(UINT32 cmd, UINT32 param)
1470{
1471        if (cmd == UPDATE_TASK_CMD_Start) {
1472                dprint(2, "start fwupdate..\n");
1473                SddsFlashUpdateCallback(0);
1474        }
1475}
1476
1477#endif // USE_FUPDATE_TASK
1478
1479
1480#if COMMENT
1481____EventProc____(){}
1482#endif
1483
1484
1485/******************************************************************************************
1486FUNCTION:
1487  - _App_SddsEventProc
1488
1489Purpose:
1490  - SDDS MW¿¡¼­ È£ÃâµÇ´Â °¢Á¾ callback 󸮱â.
1491
1492******************************************************************************************/
1493
1494static void _App_SddsEventProc(E_SDDS_CB_TYPE cbtype, void *param)
1495{
1496        dprint(3, "------- callback, cbtype %d (%s)\n", cbtype, SddsCbTypeString(cbtype));
1497
1498        if (0);
1499
1500#if 0
1501        else if (cbtype == eSDDS_CB_TYPE_GetOUI)
1502        {
1503                S_SDDS_CBPARAM_GET_OUI *cbp = (S_SDDS_CBPARAM_GET_OUI *)param;
1504                cbp->oui = APP_SDDS_CFG_MFG_OUI;
1505                if (g_bSddsTestAllowAnyOUI)
1506                        cbp->oui = 0x80000000; // special marker.. meaning accept anyone.
1507                /*  ÁÖÀÇ !!!!!!!!
1508                        ÀÌ ½ºÆä¼È ¸¶Ä¿´Â °³¹ß¿ëÀ¸·Î¸¸ »ç¿ëµÇ¾î¾ß ÇÔ!!!!
1509                        OUI´Â 24ºñÆ® À̹ǷÎ, À§ °ªÀº ½ÇÁ¦·Î´Â »ç¿ëµÇÁö ¾Ê´Â ¹üÀ§ÀÓ.
1510                */
1511                cbp->model = APP_SDDS_CFG_MODEL; // NEWBY
1512                cbp->version = 0xFFFF; // any version. we don't use version info.
1513        }
1514#else
1515        else if (cbtype == eSDDS_CB_TYPE_CheckCompatDesc) 
1516        {
1517                S_SDDS_CBPARAM_CHECK_DESC *cbp = (S_SDDS_CBPARAM_CHECK_DESC *)param;
1518                int i;
1519                for (i=0; i<cbp->desc->descriptorCount; i++) {
1520                        sddsCompatDescEntry_t *desc = &cbp->desc->desc[i];
1521                        if (desc->descriptorType != eSystemHardwareDescriptor &&
1522                                desc->descriptorType != eSystemSoftwareDescriptor)
1523                                continue;
1524                        if (desc->specifierType != compatSpecifierType_IEEE_OUI)
1525                                continue;
1526                        if (desc->specifierData != IEEE_OUI_DST)
1527                                continue;
1528                        if (desc->model != APP_SDDS_CFG_MODEL) // NEWCON2
1529                                continue;
1530                        cbp->isOk = TRUE;
1531                        break;
1532                }
1533        }
1534#endif
1535
1536        else if (cbtype == eSDDS_CB_TYPE_NotifySchedules) 
1537        {
1538                /*
1539                        ½ºÄÉÁÙ Á¤º¸´Â Ȱ¿ë ÇØµµ µÇ°í ¾ÈÇØµµ µÈ´Ù.
1540                        ´ë±â ¸ðµå µé¾î°¡¸é ±×³É ÁöÁ¤µÈ RF ¿¡ °¡¼­ sdds start ÇØµµ µÊ.
1541                        ¼­ºñ½º°¡ °ø½Ä ½ÃÀ۵DZâ Àü¿¡´Â ¾îÂ÷ÇÇ dii ºÎÅÍ´Â ÁøÇàÀÌ ¾ÈµÉ Å״ϱî..
1542                */
1543                int i;
1544                sddsScheduleDesc_t *sch = (sddsScheduleDesc_t *)param;
1545                for (i=0; sch && sch->schedules && i<sch->numSchedules; i++) {
1546                        dprint(2, "  sched[%d] %x, %d seconds\n", i,
1547                                sch->schedules[i].startTime,
1548                                sch->schedules[i].lengthInSeconds);
1549                }
1550        }
1551
1552        else if (cbtype == eSDDS_CB_TYPE_CheckModuleInfo) 
1553        {
1554        /*
1555                °¢ ¸ðµâ ÀÌ ¾î¶² °ÍÀÎÁö, download°¡ ÇÊ¿äÇÑ °ÍÀÎÁö µîÀ» Ã¼Å©ÇØ¼­ ¾Ë·ÁÁØ´Ù.
1556                ¸ðµâ Çϳª ¿¡ callbackÀÌ Çѹø ºÒ¸°´Ù. (Áï ¸ðµâ °¹¼ö¸¸Å­ ºÒ¸²)
1557
1558                ok (accept)¸¦ ¸®ÅÏÇϱâ Àü¿¡ ¹öÆÛ±îÁö ¹Ì¸® ÁغñÇØ µÎ¾î¾ß ÇÑ´Ù.
1559                ÀÌ callback ÀÌÈÄ¿¡ ¹Ù·Î À̾ data download callbackÀÌ ºÒ¸°´Ù.
1560        */
1561                S_SDDS_CBPARAM_CHECK_FILE *cbp = (S_SDDS_CBPARAM_CHECK_FILE *)param;
1562                BOOL bOk = TRUE;
1563                int err;
1564
1565                dprint(2, "check file: module id %u, '%s' '%s', %d bytes\n", cbp->id, cbp->name, cbp->version, cbp->size);
1566
1567                if (bOk)
1568                        bOk = SddsCheckFirmwareAcceptable(cbp->type, cbp->name, cbp->version, cbp->crc32);
1569
1570                // cafrii 100812 add
1571                // numSupportedHwVersions °¡ 0ÀÌ¸é ¸ðµç º¸µå¿¡ ´ëÇØ ´Ù Àû¿ë°¡´ÉÇÑ °ÍÀ¸·Î µ¿ÀÛÇÑ´Ù.
1572                if (bOk && cbp->numSupportedHwVersions)
1573                        bOk = SddsCheckBoardAcceptable(cbp->numSupportedHwVersions, cbp->supportedHwVersions);
1574
1575                if (bOk) {
1576                        // ÀÌÁ¦ ÀÌ ÆÄÀÏÀº download ÇÒ ÀÚ°ÝÀÌ µÇ¾úÀ½.
1577                        // ÀÌÁ¦ ´Ù¿î·Îµå Áغñ¸¦ ÇÑ´Ù.
1578                        int index = cbp->type == ModuleType_BootLoader ? 0 : 1;
1579                        err = SddsPrepareDownload(index, cbp->id, cbp->size, cbp->crc32);
1580                        if (err) bOk = FALSE;
1581                }
1582
1583                cbp->isOk = bOk;
1584
1585        }
1586
1587        else if (cbtype == eSDDS_CB_TYPE_DownloadNotRequired)
1588        {
1589                SddsDownloadNotRequiredCallback();
1590        }
1591       
1592        else if (cbtype == eSDDS_CB_TYPE_DownloadStarted)
1593        {
1594                SddsDownloadStartCallback((S_SDDS_CBPARAM_DOWNLOAD_START *)param);
1595        }
1596       
1597        else if (cbtype == eSDDS_CB_TYPE_BlockReceived) 
1598        {
1599                SddsReceivedOneBlockCallback((S_SDDS_CBPARAM_BLOCK_RECEIVED *)param);
1600        }
1601
1602        else if (cbtype == eSDDS_CB_TYPE_DownloadStopped) 
1603        {
1604                SddsDownloadStoppedCallback();
1605        }
1606
1607        else if (cbtype == eSDDS_CB_TYPE_ResetDownload)
1608        {
1609                SddsResetDownloadCallback();
1610        }
1611
1612        else if (cbtype == eSDDS_CB_TYPE_DownloadCompleted)
1613        {
1614                SddsDownloadCompletedCallback((int)param);
1615        }
1616       
1617#if !USE_FUPDATE_TASK
1618        else if (cbtype == eSDDS_CB_TYPE_UserAction)
1619        {
1620                SddsUserAction((UINT32)param);
1621        }
1622#endif
1623
1624}
1625
1626
1627
1628#if COMMENT
1629____API____(){}
1630#endif
1631
1632/******************************************************************************************
1633FUNCTION:
1634  - App_SddsStart
1635
1636Purpose:
1637  - ÁÖ¾îÁø pid Á¤º¸·Î sdds ±â´ÉÀ» ½ÃÀÛÇÑ´Ù.
1638    ´çÀåÀº dsi, dii µîÀÇ ¸Þ½ÃÁö¸¸ ¼ö½ÅÇÏ°Ô µÈ´Ù.
1639    ½ÇÁ¦·Î µ¥ÀÌÅÍ ´Ù¿î·Îµå¸¦ ÇÏ´Â ½ÃÁ¡Àº ³ªÁßÀÌ´Ù.
1640
1641    ÇÏÁö¸¸ ÀÌ ÇÔ¼ö°¡ Á÷Á¢ È£ÃâµÇ´Â °æ¿ì´Â º°·Î ¾ø´Ù.
1642    sdds ¼­ºñ½º°¡ Á¦°øµÇ°í ÀÖ´ÂÁö, Á¦°øµÇ°í ÀÖ´Ù¸é ¾î¶² pid ÀÎÁö µîÀÌ
1643    ã±âµµ ½±Áö ¾ÊÀ¸¹Ç·Î, º¸ÅëÀº EPG MW, Channel MW µî¿¡ discovery °úÁ¤À» ÀÇÁ¸ÇÑ´Ù.
1644   
1645******************************************************************************************/
1646void App_SddsStart(UINT16 pid, UINT32 special)
1647{
1648        dprint(2, "start sdds.. pid %x\n", pid);
1649
1650        g_SddsInfo.pid = pid;
1651        g_SddsInfo.special = special;
1652
1653        DMW_SDDS_Start(pid);
1654}
1655
1656
1657/******************************************************************************************
1658FUNCTION:
1659  - App_SddsStop
1660
1661Purpose:
1662  - ÇöÀç ä³Î¿¡¼­ ÁøÇà ÁßÀÎ sdds ´Ù¿î·Îµå¸¦ ÀϽà ÁßÁöÇÑ´Ù.
1663    ½ÇÁ¦·Î download°¡ µ¿ÀÛ ÁßÀÌÁö ¾Ê´õ¶óµµ È£ÃâÇÒ ¼ö ÀÖ´Ù.
1664
1665        º¸Åë ÇöÀç ä³Î ½Ãû ÇÏ´Ù°¡ ´Ù¸¥ ä³Î·Î ÀüȯÇϱâ Àü¿¡
1666        ÀÌ ÇÔ¼ö¸¦ ºÒ·¯ÁÖ¾î¾ß ¾ÈÀüÇÏ´Ù.
1667       
1668        --> 100803 Ãß°¡. ÀÌ ÇÔ¼ö¸¦ ¹Ýµå½Ã ºÒ·¯ÁÖ¾î¾ß ÇÑ´Ù.
1669        ¿Ö³Ä¸é sdds start launch ÇÏ´Â timer¸¦ ¿©±â¼­ cancel ½Ã۱⠶§¹®.
1670
1671    ³ªÁß¿¡ ´Ù½Ã ÇØ´ç ä³Î·Î µ¹¾Æ¿Í¼­ SddsStart·Î resumeÀÌ °¡´ÉÇÏ´Ù.
1672******************************************************************************************/
1673void App_SddsStop(void)
1674{
1675        DMW_SYS_KillTimer(TIMER_ID_SDDS_WAIT_0);
1676        DMW_SYS_KillTimer(TIMER_ID_SDDS_WAIT_1);
1677        DMW_SDDS_Stop();
1678}
1679
1680
1681/******************************************************************************************
1682FUNCTION:
1683  - App_SddsDeleteAll
1684
1685Purpose:
1686  - ÇöÀç
1687        µ¥ÀÌÅ͸¦ »èÁ¦Çϱâ À§Çؼ­ ÇöÀç µ¿ÀÛ ÁßÀÎ ´Ù¿î·Îµå ÀÛ¾÷µµ ÁßÁöµÈ´Ù.
1688        ¾î¶°ÇÑ »óȲ¿¡¼­ ÀÌ ÇÔ¼ö°¡ ÇÊ¿äÇÑÁö ¾ÆÁ÷ ¸íÈ®ÇÏÁö ¾ÊÀ½.
1689******************************************************************************************/
1690void App_SddsDeleteAll(void)
1691{
1692        dprint(2, "delete all!\n");
1693
1694        DMW_SDDS_Reset();
1695        // SddsResetDownloadCallback ÀÌ È£Ãâ µÊ.
1696}
1697
1698/******************************************************************************************
1699FUNCTION:
1700  - App_SddsServiceFoundCallback
1701
1702Purpose:
1703  - SDDS ¼­ºñ½º°¡ ¹ß°ßµÇ¸é EPG ¸ðµâ¿¡¼­ È£ÃâµÊ.
1704******************************************************************************************/
1705void App_SddsServiceFound(UINT32 n_ch, DmcEpgSddsProgramInfo *ch_list)
1706{
1707        // param: ¹ß°ßµÈ sdds ¼­ºñ½º ä³Î ¸®½ºÆ® Á¤º¸.
1708
1709        UINT16 sdds_pid = 0x1200; // todo Å×½ºÆ®..
1710        int rf, i;
1711
1712        dprint(2, "sdds service found. %d channels..\n", n_ch);
1713
1714        // ¿©·¯°³ÀÇ sdds ä³ÎÀÌ µ¿½Ã¿¡ ¼­ºñ½º µÇ°í ÀÖ´Â °æ¿ì´Â ÀÏ´Ü Á¦¿ÜÇÑ´Ù.
1715        // ºñ·Ï,
1716        //   1) ±¹³» ±Ô°ÝÀÇ ½Ã³ª¸®¿À 3Àº ÀÌ·± »óȲÀ» °¡Á¤Çϰí ÀÖÀ¸¸ç,
1717        //   2) EPG MWÀÇ discovery ±â´É ¹× ÀÎÅÍÆäÀ̽º´Â ÀÌ »óȲÀ» cover ÇÒ ¼ö ÀÖ°í,
1718        //   3) SDDS MWµµ (¾Æ¸¶µµ) º¹¼ö ä³Î ij·¯¼¿ ´Ù¿î·Îµå°¡ °¡´ÉÇÒ °Íµµ °°Áö¸¸,
1719        // app ·¹º§¿¡¼­´Â ÀÏ´Ü ´ÜÀÏ Ã¤³Î¸¸À» °í·ÁÇϵµ·Ï ÇÏÀÚ.
1720        //
1721        // Âü°í·Î ÇöÀç Á¦À۵Ǿî ÀÔ¼öµÈ KBS Å×½ºÆ® SDDS ½ºÆ®¸²Àº ½Ã³ª¸®¿À 1ÀÌ´Ù.
1722        // (´ÜÀÏ Ã¤³Î, ´ÜÀÏ ±×·ì case)
1723
1724        if (n_ch <= 0 || !ch_list) 
1725                return;
1726
1727        for (i=0; i<n_ch; i++) {
1728                dprint(2, "  (%d) rf %d, #%u, pid 0x%x\n", i, ch_list[i].id, ch_list[i].program_number, ch_list[i].pid);
1729        }
1730
1731        if (1) {
1732                UINT32 param;
1733                DST_CURCHANNEL *cur;
1734               
1735                cur = App_Ucm_GetCurChInfo(NULL);
1736
1737                // tuner °ü·Ã Á¤º¸´Â ±â·ÏÀ» ÇØ µÎ°í,
1738                g_SddsInfo.chtype = cur->nChannelType ? 1 : 0;
1739                g_SddsInfo.rf = cur->nRF;
1740
1741                // delay timer¸¦ °¡µ¿.
1742                param = (ch_list[0].program_number << 16UL) | (ch_list[0].pid);
1743                DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_1, 5000, SddsDownloadStartTimerProc, param, TRUE);         
1744        }
1745}
1746
1747
1748/*
1749        ÀÌ callbackÀº menu task ¿¡¼­ È£ÃâµÈ´Ù.
1750
1751        flash upgrade °¡ ½ÃÀÛµÉ Âû³ª¿¡ power on µîÀÌ µÇ´Â Àý¹¦ÇÑ »óȲÀ» °í·ÁÇØ º¸ÀÚ.
1752       
1753*/
1754void App_SddsPowerModeChanged(BOOL bPowerOn)
1755{
1756        if (bPowerOn) // ´ë±â¸ðµå -> ON ¸ðµå
1757        {
1758                /*
1759                        ÀÌ º¯¼ö¸¦ ¼³Á¤ Çϸé download°¡ ¿Ï·á µÇ¾îµµ flashing ½ÃÀÛÀº ¾ÈÇÑ´Ù.
1760                        ±×·¯³ª ¹Ù·Î Á÷Àü¿¡ download complete°¡ µÇ¾úÀ» ¼ö ÀÖ´Ù.
1761                        ±×·¯¸é Á¤ÇØÁø ¼ö¼ø¿¡ ÀÇÇØ flash update°¡ ½ÃÀ۵ȴÙ.
1762                */
1763                g_SddsPowerOnMode = TRUE;
1764
1765
1766                /*
1767                        ÀÏ´Ü Å¸À̸ӵµ ÁßÁöÇϰí stop message¸¦ º¸³» µÐ´Ù.
1768                        wait ¶Ç´Â download ÁøÇà ÁßÀÌ ¾ú´Ù¸é Áß´ÜÇØ¾ß ÇϹǷÎ..
1769                */
1770                DMW_SYS_KillTimer(TIMER_ID_SDDS_WAIT_2);
1771                App_SddsStop(); 
1772
1773                /*
1774                        Âü°í·Î ÀÌ¹Ì flash update°¡ ½ÃÀÛÇØ ¹ö·È´Ù¸é
1775                        À§ÀÇ stop message´Â Àû¿ëµÇÁö ¾Ê°í sdds task message queue¿¡¼­ ´ë±âµÈ´Ù.
1776
1777                        flash update°¡ ½ÃÀÛµÇ¸é °ð À̾ »óŰ¡ ÀüȯµÈ´Ù.
1778                        g_SddsInfo.state:
1779                                eSDDS_STATE_READY_FOR_FLASHING -> eSDDS_STATE_FLASHING
1780                       
1781                        ¾ÆÁÖ ¾à°£¸¸ ±â´Ù·È´Ù°¡ »óÅ üũ¸¦ ÇØ ÁÖ¸éµÈ´Ù.
1782                       
1783                        SddsDownloadCompleted --> SddsFlashUpdate ±îÁö °É¸®´Â ½Ã°£Àº
1784                        100ms º¸´Ù´Â ÈξÀ ªÀ» °ÍÀÌ´Ù.
1785                */
1786                DHL_OS_Delay(100);
1787
1788                if (g_SddsInfo.state == eSDDS_STATE_FLASHING)
1789                {
1790                        /*
1791                                ÀÌÁ¦ flash update°¡ µ¿ÀÛ ÁßÀÓÀÌ È®½ÇÇÏ´Ù.
1792                                ÇöÀç fw upgrade°¡ ÁøÇà ÁßÀ̶ó¸é ÇØ¾ß ÇÒ ÀÏÀÌ ¸¹À½.
1793                        */
1794                        dprint(0, "\n\n ********* fupdate is in progress ********\n\n\n");
1795                       
1796                       
1797                       
1798                        // show alert osd..
1799                        // DMG_MenuStart(MID_MESSAGE, ..)
1800                        /*
1801                                ÁøÇà »óȲÀº g_SddsInfo.flash_update_progress º¯¼ö¸¦ Âü°íÇÏ¸é µÈ´Ù.
1802                                api°¡ ÇÊ¿äÇÏ¸é ¸¸µéÀÚ.
1803                        */
1804                }
1805        }
1806        else  // ON ¸ðµå --> ´ë±â ¸ðµå
1807        {
1808                g_SddsPowerOnMode = FALSE;
1809
1810                if (g_SddsInfo.state > eSDDS_STATE_READY_FOR_FLASHING) {
1811                        // do nothing..
1812                        dprint(0, "!! flashing is in progress\n");
1813                }
1814                /*
1815                        ´Ù¿î·Îµå°¡ ´Ù µÇ¾î ready »óÅÂÀÎ °æ¿ì flash upgrade¸¦ ½ÃÀÛÇÑ´Ù.
1816                        ±Ô°Ý¿¡ µû¶ó ÀÏÁ¤ ½Ã°£ÀÌ Áö³­ ÈÄ¿¡ ¼öÇà..
1817                */
1818                else if (g_SddsInfo.state == eSDDS_STATE_READY_FOR_FLASHING) {
1819                        dprint(2, "ready for flashing. countdown...\n");
1820                        // ŸÀ̸Ӹ¦ µ¿ÀÛ??
1821                        // ÀÌ Å¸À̸Ӵ power onÀÌ µÉ ¶§ ´Ù½Ã cancel µÇ¾î¾ß ÇÔ.
1822
1823                        DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_2, 1000, 
1824                                                SddsUpgradeStartTimerProc, g_SddsUpgradeDelayInStandbyModeSeconds, TRUE);
1825                        //App_SddsUpgradeStart(0);
1826                }
1827                /*
1828                        download°¡ ÁøÇàÇÏ´Ù°¡ Áß´ÜÇÑ °æ¿ì,
1829                        ¶Ç´Â announcement°¡ µÇ¾î ÀÖ´Â °æ¿ì
1830                        Áö±ÝÀº micomÀÌ ¾øÀ¸¹Ç·Î ±»ÀÌ sdds ¼­ºñ½º°¡ ½ÃÀ۵Ǵ Á¤È®ÇÑ ½Ã°£¿¡ ¸ÂÃç
1831                        download¸¦ ½ÃÀÛÇÒ Çʿ䰡 ¾ø´Ù. ±×³É ¹«Á¶°Ç ½ÃÀÛÇÏ¸é µÈ´Ù.
1832                */
1833
1834                else if (g_SddsInfo.sched_rf && g_SddsInfo.sched_pid) 
1835                {
1836                        dprint(2, "---- start sdds in stdby mode, type %d, rf %d, pid %x \n", 
1837                                        g_SddsInfo.sched_chtype, g_SddsInfo.sched_rf, g_SddsInfo.sched_pid);
1838
1839                        // ´ë±â ¸ðµå ÁøÀԽÿ¡ proc_power ¿¡¼­ 5V Àü¿ø µîÀ» off ÇØ ¹ö·ÈÀ¸¹Ç·Î ´Ù½Ã ÄÑ¾ß ÇÔ.
1840                        dprint(2, "  turn on tuner 5V\n");
1841#if 0
1842                        DHL_SYS_SetGPIO(GPIO_5VDC_CTRL);
1843#endif
1844
1845                        // start tuner
1846                        DHL_FE_Start((tDHL_TunerID)0, 
1847                                        DHL_FE_ChannelToFrequency(g_SddsInfo.sched_rf, 
1848                                        g_SddsInfo.sched_chtype ? eDHL_FREQ_STD : eDHL_FREQ_AIR),
1849                                        eDHL_DEMOD_8VSB, NULL);
1850               
1851                        DMW_SYS_SetTimer(TIMER_ID_SDDS_WAIT_0, 1000, SddsTunerCheckTimerProc, 
1852                                        g_SddsInfo.sched_pid, TRUE);
1853                }
1854                else
1855                {
1856                        dprint(2, "no pending sdds jobs..\n");
1857                }
1858        }
1859}
1860
1861
1862
1863/******************************************************************************************
1864FUNCTION:
1865  - App_SddsUpgradeStart
1866
1867Purpose:
1868  - SDDS flash update ½ÃÀÛÇÑ´Ù.
1869 
1870******************************************************************************************/
1871void App_SddsUpgradeStart(UINT32 param)
1872{
1873        // background·Î ÀÛ¾÷ÇØ¾ß ÇÒ °Í °°À½..
1874
1875        // DMW_NvRam ÀÇ worker task¸¦ ¼öÁ¤Çؼ­ fupdate¿¡µµ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÏÀÚ.
1876        // todo..
1877
1878        // ÀÌ ÀÛ¾÷ µ¿¾ÈÀº NVM ¼öÁ¤ ÀÛ¾÷ µîÀÌ ¾ø¾î¾ß ÇÑ´Ù.
1879        // how to prevent this??
1880        //
1881
1882        DHL_RESULT dhr;
1883       
1884
1885#if USE_FUPDATE_TASK
1886        // paramÀº wait timeÀ¸·Î »ç¿ë..
1887        dprint(2, "upgrade will be started after %d sec..\n", param);
1888        dhr = DHL_TIMER_Start(g_fupdate_task, UPDATE_TASK_CMD_Start, 0, 
1889                        SddsUpdateTaskDispatcher, param*1000, TRUE);
1890
1891        if (dhr) {
1892                // ÀÌ °æ¿ì ´ëÃ¥ÀÌ ¾øÀ½..
1893        }
1894#else
1895        dprint(2, "upgrade is being started..\n");
1896        DMW_SDDS_UserAction(0); 
1897                // jump to SddsUserAction
1898                // »ç¿ëÀÚ ¸Þ½ÃÁö. ¿ì¸®ÀÇ °æ¿ì flash update Çϴµ¥ »ç¿ë.
1899       
1900#endif
1901
1902}
1903
1904
1905void App_SddsGetInfo(APP_SDDS_SHORT_INFO *pinfo)
1906{
1907        pinfo->state=g_SddsInfo.state;
1908        pinfo->update_progress=g_SddsInfo.flash_update_progress;
1909       
1910        if (g_SddsInfo.total_blocks != 0)
1911        {
1912                pinfo->download_progress=
1913                        (g_SddsInfo.file[0].received_blocks + g_SddsInfo.file[1].received_blocks)*100/
1914                        g_SddsInfo.total_blocks;
1915        }
1916        else
1917        {
1918                pinfo->download_progress = 0;
1919        }
1920       
1921        pinfo->chtype=g_SddsInfo.chtype;
1922        pinfo->rf=g_SddsInfo.rf;
1923        pinfo->pid=g_SddsInfo.pid;     
1924}
1925
1926
1927/******************************************************************************************
1928FUNCTION:
1929  - App_SddsInit
1930
1931Purpose:
1932  - SDDS ¸ðµâÀ» ÃʱâÈ­ ÇÑ´Ù.
1933 
1934******************************************************************************************/
1935void App_SddsInit(void)
1936{
1937        DMW_SDDS_Init();
1938
1939#if 0
1940        DHL_DBG_RegisterFunctionSymbol("epg_start", App_EpgUpdateStart);
1941        DHL_DBG_RegisterFunctionSymbol("epg_stop", App_EpgUpdateCancel);
1942        DHL_DBG_RegisterFunctionSymbol("epg_delete", App_EpgDeleteAll);
1943        DHL_DBG_RegisterFunctionSymbol("epg_list", Dmc_EpgPrintAllTables);
1944#endif
1945        DHL_DBG_RegisterVarSymbol(DHL_VAR_SYM_ARGS(g_bSddsTestAllowAnyOUI));
1946        DHL_DBG_RegisterVarSymbol(DHL_VAR_SYM_ARGS(g_SddsUpgradeDelayInStandbyModeSeconds));
1947        DHL_DBG_RegisterVarSymbol(DHL_VAR_SYM_ARGS(g_SddsUpgradeSkipDelay));
1948
1949        DMW_SDDS_RegisterCallback(_App_SddsEventProc);
1950
1951        SddsResetDownloadCallback();
1952
1953        SddsReadCurrentFwVersion();
1954
1955#if USE_FUPDATE_TASK
1956        SddsInitUpdateTask();
1957#endif
1958
1959}
1960
1961
1962#endif /* SUPPORT_SDDS */
1963
1964
1965int get_sdds_state()
1966{
1967        APP_SDDS_SHORT_INFO info;
1968
1969        App_SddsGetInfo(&info);
1970       
1971        return info.state;
1972}
1973
1974
1975/* end of file */
Note: See TracBrowser for help on using the repository browser.