static void entry0( cyg_addrword_t data ) { cyg_count32 val; cyg_semaphore_wait(&s0); CHECK( 1 == q++ ); cyg_semaphore_post(&s1); cyg_semaphore_wait(&s0); CHECK( 3 == q++ ); cyg_semaphore_peek(&s0, &val); CHECK( 0 == val); CHECK( ! cyg_semaphore_trywait(&s0) ); cyg_semaphore_post(&s0); CHECK( 4 == q++ ); cyg_semaphore_peek(&s0, &val); CHECK( 1 == val); cyg_semaphore_post(&s0); cyg_semaphore_peek(&s0, &val); CHECK( 2 == val); cyg_semaphore_post(&s1); cyg_semaphore_peek(&s2, &val); CHECK( 0 == val); cyg_semaphore_wait(&s2); CHECK( 6 == q++ ); CYG_TEST_PASS_FINISH("Kernel C API Semaphore 1 OK"); }
static void entry1( cyg_addrword_t data ) { cyg_count32 val; cyg_semaphore_peek(&s1, &val); CHECK( 2 == val); cyg_semaphore_wait(&s1); cyg_semaphore_peek(&s1, &val); CHECK( 1 == val); cyg_semaphore_wait(&s1); CHECK( 0 == q++ ); cyg_semaphore_peek(&s0, &val); CHECK( 0 == val); cyg_semaphore_post(&s0); cyg_semaphore_wait(&s1); CHECK( 2 == q++ ); cyg_semaphore_post(&s0); cyg_semaphore_wait(&s1); CHECK( 5 == q++ ); cyg_semaphore_peek(&s0, &val); CHECK( 2 == val); CHECK( cyg_semaphore_trywait(&s0) ); cyg_semaphore_peek(&s0, &val); CHECK( 1 == val); CHECK( cyg_semaphore_trywait(&s0) ); cyg_semaphore_peek(&s0, &val); CHECK( 0 == val); cyg_semaphore_post(&s2); cyg_semaphore_wait(&s0); CYG_TEST_FAIL_FINISH("Not reached"); }
void vjpegInit(void) { #ifndef ECOS tt_rmutex_init(&g_vpJPEG.mtLock); tt_rmutex_init(&g_vpJPEG.mtLockEncoder); tt_rmutex_init(&g_vpJPEG.mtLockDecoder); tt_sem_init(&g_vpJPEG.semEncoder, 1); tt_sem_init(&g_vpJPEG.semDecoder, 1); tt_sem_down(&g_vpJPEG.semEncoder); tt_sem_down(&g_vpJPEG.semDecoder); #else cyg_mutex_init(&g_vpJPEG.mtLock); cyg_mutex_init(&g_vpJPEG.mtLockEncoder); cyg_mutex_init(&g_vpJPEG.mtLockDecoder); cyg_semaphore_init(&g_vpJPEG.semEncoder, 1); cyg_semaphore_init(&g_vpJPEG.semDecoder, 1); cyg_semaphore_wait(&g_vpJPEG.semEncoder); cyg_semaphore_wait(&g_vpJPEG.semDecoder); #endif g_vpJPEG.nRefCount = 0; g_vpJPEG.nRefCount_Encoder = 0; g_vpJPEG.nRefCount_Decoder = 0; g_vpJPEG.pJPEGEncodeBuffer = NULL; listInit (&g_vpJPEG.listEncodedJPEG); g_vpJPEG.nJPEGQua = 2; g_vpJPEG.bOnTheFly = TRUE; g_vpJPEG.nOnTheFlyCount = 0; #ifndef ECOS sysInstallISR(IRQ_LEVEL_1, IRQ_JPEG, (void*)jpegIntHandler); #else cyg_interrupt_disable(); cyg_interrupt_create(IRQ_JPEG, IRQ_LEVEL_1, NULL, &jpegIntHandler, &jpegIntHandler_DSR, &(g_vpJPEG.cygIntrHandle), &(g_vpJPEG.cygIntrBuffer)); cyg_interrupt_attach(g_vpJPEG.cygIntrHandle); cyg_interrupt_unmask(IRQ_JPEG); cyg_interrupt_enable(); #endif jpegSetIRQHandler(C_JPEG_CALLBACK_ENCODE_COMPLETE_INTERRUPT, vjpegEncoderCom_Callback); jpegSetIRQHandler(C_JPEG_CALLBACK_DECODE_COMPLETE_INTERRUPT, vjpegDecoderCom_Callback); jpegSetIRQHandler(C_JPEG_CALLBACK_DECODE_ERROR_INTERRUPT, vjpegDecoderErr_Callback); if(g_vpJPEG.bOnTheFly == TRUE) { jpegSetIRQHandler(C_JPEG_CALLBACK_ENCODE_SWONTHEFLY_WAIT_INTERRUPT, vjpegOnTheFlyCom_Callback); } bJPEGInit = TRUE; }
u32 _down_sema(_sema *sema) { #ifdef PLATFORM_LINUX #if 0 //eason 20100210 if (down_interruptible(sema)) return _FAIL; else return _SUCCESS; #else cyg_semaphore_wait(sema); return _SUCCESS; #endif //eason 20100210 #endif #ifdef PLATFORM_OS_XP if(STATUS_SUCCESS == KeWaitForSingleObject(sema, Executive, KernelMode, TRUE, NULL)) return _SUCCESS; else return _FAIL; #endif #ifdef PLATFORM_OS_CE if(WAIT_OBJECT_0 == WaitForSingleObject(*sema, INFINITE )) return _SUCCESS; else return _FAIL; #endif }
void thread_write_audio(cyg_addrword_t data) { VP_BUFFER_TEST_AUDIO_BITSTREAM_T *ptestaudio; IO_THREAD_READ_T readarg; while(1) { cyg_semaphore_wait(&g_testaudio.pcAudio.consumer); if (!listIsEmpty (&g_testaudio.listAudio)) { ptestaudio = GetParentAddr (g_testaudio.listAudio.pNext, VP_BUFFER_TEST_AUDIO_BITSTREAM_T, list); listDetach(&ptestaudio->list); } else { diag_printf("No auido data???\n"); while(1); } readarg.txbuf = ptestaudio->aucAudio; readarg.txlen = ptestaudio->iAudioLen; readarg.mediatype = MEDIA_TYPE_AUDIO; iothread_Write(&readarg); bufTestAudioDecRef(ptestaudio); cyg_semaphore_post(&g_testaudio.pcAudio.producer); } cyg_thread_exit(); }
static void cleanup_thread(cyg_addrword_t data) { shell_thread_t *nt; /* * This thread sleeps on the cleanup semaphore * Any time that gets tagged, we wakeup, read from the mailbox * (which should contain the thread info about the thread(s) waiting * to be cleaned up, delete the thread, free up it's context, * and go back to sleep until more work comes in * * As a possible optimization for the future -- should I check * the mailbox for any more waiting entries? If the semaphore gets * incremented while in here, do we have a race? It doesn't look * like it, but check more carefully... */ while(1) { cyg_semaphore_wait(&cleanup.cleanup_sem); do { nt = cyg_mbox_get(cleanup.mbox_handle); if(nt) { cyg_thread_kill(nt->thread_handle); cyg_thread_delete(nt->thread_handle); free(nt->name); free(nt); } else SHELL_PRINT("Cleanup received a NULL in mbox?!\n"); } while(nt); } }
void get_back_audio(unsigned char* input_buf,int *input_len) { cyg_semaphore_wait(&audio_sem0); *input_len = len; memcpy((char*)(input_buf), (char*)(g_DataBuffer), len); cyg_semaphore_post(&audio_sem1); }
// ------------------------------------------------------------------------ static void sender( cyg_addrword_t which ) // which means which set (odd/even) here... { int s_source; struct sockaddr_in local; int len; diag_printf("client %d [%s] :started\n", which, (which & 1) ? "odd" : "even" ); for ( /* which as is */; which < NLISTENERS; which += 2 ) { s_source = socket(AF_INET, SOCK_STREAM, 0); if (s_source < 0) { pexit("stream socket"); } memset(&local, 0, sizeof(local)); local.sin_family = AF_INET; local.sin_len = sizeof(local); local.sin_port = htons( SOURCE_PORT1 + which ); local.sin_addr.s_addr = htonl(INADDR_LOOPBACK); if (connect(s_source, (struct sockaddr *)&local, sizeof(local)) < 0) { pexit("Can't connect to target"); } if ((len = write(s_source,data_buf_write1,sizeof(data_buf_write1) )) < 0) { CYG_TEST_FAIL_FINISH("Error writing buffer"); } cyg_semaphore_wait( &listen_sema[which] ); // wait for the appropriate semaphore "reply" cyg_semaphore_post( &send_sema ); // count up successful sends close ( s_source ); } cyg_thread_exit(); // explicitly }
void vjpegWaitDecoderCom(void) { #ifndef ECOS tt_sem_down(&g_vpJPEG.semDecoder); #else cyg_semaphore_wait(&g_vpJPEG.semDecoder); #endif }
void CECOSTimerHandler::run(void){ CECOSThread::setPriority(0); //we want to be a very important thread while(isAlive()){ cyg_semaphore_wait(&m_stSemaphore); //FIXME add compensation code for timer activation jitter similar to the code in the posix architecture sm_poFORTETimer->nextTick(); } }
static int usblp_read( struct usblp *usblp, char *buffer, size_t count, int *ppos) { if (!usblp->bidir) return -EINVAL; if (usblp->readurb.status == -EINPROGRESS) { // if (file->f_flags & O_NONBLOCK) // return -EAGAIN; #if 0 //ZOT716u2 while (usblp->readurb.status == -EINPROGRESS) { // if (signal_pending(current)) // return -EINTR; cyg_thread_yield(); // interruptible_sleep_on(&usblp->wait); } #else //ZOT716u2 while (usblp->readurb.status == -EINPROGRESS) { cyg_semaphore_wait(usblp->wait); } #endif //ZOT716u2 } if (!usblp->dev) return -ENODEV; #ifdef SUPPORT_PRN_COUNT count = count < USBLP_BUF_SIZE ? count : USBLP_BUF_SIZE; copy_to_user(buffer, (uint8 *)usblp->readurb.transfer_buffer + usblp->readcount, count); #else if (usblp->readurb.status) { //{{MARK_DEBUG // err("usblp%d: error %d reading from printer", // usblp->minor, usblp->readurb.status); //}}MARK_DEBUG usblp->readurb.dev = usblp->dev; usblp->readcount = 0; usb_submit_urb(&usblp->readurb); return -EIO; } count = count < usblp->readurb.actual_length - usblp->readcount ? count : usblp->readurb.actual_length - usblp->readcount; if (copy_to_user(buffer, (uint8 *)usblp->readurb.transfer_buffer + usblp->readcount, count)) return -EFAULT; #endif //SUPPORT_PRN_COUNT if ((usblp->readcount += count) == usblp->readurb.actual_length) { usblp->readcount = 0; usblp->readurb.dev = usblp->dev; usb_submit_urb(&usblp->readurb); } return count; }
// // This thread does nothing but count. It will be allowed to count // as long as the semaphore is "free". // void net_idle(cyg_addrword_t param) { while (true) { cyg_semaphore_wait(&idle_thread_sem); idle_thread_count++; cyg_semaphore_post(&idle_thread_sem); } }
// Wait on the semaphore for a given port number. static void sem_wait(int port) { int i; CYG_ASSERT(port != 0, "Invalid port number"); for (i=0; i < CYGNUM_NET_TFTPD_MULTITHREADED_PORTS; i++) { if (tftpd_sems[i].port == port) { cyg_semaphore_wait(&tftpd_sems[i].sem); return; } } diag_printf("TFTPD: No semaphore for port %d\n",port); }
// // These thread(s) do some amount of "background" computing. This is used // to simulate a given load level. They need to be run at a higher priority // than the network code itself. // // Like the "idle" thread, they run as long as their "switch" (aka semaphore) // is enabled. // void net_load(cyg_addrword_t who) { int i; while (true) { cyg_semaphore_wait(&load_thread_sem[who]); for (i = 0; i < load_thread_level; i++) { do_some_random_computation(i); } cyg_thread_delay(1); // Wait until the next 'tick' cyg_semaphore_post(&load_thread_sem[who]); } }
void Give_ip_by_myself(struct netif *netif){ if(EEPROM_Data.RENVEnable == 1) { SetLinkLocalIP(netif ,0); cyg_semaphore_init(&DhcpWaitLinklocal_sem,0); cyg_semaphore_post(&linklocal_sem); cyg_semaphore_wait(&DhcpWaitLinklocal_sem); } else set_factory_ip(); }
// Thread B - waits for semaphore signal from thread A. void thread_b(cyg_addrword_t data) { // Store the data value passed in for this thread. int msg = (int)data; while(1) { // Signal thread B using the semaphore. cyg_semaphore_wait(&sem_signal_thread); // Send out a message to the diagnostic port. diag_printf("INFO:< Thread B, message: %d>\n", msg); } }
void GetAudioThread(cyg_addrword_t pParam) { W99702_DATA_EXCHANGE_T * pExData = (W99702_DATA_EXCHANGE_T *)pParam; int iRt; IO_THREAD_READ_T readarg; while (!AudioExit) { iRt = iothread_ReadAudio(&readarg); if(iRt == -1) { diag_printf("Encode Core Quit!\n"); iothread_ReadAudio_Complete(&readarg); continue; } else if(iRt ==0) { diag_printf("%d buffer too small.\n",readarg.mediatype); iothread_ReadAudio_Complete(&readarg); continue; } else { switch(readarg.mediatype) { case MEDIA_TYPE_AUDIO: //diag_printf("get audio\n"); cyg_semaphore_wait(&(pExData->pcAudio).producer); memcpy((char*)(pExData->acAudioBuf), (char*)(readarg.txbuf), readarg.txlen); pExData->szAudioLen = readarg.txlen; iothread_ReadAudio_Complete(&readarg); #ifdef RECORDER if((pExData->szAudioLen > 0) && RecordInit) recorder_add_audio(pExData->acAudioBuf,pExData->szAudioLen); #endif cyg_semaphore_post (&(pExData->pcAudio).consumer); break; default: break; } } } }
/* * 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); }
// // This function is called to set up a load level of 'load' percent (given // as a whole number, e.g. start_load(20) would mean initiate a background // load of 20%, leaving the cpu 80% idle). // static void start_load(int load) { static int prev_load = 0; int i; test_printf("Set background load = %d%%\n", load); if (load == 0) { if (prev_load == 0) return; // Nothing out there to stop for (i = 0; i < prev_load/10; i++) { cyg_semaphore_wait(&load_thread_sem[i]); } prev_load = 0; } else { for (i = 0; i < load/10; i++) { cyg_semaphore_post(&load_thread_sem[i]); } prev_load = load; } }
// ------------------------------------------------------------------------ // The management thread function void dhcp_mgt_entry( cyg_addrword_t loop_on_failure ) { int j; while ( 1 ) { while ( 1 ) { cyg_semaphore_wait( &dhcp_needs_attention ); if ( ! dhcp_bind() ) // a lease expired break; // If we need to re-bind } dhcp_halt(); // tear everything down if ( !loop_on_failure ) return; // exit the thread/return init_all_network_interfaces(); // re-initialize for ( j = 0; j < CYGPKG_NET_NLOOP; j++ ) init_loopback_interface( j ); #ifdef CYGPKG_SNMPAGENT SnmpdShutDown(0); // Cycle the snmpd state #endif } }
// // This function is called to set up a load level of 'load' percent (given // as a whole number, e.g. start_load(20) would mean initiate a background // load of 20%, leaving the cpu 80% idle). // static void start_load(int load) { static int prev_load = 0; int i; if (load == 0) { diag_printf("Set no background load\n"); if (prev_load == 0) return; // Nothing out there to stop for (i = 0; i < prev_load * NUM_LOAD_THREADS/100; i++) { cyg_semaphore_wait(&load_thread_sem[i]); } prev_load = 0; } else { diag_printf("Set background load = %d%% starting %d threads\n", load, load * NUM_LOAD_THREADS/100 ); for (i = 0; i < load * NUM_LOAD_THREADS/100; i++) { cyg_semaphore_post(&load_thread_sem[i]); } prev_load = load; } }
void USB_init(cyg_addrword_t data) { cyg_sem_t sem; cyg_semaphore_init(&sem, 0); ppause(200); //20 Ticks, 200m seconds //init memory pci_usb_pool_init(); //usb usb_init(); //ohci ohci_hcd_init(0x5C, SYSPA_USB11_OPERATION_BASE_ADDR); //ehci ehci_hcd_init(0x6B, SYSPA_USB20_OPERATION_BASE_ADDR); //Printer Class usblp_init(); cyg_semaphore_wait(&sem); cyg_semaphore_destroy(&sem); }
void LinkLocal_ip_Task(cyg_addrword_t arg) { int prob_conut, retry_count; uint32 LinkLocalIP; int get_conflict; //get arp reply to conflict our IP LinkLocal_set_state( NO_USE ); while(1){ cyg_semaphore_init(&linklocal_sem, 0); cyg_semaphore_wait(&linklocal_sem); init_LinkLocal(); if(rendezvous_TaskHdl != 0) { cyg_thread_suspend(rendezvous_TaskHdl); } prob_conut = 0; retry_count = 0; while(1){ switch( LinkLocal_get_current_state() ){ case PROBE: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 0 ); LinkLocalIP = SetLinkLocalIP(Lanface, 0 ); //ZOTIPS break; case RETRY: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 1 ); LinkLocalIP = SetLinkLocalIP(Lanface, 1 ); //ZOTIPS break; case ANNOUNCE: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 0 ); //ZOTIPS set_netif_ip(WLanface); LinkLocalIP = SetLinkLocalIP(Lanface, 0 ); //ZOTIPS set_netif_ip(Lanface); //ZOTIPS break; } //ZOTIPS LinkLocal_IP_Query(LinkLocalIP, WLanface); LinkLocal_IP_Query(LinkLocalIP, Lanface); //ZOTIPS get_conflict = cyg_semaphore_timed_wait(&linklocal_conflict, cyg_current_time() +(900/MSPTICK)); switch( LinkLocal_get_current_state() ){ case PROBE: if( get_conflict ) { LinkLocal_set_state( RETRY ); ppause(1000); } else prob_conut++; if( prob_conut == 3) { ppause(900); LinkLocal_set_state( ANNOUNCE ); } break; case RETRY: if( get_conflict ) { retry_count++; } else{ LinkLocal_set_state( PROBE ); prob_conut = 1; } ppause(1000); if( retry_count == 15) { ppause(900); LinkLocal_set_state( ANNOUNCE ); } break; case ANNOUNCE: if(get_conflict) ppause(1000); //ZOTIPS LinkLocal_IP_Query(LinkLocalIP, WLanface); LinkLocal_IP_Query(LinkLocalIP, Lanface); //ZOTIPS WriteToEEPROM(&EEPROM_Data); LinkLocal_set_state( IDLE ); break; } if( LinkLocal_get_current_state() == IDLE) break; } if( rendezvous_TaskHdl == 0) cyg_semaphore_post( &rendezvous_sem); else { cyg_thread_resume(rendezvous_TaskHdl); Need_Rendezous_Reload = 1; } cyg_semaphore_post(&DhcpWaitLinklocal_sem); } }
//----------------------------------------- // eCos HW scheduling thread //----------------------------------------- void reconos_hw_scheduler(cyg_addrword_t data) { cyg_bool_t retval; rthread_attr_t *t_r; // thread to reconfigure rthread_attr_t *t_y; // yielding thread reconos_slot_t *s_f; // free slot reconos_bitstream_t *t_r_bit; // bitstream for t_r in s_f #ifdef UPBFUN_RECONOS_CHECK_HWTHREAD_SIGNATURE uint32 signature; // hardware thread signature volatile int z; // counter to delay DCR access #endif #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: created\n"); #endif // loop forever for (;;) { // wait for signal (reschedule request) retval = cyg_semaphore_wait( &reconos_hwsched_semaphore ); CYG_ASSERT(retval, "cyg_semaphore_wait returned false"); #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: wakeup\n"); #endif // lock scheduling mutex if (!cyg_mutex_lock(&reconos_hwsched_mutex)) { CYG_FAIL("mutex lock failed, aborting thread\n"); } else { #ifdef UPBDBG_RECONOS_DEBUG { int i; for (i = 0; i < NUM_OSIFS; i++) { dump_slot( &reconos_slots[i] ); } } #endif // find thread t_r that wants to run (FIXME: no priorities or // queuing!) t_r = reconos_hwthread_list; while ( t_r != NULL && ((t_r->flags & RTHREAD_ATTR_RECONFIGURE) == 0) ) { t_r = t_r->next; } if (t_r == NULL) { // no hw threads to reconfigure, nothing to do #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: no threads to reconfigure\n"); #endif // clear all yield requests! while (num_global_yield_requests) { pop_yield_request(); } } else { #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: found thread @ 0x%08X to reconfigure\n", (uint32)t_r); #endif CYG_ASSERT( t_r->flags & RTHREAD_ATTR_IS_DYNAMIC, "trying to load a static thread" ); // find free slot s_f s_f = find_free_slot( t_r ); if ( s_f == NULL ) { // no free slot // try to find thread that yields in a slot we have a // bitstream for #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: no free slots\n"); #endif t_y = reconos_hwthread_list; while ( t_y != NULL && ( ( (t_y->flags & RTHREAD_ATTR_YIELDS ) == 0) || ( get_bit_for_slot( t_r, t_y->slot ) == NULL ) ) ) { t_y = t_y->next; } if (t_y == NULL) { // no yielding thread #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: no yielding threads, sending yield requests to slots\n"); #endif // ask all slots to yield // FIXME: this will also ask slots that t_r possibly // doesn't have a bitstream for push_yield_request(); } else { // if found CYG_ASSERT( t_y->flags & RTHREAD_ATTR_IS_DYNAMIC, "trying to replace a static thread" ); CYG_ASSERT( t_y->slot, "trying to replace a not-resident thread" ); #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: found yielding thread @ 0x%08X in slot %d\n", (uint32)t_y, t_y->slot->num); #endif // use t_y's slot as s_f s_f = t_y->slot; // clear yield flag of t_y t_y->flags = t_y->flags & ~RTHREAD_ATTR_YIELDS; // remove t_y from s_f s_f->thread = NULL; t_y->slot = NULL; s_f->state = FREE; } } else { #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: found free slot %d\n", s_f->num); #endif } if ( s_f != NULL) { // if we found a free slot // one way or the other // get bitstream for t_r in s_f t_r_bit = get_bit_for_slot( t_r, s_f ); CYG_ASSERT( t_r_bit, "no bitstream" ); CYG_ASSERT( s_f->state == FREE || s_f->thread->flags & RTHREAD_ATTR_IS_DYNAMIC, "slot not free or present thread is static" ); #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: configuring thread @ 0x%08X into slot %d using bitstream '%s'\n", (uint32)t_r, s_f->num, t_r_bit->filename); #endif // configure t_r into s_f // NOTE: we don't need to synchronize this with the // slot's mutex, since the slot is yielding and will // not perform any hardware operations while the // scheduling mutex is locked // disable bus macros (just in case) osif_set_busmacro(s_f, OSIF_DATA_BUSMACRO_DISABLE); #ifdef UPBHWR_VIRTEX4_ICAP icap_load( t_r_bit->data, t_r_bit->size ); #endif #ifdef UPBFUN_RECONOS_ECAP_NET ecap_load( t_r_bit ); #endif #ifdef UPBFUN_RECONOS_CHECK_HWTHREAD_SIGNATURE // reset thread, enable busmacros, reset again (to // retrieve signature), read signature, and disable // busmacros osif_reset( s_f ); cyg_thread_delay(1); osif_set_busmacro(s_f, OSIF_DATA_BUSMACRO_ENABLE); // cyg_thread_delay(1); osif_reset( s_f ); cyg_thread_delay(1); osif_read_hwthread_signature(s_f, &signature); // cyg_thread_delay(1); // osif_set_busmacro(s_f, OSIF_DATA_BUSMACRO_DISABLE); // cyg_thread_delay(1); #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: read signature: 0x%08X, expected: 0x%08X.\n", signature, t_r->circuit->signature); #endif // check whether the signatures match CYG_ASSERT(signature == t_r->circuit->signature, "hwthread signatures don't match"); #endif // assign thread to slot and set slot state to READY s_f->thread = t_r; t_r->slot = s_f; s_f->state = READY; // clear t_r's RECONFIGURE bit t_r->flags = t_r->flags & ~RTHREAD_ATTR_RECONFIGURE; // wake any threads waiting for a scheduling change cyg_cond_broadcast( &reconos_hwsched_condvar ); // clear one yield request pop_yield_request(); } } #ifdef UPBDBG_RECONOS_DEBUG diag_printf("hw_sched: done\n"); #endif // unlock scheduling mutex cyg_mutex_unlock(&reconos_hwsched_mutex); } // if (mutex_lock) } // for (;;) }
static void lcd_panel_server(cyg_addrword_t p) { int iX, iY, newX, newY, diffX, diffY, timeout, samples; cyg_uint32 event; diag_printf("LCD panel server here\n"); while (TRUE) { cyg_semaphore_wait(&lcd_panel_sem); samples = 0; iX = 0; iY = 0; // Wait for press to go away (no drag support) timeout = 0; while (timeout < LCD_PANEL_TIMEOUT) { *(volatile cyg_uint8 *)TOUCH_CTL = 0x00; // Disable drives while (*(volatile cyg_uint32 *)INTSR1 & INTSR1_EINT2) ; *(volatile cyg_uint8 *)TOUCH_CTL = 0x70; // Idle state (so interrupt works) cyg_thread_delay(2); // Wait 20 ms if (*(volatile cyg_uint32 *)INTSR1 & INTSR1_EINT2) { // Still pressed // Drive TSPY, ground TSMY, and disconnect TSPX and TSMX *(volatile cyg_uint8 *)TOUCH_CTL = 0x50; panel_delay(); newY = adc_sample(2); // Drive TSPX, ground TSMX, and disconnect TSPY and TSMY *(volatile cyg_uint8 *)TOUCH_CTL = 0xA0; panel_delay(); newX = adc_sample(7); #if 0 diag_printf("timeout: %d, ISR: %x, newX: %d, newY: %d\n", timeout, *(volatile cyg_uint32 *)INTSR1, newX, newY); #endif // See if this sample makes any sense if (samples) { diffX = abs(iX/samples - newX); diffY = abs(iY/samples - newY); if ((diffX <= ((iX/samples)/4)) && (diffY <= ((iY/samples)/4))) { samples++; iX += newX; iY += newY; } else { #if 0 diag_printf("Discard - newX: %d, X: %d, newY: %d, Y: %d\n", newX, iX/samples, newY, iY/samples); #endif break; } } else { iX = newX; iY = newY; samples = 1; } timeout = 0; } else { timeout++; } } if (samples) { // Send event to user level event = (iX/samples)<<16 | (iY/samples); if (!cyg_mbox_tryput(lcd_panel_events_mbox_handle, (void *)event)) { diag_printf("LCD event lost: %x\n", event); } } *(volatile cyg_uint8 *)TOUCH_CTL = 0x00; // Disable drives while (*(volatile cyg_uint32 *)INTSR1 & INTSR1_EINT2) ; *(volatile cyg_uint8 *)TOUCH_CTL = 0x70; // Idle state (so interrupt works) cyg_thread_delay(10); cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EINT2); } }
// // This function is called to calibrate the "background load" which can be // applied during testing. It will be called before any commands from the // host are managed. // static void calibrate_load(int desired_load) { long long no_load_idle, load_idle; int percent_load; int high, low; // Set limits high = MAX_LOAD_THREAD_LEVEL; low = MIN_LOAD_THREAD_LEVEL; test_printf("Start Network Characterization - SLAVE\n"); // Compute the "no load" idle value idle_thread_count = 0; cyg_semaphore_post(&idle_thread_sem); // Start idle thread test_printf("Start Network Characterization - SLAVE\n"); cyg_thread_delay(1*100); // Pause for one second test_printf("Start Network Characterization - SLAVE\n"); cyg_semaphore_wait(&idle_thread_sem); // Stop idle thread test_printf("Start Network Characterization - SLAVE\n"); no_load_idle = idle_thread_count; diag_printf("No load = %d\n", (int)idle_thread_count); // First ensure that the HIGH level is indeed higher while (true) { load_thread_level = high; start_load(desired_load); // Start up a given load idle_thread_count = 0; cyg_semaphore_post(&idle_thread_sem); // Start idle thread cyg_thread_delay(1*100); // Pause for one second cyg_semaphore_wait(&idle_thread_sem); // Stop idle thread load_idle = idle_thread_count; start_load(0); // Shut down background load percent_load = 100 - ((load_idle * 100) / no_load_idle); diag_printf("High Load[%ld] = %d => %d%%\n", load_thread_level, (int)idle_thread_count, percent_load); if ( percent_load > desired_load ) break; // HIGH level is indeed higher low = load_thread_level; // known to be lower high *= 2; // else double it and try again } // Now chop down to the level required while (true) { load_thread_level = (high + low) / 2; start_load(desired_load); // Start up a given load idle_thread_count = 0; cyg_semaphore_post(&idle_thread_sem); // Start idle thread cyg_thread_delay(1*100); // Pause for one second cyg_semaphore_wait(&idle_thread_sem); // Stop idle thread load_idle = idle_thread_count; start_load(0); // Shut down background load percent_load = 100 - ((load_idle * 100) / no_load_idle); diag_printf("Load[%ld] = %d => %d%%\n", load_thread_level, (int)idle_thread_count, percent_load); if (((high-low) <= 1) || (abs(desired_load-percent_load) <= 2)) break; if (percent_load < desired_load) { low = load_thread_level; } else { high = load_thread_level; } } // Now we are within a few percent of the target; scale the load // factor to get a better fit, and test it, print the answer. load_thread_level *= desired_load; load_thread_level /= percent_load; start_load(desired_load); // Start up a given load idle_thread_count = 0; cyg_semaphore_post(&idle_thread_sem); // Start idle thread cyg_thread_delay(1*100); // Pause for one second cyg_semaphore_wait(&idle_thread_sem); // Stop idle thread load_idle = idle_thread_count; start_load(0); // Shut down background load percent_load = 100 - ((load_idle * 100) / no_load_idle); diag_printf("Final load[%ld] = %d => %d%%\n", load_thread_level, (int)idle_thread_count, percent_load); // no_load_idle_count_1_second = no_load_idle; }
// // 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. } }
void PortNWrite(cyg_addrword_t data) { uint32 start; int written; int port = UsedPortNumber; #ifdef SUPPORT_PRN_COUNT BYTE reqbuf[40] = {0x1B,0x25,0x2D,0x31,0x32,0x33,0x34,0x35,0x58, 0x40,0x50,0x4A,0x4C,0x20,0x49,0x4E,0x46,0x4F,0x20, 0x50,0x41,0x47,0x45,0x43,0x4F,0x55,0x4E,0x54,0x20,0x0D,0x0A, 0x1B,0x25,0x2D,0x31,0x32,0x33,0x34,0x35,0x58}; BYTE respbuf[40] = {0}; #endif while( 1 ) { cyg_semaphore_wait (&SP_SIGNAL_PORT_1); PNW_Statu[port] = 1; //for dbg //ZOTIPS PrnStartPrintNegotiate( port ); while(PrnStartPrintNegotiate( port )!=0) cyg_thread_yield(); #ifdef SUPPORT_PRN_COUNT // check if it is IEEE1284 or USB printer device // if( port >= NUM_OF_1284_PORT ){ if(PrnLangSupport(port,P1284_PJL)) usbprn_write( port, reqbuf, 40 ); // } #endif //SUPPORT_PRN_COUNT //ZOTIPS armond_printf("Start writing, Data size: %d\n",PortIO[port].DataSize); start = jiffies; while( jiffies - start < PRN_EXIT_PRINT_MODE_TIME ) { if( PortIO[port].DataSize ) { written = 0; PortIO[port].TotalSize = PortIO[port].DataSize; //for simonsay.htm to debug Printing_StartNum[port] = (jiffies ? jiffies : 1); do { #ifndef PRNTEST // check if it is IEEE1284 or USB printer device written = usbprn_write( port, PortIO[port].DataPtr, PortIO[port].DataSize ); //written = PortIO[port].DataSize; #else written = PortIO[port].DataSize; //615wu-spooler-temp #endif PortIO[port].DataSize = PortIO[port].TotalSize - written; if( PortIO[port].DataSize ) PortIO[port].PortTimeout++; else PortIO[port].PortTimeout = 0; } while( written < PortIO[port].TotalSize ); start = jiffies; PortIO[port].DataSize = 0; //for simonsay.htm to debug Printing_StartNum[port] = 0; } // cyg_thread_yield(); if( DMAPrinting( port ) == 0 ) { // ppause( 20 ); ppause( 10 ); if( PrnGetPrinterStatus( port ) == PrnNoUsed ) ppause( 100 ); } } //ZOTIPS armond_printf("End writing\n"); PrnEndPrintNegotiate( port ); adjPortType[port] = PrnReadPortStatus( port ); #ifdef SUPPORT_PRN_COUNT //read pagecount info from printer if(PrnLangSupport(port,P1284_PJL)){ memset(respbuf,0,40); usbprn_read( port, respbuf, 30 ); PageCount[port] = atol(memchr(respbuf,0x0A,30)); } #endif PNW_Statu[port] = 0; //for dbg G_PortReady |= ( 1 << port ); } }
void Philosopher( cyg_addrword_t vid ) { cyg_uint32 id = (cyg_uint32)vid; cyg_sem_t *first_stick = &chopstick[id]; cyg_sem_t *second_stick = &chopstick[(id+1)%PHILOSOPHERS]; #ifdef CYGPKG_INFRA_DEBUG int left_philo = ((id==0)?PHILOSOPHERS:id)-1; int right_philo = (id==PHILOSOPHERS-1)?0:(id+1); #endif CYG_ASSERT( id >= 0 && id < PHILOSOPHERS, "Bad id"); // Deadlock avoidance. The easiest way to make the philosophers // behave is to make each pick up the lowest numbered stick // first. This is how it works out anyway for all the philosophers // except the last, who must have his sticks swapped. if( id == PHILOSOPHERS-1 ) { cyg_sem_t *t = first_stick; first_stick = second_stick; second_stick = t; } for(;;) { cyg_ucount32 val; // The following variable is shared by all philosophers. // It is incremented unprotected, but this does not matter // since it is only present to introduce a little variability // into the think and eat times. static volatile int cycle = 0; // Think for a bit cyg_thread_delay((id+cycle++)%12); // Cogito ergo sum... // I am now hungry, try to get the chopsticks change_state(id,'H'); // Get the first stick cyg_semaphore_wait(first_stick); // Get the second stick cyg_semaphore_wait(second_stick); // Got them, now eat change_state(id,'E'); // Check that the world is as I think it is... cyg_semaphore_peek( first_stick, &val); CYG_ASSERT( val == 0, "Not got first stick"); cyg_semaphore_peek( second_stick, &val); CYG_ASSERT( val == 0, "Not got second stick"); CYG_ASSERT( get_state(left_philo) != 'E', "Left neighbour also eating!!"); CYG_ASSERT( get_state(right_philo) != 'E', "Right neighbour also eating!!"); cyg_thread_delay((id+cycle++)%6); // munch munch // Finished eating, put down sticks. change_state(id,'T'); cyg_semaphore_post( first_stick ); cyg_semaphore_post( second_stick ); } }