コード例 #1
0
ファイル: ksem1.c プロジェクト: lijinlei/Kernel_BOOX60
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");
}
コード例 #2
0
ファイル: ksem1.c プロジェクト: lijinlei/Kernel_BOOX60
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");
}
コード例 #3
0
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);
}
コード例 #4
0
ファイル: videophone_testaudio.c プロジェクト: LucidOne/Rovio
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();
}
コード例 #5
0
ファイル: hello.c プロジェクト: Palantir555/ecos-mars-zx3
// Thread A - signals thread B via semaphore.
void thread_a(cyg_addrword_t data)
{
    // Store the data value passed in for this thread.
    int msg = (int)data;

    weak_function ();
    
    while(thread_a_count < 5)
    {
        // Increment the thread a count.
        thread_a_count++;


        // Send out a message to the diagnostic port.
        diag_printf("INFO:<Thread A, count: %d  message: %d>\n", thread_a_count, msg);

        // Delay for 1 second.
        cyg_thread_delay(100);

        // Signal thread B using the semaphore.
        cyg_semaphore_post(&sem_signal_thread);
    }
    
    CYG_TEST_CHECK(weak_fn_called == 2 , "Application week function not called");
    CYG_TEST_FINISH("Object loader test finished");
}
コード例 #6
0
// ------------------------------------------------------------------------
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 linklocal_msg_timer(cyg_handle_t handle, cyg_addrword_t ptr){
	int need_post_linklocal = ip_conflict_cnt;

	if( start_timer_flag == 0 )
	{
		linklocal_start_time = msclock(); 
		start_timer_flag = 1;
	}
	
	linklocal_stop_time = msclock();
	
	if( (linklocal_stop_time - linklocal_start_time) > 10000)
	{
		ip_conflict_cnt = 0; // reset counter anyway
		start_timer_flag = 0;
		linklocal_stop_time = 0; 
		cyg_alarm_delete(hAlarm);				//eCos
		cyg_clock_delete(hSysClk);			    //eCos
		cyg_counter_delete(hCounter);			//eCos		
	}
	

    if( (LinkLocal_get_current_state() != IDLE) )
    {
    	ip_conflict_cnt = 0; // reset counter anyway
    	start_timer_flag = 0; 
    	cyg_semaphore_post(&linklocal_conflict);
    	cyg_alarm_delete(hAlarm);				//eCos
		cyg_clock_delete(hSysClk);			    //eCos
		cyg_counter_delete(hCounter);			//eCos
    }	
	
	if ( (need_post_linklocal > 1) && (LinkLocal_get_current_state() == IDLE) ){
//		cyg_semaphore_post(&linklocal_conflict);//signal to inform ip conflict
		ip_conflict_cnt = 0; // reset counter anyway
		start_timer_flag = 0; 
		
		if( ReadPrintStatus() != 3 )
		{	
		LinkLocal_set_state(RETRY);	
		cyg_semaphore_post(&linklocal_sem); //signal to restart set link local ip
		}
		cyg_alarm_delete(hAlarm);				//eCos
		cyg_clock_delete(hSysClk);			    //eCos
		cyg_counter_delete(hCounter);			//eCos		
	}	   
}
コード例 #8
0
//
// 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);
    }
}
コード例 #9
0
ファイル: vp_jpeg.c プロジェクト: LucidOne/Rovio
UINT32 vjpegEncoderCom_Callback(void)
{
#ifndef ECOS
	tt_sem_up(&g_vpJPEG.semEncoder);
#else
	cyg_semaphore_post(&g_vpJPEG.semEncoder);
#endif
	return 0;
}
BYTE StartDMAIO(BYTE *SrcBuf, WORD DataSize, BYTE Port)
{
	PortIO[Port].DataSize = DataSize;
	PortIO[Port].DataPtr = SrcBuf;

	if( G_PortReady & ( 1 << Port ) )
		cyg_semaphore_post (&SP_SIGNAL_PORT_1);

	return 1;
}
コード例 #11
0
ファイル: vp_jpeg.c プロジェクト: LucidOne/Rovio
UINT32 vjpegDecoderErr_Callback(void)
{
#ifndef ECOS
	tt_sem_up(&g_vpJPEG.semDecoder);
#else
	g_DecodeStatus = false;
	cyg_semaphore_post(&g_vpJPEG.semDecoder);
#endif
	return 0;
}
コード例 #12
0
// Release the semaphore for a given port number.
static void sem_post(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_post(&tftpd_sems[i].sem);
      return;
    }
  }
  diag_printf("TFTPD: No semaphore for port %d\n",port);
}
コード例 #13
0
//
// 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();

}
コード例 #15
0
ファイル: sys-ecos.c プロジェクト: KublaikhanGeek/dd-wrt
void
sys_exit(void)
{
db_printf("%s called\n", __PRETTY_FUNCTION__);    
    phase = PHASE_DEAD;
    while( ppp_tty.tx_thread_running )
    {
        db_printf("kick tx thread\n");        
        cyg_semaphore_post( &ppp_tty.tx_sem );
        cyg_thread_delay(100);
    }
    ppp_tty.pppd_thread_running = false;
    cyg_thread_exit();
}
コード例 #16
0
ファイル: synch.c プロジェクト: perryhg/terkos
//
// Signal an event
void
cyg_wakeup(void *chan)
{
    int i;
    struct wakeup_event *ev;
    cyg_scheduler_lock(); // Ensure scan is safe
    // NB this is broadcast semantics because a sleeper/wakee holds the
    // slot until they exit.  This avoids a race condition whereby the
    // semaphore can get an extra post - and then the slot is freed, so the
    // sem wait returns immediately, AOK, so the slot wasn't freed.
    for (i = 0, ev = wakeup_list;  i < CYGPKG_NET_NUM_WAKEUP_EVENTS;  i++, ev++)
        if (ev->chan == chan)
            cyg_semaphore_post(&ev->sem);

    cyg_scheduler_unlock();
}
static void usblp_bulk(struct urb *urb)
{
	struct usblp *usblp = urb->context;

	if (!usblp || !usblp->dev || !usblp->used)
		return;

//{{MARK_DEBUG
//	if (urb->status)
//		warn("usblp%d: nonzero read/write bulk status received: %d",
//			usblp->minor, urb->status);
//}}MARK_DEBUG

	cyg_semaphore_post(usblp->wait);	//ZOT716u2
//	wake_up_interruptible(&usblp->wait);
}
コード例 #18
0
ファイル: CameraCtl.c プロジェクト: LucidOne/Rovio
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;			
			}
		}
	}
	
}
コード例 #19
0
//
// 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;
    }
}
void _up_sema(_sema	*sema)
{

#ifdef PLATFORM_LINUX

	//eason 20100210 up(sema);
	cyg_semaphore_post(sema);
#endif	

#ifdef PLATFORM_OS_XP

	KeReleaseSemaphore(sema, IO_NETWORK_INCREMENT, 1,  FALSE );

#endif

#ifdef PLATFORM_OS_CE
	ReleaseSemaphore(*sema,  1,  NULL );
#endif
}
コード例 #21
0
ファイル: tcp_echo.c プロジェクト: LucidOne/Rovio
//
// 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;
    }
}
コード例 #22
0
// This DSR handles the keyboard [logical] processing
static void
keyboard_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
{
    // Tell the keyboard processing thread to give it a shot
    cyg_semaphore_post(&kbd_sem);
}
コード例 #23
0
//
// 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;
}
コード例 #24
0
//
// 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 zot_network_task(cyg_addrword_t arg)
{
	sys_sem_t sem;

	sys_init();
	mem_init();
	memp_init();
	pbuf_init();
	
	sem = sys_sem_new(0);
	tcpip_init(tcpip_init_done, &sem);

#ifdef PRINT_DIAGNOSTIC
//	if( !diag_flag )
	if( 1 )
#endif
	{
		if(EEPROM_Data.PrintServerMode & PS_DHCP_ON)
		{

#ifdef LINKLOCAL_IP	
            #if defined(N716U2W) || defined(N716U2)
			if(EEPROM_Data.RENVEnable == 1)
            #endif
				Link_local_ip_init();	
#endif
			
			mib_DHCP_p->IPAddr = 0;
			mib_DHCP_p->SubnetMask = 0;
			mib_DHCP_p->GwyAddr = 0;
/*				
			memset( EEPROM_Data.BoxIPAddress, 0, 4);
			memset( EEPROM_Data.SubNetMask, 0, 4);
			memset( EEPROM_Data.GetwayAddress, 0, 4);
*/			
			//Create DHCP Thread
		    cyg_thread_create(DHCP_TASK_PRI,
		                  dhcp_init,
		                  0,
		                  "dhcp_init",
		                  (void *) (DHCP_Stack),
		                  DHCP_TASK_STACK_SIZE,
		                  &DHCP_TaskHdl,
		                  &DHCP_Task);
			
			//Start DHCP Thread
			cyg_thread_resume(DHCP_TaskHdl);

		}
#ifdef RENDEZVOUS
		else
		{
			ppause(3000);
			cyg_semaphore_post( &rendezvous_sem);
		}
#endif		
		
		
	}
	
	sys_sem_wait(sem);
	sys_sem_free(sem);
}
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.
				
	}
	
}
コード例 #27
0
ファイル: kphilo.c プロジェクト: EPiCS/reconos_v2
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 );

    }
}
コード例 #28
0
ファイル: tcp_echo.c プロジェクト: LucidOne/Rovio
static void
echo_test(cyg_addrword_t p)
{
    int s_source, s_sink, e_source, e_sink;
    struct sockaddr_in e_source_addr, e_sink_addr, local;
    int one = 1;
    fd_set in_fds;
    int i, num, len;
    struct test_params params,nparams;
    struct test_status status,nstatus;

    cyg_tick_count_t starttime, stoptime;

    s_source = socket(AF_INET, SOCK_STREAM, 0);
    if (s_source < 0) {
        pexit("stream socket");
    }
    if (setsockopt(s_source, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
        pexit("setsockopt /source/ SO_REUSEADDR");
    }
    if (setsockopt(s_source, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) {
        pexit("setsockopt /source/ SO_REUSEPORT");
    }
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_len = sizeof(local);
    local.sin_port = ntohs(SOURCE_PORT);
    local.sin_addr.s_addr = INADDR_ANY;
    if(bind(s_source, (struct sockaddr *) &local, sizeof(local)) < 0) {
        pexit("bind /source/ error");
    }
    listen(s_source, SOMAXCONN);

    s_sink = socket(AF_INET, SOCK_STREAM, 0);
    if (s_sink < 0) {
        pexit("stream socket");
    }
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_len = sizeof(local);
    local.sin_port = ntohs(SINK_PORT);
    local.sin_addr.s_addr = INADDR_ANY;
    if(bind(s_sink, (struct sockaddr *) &local, sizeof(local)) < 0) {
        pexit("bind /sink/ error");
    }
    if (setsockopt(s_sink, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
        pexit("setsockopt /sink/ SO_REUSEADDR");
    }
    if (setsockopt(s_sink, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) {
        pexit("setsockopt /sink/ SO_REUSEPORT");
    }
    listen(s_sink, SOMAXCONN);

    e_source = 0;  e_sink = 0;
    while (true) {
        // Wait for a connection on either of the ports
        FD_ZERO(&in_fds);
        FD_SET(s_source, &in_fds);
        FD_SET(s_sink, &in_fds);
        num = select(max(s_sink,s_source)+1, &in_fds, 0, 0, 0);
        if (FD_ISSET(s_source, &in_fds)) {
            len = sizeof(e_source_addr);
            if ((e_source = accept(s_source, (struct sockaddr *)&e_source_addr, &len)) < 0) {
                pexit("accept /source/");
            }
            diag_printf("SOURCE connection from %s:%d\n", 
                        inet_ntoa(e_source_addr.sin_addr), ntohs(e_source_addr.sin_port));
        }
        if (FD_ISSET(s_sink, &in_fds)) {
            len = sizeof(e_sink_addr);
            if ((e_sink = accept(s_sink, (struct sockaddr *)&e_sink_addr, &len)) < 0) {
                pexit("accept /sink/");
            }
            diag_printf("SINK connection from %s:%d\n", 
                        inet_ntoa(e_sink_addr.sin_addr), ntohs(e_sink_addr.sin_port));
        }
        // Continue with test once a connection is established in both directions
        if ((e_source != 0) && (e_sink != 0)) {
            break;
        }
    }

    // Wait for "source" to tell us the testing paramters
    if (do_read(e_source, &nparams, sizeof(nparams)) != sizeof(nparams)) {
        pexit("Can't read initialization parameters");
    }
  
    params.nbufs = ntohl(nparams.nbufs);
    params.bufsize = ntohl(nparams.bufsize);
    params.load = ntohl(nparams.load);
  
    diag_printf("Using %d buffers of %d bytes each, %d%% background load\n", 
                params.nbufs, params.bufsize, params.load);

    // Tell the sink what the parameters are
    if (do_write(e_sink, &nparams, sizeof(nparams)) != sizeof(nparams)) {
        pexit("Can't write initialization parameters");
    }

    status.ok = 1;
    nstatus.ok = htonl(status.ok);
  
    // Tell the "source" to start - we're all connected and ready to go!
    if (do_write(e_source, &nstatus, sizeof(nstatus)) != sizeof(nstatus)) {
        pexit("Can't send ACK to 'source' host");
    }

    idle_thread_count = 0;
    cyg_semaphore_post(&idle_thread_sem);  // Start idle thread
    starttime = cyg_current_time();
    start_load(params.load);

    // Echo the data from the source to the sink hosts
    for (i = 0;  i < params.nbufs;  i++) {
        if ((len = do_read(e_source, data_buf, params.bufsize)) != params.bufsize) {
            diag_printf("Can't read buf #%d: ", i+1);
            if (len < 0) {
                perror("I/O error");
            } else {
                diag_printf("short read - only %d bytes\n", len);
            }
        }
//        else diag_printf("Got %d bytes\n",len);        
        if ((len = do_write(e_sink, data_buf, params.bufsize)) != params.bufsize) {
            diag_printf("Can't write buf #%d: ", i+1);
            if (len < 0) {
                perror("I/O error");
            } else {
                diag_printf("short write - only %d bytes\n", len);
            }
        }
//        else diag_printf("Sent %d bytes\n",len);        
    }

    // Wait for the data to drain and the "sink" to tell us all is OK.
    if (do_read(e_sink, &status, sizeof(status)) != sizeof(status)) {
        pexit("Can't receive ACK from 'sink' host");
    }

    start_load(0);
    cyg_semaphore_wait(&idle_thread_sem);  // Stop idle thread
    stoptime = cyg_current_time();
    stoptime -= starttime; // time taken in cS
    // expected idle loops in that time period for an idle system:
    starttime = no_load_idle_count_1_second * stoptime / 100;
    diag_printf( "%d ticks elapsed, %d kloops predicted for an idle system\n",
                 (int)stoptime, (int)(starttime/1000) );
    diag_printf( "actual kloops %d, CPU was %d%% idle during transfer\n",
                 (int)(idle_thread_count/1000),
                 (int)(idle_thread_count * 100 / starttime) );

    // Now examine how close that loading actually was:
    start_load(params.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
    start_load(0);                         // Shut down background load
    i = 100 - ((idle_thread_count * 100) / no_load_idle_count_1_second );
    diag_printf("Final load[%d] = %d => %d%%\n", load_thread_level, 
                (int)idle_thread_count, i);

//#ifdef CYGDBG_USE_ASSERTS
#ifdef CYGDBG_NET_TIMING_STATS 
    {
        extern void show_net_times(void);
        show_net_times();
    }
#endif
//#endif
}
コード例 #29
0
ファイル: lcd_panel_support.c プロジェクト: 0xCA5A/dd-wrt
// This DSR starts up the touch panel [logical] processing
static void
lcd_panel_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
{
    // Tell the panel processing thread to give it a shot
    cyg_semaphore_post(&lcd_panel_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);
		
	}	
}