static void time0DI(register cyg_uint32 stride) { register cyg_uint32 j,k; volatile cyg_tick_count_t count0; cyg_tick_count_t count1; cyg_ucount32 t; register char c; register CYG_INTERRUPT_STATE oldints; count0 = cyg_current_time(); HAL_DISABLE_INTERRUPTS(oldints); HAL_DCACHE_SYNC(); k = 0; if ( cyg_test_is_simulator ) k = 3960; for(; k<4000;k++) { for(j=0; j<(HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE); j++) { HAL_DCACHE_INVALIDATE_ALL(); c=m[stride*j]; } } HAL_RESTORE_INTERRUPTS(oldints); count1 = cyg_current_time(); t = count1 - count0; diag_printf("stride=%d, time=%d\n", stride, t); }
void Reset_Int_ISR_MP4EVB_Board(void) { #if defined IPCAM_CONFIG_MP4_EVB_VER_0 /* UINT32 code1, code2; outpw(REG_GPIO_DAT, inpw(REG_GPIO_DAT)&~0x100); code1 = inpw(REG_GPIO_STS); outpw(REG_GPIO_DAT, inpw(REG_GPIO_DAT)|0x100); code2 = inpw(REG_GPIO_STS); diag_printf("state: %08x-%08x\n", code1, code2); if ((((code1 >> 13) & 0x1) != 0) && (((code2 >> 13) & 0x1) != 0)) //GPIO13 { outpw(REG_GPIO_IS, inpw(REG_GPIO_IS) &(0x2000) ); return; } */ //cyg_interrupt_disable(); switch(g_KeyStatus) { case KEY_RELEASED: g_KeyStatus = KEY_PRESSED; g_StartTime = cyg_current_time(); diag_printf("**********pressed\n"); break; case KEY_PRESSED: g_KeyStatus = KEY_RELEASED; g_EndTime = cyg_current_time(); diag_printf("*************************released\n"); if((g_EndTime - g_StartTime) >= 500) //Reset time is 5s { diag_printf("Set factory default\n"); #if 0 if (ReadFactoryDefault(&g_ConfigParam)) { __WriteFlashMemory(&g_ConfigParam, FALSE, FALSE); diag_printf("Set factory default OK\n"); } else diag_printf("Set factory default error\n"); #else //InitDefaultParam(&g_ConfigParam); //WriteFlashMemory(&g_ConfigParam); g_ConfigParam.ulCheckSum = GetConfigCheckSum(&g_ConfigParam) + 1; __WriteFlashMemory(&g_ConfigParam, FALSE, FALSE); WebCameraSIGTERM(0); W99802Reboot(); #endif } break; default: ; } outpw(REG_GPIO_IS, inpw(REG_GPIO_IS) &(0x2000) ); // cyg_interrupt_enable(); #endif }
/* this is a simple program which runs in a thread */ void simple_program(cyg_addrword_t data) { int message = (int) data; int delay; cyg_mutex_lock(&cliblock); printf("Beginning execution; thread data is %d\n", message); cyg_mutex_unlock(&cliblock); cyg_thread_delay(200); for (;;) { /* delay = 1000 + (rand() % 50); */ delay = 5000*(1+message) + (rand() % 50); /* note: printf() must be protected by a call to cyg_mutex_lock() */ cyg_mutex_lock(&cliblock); { cyg_tick_count_t tick; tick = cyg_current_time(); #if 0 printf("(%llu) Thread %d: and now a delay of %d clock ticks\n", tick, message, delay); #else // printf("(%llu) Thread %d\n", tick, message); #endif } cyg_mutex_unlock(&cliblock); cyg_thread_delay(delay); } }
static time_t mytime(void) { time_t cur_sec; cyg_tick_count_t cur_time; cur_time = cyg_current_time(); cur_sec = (cur_time*10) / 1000; return cur_sec; }
int gettimeofday(struct timeval *tv, struct timezone *tz) { cyg_tick_count_t cur_time; cur_time = cyg_current_time(); tv->tv_sec = cur_time / 100; tv->tv_usec = (cur_time % 100) * 10000; }
void fptest_main( void ) { CYG_TEST_INIT(); if( cyg_test_is_simulator ) { run_ticks = RUN_TICKS_SIM; } CYG_TEST_INFO("Run fptest in cyg_start"); do_test( fpt3_values, FP3_COUNT, 1000, 0, "start" ); CYG_TEST_INFO( "cyg_start run done"); cyg_thread_create( BASE_PRI-1, fptest1, 0, "fptest1", &stacks[0][0], STACK_SIZE, &thread[0], &thread_struct[0]); cyg_thread_resume( thread[0] ); cyg_thread_create( BASE_PRI, fptest2, 1, "fptest2", &stacks[1][0], STACK_SIZE, &thread[1], &thread_struct[1]); cyg_thread_resume( thread[1] ); cyg_thread_create( BASE_PRI, fptest3, 2, "fptest3", &stacks[2][0], STACK_SIZE, &thread[2], &thread_struct[2]); cyg_thread_resume( thread[2] ); cyg_alarm_create( cyg_real_time_clock(), alarm_fn, 0, &alarm, &alarm_struct ); cyg_alarm_initialize( alarm, cyg_current_time()+1, 1 ); cyg_scheduler_start(); }
int main( int argc, char *argv[] ) { int i; HAL_DCACHE_ENABLE(); printf("begin mutex_test_posix\n"); // initialize mutex with default attributes pthread_mutex_init(&mutex, NULL); pthread_mutex_lock(&mutex); printf("creating hw thread... "); POSIX_HWT_CREATE(0,0,thread_resources); printf("ok\n"); cyg_thread_delay(50); for(i = 0; i < 10; i++){ unsigned long ticks = cyg_current_time(); //printf("current time = %ld ticks\n",ticks); // XXX remove pthread_mutex_unlock(&mutex); while(cyg_current_time() - ticks < 10); // wait for 0.1 seconds pthread_mutex_lock(&mutex); ticks = cyg_current_time() - ticks; //printf("delta t = %ld ticks\n", ticks); // XXX remove printf("mutex lock and release by hwthread: "); if(ticks > 20 && ticks < 40){ printf("success\n"); } else if(ticks <= 20){ printf("too early\n"); // should not happen } else { printf("too late\n"); // should not happen } cyg_thread_delay(50); } printf("mutex_test_posix done.\n"); return 0; }
/* * Wait on a semaphore for at most timeout millisecs * Return -1 if timed out otherwise time spent waiting. */ u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout) { cyg_bool_t r; cyg_tick_count_t end_time = 0, start_time = 0; if (timeout) { start_time = cyg_current_time(); r = cyg_semaphore_timed_wait(sem, start_time + msec_to_tick(timeout)); end_time = cyg_current_time(); if (r == false) { return SYS_ARCH_TIMEOUT; } } else { cyg_semaphore_wait(sem); } return tick_to_msec(end_time - start_time); }
int simple_multi_thread(void) { NET_DATA_T netdata1, netdata2, netdata3, netdata4, netdata5, netdata6, netdata7; netdata1.iport = 40; netdata1.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf1); netdata2.iport = 41; netdata2.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf2); netdata3.iport = 42; netdata3.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf3); netdata4.iport = 43; netdata4.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf4); netdata5.iport = 44; netdata5.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf5); netdata6.iport = 45; netdata6.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf6); netdata7.iport = 46; netdata7.pbuf = (char*)NON_CACHE(g_RemoteNet_Buf7); cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata1, "simple_tcpserver1", thread_stack1, STACK_SIZE, &thread_handle1, &thread1); cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata2, "simple_tcpserver2", thread_stack2, STACK_SIZE, &thread_handle2, &thread2); cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata3, "simple_tcpserver3", thread_stack3, STACK_SIZE, &thread_handle3, &thread3); cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata4, "simple_tcpserver4", thread_stack4, STACK_SIZE, &thread_handle4, &thread4); cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata5, "simple_tcpserver5", thread_stack5, STACK_SIZE, &thread_handle5, &thread5); cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata6, "simple_tcpserver6", thread_stack6, STACK_SIZE, &thread_handle6, &thread6); //cyg_thread_create(THREAD_PRIORITY, &simple_tcpserver, (cyg_addrword_t)&netdata7, "simple_tcpserver7", // thread_stack7, STACK_SIZE, &thread_handle7, &thread7); /* cyg_thread_create(THREAD_PRIORITY, &simple_udpserver, (cyg_addrword_t)&netdata1, "simple_udpserver1", thread_stack1, STACK_SIZE, &thread_handle1, &thread1); cyg_thread_create(THREAD_PRIORITY, &simple_udpserver, (cyg_addrword_t)&netdata2, "simple_udpserver2", thread_stack2, STACK_SIZE, &thread_handle2, &thread2); cyg_thread_create(THREAD_PRIORITY, &simple_udpserver, (cyg_addrword_t)&netdata3, "simple_udpserver3", thread_stack3, STACK_SIZE, &thread_handle3, &thread3); */ tbegin = cyg_current_time(); cyg_thread_resume(thread_handle1); cyg_thread_resume(thread_handle2); cyg_thread_resume(thread_handle3); cyg_thread_resume(thread_handle4); cyg_thread_resume(thread_handle5); cyg_thread_resume(thread_handle6); //cyg_thread_resume(thread_handle7); while(1) { cyg_thread_delay(100000); } }
int os_get_time(struct os_time *t) { if (t != NULL) { cyg_tick_count_t ticks = cyg_current_time(); t->sec = ticks / 100; t->usec = (ticks - t->sec * 100) * 1000; return 0; } return -1; }
static void sco_sock_set_timer(struct sock *sk, long timeout) { BT_DBG("sock %p state %d timeout %ld", sk, sk->state, timeout); // if (!mod_timer(&sk->timer, jiffies + timeout)) // sock_hold(sk); cyg_alarm_disable(sk->timeout_alarm_handle); cyg_alarm_initialize(sk->timeout_alarm_handle, cyg_current_time()+timeout, 0); cyg_alarm_enable(sk->timeout_alarm_handle); sock_hold(sk); }
/** * Check if a timer has expired. * * This function tests if a timer has expired and returns true or * false depending on its status. * * \param t A pointer to the timer * * \return Non-zero if the timer has expired, zero otherwise. * */ int timer_expired(struct timer *t) { /* Note: Can not return diff >= t->interval so we add 1 to diff and return t->interval < diff - required to avoid an internal error in mspgcc. */ if(t->interval==0){ return 0; } cyg_tick_count_t diff = (cyg_current_time() - t->start) + 1; return t->interval < diff; }
// ------------------------------------------------------------------------ // HANDLER THREAD ENTRY ROUTINE // This waits on the DSR to tell it to run: static void alarm_thread(cyg_addrword_t param) { // This is from the logical ethernet dev; it calls those delivery // functions who need attention. extern void eth_drv_run_deliveries( void ); // This is from the logical ethernet dev; it tickles somehow // all ethernet devices in case one is wedged. extern void eth_drv_tickle_devices( void ); while ( 1 ) { int spl; int x; #ifdef CYGPKG_NET_FAST_THREAD_TICKLE_DEVS cyg_tick_count_t later = cyg_current_time(); later += CYGNUM_NET_FAST_THREAD_TICKLE_DEVS_DELAY; x = cyg_flag_timed_wait( &alarm_flag, -1, CYG_FLAG_WAITMODE_OR | CYG_FLAG_WAITMODE_CLR, later ); #else x = cyg_flag_wait( &alarm_flag, -1, CYG_FLAG_WAITMODE_OR | CYG_FLAG_WAITMODE_CLR ); CYG_ASSERT( 3 & x, "Lost my bits" ); #endif // CYGPKG_NET_FAST_THREAD_TICKLE_DEVS CYG_ASSERT( !((~3) & x), "Extra bits" ); spl = cyg_splinternal(); CYG_ASSERT( 0 == spl, "spl nonzero" ); if ( 2 & x ) eth_drv_run_deliveries(); #ifdef CYGPKG_NET_FAST_THREAD_TICKLE_DEVS // This is in the else clause for "do we deliver" because the // network stack might have continuous timing events anyway - so // the timeout would not occur, x would be 1 every time. else // Tickle the devices... eth_drv_tickle_devices(); #endif // CYGPKG_NET_FAST_THREAD_TICKLE_DEVS if ( 1 & x ) do_timeout(); cyg_splx(spl); } }
double OSCR_wtime() { #ifdef __ECOS__ static double sec = 0; sec = ((double)cyg_current_time() / 100) - sec; return sec; #else static int sec = -1; struct timeval tv; gettimeofday(&tv, (timezone *)0); if (sec < 0) sec = tv.tv_sec; return (tv.tv_sec - sec) + 1.0e-6*tv.tv_usec; #endif }
static long long ns_time(void) { cyg_uint32 off; long long ns, clocks; ns_per_system_clock = 1000000/rtc_resolution[1]; HAL_CLOCK_READ(&off); ns = (ns_per_system_clock * (long long)off) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD; ns += 5; // for rounding to .01us clocks = (cyg_current_time() * 10000000) + ns; return clocks; }
static void time0(register cyg_uint32 stride) { register cyg_uint32 j,k; cyg_tick_count_t count0, count1; cyg_ucount32 t; register char c; count0 = cyg_current_time(); k = 0; if ( cyg_test_is_simulator ) k = 3960; for(; k<4000;k++) { for(j=0; j<(HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE); j++) { c=m[stride*j]; } } count1 = cyg_current_time(); t = count1 - count0; diag_printf("stride=%d, time=%d\n", stride, t); }
/* * Fetch data from a mbox.Wait for at most timeout millisecs * Return -1 if timed out otherwise time spent waiting. */ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **data, u32_t timeout) { void *d; cyg_tick_count_t end_time = 0, start_time = 0; if (timeout) { start_time = cyg_current_time(); d = cyg_mbox_timed_get(mbox, start_time + msec_to_tick(timeout)); end_time = cyg_current_time(); if (d == NULL) return SYS_ARCH_TIMEOUT; } else { d = cyg_mbox_get(mbox); } if (data) { if (d == (void *)&dummy_msg) *data = NULL; else *data = d; } return tick_to_msec(end_time - start_time); }
// ------------------------------------------------------------------------ // CALLBACK FUNCTION // Called from the thread, this runs the alarm callbacks. // Locking is already in place when this is called. static void do_timeout(void) { int i; cyg_int32 min_delta; timeout_entry *e; CYG_ASSERT( 0 < last_delta, "last_delta underflow" ); min_delta = last_delta; // local copy last_delta = -1; // flag recursive call underway for (e = timeouts, i = 0; i < NTIMEOUTS; i++, e++) { if (e->delta) { CYG_ASSERT( e->delta >= min_delta, "e->delta underflow" ); e->delta -= min_delta; if (e->delta <= 0) { // Defensive // Time for this item to 'fire' timeout_fun *fun = e->fun; void *arg = e->arg; // Call it *after* cleansing the record e->fun = 0; e->delta = 0; (*fun)(arg); } } } // Now scan for a new timeout *after* running all the callbacks // (because they can add timeouts themselves) min_delta = 0x7FFFFFFF; // Maxint for (e = timeouts, i = 0; i < NTIMEOUTS; i++, e++) if (e->delta) if (e->delta < min_delta) min_delta = e->delta; CYG_ASSERT( 0 < min_delta, "min_delta underflow" ); if (min_delta != 0x7FFFFFFF) { // Still something to do, schedule it last_set_time = cyg_current_time(); cyg_alarm_initialize(timeout_alarm_handle, last_set_time+min_delta, 0); last_delta = min_delta; } else { last_delta = 0; // flag no activity } }
void usbTerm::rx_thread_func(cyg_addrword_t arg) { diag_printf("USB started\n"); for(;;) { cyg_mutex_lock(&(__instance->mUSBmutex)); if(cyg_cond_timed_wait(&(__instance->mUSBrxCond), cyg_current_time() + 5000)) //keep the thread running to prevent lock ups { if(__instance->mUSBRXlen) { __instance->handleData(__instance->mUSBRXbuff, __instance->mUSBRXlen); } } cyg_mutex_unlock(&(__instance->mUSBmutex)); } }
void tcp_hole() { int interval = 30000; TCP_HOLE_FLAG = 1; /* Attach the timer to the CloseTcpHole clock */ CloseTcpHole_SysClk = cyg_real_time_clock(); cyg_clock_to_counter(CloseTcpHole_SysClk, &CloseTcpHole_Counter); cyg_alarm_create(CloseTcpHole_Counter, (cyg_alarm_t *)CloseTcpHole, 0, &CloseTcpHole_Alarm, &CloseTcpHole_timerAlarm); /* This creates a periodic timer */ cyg_alarm_initialize(CloseTcpHole_Alarm, cyg_current_time() + interval, 0); //only trigger once after 5 minutes }
void linklocal_alarm(void){ /* 10 sec, Follow Link Local IP Stard. If we got ip conflict twice within 10 seconds, we have to change our link local ip. <<<Ron 12/13/04 >>> */ int interval = 10; //10 sec /* Attach the timer to the real-time clock */ hSysClk = cyg_real_time_clock(); cyg_clock_to_counter(hSysClk, &hCounter); // cyg_alarm_create(hCounter, (cyg_alarm_t *)linklocal_msg_post, cyg_alarm_create(hCounter, (cyg_alarm_t *)linklocal_msg_timer, (cyg_addrword_t) &alarmData, &hAlarm, &timerAlarm); /* This creates a periodic timer */ cyg_alarm_initialize(hAlarm, cyg_current_time() + interval, 10); }
static void jffs2_garbage_collect_thread(cyg_addrword_t data) { struct jffs2_sb_info *c=(struct jffs2_sb_info *)data; struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_flag_value_t flag; cyg_mtab_entry *mte; D1(printk("jffs2_garbage_collect_thread START\n")); while(1) { flag=cyg_flag_timed_wait(&sb->s_gc_thread_flags, GC_THREAD_FLAG_TRIG|GC_THREAD_FLAG_STOP, CYG_FLAG_WAITMODE_OR| CYG_FLAG_WAITMODE_CLR, cyg_current_time()+ CYGNUM_JFFS2_GS_THREAD_TICKS); if (flag & GC_THREAD_FLAG_STOP) break; D1(printk("jffs2: GC THREAD GC BEGIN\n")); mte=cyg_fs_root_lookup((cyg_dir *) sb->s_root); CYG_ASSERT(mte, "Bad mount point"); cyg_fs_lock(mte, mte->fs->syncmode); if (jffs2_garbage_collect_pass(c) == -ENOSPC) { printf("No space for garbage collection. " "Aborting JFFS2 GC thread\n"); break; } cyg_fs_unlock(mte, mte->fs->syncmode); D1(printk("jffs2: GC THREAD GC END\n")); } D1(printk("jffs2_garbage_collect_thread EXIT\n")); cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_HAS_EXIT); }
static void jffs2_garbage_collect_thread(unsigned long data) { struct jffs2_sb_info *c=(struct jffs2_sb_info *)data; struct super_block *sb=OFNI_BS_2SFFJ(c); cyg_mtab_entry *mte; rt_uint32_t flag = 0; D1(printk("jffs2_garbage_collect_thread START\n")); while(1) { rt_event_recv(&sb->s_gc_thread_flags, GC_THREAD_FLAG_TRIG | GC_THREAD_FLAG_STOP, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, cyg_current_time() + CYGNUM_JFFS2_GS_THREAD_TICKS, &flag); if (flag & GC_THREAD_FLAG_STOP) break; D1(printk("jffs2: GC THREAD GC BEGIN\n")); mte=(cyg_dir *) sb->s_root; RT_ASSERT(mte != NULL); // rt_mutex_take(&mte->fs->syncmode, RT_WAITING_FOREVER); if (jffs2_garbage_collect_pass(c) == -ENOSPC) { printf("No space for garbage collection. " "Aborting JFFS2 GC thread\n"); break; } // rt_mutex_release(&mte->fs->syncmode); D1(printk("jffs2: GC THREAD GC END\n")); } D1(printk("jffs2_garbage_collect_thread EXIT\n")); rt_event_send(&sb->s_gc_thread_flags,GC_THREAD_FLAG_HAS_EXIT); }
static void entry0( cyg_addrword_t data ) { int tick; // Scheduler and thus timer interrupts are running by the // time we get here. // Wait for next tick tick = cyg_current_time(); do {} while (cyg_current_time() == tick); tick = cyg_current_time(); // Then mask timer interrupts HAL_INTERRUPT_MASK(CYGNUM_HAL_INTERRUPT_RTC); // and wait for the time when the next tick should have come // and check it didn't trigger an interrupt hal_delay_us(TICK_DELAY); CYG_TEST_CHECK(cyg_current_time() == tick, "Timer interrupt while masked"); // Now change interrupt level, and make the check again. Changing // level should not affect interrupt mask state. HAL_INTERRUPT_SET_LEVEL(CYGNUM_HAL_INTERRUPT_RTC, 8); hal_delay_us(TICK_DELAY); CYG_TEST_CHECK(cyg_current_time() == tick, "Timer interrupt after changing level"); // Finally unmask the interrupt and make sure it results in ticks. HAL_INTERRUPT_UNMASK(CYGNUM_HAL_INTERRUPT_RTC); hal_delay_us(TICK_DELAY); CYG_TEST_CHECK(cyg_current_time() != tick, "No timer interrupt after unmask"); CYG_TEST_PASS_FINISH("SH intr0 test end"); }
// // Protocol driver for testing slave. // // This function is the main routine running here, handling requests sent from // the master and providing various responses. // static void nc_slave(test_param_t param) { int s, masterlen; struct sockaddr_in my_addr, master; struct nc_request req; struct nc_reply reply; int done = false; test_printf("Start test for eth%d\n", param); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { pexit("datagram socket"); } memset((char *) &my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_len = sizeof(my_addr); my_addr.sin_addr.s_addr = htonl(INADDR_ANY); my_addr.sin_port = htons(NC_SLAVE_PORT); if (bind(s, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0) { pexit("bind"); } while (!done) { masterlen = sizeof(master); if (recvfrom(s, &req, sizeof(req), 0, (struct sockaddr *)&master, &masterlen) < 0) { pexit("recvfrom"); } #if 0 test_printf("Request %d from %s:%d\n", ntohl(req.type), inet_ntoa(master.sin_addr), ntohs(master.sin_port)); #endif reply.response = htonl(NC_REPLY_ACK); reply.seq = req.seq; switch (ntohl(req.type)) { case NC_REQUEST_DISCONNECT: done = true; break; case NC_REQUEST_UDP_SEND: test_printf("UDP send - %d buffers, %d bytes\n", ntohl(req.nbufs), ntohl(req.buflen)); break; case NC_REQUEST_UDP_RECV: test_printf("UDP recv - %d buffers, %d bytes\n", ntohl(req.nbufs), ntohl(req.buflen)); break; case NC_REQUEST_UDP_ECHO: test_printf("UDP echo - %d buffers, %d bytes\n", ntohl(req.nbufs), ntohl(req.buflen)); break; case NC_REQUEST_TCP_SEND: test_printf("TCP send - %d buffers, %d bytes\n", ntohl(req.nbufs), ntohl(req.buflen)); break; case NC_REQUEST_TCP_RECV: test_printf("TCP recv - %d buffers, %d bytes\n", ntohl(req.nbufs), ntohl(req.buflen)); break; case NC_REQUEST_TCP_ECHO: test_printf("TCP echo - %d buffers, %d bytes\n", ntohl(req.nbufs), ntohl(req.buflen)); break; case NC_REQUEST_SET_LOAD: start_load(ntohl(req.nbufs)); break; case NC_REQUEST_START_IDLE: test_printf("Start IDLE thread\n"); idle_thread_count = 0; idle_thread_start_time = cyg_current_time(); cyg_semaphore_post(&idle_thread_sem); break; case NC_REQUEST_STOP_IDLE: cyg_semaphore_wait(&idle_thread_sem); idle_thread_stop_time = cyg_current_time(); test_printf("Stop IDLE thread\n"); reply.misc.idle_results.elapsed_time = htonl(idle_thread_stop_time - idle_thread_start_time); reply.misc.idle_results.count[0] = htonl(idle_thread_count >> 32); reply.misc.idle_results.count[1] = htonl((long)idle_thread_count); break; default: test_printf("Unrecognized request: %d\n", ntohl(req.type)); reply.response = htonl(NC_REPLY_NAK); reply.reason = htonl(NC_REPLY_NAK_UNKNOWN_REQUEST); break; } if (sendto(s, &reply, sizeof(reply), 0, (struct sockaddr *)&master, masterlen) < 0) { pexit("sendto"); } if (reply.response == ntohl(NC_REPLY_NAK)) { continue; } switch (ntohl(req.type)) { case NC_REQUEST_UDP_SEND: case NC_REQUEST_UDP_RECV: case NC_REQUEST_UDP_ECHO: do_udp_test(s, &req, &master); break; case NC_REQUEST_TCP_SEND: case NC_REQUEST_TCP_RECV: case NC_REQUEST_TCP_ECHO: do_tcp_test(s, &req, &master); break; case NC_REQUEST_START_IDLE: case NC_REQUEST_STOP_IDLE: case NC_REQUEST_SET_LOAD: default: break; } } close(s); }
void dhcp_init(cyg_addrword_t arg) { uint no_timeout = 1; int need_LinkLocal = 1; while( Network_TCPIP_ON == 0 ) ppause(100); //ZOTIPS dhcp_start(WLanface); dhcp_start(Lanface); //ZOTIPS ppause(2000); if ( !strcmp(EEPROM_Data.WLESSID, "") || !strcmp(EEPROM_Data.WLESSID, "< ANY >")) dhcp_serch(45); // original:25. Jesse modified this at build0006 of 716U2W on April 28, 2011. else dhcp_serch(45); // original:13. Jesse modified this at build0006 of 716U2W on April 28, 2011. while(1) { cyg_semaphore_init( &dhcp_sem, 0); no_timeout = 1; #ifdef LINKLOCAL_IP // Ron Add 11/28/04 if ( (mib_DHCP_p->IPAddr == 0x0) && need_LinkLocal ) //ZOTIPS Give_ip_by_myself(WLanface); Give_ip_by_myself(Lanface); //ZOTIPS else { if(EEPROM_Data.RENVEnable == 1) { if( rendezvous_TaskHdl == 0) cyg_semaphore_post( &rendezvous_sem); else Need_Rendezous_Reload = 1; } } #else if( mib_DHCP_p->IPAddr == 0x0 ) set_factory_ip(); #endif if( (mib_DHCP_p->IPAddr == 0x0 ) || ((NGET32(EEPROM_Data.BoxIPAddress) & 0x0000FFFF)==0x0000FEA9) ) no_timeout = cyg_semaphore_timed_wait( &dhcp_sem, cyg_current_time() + 90000); else cyg_semaphore_wait( &dhcp_sem); if( no_timeout == 0 ) need_LinkLocal = 0; else need_LinkLocal = 1; erase_netif_ipaddr(); delete_dhcp_time(); ppause(500); dhcp_serch(10); // original:3. Jesse modified this at build0006 of 716U2W on April 28, 2011. } }
static void serial_rcv_char(serial_channel *chan, unsigned char c) { cbuf_t *cbuf = &chan->in_cbuf; #ifdef CYGPKG_NET_BLUEZ_STACK if(chan->receive)//clyu { extern unsigned char bluetooth_buf[]; int len = 0; struct tty_ldisc *ldisc = chan->tty_ldisc; if(ldisc && ldisc->receive_buf && cbuf->nb) { diag_printf("bluetooth\n"); if(cbuf->put < cbuf->get) { memcpy(bluetooth_buf, cbuf->data + cbuf->get, cbuf->len - cbuf->get); len = cbuf->len - cbuf->get; //ldisc->receive_buf(serial_driver, cbuf->data + cbuf->get, (char*)cbuf, cbuf->len - cbuf->get); cbuf->nb -= len; cbuf->get = 0; } memcpy(bluetooth_buf + len, cbuf->data + cbuf->get, cbuf->put); len += cbuf->put; cbuf->get = cbuf->put; cbuf->nb -= len; //ldisc->receive_buf(serial_driver, cbuf->data + cbuf->get, (char*)cbuf, cbuf->nb); ldisc->receive_buf(serial_driver, bluetooth_buf, (char*)cbuf, len); } chan->receive = 0; return; } #endif #if CYGINT_IO_SERIAL_BLOCK_TRANSFER CYG_ASSERT(false == cbuf->block_mode_xfer_running, "Attempting char rcv while block transfer is running"); #endif #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE // for software flow control, if the driver returns one of the characters // we act on it and then drop it (the app must not see it) if ( chan->config.flags & CYGNUM_SERIAL_FLOW_XONXOFF_TX ) { if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XOFF_CHAR ) { throttle_tx( chan ); return; // it wasn't a "real" character } else if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XON_CHAR ) { restart_tx( chan ); return; // it wasn't a "real" character } } #endif #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL // If we've hit the high water mark, tell the other side to stop if ( cbuf->nb >= cbuf->high_water ) { throttle_rx( chan, false ); } #endif #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT // Wake up any pending selectors if we are about to // put some data into a previously empty buffer. if( cbuf->nb == 0 ) cyg_selwakeup( &cbuf->selinfo ); #endif // If the flow control is not enabled/sufficient and the buffer is // already full, just throw new characters away. if ( cbuf->nb < cbuf->len ) { cbuf->data[cbuf->put++] = c; if (cbuf->put == cbuf->len) cbuf->put = 0; cbuf->nb++; } // note trailing else #ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS else { // Overrun. Report the error. cyg_serial_line_status_t stat; stat.which = CYGNUM_SERIAL_STATUS_OVERRUNERR; serial_indicate_status(chan, &stat); } #endif if (cbuf->waiting) { #ifdef XX_CYGDBG_DIAG_BUF extern int enable_diag_uart; int _enable = enable_diag_uart; int _time, _stime; externC cyg_tick_count_t cyg_current_time(void); enable_diag_uart = 0; HAL_CLOCK_READ(&_time); _stime = (int)cyg_current_time(); diag_printf("Signal reader - time: %x.%x\n", _stime, _time); enable_diag_uart = _enable; #endif // CYGDBG_DIAG_BUF cbuf->waiting = false; cyg_drv_cond_signal(&cbuf->wait); } }
static Cyg_ErrNo serial_read(cyg_io_handle_t handle, void *_buf, cyg_uint32 *len) { cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle; serial_channel *chan = (serial_channel *)t->priv; serial_funs *funs = chan->funs; cyg_uint8 *buf = (cyg_uint8 *)_buf; cyg_int32 size = 0; cbuf_t *cbuf = &chan->in_cbuf; Cyg_ErrNo res = ENOERR; #ifdef XX_CYGDBG_DIAG_BUF extern int enable_diag_uart; int _enable = enable_diag_uart; int _time, _stime; externC cyg_tick_count_t cyg_current_time(void); #endif // CYGDBG_DIAG_BUF cyg_drv_mutex_lock(&cbuf->lock); cbuf->abort = false; if (cbuf->len == 0) { // Non interrupt driven (i.e. polled) operation while (size++ < *len) { cyg_uint8 c = (funs->getc)(chan); #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE // for software flow control, if the driver returns one of the // characters we act on it and then drop it (the app must not // see it) if ( chan->config.flags & CYGNUM_SERIAL_FLOW_XONXOFF_TX ) { if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XOFF_CHAR ) { throttle_tx( chan ); } else if ( c == CYGDAT_IO_SERIAL_FLOW_CONTROL_XON_CHAR ) { restart_tx( chan ); } else *buf++ = c; } else *buf++ = c; #else *buf++ = c; #endif } } else { cyg_drv_dsr_lock(); // Avoid races while (size < *len) { if (cbuf->nb > 0) { #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL if ( (cbuf->nb <= cbuf->low_water) && (chan->flow_desc.flags & CYG_SERIAL_FLOW_IN_THROTTLED) ) restart_rx( chan, false ); #endif *buf++ = cbuf->data[cbuf->get]; if (++cbuf->get == cbuf->len) cbuf->get = 0; cbuf->nb--; size++; } else { #ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING if (!cbuf->blocking) { *len = size; // characters actually read res = -EAGAIN; break; } #endif // CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING cbuf->waiting = true; #ifdef XX_CYGDBG_DIAG_BUF enable_diag_uart = 0; HAL_CLOCK_READ(&_time); _stime = (int)cyg_current_time(); diag_printf("READ wait - get: %d, put: %d, time: %x.%x\n", cbuf->get, cbuf->put, _stime, _time); enable_diag_uart = _enable; #endif // CYGDBG_DIAG_BUF if( !cyg_drv_cond_wait(&cbuf->wait) ) cbuf->abort = true; #ifdef XX_CYGDBG_DIAG_BUF enable_diag_uart = 0; HAL_CLOCK_READ(&_time); _stime = (int)cyg_current_time(); diag_printf("READ continue - get: %d, put: %d, time: %x.%x\n", cbuf->get, cbuf->put, _stime, _time); enable_diag_uart = _enable; #endif // CYGDBG_DIAG_BUF if (cbuf->abort) { // Give up! *len = size; // characters actually read cbuf->abort = false; cbuf->waiting = false; res = -EINTR; break; } } } cyg_drv_dsr_unlock(); } #ifdef XX_CYGDBG_DIAG_BUF cyg_drv_isr_lock(); enable_diag_uart = 0; HAL_CLOCK_READ(&_time); _stime = (int)cyg_current_time(); diag_printf("READ done - size: %d, len: %d, time: %x.%x\n", size, *len, _stime, _time); enable_diag_uart = _enable; cyg_drv_isr_unlock(); #endif // CYGDBG_DIAG_BUF cyg_drv_mutex_unlock(&cbuf->lock); return res; }
void CECOSTimerHandler::enableHandler(void){ cyg_alarm_initialize(m_stAlarmHandle, cyg_current_time() + 1, 1); }
// Time in seconds. double dtime(void) { return (double) cyg_current_time() / 100; }