source: svn/trunk/newcon3bcm2_21bu/dta/src/nexus/dta_app_ucos.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 12.1 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile:  $
11 * $brcm_Revision:  $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log:  $
19 *
20 ***************************************************************************/
21
22#include "ministd.h"
23#include "serial.h"
24#include "ucos_ii.h"
25#include "bos.h"
26#include "bos_task_priorities.h"
27
28#include "nexus_platform.h"
29#include "nexus_core_utils.h"
30
31
32#define BPRINT_STK_SIZE                         0x400
33#define CONSOLE_STK_SIZE                        4096
34#define TEST_TASKINFO_STK_SIZE          512             /* in words */
35#define APP_STK_SIZE                            2048    /* in words */
36#ifdef CONFIG_ENABLE_EMU
37        #define TASKINFO_SLEEP_ms       100
38#else
39        #define TASKINFO_SLEEP_ms       2000
40#endif
41
42BDBG_MODULE(boot_nexus);                /* Register software module with debug interface */
43
44static b_task_t app_task_h;
45static b_task_t info_task_h;
46static b_task_t console_task_h;
47static b_task_t bprint_task_h;
48
49static unsigned int bprint_stack[BPRINT_STK_SIZE];
50
51extern void ram_start(void);
52extern void bapp_util_start_profiling(void);
53extern void bapp_util_stop_profiling(void);
54
55unsigned get_opt(void);
56void test_taskinfo_main(void *data);
57int console_main(void *data);
58static void bprint_entry(void *data);
59
60bool s_printing_enabled;
61
62//static void set_cpu_frequency(unsigned int pll_div);
63
64void bcm_main(void)
65{
66        b_task_params console_params;
67        BERR_Code berr;
68
69//      set_cpu_frequency(6);
70       
71        bos_init();
72        /* kni and dbg must be initialized after os since they use os primitives */
73        berr = BKNI_Init();
74        BKNI_Print_Init();
75        berr = BDBG_Init();
76        /* test message for BDBG routines */
77        BDBG_ERR(("### BOS INIT DONE ###"));
78
79        calc_cache_sizes();
80        print_cache_sizes();
81
82        console_params.name = "console";
83        console_params.priority = CONSOLE_PRIORITY;
84        console_params.stack_size = CONSOLE_STK_SIZE;
85        console_params.stack = (unsigned int *)malloc(console_params.stack_size * sizeof(unsigned int));
86       
87        printf("%s stack @ 0x%08x\n",console_params.name, console_params.stack);
88        bos_start_task(&console_task_h,&console_params,console_main,&console_task_h);
89
90        console_params.name = "bprint";
91        console_params.priority = BPRINT_PRIORITY;
92        console_params.stack_size = BPRINT_STK_SIZE;
93        console_params.stack = bprint_stack;
94
95        bos_start_task(&bprint_task_h, &console_params, bprint_entry,&bprint_task_h);
96        bos_start();
97
98        printf("%s..SHOULD NEVER GET HERE.\n",__FUNCTION__);
99        __asm("break 2");
100}
101
102int console_main(void *data)
103{
104        unsigned int *stack;
105        unsigned int *info_stack;
106        b_task_params params;
107        unsigned int cmd;
108
109        bos_calibrate();
110        stack = malloc(APP_STK_SIZE * 4);
111        if (NULL != stack)
112        {
113                params.priority = APP_PRIORITY;
114                params.stack_size = APP_STK_SIZE;
115                params.stack = stack;
116                params.name = "ram_start";
117                bos_start_task(&app_task_h, &params, (void *)ram_start, &app_task_h);
118        }
119
120        while (1) 
121        {
122                printf("Console Menu:\n");
123#ifdef BCM_DEBUG
124                printf("1)  Memory Use...\n");
125#endif
126#ifdef PROFILE
127                printf("2)  Profile Start...\n");
128                printf("3)  Profile Stop...\n");
129#endif
130                printf("4)  Download and update signed image\n");
131                printf("5)  Download and update software in flash\n");
132                printf("6)  Toggle TASKINFO periodic display\n");
133#ifdef CONFIG_SMARTCARD_TEST
134                printf("7)  Smartcard test\n");
135#endif
136                printf("8)  Print system status...\n");
137                printf("9)  Enter FM deviation factor...\n");
138                printf("11) Reboot\n");
139#ifdef BCM_DEBUG
140                printf("12) MVD Debug Info\n");
141                printf("13) Scratch Info\n");
142#endif
143                printf("21) Erase second image\n");
144                printf("22) Invoke debug stub\n");
145#if defined(CONFIG_DTA_CABLE) && defined(FOR_DOLBY_CERTIFICATION)
146                printf("30) Toggle Dolby operational mode or diable\n");
147                printf("31) Change Audio parameters\n");
148#endif
149                printf("70) Set BTSC Volume...\n");
150                printf("71) Set BTSC Volume Scale Factor...\n");
151#ifdef CONFIG_GP
152                printf("85) GP EVAL App\n");
153                printf("86) GP FTS App\n");
154#endif
155                printf("91) Set deinterlacer output affinity\n");
156                printf("92) Set HD H_SCL Coefficient Index\n");
157                printf("93) Set SD H_SCL Coefficient Index\n");
158                printf("94) Set HD V_SCL Coefficient Index\n");
159                printf("95) Set SD V_SCL Coefficient Index\n");
160
161                printf("100) Set L+R value\n");
162                printf("101) Set L-R value\n");
163
164                printf("Enter Command:  ");
165
166                cmd = get_opt();
167                switch(cmd) 
168                {
169#ifdef BCM_DEBUG
170                        case 1:
171                        {
172                                NEXUS_PlatformConfiguration platformConfig;
173                                NEXUS_HeapHandle heap;
174
175                                m_report();
176                                NEXUS_Platform_GetConfiguration(&platformConfig);
177                                heap = platformConfig.heap[0];
178                                NEXUS_Heap_Dump(heap);
179                                break;
180                        }
181#endif
182#ifdef PROFILE
183                        case 2:
184                                bapp_util_start_profiling();
185                                break;
186                        case 3:
187                                bapp_util_stop_profiling();
188                                break;
189#endif
190                        case 4:
191                        case 5:
192                                break;
193                        case 6:
194                                if (0 == info_task_h) {
195                                        printf("TASKinfo periodic dump every %d ms...........................\n", TASKINFO_SLEEP_ms);
196                                        info_stack = malloc(TEST_TASKINFO_STK_SIZE * 4);
197                                        if (NULL != info_stack)
198                                        {
199                                                params.name = "TASKinfo";
200                                                params.priority = TASK_INFO_PRIORITY;
201                                                params.stack_size = TEST_TASKINFO_STK_SIZE;
202                                                params.stack = info_stack;
203                                                bos_start_task(&info_task_h, &params, test_taskinfo_main, &info_task_h);
204                                                BDBG_ASSERT(info_task_h);
205                                        }
206                                }
207                                else {
208                                        bos_stop_task(info_task_h);
209                                        free(info_stack);
210                                        info_task_h = 0;
211                                }
212                                break; 
213                        case 8:
214                        {
215                                b_cpu_load load;
216                                bos_print_taskinfo();
217                                bos_getload(&load);
218                                printf("LOAD: %u ms IDLE:%u ISR:%u:%u %u us CSW:%u\n",
219                                        load.duration, load.idle, load.isr_rate, load.isr, load.isr_us, load.ctxsw_rate);
220                                break;
221                        }
222#if 0
223                        case 9:
224                        {
225                                int value;
226                                printf("Enter FM deviation factor (current = %d):", get_fm_deviation_value());
227                                value = (int)get_opt();
228                                printf("\n");
229                                set_fm_deviation_value(value);
230                                break;
231                        }
232#endif
233#ifdef CONFIG_STANDBY
234                        case 11:
235                                b_irw_power_off();
236                                break;
237#endif
238                        case 12:               
239                        case 13:
240                                break;
241                        case 21:
242                                printf("Erasing second image header...\n");
243                                console_shutdown();
244                                OSSchedLock();
245                                OSSchedUnlock();
246                                printf("Done.\n");
247                                break;
248                        case 22:
249                                __asm__("break 2");
250                                break;
251#if defined(CONFIG_DTA_CABLE) && defined(FOR_DOLBY_CERTIFICATION)
252                        case 30:
253                                break;
254                        case 31:
255                                break;
256#endif
257#if 0
258                        case 70:
259                        {
260                                int volume;
261                                printf("Enter BTSC Volume: ");
262                                volume = (int)input_number();
263                                printf("\nSetting volume to %d (0x%08x)\n", volume, volume);
264                                boutput_set_postprocessing_volume(volume);
265                                break;
266                        }
267                        case 71:
268                        {
269                                extern int g_overmod_pct;
270                                extern int boutput_get_postprocessing_volume();
271                                int pct;
272                                printf("Enter BTSC scale factor (percentage value): ");
273                                pct = (int)input_number();
274                                printf("\nBTSC scale factor %d(0x%08x)\n", pct, pct);
275                                boutput_set_postprocessing_volume(boutput_get_postprocessing_volume());
276                                break;
277                        }
278#endif
279#ifdef CONFIG_GP
280                        case 85: /* GP evaluation application is loaded */
281                        {
282                                char cmdStr[20] = {0};
283                                gpDta_TstSetAppType(1);
284                                while (1) {
285                                        gets(cmdStr);
286                                        gpDta_TstSerialRx(strnlen(cmdStr,20), cmdStr);
287                                }
288                                break;
289                        }
290                        case 86: /* GP FTS application is loaded */
291                        {
292                                extern int GP_getchar(void);
293                                char ch;
294                                /* following BDBG_SetLevel will set default log level as 'error'.
295                                 * It's needed because our DBG code doesn't allow the higher log level than default log level */
296                                BDBG_SetLevel(BDBG_eErr);
297                                BDBG_SetModuleLevel("chan_mgr", BDBG_eErr);
298                                BDBG_SetModuleLevel("bscreen", BDBG_eErr);
299                                BDBG_SetModuleLevel("eia708", BDBG_eErr);
300
301                                gpDta_TstSetAppType(2);
302                                while(1) {
303                                        ch = GP_getchar();
304                                        gpDta_TstSerialRx(1, &ch);
305                                }
306                                break;
307                        }
308#endif
309#if 0
310                        case 91:
311                        {
312                                int mode;
313                                printf("Select deinterlacer output affinity (1:HD, 2:SD)\n");
314                                mode = get_opt();
315                                if (mode == 1 || mode == 2)
316                                        bapp_select_primary_output(NULL, mode);
317                                break;
318                        }
319                        case 92:
320                        {
321                                int coeff_idx; 
322                                printf("Select H_SCL coefficient Index of HD path (1-26, which is softness->sharpness)\n");
323                                coeff_idx = get_opt();
324                                if (coeff_idx >= 1 && coeff_idx <= 26)
325                                        bapp_select_scaler_coefficient(NULL, true, 0, coeff_idx);
326                                break;
327                        }
328                        case 93:
329                        {
330                                int coeff_idx;
331                                printf("Select H_SCL coefficient Index of SD path (1-26, which is softness->sharpness)\n");
332                                coeff_idx = get_opt();
333                                if (coeff_idx >=1 && coeff_idx <=26)
334                                        bapp_select_scaler_coefficient(NULL,true,1,coeff_idx);
335                                break;
336                        }
337                        case 94:
338                        {
339                                int coeff_idx;
340                                printf("Select V_SCL coefficient Index of HD path (1-26, which is softness->sharpness)\n");
341                                coeff_idx = get_opt();
342                                if (coeff_idx >=1 && coeff_idx <=26)
343                                        bapp_select_scaler_coefficient(NULL,false,0,coeff_idx);
344                                break;
345                        }
346                        case 95:
347                        {
348                                int coeff_idx;
349                                printf("Select V_SCL coefficient Index of SD path (1-26, which is softness->sharpness)\n");
350                                coeff_idx = get_opt();
351                                if (coeff_idx >=1 && coeff_idx <=26)
352                                        bapp_select_scaler_coefficient(NULL,false,1,coeff_idx);
353                                break;
354                        }
355                        /* support to set L+R carrier amplitude value */
356                        case 100:
357                        {
358                                int value;
359                                value = get_sum_channel_level();
360                                printf("Enter L+R value (current = %d, 0x%x):", value, value);
361                                value = (int)get_opt();
362                                printf("\n");
363                                set_sum_channel_level(value);
364                                break;
365                        }
366                        /* support to set L-R carrier amplitude value */
367                        case 101:
368                        {
369                                int value;
370                                value = get_diff_channel_level();
371                                printf("Enter L-R value (current= %d, 0x%x):", value, value);
372                                value = (int)get_opt();
373                                printf("\n");
374                                set_diff_channel_level(value);
375                                break;
376                        }
377#endif
378                        default:
379                                break;
380                }       
381        }
382}
383
384void test_taskinfo_main(void *data)
385{
386        int cnt = 0;
387        b_cpu_load load;
388
389        while (1)
390        {
391                printf("----------- TASKINFO: %d -----------\n", cnt++);
392                bos_print_taskinfo();
393                bos_getload(&load);
394                printf("LOAD: %u ms IDLE:%u ISR:%u:%u %u us CSW:%u\n",
395                        load.duration, load.idle, load.isr_rate, load.isr, load.isr_us, load.ctxsw_rate);
396
397                bos_sleep(TASKINFO_SLEEP_ms);
398        }
399}
400
401unsigned get_opt(void)
402{
403        unsigned opt = 0;
404        char entry[8] = {0};
405
406        gets(entry);
407        sscanf(entry, "%d", &opt);
408        printf("\n");
409        return opt;
410}
411
412/* this two functions probably should be moved somewhere more suitable */
413static size_t out_string(const void * buf, size_t count)
414{
415        size_t i;
416        const unsigned char * pc = buf;
417        for (i = 0; i <= count; i++) {
418                if (pc[i]=='\n') {
419                        serial_putc(CONSOLE_UART, '\r');
420                }
421                serial_putc(CONSOLE_UART, pc[i]);
422        }
423        return count;
424}
425
426static void bprint_entry(void *data)
427{
428        BDBG_ERR(("PRINT TASK ONLINE"));
429        s_printing_enabled = true;
430        while (1)
431        {
432                if (s_printing_enabled)
433                {
434                        BKNI_Print_Worker(out_string);
435                }
436                else
437                {
438                        bos_sleep(200);
439                }
440        }
441        __asm__("sdbbp");
442}
443
444void bprint_flush(void)
445{
446        BKNI_Print_Flush(out_string);
447}
448
449#if 0
450#include "bchp_vcxo_ctl_config_fsm.h"
451
452#ifndef BCHP_K0_OFFSET
453#define BCHP_K0_OFFSET  (0xA0000000 | 0x10000000)
454#endif
455#ifndef WriteReg32
456#define WriteReg32(x,v) { *((volatile unsigned int*)(BCHP_K0_OFFSET + (unsigned int)(x))) = (v); }
457#endif
458#ifndef ReadReg32
459#define ReadReg32(x)    *((volatile unsigned int*)(BCHP_K0_OFFSET + (unsigned int)(x)))
460#endif
461
462/*
463 * Summary:
464 *      Set the CPU frequency using the PLL divider value.
465 * freq = 1296Hz/pll_div.
466 * The frequency should be set before OS is initialized.
467 **/
468static void set_cpu_frequency(unsigned int pll_div)
469{
470        unsigned int reg;
471
472        reg = ReadReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B);
473        reg &= ~BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B_m5div_MASK;
474        reg |= (pll_div << BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B_m5div_SHIFT);   /* 3: for MIPS channel gives: 432 MHz */
475        WriteReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B, reg);
476
477        reg = ReadReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A);
478        reg &= ~BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A_en_reg_ctrl_cfg_3_MASK;
479        reg |= (1 << BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A_en_reg_ctrl_cfg_3_SHIFT);
480        WriteReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A, reg);
481
482        /* Issue the PLL update command */
483        reg = ReadReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_UPDATE);
484        reg |= BCHP_VCXO_CTL_CONFIG_FSM_PLL_UPDATE_update_MASK;
485        WriteReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_UPDATE, reg);
486}
487#endif
488
489
490
Note: See TracBrowser for help on using the repository browser.