void NSFOSThread_eCOS::setPriority(int priority) { this->priority = priority; cyg_thread_set_priority(handle, priority); }
static void master(cyg_addrword_t param) { int i; cyg_handle_t self = cyg_thread_self(); cyg_semaphore_init( &send_sema, 0 ); cyg_semaphore_init( &recv_sema, 0 ); for ( i = 0 ; i < NLISTENERS; i++ ) cyg_semaphore_init( &listen_sema[i], 0 ); init_all_network_interfaces(); CYG_TEST_INFO("Start multiple loopback select test"); #if NLOOP > 0 // We are currently running at high prio, so we can just go and make // loads of threads: // Some at higher prio for ( i = 0; i < NLISTENERS/2; i++ ) cyg_thread_create(PRIO_LISTENER_HI, // Priority listener, // entry i, // entry parameter "listener", // Name &stack_listener[i][0], // Stack STACK_SIZE, // Size &listener_thread_handle[i], // Handle &listener_thread_data[i] // Thread data structure ); // the rest at lower prio for ( ; i < NLISTENERS ; i++ ) cyg_thread_create(PRIO_LISTENER_LO, // Priority listener, // entry i, // entry parameter "listener", // Name &stack_listener[i][0], // Stack STACK_SIZE, // Size &listener_thread_handle[i], // Handle &listener_thread_data[i] // Thread data structure ); // make the dummy event-grabber threads for ( i = 0; i < NDUMMIES; i++ ) cyg_thread_create(PRIO_DUMMY, // Priority dummy, // entry i, // entry parameter "dummy", // Name &stack_dummy[i][0], // Stack STACK_SIZE, // Size &dummy_thread_handle[i], // Handle &dummy_thread_data[i] // Thread data structure ); // Start those threads for ( i = 0; i < NLISTENERS; i++ ) cyg_thread_resume(listener_thread_handle[i]); for ( i = 0; i < NDUMMIES; i++ ) cyg_thread_resume( dummy_thread_handle[i]); // and let them start up and start listening... cyg_thread_set_priority( self, PRIO_MASTERLOW ); CYG_TEST_INFO("All listeners should be go now"); cyg_thread_set_priority( self, PRIO_MASTERHIGH ); for ( i = 0; i < NSENDERS; i++ ) { cyg_thread_create( (0 == i) ?PRIO_SENDER_MID : PRIO_SENDER_LOW, // Priority sender, // entry i, // entry parameter "sender", // Name &stack_sender[i][0], // Stack STACK_SIZE, // Size &sender_thread_handle[i], // Handle &sender_thread_data[i] // Thread data structure ); cyg_thread_resume(sender_thread_handle[i]); } // Now we are still higher priority; so go low and let everyone else // have their head. When we next run after this, it should all be // over. cyg_thread_set_priority( self, PRIO_MASTERLOW ); cyg_semaphore_peek( &recv_sema, &i ); CYG_TEST_CHECK( NLISTENERS == i, "Not enough recvs occurred!" ); cyg_semaphore_peek( &send_sema, &i ); CYG_TEST_CHECK( NLISTENERS == i, "Not enough sends occurred!" ); CYG_TEST_PASS_FINISH("Master returned OK"); #endif CYG_TEST_NA( "No loopback devs" ); }
void ServerStart(void) { int i, j; char *pcDocRoot = "./"; static int aiPort[] = {80, 0}; #ifndef WLAN FMI_CARD_DETECT_T card; #endif cyg_mutex_init(&g_ptmConfigParam); cyg_mutex_init(&g_ptmState); cyg_mutex_init(&g_ptmTimeSetting); cyg_mutex_init(&g_ptmWebCameraLog); tt_rmutex_init(&g_rmutex); { UINT32 uFlashTotal, uFlashFreeBegin, uFlashFreeEnd; GetFlashCapability(&uFlashTotal, &uFlashFreeBegin, &uFlashFreeEnd); diag_printf("Flash total: %d, free space [%d - %d]\n", uFlashTotal, uFlashFreeBegin, uFlashFreeEnd); } #ifndef WLAN /*init the sd card*/ //do {outpw (REG_CLKCON, inpw (REG_CLKCON) | FMICLK_EN); } while (0); fmiSetFMIReferenceClock(OPT_UPLL_OUT_CLOCK/3/1000); fsFixDriveNumber('D', 'C', 'Z'); fsInitFileSystem(); card.uCard = FMI_SD_CARD; // card type card.uGPIO = 4; // card detect GPIO pin card.uWriteProtect = 16; // card detect GPIO pin card.uInsert = 0; // 0/1 which one is insert card.nPowerPin = 12; // card power pin, -1 means no power pin card.bIsTFlashCard = FALSE; fmiSetCardDetection(&card); fmiInitSDDevice(); diag_printf("Init the SD Card ok!\n"); g_StreamServer_Buf = (char*)(g_StreamServer_Buf1); #endif #ifdef FILESYSTEM /* Check if disk need to be formatted. */ ipcCheckDisk( ); #endif /*register reset interrupt*/ InitResetGPIO(); // Set HIC ready outpw(REG_HICSR, inpw(REG_HICSR) & 0xFFFFFF7F); if (0) { int j = 0; for(;j<5;j++) init_loopback_interface(0); } /* 初始化camera的参数 */ ResetCameraParam(); /* 挂载需要额外处理的URL */ RegisterUrls(); //GetDHCPInfo(); /* 設置进入不同特权领域的提示语 */ httpSetAuthPrompt(CONFIG_LOGIN_PROMPT_USER, CONFIG_LOGIN_PROMPT_ADMIN, NULL); /* 选择从命令行或者配置参数中设定的http端口 */ for (i = 0; i < sizeof(g_ConfigParam.usHttpPort) / sizeof(unsigned short); i++) { if (g_ConfigParam.usHttpPort[i] == 0) g_ConfigParam.usHttpPort[i] = aiPort[i]; } for (i = 0, j = 0; i < sizeof(g_ConfigParam.usHttpPort) / sizeof(unsigned short); i++) { if (g_ConfigParam.usHttpPort[i] != 0) aiPort[j++] = g_ConfigParam.usHttpPort[i]; } aiPort[j] = 0; diag_printf("Port is %d,%d\n",aiPort[0],aiPort[1]); ResetOtherThread(); { cyg_thread_create(PTD_PRIORITY, &MctestThread, (cyg_addrword_t)aiPort, "ptdMctest", ptdMctest_stack, STACKSIZE2, &ptdMctest_handle, &g_ptdMctest); if ( ptdMctest_handle == NULL) { fprintf(stderr, "Thread for mctest creation failed!\n"); return; } cyg_thread_resume(ptdMctest_handle); } cyg_thread_set_priority(cyg_thread_self(), PTD_PRIORITY); // 开始http服务 httpdStartEx(pcDocRoot, aiPort,3600, 30 * 60 * 60 , 20, OnHttpInit, OnRequestBegin); }
void run_test_timeslice(int nthread) { int i,j; cyg_uint32 cpu_total[CYGNUM_KERNEL_CPU_MAX]; cyg_uint32 cpu_threads[CYGNUM_KERNEL_CPU_MAX]; cyg_uint32 thread_total[NTHREADS_MAX]; CYG_TEST_INFO( "Timeslice Test: Check timeslicing works"); // Init flags. for (i = 0; i < nthread; i++) for( j = 0; j < ncpus; j++ ) slicerun[i][j] = 0; // Set my priority higher than any I plan to create cyg_thread_set_priority(cyg_thread_self(), 2); for (i = 0; i < nthread; i++) { cyg_thread_create(10, // Priority - just a number test_thread_timeslice, // entry i, // index "test_thread", // Name &stacks[i][0], // Stack STACK_SIZE, // Size &threads[i], // Handle &test_threads[i] // Thread data structure ); cyg_thread_resume( threads[i]); } // Just wait a while, until the threads have all run for a bit. cyg_thread_delay( CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS*100 ); // Suspend all the threads for (i = 0; i < nthread; i++) { cyg_thread_suspend(threads[i]); } // And check that a thread ran on each CPU, and that each thread // ran. diag_printf(" Thread "); for( j = 0; j < ncpus; j++ ) { cpu_total[j] = 0; cpu_threads[j] = 0; // " %11d" __123456789ab" diag_printf(" CPU %2d",j); } // " %11d" __123456789ab" diag_printf(" Total\n"); for (i = 0; i < nthread; i++) { thread_total[i] = 0; diag_printf(" %2d ",i); for( j = 0; j < ncpus; j++ ) { thread_total[i] += slicerun[i][j]; cpu_total[j] += slicerun[i][j]; if( slicerun[i][j] > 0 ) cpu_threads[j]++; diag_printf(" %11d",slicerun[i][j]); } diag_printf(" %11d\n",thread_total[i]); if( thread_total[i] == 0 ) failed++; } diag_printf(" Total "); for( j = 0; j < ncpus; j++ ) diag_printf(" %11d",cpu_total[j]); diag_printf("\n"); diag_printf("Threads "); for( j = 0; j < ncpus; j++ ) { diag_printf(" %11d",cpu_threads[j]); if( cpu_threads[j] < 2 ) failed++; } diag_printf("\n"); // Delete all the threads for (i = 0; i < nthread; i++) { cyg_thread_delete(threads[i]); } CYG_TEST_INFO( "Timeslice Test: done"); }