source: svn/newcon3bcm2_21bu/dst/app/src/Function/App_Fnc_NvRam.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: 13.4 KB
Line 
1/****************************************************************************
2* NAME: App_Fnc_NvRam.c
3*----------------------------------------------------------------------------
4* Copyright (c) 2009 DIGITAL STREAM Technology Inc.
5*----------------------------------------------------------------------------
6* CREATED_BY: Sang Jae Park
7* CREATION_DATE: 2009/08/31
8* $Author: sjpark $
9* $Revision: 1.0 $
10* $Date: 2009/08/31 $
11*----------------------------------------------------------------------------
12* PURPOSE:
13*       -
14*****************************************************************************/
15
16/*_____ I N C L U D E __________________________________________*/
17
18#include "App_Main.h"
19
20#if SUPPORT_NVRAM
21
22#include "App_Fnc_Common.h"
23
24#include "App_Fnc_RRT.h"
25
26#include "App_Res_Resources.h"
27        /* TODO : why does this file included ? */
28
29
30
31
32/*_____ D E F I N I T I O N ____________________________________*/
33
34#if COMMENT
35____DbgPrint____(){}
36#endif
37
38DHL_MODULE("@f_nvm", 1);
39
40
41
42
43
44#if COMMENT
45____Config____(){}
46#endif
47
48#define NEO_REGISTER_DEBUG_SYMBOL       0
49
50#define NEO_NVM_USERPARAM_OFFSET        0x80000010
51
52#define NEO_NVM_SYNC_DELAY_SEC  3 // ÃÊ ´ÜÀ§ÀÇ nvram sync delay.       
53
54
55
56
57#if COMMENT
58____Types____(){}
59#endif
60
61
62typedef struct 
63{
64        UINT32 magic;
65        UINT8 version;
66       
67        UINT8 param[MAX_SIZE_SYSDB_IN_FLASH-8];
68} tPriv_NvmParam;
69
70static DHL_OS_SEMA_ID p_sema;
71
72#if COMMENT
73____Variable___(){}
74#endif
75
76static tPriv_NvmParam p_nvm_cache;
77
78static struct {
79        tApp_NvmModule module;
80        int size;
81        tApp_NvmFormatFunc func;
82} p_nvr_module_table[eAPP_NVR_MAX_NUM_MODULE];
83
84
85static struct
86{
87        BOOL bscan_when_booting;
88        BOOL bshow_boot_logo;
89        BOOL bshow_setup_wizard;
90
91        UINT8 custom1;
92        UINT8 custom2;
93        UINT8 custom3;
94        UINT8 custom4;
95} p_nvr_global;
96
97
98#if COMMENT
99____Defines___(){}
100#endif
101
102
103#define IsValidChannelType(type) \
104                ((type)==ChannelType_Air || (type)==ChannelType_Cable)
105
106
107#define UCMIdString(id) ( \
108                (id) == DB_ID_AIR_UCM ? "Air" : \
109                (id) == DB_ID_CABLE_UCM ? "Cable" : "??")
110
111
112#define OFFSET_UCM_DB(id) ( \
113                (id)==DB_ID_AIR_UCM ?   OFFSET_AIR_UCM_DB : \
114                (id)==DB_ID_CABLE_UCM ? OFFSET_CABLE_UCM_DB : OFFSET_AIR_UCM_DB)
115                               
116#define MAX_SIZE_UCM_DB(id) ( \
117                (id)==DB_ID_AIR_UCM   ? MAX_SIZE_AIR_UCM_DB : \
118                (id)==DB_ID_CABLE_UCM ? MAX_SIZE_CABLE_UCM_DB : MAX_SIZE_CABLE_UCM_DB)
119
120
121
122
123#if COMMENT
124____Private_func___(){}
125#endif
126
127
128
129
130
131
132static STATUS p_lock_mutex()
133{
134        return (STATUS)DHL_OS_TakeSemaphore(p_sema, DHL_TIMEOUT_FOREVER);
135}
136
137static void p_unlock_mutex()
138{
139        DHL_OS_GiveSemaphore(p_sema);
140}
141
142
143
144
145
146#if COMMENT
147____Sync___(){}
148#endif
149
150
151/*
152        nv parameter¸¦ ÀúÀåÇϱâ À§ÇÑ Å¸À̸Ӹ¦ ±âµ¿ÇÏ´Â ÇÔ¼ö
153        ¸¸¾à ŸÀӾƿôÀÌ ¹ß»ýÇϸé App_NVM_SaveNvParamÀÌ È£ÃâµÇ¾î ¸ðµç nv parameter¸¦ ÀúÀåÇÏ´Â ·çƾÀ» ¼öÇàÇÔ.
154*/
155static STATUS p_trigger_nvm_sync(void)
156{
157        // Timer°¡ ÀÖÀ¸¸é Á¦°Å
158        DMW_SYS_KillTimer(TIMER_ID_NVM_SYNC);
159
160        dprint(0, "trigger nvsync..\n");
161       
162        // Timer¸¦ ¼¼ÆÃÇÏ¿© ÀûÁ¤ ½Ã°£ µÚ¿¡ Flash¿¡ sync
163        return DMW_SYS_SetTimer(TIMER_ID_NVM_SYNC, NEO_NVM_SYNC_DELAY_SEC*1000, 
164                        (DMW_TIMER_PROC)App_NVM_Sync, 0, TRUE);
165}
166
167
168/*
169        flash¿¡ ÇÒ´ç µÈ NVM ¿µ¿ª¿¡ µ¥ÀÌÅ͸¦ ±â·ÏÇÒ ¶§,
170        DMW_CDB_WriteNvRam() ¸¸ È£ÃâÇϸé cache ¹öÆÛ¿¡¸¸ ±â·ÏµÇ°í ½ÇÁ¦ flash¿¡´Â ±â·ÏµÇÁö ¾Ê´Â´Ù.
171        ½ÇÁ¦ flash¿¡´Â sync ÀÛ¾÷À» ¼öÇà ÇÒ ¶§ ±â·ÏÀÌ µÈ´Ù.
172       
173        sync¸¦ ÇÏ´Â ¹æ¹ýÀº µÎ°¡Áö ¹æ½ÄÀÌ ÀÖ´Ù.
174         1. Áö±Ý ¹Ù·Î NVM¿¡ µ¥ÀÌÅ͸¦ ½ÇÁ¦·Î ±â·Ï (sync)ÇÒ ¼öµµ ÀÖ°í
175         2. ±×³É Áö±Ý ´çÀåÀº trigger¸¸ ½ÃÄÑµÎ°í ³ªÁß¿¡ ±â·ÏÀ» (sync) ÇÒ ¼öµµ ÀÖ´Ù.
176         
177        º¯°æ µÈ µ¥ÀÌÅÍÀÇ Á߿䵵 ¹× NVM ÀåÄ¡ÀÇ ¼ö¸íÀ» °í·ÁÇÏ¿© ÀûÀýÇÏ°Ô ÆÇ´ÜÇÑ´Ù.
178   1. p_trigger_nvm_sync() ³ªÁß¿¡ sync¸¦ ÇÑ´Ù.
179   2. App_NVM_NvSync() Áö±Ý ´çÀå sync¸¦ ÇÑ´Ù.
180*/
181
182STATUS App_NVM_Sync(void)
183{
184        STATUS status;
185
186        dprint(0, "nvm sync\n");
187       
188        // Timer°¡ ÀÖÀ¸¸é Á¦°Å
189        DMW_SYS_KillTimer(TIMER_ID_NVM_SYNC);
190
191        status = DMW_CDB_SyncNvRam(OFFSET_SYSDB_SAVED_IN_FLASH);
192        if(status)
193                dprint(0, "!! Fail NvRamSync err %d\n", status);
194
195        return status;
196}
197
198
199
200
201
202
203
204
205#if COMMENT
206____App_NVM_SysParam___(){}
207#endif
208
209/*
210*/
211STATUS App_NVM_LoadNvParam(void)
212{
213        STATUS status=statusOK;
214       
215        // load.....
216        status = DMW_CDB_ReadNvRam(NEO_NVM_USERPARAM_OFFSET, sizeof(p_nvm_cache), 
217                (UINT8 *)&p_nvm_cache);
218
219        if (status != statusOK) 
220        {
221                dprint(0, "!!%s: Read NvRam error %d\n",__func__, status);
222                return statusNvRamNotFormatted;
223        }
224        // check magic
225        if (p_nvm_cache.magic != APP_NVM_MAGIC)
226        {
227                dprint(0, "!!%s: missmatched NvRam magic [0x%08x:0x%08x]\n",
228                        __func__, p_nvm_cache.magic, APP_NVM_MAGIC);
229                return statusNvRamNotFormatted;
230        }
231        // check version
232        if (p_nvm_cache.version != APP_NVM_VERSION)
233        {
234                dprint(0, "!!%s: missmatched NvRam version[0x%x:0x%x] \n",
235                        __func__, p_nvm_cache.version, APP_NVM_VERSION);
236                return statusNvRamNotFormatted;
237        }
238       
239        App_NVM_LoadModuleParam(eAPP_NVR_GLOBAL, &p_nvr_global);
240
241        return status;
242}
243
244
245/*
246        App_Fnc_NvRam¿¡¼­ °ü¸®ÇÏ´Â nvcacheÀÇ Àüü ³»¿ëÀ» NVM¿¡ writeÇÏ´Â ÇÔ¼ö.
247        sync ¸¦ ¹Ù·Î ÇÏÁö ¾Ê°í trigger¸¸ ¼öÇàÇÑ´Ù.
248*/
249STATUS App_NVM_SaveNvParam(void)
250{
251        STATUS status;
252       
253        status = DMW_CDB_WriteNvRam(NEO_NVM_USERPARAM_OFFSET, sizeof(p_nvm_cache), 
254                (UINT8 *)&p_nvm_cache);
255               
256        if (status) {
257                dprint(0, "!!%s: Write NvRam err %d\n", __func__, status);
258                return status;
259        }
260        status = p_trigger_nvm_sync();
261        return status;
262}
263
264
265/*
266        nv parameter¸¦ ÃʱâÈ­ ÇÏ´Â ÇÔ¼ö
267        bWaitComplete           : flash¿¡ writeµÇ´Â µ¿¾È ´ë±â ÇÒÁö ¸»ÁöÀÇ ¿©ºÎ
268*/
269STATUS App_NVM_FormatNvParam(BOOL bWaitComplete)
270{
271        int i;
272        STATUS status=statusOK;
273        // nvm Àüü¸¦ format ÇÑ´Ù.
274        dprint(3, "Format NvRAM...\n");
275        status = DMW_CDB_LowLevelFormatNvRam();
276       
277        if (status) {
278                dprint(0, "!! NvRAM format error %d %s, check eeprom or flash! \n", 
279                        status, DMW_CDB_ErrString(status));
280                return status; 
281        }
282       
283        p_nvm_cache.magic = APP_NVM_MAGIC;
284        p_nvm_cache.version = APP_NVM_VERSION;
285       
286        dprint(3, "preparing default param values...\n");
287       
288        // °¢ ¸ðµâº°·Î ÁöÁ¤µÇ¾îÀÖ´Â func¸¦ È£ÃâÇØ¼­ ÃʱâÈ­ÇÑ´Ù.
289        for(i=0; i<eAPP_NVR_MAX_NUM_MODULE; i++) {
290                if(p_nvr_module_table[i].func) (*p_nvr_module_table[i].func)();
291        }
292       
293        // channel db¸¦ reset ÇÑ´Ù.
294        if (1) {
295                UINT32 addr[2];
296               
297                addr[0] = OFFSET_AIR_UCM_DB;
298                addr[1] = OFFSET_CABLE_UCM_DB;
299               
300                status = DMW_CDB_InitUCM2(addr, 2, FALSE); // ³ªÁß¿¡ ÇѲ¨¹ø¿¡ sync ÇÒ °ÍÀÓ..
301                if (status) {
302                        dprint(0, "!! FormatNvRam: InitUCM2 err %d\n", status);
303                        return status; // ¿¡·¯ ¸®ÅÏ ¹æ¹ý ÇÊ¿ä..
304                }
305        }
306       
307        // RRT
308        AppRrt_ResetRrtDB(FALSE); // don't sync now.
309       
310        App_NVM_SaveNvParam(); // ³»ºÎ¿¡¼­ sync trigger´Â Çϴµ¥, µÚ¿¡¼­ ¹Ù·Î syncÇϹǷΠignore µÈ´Ù.
311       
312        App_NVM_Sync();
313       
314        if (bWaitComplete)
315                DMW_CDB_WaitForNvRamSyncDone();
316               
317        return status;
318}
319
320
321STATUS App_NVM_RegisterModule(tApp_NvmModule module, int size, tApp_NvmFormatFunc func)
322{
323        p_nvr_module_table[module].module=module;
324        p_nvr_module_table[module].size=size;
325        p_nvr_module_table[module].func=func;
326       
327        return statusOK;
328}
329
330
331STATUS App_NVM_SaveModuleParam(tApp_NvmModule module, void *pparam)
332{
333        int i;
334        int offset=0;
335        STATUS status=statusError;
336       
337        p_lock_mutex();
338       
339        for(i=0; i<eAPP_NVR_MAX_NUM_MODULE; i++) {
340                if(p_nvr_module_table[i].module==module) {
341                        memcpy(p_nvm_cache.param+offset, pparam, p_nvr_module_table[i].size);
342                        status=statusOK;
343                        break;
344                }
345                else {
346                        offset+=p_nvr_module_table[i].size;
347                }
348        }
349       
350        p_unlock_mutex();
351       
352        App_NVM_SaveNvParam();
353       
354        return status;
355}
356
357
358STATUS App_NVM_LoadModuleParam(tApp_NvmModule module, void *pparam)
359{
360        int i;
361        int offset=0;
362        STATUS status=statusError;
363       
364        p_lock_mutex();
365       
366        for(i=0; i<eAPP_NVR_MAX_NUM_MODULE; i++) {
367                if(p_nvr_module_table[i].module==module) {
368                        memcpy(pparam, p_nvm_cache.param+offset, p_nvr_module_table[i].size);
369                        status=statusOK;
370                        break;
371                }
372                else {
373                        offset+=p_nvr_module_table[i].size;
374                }
375        }
376       
377        p_unlock_mutex();
378       
379        return status;
380}
381
382
383
384
385#if COMMENT
386____App_NVM_UCM___(){}
387#endif
388
389void App_NVM_PrintUcm(int level)
390{
391        // ucm printing is not masked by trace value.
392        // so, before printing ucm, check first.
393        // if this is shell, then always print message.
394
395        DST_CURCHANNEL ChannelInfo;
396        App_Ucm_GetCurChInfo(&ChannelInfo);
397
398        if (!AppCheckPrintable() && !DHL_DBG_IsDbgShell()) 
399                return;
400
401        // cafrii add message
402        DHL_OS_Printf("Current: '%s' %d-%d, RF %d #%d, uid %d\n", 
403                ChannelInfo.nChannelType == ChannelType_Air ? "Air" : "Cable",
404                ChannelInfo.nMajor, ChannelInfo.nMinor,
405                ChannelInfo.nRF, ChannelInfo.nProgramNumber,
406                ChannelInfo.nUid);
407
408        DMW_CDB_PrintUcm(level);
409}
410
411
412/************************************************************************
413        Channel DB Load/Save API
414
415        g_CurChannelType, POD Inserted »óÅ °ª¿¡ µû¶ó¼­ ¾î¶² DB¸¦ »ç¿ëµÉ °ÍÀÎÁö °áÁ¤µÈ´Ù.
416       
417        ChannelType_Cable¿¡´Â ¼¼ Á¾·ùÀÇ Frequency Standard°¡ Àִµ¥,
418        ÀÌµé °£ÀÇ ±¸ºÐÀº ¾ø´Ù.
419**************************************************************************/
420STATUS App_NVM_LoadUcm(void)
421{
422        STATUS status;
423        int type = g_CurChannelType;
424
425        int db_index = 
426                                (type) == ChannelType_Air ? DB_ID_AIR_UCM : DB_ID_CABLE_UCM;
427       
428        // cafrii 041110
429        // use new UCM access API (level 4).. 
430        //
431        dprint(3,"Load %s UCM\n", UCMIdString(db_index));
432        status = DMW_CDB_ReadUCM2(OFFSET_UCM_DB(db_index));
433       
434        if (status) {
435                dprint(0,"Ucm load status %d\n", status);
436                return status;
437        }
438
439        App_NVM_PrintUcm(0);   // cafrii 041126 fix, now MW has its own DB print function..
440       
441        return statusOK;
442}
443
444
445STATUS App_NVM_SaveUcm(void)
446{
447        STATUS status;
448        int type = g_CurChannelType;
449       
450        UINT32 ucm_save_size;
451        //UINT32 ucm_save_addr;
452       
453        int db_index = 
454                (type) == ChannelType_Air ? DB_ID_AIR_UCM :     DB_ID_CABLE_UCM;
455       
456
457        // NVM UCM size°¡ non-uniform À̹ǷÎ, ¹Ì¸® °¹¼ö üũ¸¦ ÇÒ ¼ö ¾ø´Ù.
458        // Â÷·Ê·Î ÀúÀå ÇØ °¡´Ù°¡ overflow µÇ¸é ±× ½ÃÁ¡¿¡¼­ Áß´ÜÇÏ´Â ¹æ¹ý ¹Û¿¡ ¾øÀ½.
459        dprint(3,"Save %d %s UCM item to NvRAM.\n", g_UCM_number, UCMIdString(db_index));
460       
461        // cafrii 041110
462        // use new UCM access API (level 4).. we only need to know nvram start address
463        //
464        // cafrii 041129, change API prototype
465        // now WriteUCM2 has new db_max_size parameter
466        //
467        // cafrii 041215, bugfix.. although ucm_size is zero, we have to save it!
468        //if (ucm_save_size)
469        {
470                status = DMW_CDB_WriteUCM2(OFFSET_UCM_DB(db_index), MAX_SIZE_UCM_DB(db_index), UCMIdString(db_index));
471                                                        // cafrii 041129 prototype changed, add new parameter
472                if (status) {
473                        dprint(0,"!! WriteUCM status %d\n", status);
474                        return status;
475                }
476
477                // ucm dbÀÇ °æ¿ì ¹Ù·Î ¹Ù·Î sync¸¦ Çϵµ·Ï ÇÏÀÚ.
478                status = App_NVM_Sync();
479                if(status)
480                {
481                        dprint(0,"!! NvRam Sync status %d\n", status);
482                }
483        }
484        dprint(3,"     %s UCM DB update completed!\n", UCMIdString(db_index));
485
486        return statusOK;
487}
488
489
490/*
491        App_EraseUcmInNvRam:
492       
493        NVRAM ¿µ¿ª¿¡¼­ UCMÀ» »èÁ¦ÇÑ´Ù.
494        ÇöÀç channel type¿¡ ÇØ´çÇÏ´Â UCM DB¸¸ »èÁ¦ÇÑ´Ù.
495*/
496void App_NVM_EraseUcm(void)
497{
498        UINT32 address; //, db_size;
499        int type = g_CurChannelType;
500       
501        if (IsValidChannelType(type)) {
502               
503                int db_index = 
504                        (type) == ChannelType_Air ? DB_ID_AIR_UCM : DB_ID_CABLE_UCM;
505               
506                address = OFFSET_UCM_DB(db_index);
507                DMW_CDB_InitUCM2(&address, 1, TRUE); // sync µµ °°ÀÌ ¼öÇà.
508        }
509        else {
510                dprint(3,"!! EraseUcmInNvRam: invalid channel type %d\n", type);
511        }
512}
513
514
515#if COMMENT
516____Global_Nvram____(){}
517#endif
518
519
520static void p_format_global_param()
521{
522        p_nvr_global.bscan_when_booting=FALSE;
523        p_nvr_global.bshow_boot_logo=FALSE;
524        p_nvr_global.bshow_setup_wizard=TRUE;
525       
526        //p_nvr_global.custom1=0;
527        p_nvr_global.custom1=1; //0Àº english, 1Àº spanish
528        p_nvr_global.custom2=0;
529        p_nvr_global.custom3=0;
530        p_nvr_global.custom4=0;
531       
532        App_NVM_SaveModuleParam(eAPP_NVR_GLOBAL, &p_nvr_global);
533}
534
535
536void App_NVM_SetBootingScan(BOOL bset)
537{
538        p_nvr_global.bscan_when_booting=bset;
539        App_NVM_SaveModuleParam(eAPP_NVR_GLOBAL, &p_nvr_global);
540}
541
542BOOL App_NVM_GetBootingScan()
543{
544        return p_nvr_global.bscan_when_booting;
545}
546
547
548int App_NVM_GetMenuLang()
549{
550        return p_nvr_global.custom1;
551}
552
553
554void App_NVM_SetMenuLang(int menu_id)
555{
556        p_nvr_global.custom1=menu_id;
557        App_NVM_SaveModuleParam(eAPP_NVR_GLOBAL, &p_nvr_global);
558}
559
560
561void App_NVM_SetShowSetupWizard(BOOL bshow)
562{
563        p_nvr_global.bshow_setup_wizard=bshow;
564        App_NVM_SaveModuleParam(eAPP_NVR_GLOBAL, &p_nvr_global);
565}
566
567BOOL App_NVM_GetShowSetupWizard()
568{
569        return p_nvr_global.bshow_setup_wizard;
570}
571
572
573#if COMMENT
574____Debug____(){}
575#endif
576
577
578
579
580
581#if COMMENT
582____Symbol____(){}
583#endif
584
585#if NEO_REGISTER_DEBUG_SYMBOL
586static DHL_SymbolTable _NvRamSymbols[] =
587{
588        DHL_FNC_SYM_ENTRY2("nvm_format", App_NVM_FormatNvParam),
589        DHL_FNC_SYM_ENTRY2("nvm_load", App_NVM_LoadNvParam),
590        DHL_FNC_SYM_ENTRY2("nvm_save", App_NVM_SaveNvParam),
591
592        DHL_FNC_SYM_ENTRY2("ucm", App_NVM_PrintUcm),
593
594};
595static void RegisterSymbols(void)
596{
597        DHL_DBG_RegisterSymbols(_NvRamSymbols, DHL_NUMSYMBOLS(_NvRamSymbols));
598}
599
600#else
601static void RegisterSymbols(void) { }
602
603#endif  /* NEO_REGISTER_DEBUG_SYMBOL */
604
605
606
607
608
609#if COMMENT
610____Init____(){}
611#endif
612
613
614
615void App_NVM_Init(void)
616{
617        static BOOL is_inited=FALSE;
618       
619        if(is_inited) return;
620               
621        is_inited=TRUE;
622       
623        /* °¢Á¾ init code */
624        //dprint(0, "NVM max size: %d (0x%x)\n", OFFSET_NVM_END, OFFSET_NVM_END);
625       
626        p_sema=DHL_OS_CreateMutexSemaphore("nvm");
627       
628        RegisterSymbols();
629       
630        //except variables in each module, global variables which must be stored in NVRAM can be added here !
631        App_NVM_RegisterModule(eAPP_NVR_GLOBAL, sizeof(p_nvr_global), p_format_global_param);
632       
633}
634
635#endif /* SUPPORT_NVRAM */
636
637
638void test_load_global() 
639{
640        App_NVM_LoadModuleParam(eAPP_NVR_GLOBAL, &p_nvr_global);
641}
642
643
644
645/* end of file */
Note: See TracBrowser for help on using the repository browser.