/*************************************************************************** * Copyright (c) 2012, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: * * Revision History: * * $brcm_Log: $ * ***************************************************************************/ #include "ministd.h" #include "serial.h" #include "ucos_ii.h" #include "bos.h" #include "bos_task_priorities.h" #include "nexus_platform.h" #include "nexus_core_utils.h" #define BPRINT_STK_SIZE 0x400 #define CONSOLE_STK_SIZE 4096 #define TEST_TASKINFO_STK_SIZE 512 /* in words */ #define APP_STK_SIZE 2048 /* in words */ #ifdef CONFIG_ENABLE_EMU #define TASKINFO_SLEEP_ms 100 #else #define TASKINFO_SLEEP_ms 2000 #endif BDBG_MODULE(boot_nexus); /* Register software module with debug interface */ static b_task_t app_task_h; static b_task_t info_task_h; static b_task_t console_task_h; static b_task_t bprint_task_h; static unsigned int bprint_stack[BPRINT_STK_SIZE]; extern void ram_start(void); extern void bapp_util_start_profiling(void); extern void bapp_util_stop_profiling(void); unsigned get_opt(void); void test_taskinfo_main(void *data); int console_main(void *data); static void bprint_entry(void *data); bool s_printing_enabled; //static void set_cpu_frequency(unsigned int pll_div); void bcm_main(void) { b_task_params console_params; BERR_Code berr; // set_cpu_frequency(6); bos_init(); /* kni and dbg must be initialized after os since they use os primitives */ berr = BKNI_Init(); BKNI_Print_Init(); berr = BDBG_Init(); /* test message for BDBG routines */ BDBG_ERR(("### BOS INIT DONE ###")); calc_cache_sizes(); print_cache_sizes(); console_params.name = "console"; console_params.priority = CONSOLE_PRIORITY; console_params.stack_size = CONSOLE_STK_SIZE; console_params.stack = (unsigned int *)malloc(console_params.stack_size * sizeof(unsigned int)); printf("%s stack @ 0x%08x\n",console_params.name, console_params.stack); bos_start_task(&console_task_h,&console_params,console_main,&console_task_h); console_params.name = "bprint"; console_params.priority = BPRINT_PRIORITY; console_params.stack_size = BPRINT_STK_SIZE; console_params.stack = bprint_stack; bos_start_task(&bprint_task_h, &console_params, bprint_entry,&bprint_task_h); bos_start(); printf("%s..SHOULD NEVER GET HERE.\n",__FUNCTION__); __asm("break 2"); } int console_main(void *data) { unsigned int *stack; unsigned int *info_stack; b_task_params params; unsigned int cmd; bos_calibrate(); stack = malloc(APP_STK_SIZE * 4); if (NULL != stack) { params.priority = APP_PRIORITY; params.stack_size = APP_STK_SIZE; params.stack = stack; params.name = "ram_start"; bos_start_task(&app_task_h, ¶ms, (void *)ram_start, &app_task_h); } while (1) { printf("Console Menu:\n"); #ifdef BCM_DEBUG printf("1) Memory Use...\n"); #endif #ifdef PROFILE printf("2) Profile Start...\n"); printf("3) Profile Stop...\n"); #endif printf("4) Download and update signed image\n"); printf("5) Download and update software in flash\n"); printf("6) Toggle TASKINFO periodic display\n"); #ifdef CONFIG_SMARTCARD_TEST printf("7) Smartcard test\n"); #endif printf("8) Print system status...\n"); printf("9) Enter FM deviation factor...\n"); printf("11) Reboot\n"); #ifdef BCM_DEBUG printf("12) MVD Debug Info\n"); printf("13) Scratch Info\n"); #endif printf("21) Erase second image\n"); printf("22) Invoke debug stub\n"); #if defined(CONFIG_DTA_CABLE) && defined(FOR_DOLBY_CERTIFICATION) printf("30) Toggle Dolby operational mode or diable\n"); printf("31) Change Audio parameters\n"); #endif printf("70) Set BTSC Volume...\n"); printf("71) Set BTSC Volume Scale Factor...\n"); #ifdef CONFIG_GP printf("85) GP EVAL App\n"); printf("86) GP FTS App\n"); #endif printf("91) Set deinterlacer output affinity\n"); printf("92) Set HD H_SCL Coefficient Index\n"); printf("93) Set SD H_SCL Coefficient Index\n"); printf("94) Set HD V_SCL Coefficient Index\n"); printf("95) Set SD V_SCL Coefficient Index\n"); printf("100) Set L+R value\n"); printf("101) Set L-R value\n"); printf("Enter Command: "); cmd = get_opt(); switch(cmd) { #ifdef BCM_DEBUG case 1: { NEXUS_PlatformConfiguration platformConfig; NEXUS_HeapHandle heap; m_report(); NEXUS_Platform_GetConfiguration(&platformConfig); heap = platformConfig.heap[0]; NEXUS_Heap_Dump(heap); break; } #endif #ifdef PROFILE case 2: bapp_util_start_profiling(); break; case 3: bapp_util_stop_profiling(); break; #endif case 4: case 5: break; case 6: if (0 == info_task_h) { printf("TASKinfo periodic dump every %d ms...........................\n", TASKINFO_SLEEP_ms); info_stack = malloc(TEST_TASKINFO_STK_SIZE * 4); if (NULL != info_stack) { params.name = "TASKinfo"; params.priority = TASK_INFO_PRIORITY; params.stack_size = TEST_TASKINFO_STK_SIZE; params.stack = info_stack; bos_start_task(&info_task_h, ¶ms, test_taskinfo_main, &info_task_h); BDBG_ASSERT(info_task_h); } } else { bos_stop_task(info_task_h); free(info_stack); info_task_h = 0; } break; case 8: { b_cpu_load load; bos_print_taskinfo(); bos_getload(&load); printf("LOAD: %u ms IDLE:%u ISR:%u:%u %u us CSW:%u\n", load.duration, load.idle, load.isr_rate, load.isr, load.isr_us, load.ctxsw_rate); break; } #if 0 case 9: { int value; printf("Enter FM deviation factor (current = %d):", get_fm_deviation_value()); value = (int)get_opt(); printf("\n"); set_fm_deviation_value(value); break; } #endif #ifdef CONFIG_STANDBY case 11: b_irw_power_off(); break; #endif case 12: case 13: break; case 21: printf("Erasing second image header...\n"); console_shutdown(); OSSchedLock(); OSSchedUnlock(); printf("Done.\n"); break; case 22: __asm__("break 2"); break; #if defined(CONFIG_DTA_CABLE) && defined(FOR_DOLBY_CERTIFICATION) case 30: break; case 31: break; #endif #if 0 case 70: { int volume; printf("Enter BTSC Volume: "); volume = (int)input_number(); printf("\nSetting volume to %d (0x%08x)\n", volume, volume); boutput_set_postprocessing_volume(volume); break; } case 71: { extern int g_overmod_pct; extern int boutput_get_postprocessing_volume(); int pct; printf("Enter BTSC scale factor (percentage value): "); pct = (int)input_number(); printf("\nBTSC scale factor %d(0x%08x)\n", pct, pct); boutput_set_postprocessing_volume(boutput_get_postprocessing_volume()); break; } #endif #ifdef CONFIG_GP case 85: /* GP evaluation application is loaded */ { char cmdStr[20] = {0}; gpDta_TstSetAppType(1); while (1) { gets(cmdStr); gpDta_TstSerialRx(strnlen(cmdStr,20), cmdStr); } break; } case 86: /* GP FTS application is loaded */ { extern int GP_getchar(void); char ch; /* following BDBG_SetLevel will set default log level as 'error'. * It's needed because our DBG code doesn't allow the higher log level than default log level */ BDBG_SetLevel(BDBG_eErr); BDBG_SetModuleLevel("chan_mgr", BDBG_eErr); BDBG_SetModuleLevel("bscreen", BDBG_eErr); BDBG_SetModuleLevel("eia708", BDBG_eErr); gpDta_TstSetAppType(2); while(1) { ch = GP_getchar(); gpDta_TstSerialRx(1, &ch); } break; } #endif #if 0 case 91: { int mode; printf("Select deinterlacer output affinity (1:HD, 2:SD)\n"); mode = get_opt(); if (mode == 1 || mode == 2) bapp_select_primary_output(NULL, mode); break; } case 92: { int coeff_idx; printf("Select H_SCL coefficient Index of HD path (1-26, which is softness->sharpness)\n"); coeff_idx = get_opt(); if (coeff_idx >= 1 && coeff_idx <= 26) bapp_select_scaler_coefficient(NULL, true, 0, coeff_idx); break; } case 93: { int coeff_idx; printf("Select H_SCL coefficient Index of SD path (1-26, which is softness->sharpness)\n"); coeff_idx = get_opt(); if (coeff_idx >=1 && coeff_idx <=26) bapp_select_scaler_coefficient(NULL,true,1,coeff_idx); break; } case 94: { int coeff_idx; printf("Select V_SCL coefficient Index of HD path (1-26, which is softness->sharpness)\n"); coeff_idx = get_opt(); if (coeff_idx >=1 && coeff_idx <=26) bapp_select_scaler_coefficient(NULL,false,0,coeff_idx); break; } case 95: { int coeff_idx; printf("Select V_SCL coefficient Index of SD path (1-26, which is softness->sharpness)\n"); coeff_idx = get_opt(); if (coeff_idx >=1 && coeff_idx <=26) bapp_select_scaler_coefficient(NULL,false,1,coeff_idx); break; } /* support to set L+R carrier amplitude value */ case 100: { int value; value = get_sum_channel_level(); printf("Enter L+R value (current = %d, 0x%x):", value, value); value = (int)get_opt(); printf("\n"); set_sum_channel_level(value); break; } /* support to set L-R carrier amplitude value */ case 101: { int value; value = get_diff_channel_level(); printf("Enter L-R value (current= %d, 0x%x):", value, value); value = (int)get_opt(); printf("\n"); set_diff_channel_level(value); break; } #endif default: break; } } } void test_taskinfo_main(void *data) { int cnt = 0; b_cpu_load load; while (1) { printf("----------- TASKINFO: %d -----------\n", cnt++); bos_print_taskinfo(); bos_getload(&load); printf("LOAD: %u ms IDLE:%u ISR:%u:%u %u us CSW:%u\n", load.duration, load.idle, load.isr_rate, load.isr, load.isr_us, load.ctxsw_rate); bos_sleep(TASKINFO_SLEEP_ms); } } unsigned get_opt(void) { unsigned opt = 0; char entry[8] = {0}; gets(entry); sscanf(entry, "%d", &opt); printf("\n"); return opt; } /* this two functions probably should be moved somewhere more suitable */ static size_t out_string(const void * buf, size_t count) { size_t i; const unsigned char * pc = buf; for (i = 0; i <= count; i++) { if (pc[i]=='\n') { serial_putc(CONSOLE_UART, '\r'); } serial_putc(CONSOLE_UART, pc[i]); } return count; } static void bprint_entry(void *data) { BDBG_ERR(("PRINT TASK ONLINE")); s_printing_enabled = true; while (1) { if (s_printing_enabled) { BKNI_Print_Worker(out_string); } else { bos_sleep(200); } } __asm__("sdbbp"); } void bprint_flush(void) { BKNI_Print_Flush(out_string); } #if 0 #include "bchp_vcxo_ctl_config_fsm.h" #ifndef BCHP_K0_OFFSET #define BCHP_K0_OFFSET (0xA0000000 | 0x10000000) #endif #ifndef WriteReg32 #define WriteReg32(x,v) { *((volatile unsigned int*)(BCHP_K0_OFFSET + (unsigned int)(x))) = (v); } #endif #ifndef ReadReg32 #define ReadReg32(x) *((volatile unsigned int*)(BCHP_K0_OFFSET + (unsigned int)(x))) #endif /* * Summary: * Set the CPU frequency using the PLL divider value. * freq = 1296Hz/pll_div. * The frequency should be set before OS is initialized. **/ static void set_cpu_frequency(unsigned int pll_div) { unsigned int reg; reg = ReadReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B); reg &= ~BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B_m5div_MASK; reg |= (pll_div << BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B_m5div_SHIFT); /* 3: for MIPS channel gives: 432 MHz */ WriteReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3B, reg); reg = ReadReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A); reg &= ~BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A_en_reg_ctrl_cfg_3_MASK; reg |= (1 << BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A_en_reg_ctrl_cfg_3_SHIFT); WriteReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_NEXT_CFG_3A, reg); /* Issue the PLL update command */ reg = ReadReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_UPDATE); reg |= BCHP_VCXO_CTL_CONFIG_FSM_PLL_UPDATE_update_MASK; WriteReg32( BCHP_VCXO_CTL_CONFIG_FSM_PLL_UPDATE, reg); } #endif