Exemple #1
0
/*------------------------------------------------------------------------
 * sleep  --  delay the calling process n seconds
 *------------------------------------------------------------------------
 */
SYSCALL	sleep(int n)
{
	STATWORD ps;    
	if (n<0 || clkruns==0)
		return(SYSERR);
	if (n == 0) {
	        disable(ps);
		resched();
		restore(ps);
		return(OK);
	}
	while (n >= 1000) {
		sleep10(10000);
		n -= 1000;
	}
	if (n > 0)
		sleep10(10*n);

	if( syscalls_trace ) 
	{
		sleep_freq[currpid]++;
	}

	return(OK);
}
Exemple #2
0
/*------------------------------------------------------------------------
 *  hgjoin  -  handle application request to join a host group
 *------------------------------------------------------------------------
 */
int
hgjoin(unsigned ifnum, IPaddr ipa, Bool islocal)
{
	struct	hg	*phg;
	int		i;

	if (!IP_CLASSD(ipa))
		return SYSERR;
	/* restrict multicast in multi-homed host to primary interface */
	if (ifnum != NI_PRIMARY)
		return SYSERR;
	wait(HostGroup.hi_mutex);
	if (phg = hglookup(ifnum, ipa)) {
		phg->hg_refs++;
		signal(HostGroup.hi_mutex);
		return OK;	/* already in it */
	}
	signal(HostGroup.hi_mutex);
	/* add to host group and routing tables */
	if (hgadd(ifnum, ipa, islocal) == SYSERR)
		return SYSERR;
	rtadd(ipa, ip_maskall, ipa, 0, NI_LOCAL, RT_INF);
	/*
	 * advertise membership to multicast router(s); don't advertise
	 * 224.0.0.1 (all multicast hosts) membership.
	 */
	if (ipa != ig_allhosts)
		for (i=0; i < IG_NSEND; ++i) {
			igmp(IGT_HREPORT, ifnum, ipa);
			sleep10(IG_DELAY);
		}
	return OK;
}
Exemple #3
0
/*------------------------------------------------------------------------
 *  main  --  fiddle around while Ethernet runs...
 *------------------------------------------------------------------------
 */
main()
{
	int	snd();

	resume(create(snd, 200, 20, "sender", 0));

	while(TRUE) {
		printf("\nAlive\n");
		sleep10(200);
	}
}
Exemple #4
0
SYSCALL	sleep(int n)
{	
	if(trace) sleep_count[currpid]++;
	STATWORD ps;    
	if (n<0 || clkruns==0)
		return(SYSERR);
	if (n == 0) {
	        disable(ps);
		resched();
		restore(ps);
		return(OK);
	}
	while (n >= 1000) {
		sleep10(10000);
		n -= 1000;
	}
	if (n > 0)
		sleep10(10*n);
	
	return(OK);
}
void test6 ()
{
    int     lck;
    int     rd1, rd2, rd3, rd4;
    int     wr1;

    count7 = 0;
    kprintf("\nTest 6: wait on locks with priority. Expected order of "
    "lock acquisition is: reader A, reader B, reader C, writer E, reader D\n");
    lck  = lcreate ();
    assert (lck != SYSERR,"Test 6 FAILED\n");

    rd1 = create(reader6, 2000, 20, "reader6", 3, 'A', lck, 20);
    rd2 = create(reader6, 2000, 20, "reader6", 3, 'B', lck, 30);
    rd3 = create(reader6, 2000, 20, "reader6", 3, 'C', lck, 40);
    rd4 = create(reader6, 2000, 20, "reader6", 3, 'D', lck, 20);
    wr1 = create(writer6, 2000, 20, "writer6", 3, 'E', lck, 25);
    
    //kprintf("-start reader A, then sleep 1s. lock granted to reader A\n");
    resume(rd1);
    sleep (1);

    //kprintf("-start writer C, then sleep 1s. writer waits for the lock\n");
    resume(wr1);
    sleep (1);

    //kprintf("-start reader B, D, E. reader B is granted lock.\n");
    resume (rd2);
    sleep10(1);
    resume (rd3);
    sleep10(1);
    resume (rd4);


    sleep (10);
    ldelete (lck);
    kill(rd1);kill(rd2);kill(rd3);kill(rd4);kill(wr1);
    kprintf("Output is %s\n",output7);

}
Exemple #6
0
/*------------------------------------------------------------------------
 * sleep  --  delay the calling process n seconds
 *------------------------------------------------------------------------
 */
SYSCALL	sleep(int n)
{
        int start;
	int i,j;
	if(activated == 1)
		start = ctr1000;
	STATWORD ps;    
	if (n<0 || clkruns==0)
	{
		if(activated == 1)
		{
		        Info[currpid][SLEEP].freq++;
		        Info[currpid][SLEEP].time += (ctr1000 - start);
		}
		return(SYSERR);
	}
	if (n == 0) {
	        disable(ps);
		resched();
		restore(ps);
		if(activated == 1)
		{
	        	Info[currpid][SLEEP].freq++;
		        Info[currpid][SLEEP].time += (ctr1000 - start);
		}
		return(OK);
	}
	while (n >= 1000) {
		sleep10(10000);
		n -= 1000;
	}
	if (n > 0)
		sleep10(10*n);
	if(activated == 1)
	{
	        Info[currpid][SLEEP].freq++;
	        Info[currpid][SLEEP].time += (ctr1000 - start);
	}
	return(OK);
}
procsleepmore(char c) {
    int i;
    int count = 0;
    while (count++ < LOOP*2/6) {
        kprintf("%c", c);
        for (i = 0; i < 10000000; i++);
    }
    kprintf("X");
    sleep10(2);
    kprintf("X");
    while (count++ < LOOP*2) {
        kprintf("%c", c);
        for (i = 0; i < 10000000; i++);
    }
}
procsleep(char c) {
    int i;
    int count = 0;
    while (count++ < LOOP/3) {
        kprintf("%c", c);
        for (i = 0; i < 10000000; i++);
    }
    kprintf("X");
    sleep10(1);
    kprintf("X");
    while (count++ < LOOP) {
        kprintf("%c", c);
        for (i = 0; i < 10000000; i++);
    }
}
Exemple #9
0
/*------------------------------------------------------------------------
 *  snd  -  send datagram just for kicks
 *------------------------------------------------------------------------
 */
snd()
{
	char	*ch;
	int	i, r;
	struct	epacket	*packet;

	sleep10(50);
	kprintf("Sending a datagram\n");
	packet = (struct epacket *) getbuf(netpool);
	ch = (char *) ( (struct udpip *)packet->ep_data)->u_data;
	for (i=0 ; i<10; i++)
		*ch++ = 'D';
	r = udpsend(netgate, 7/*ECHO*/, 50, packet, 10);
	kprintf("udpsend returns %d\n",r);
}
Exemple #10
0
/*------------------------------------------------------------------------
 * ospfhello - send OSPF hello packets
 *------------------------------------------------------------------------
 */
PROCESS
ospfhello(void)
{
	struct ospf_if	*pif;
	int		ifn, rnd;

	/* select initial "random" offset to stagger hello's */
	rnd = nif[NI_PRIMARY].ni_ip % OSPFDELTA;

	/* do state changes first so we can receive while waiting */
	for (ifn=0; ifn<Net.nif; ++ifn) {
		if (ifn == NI_LOCAL)
			continue;
		if (nif[ifn].ni_state != NIS_UP)
			continue;
		pif = &ospf_if[ifn];
		switch (pif->if_type) {
		case IFT_MULTI:
		case IFT_BROADCAST:
			if (pif->if_prio > 0) {
				pif->if_twait = pif->if_rdintv;
				pif->if_state = IFS_WAITING;
			} else
				pif->if_state = IFS_DROTHER;
			break;
		case IFT_PT2PT:
		case IFT_VIRTUAL:
			pif->if_state = IFS_PT2PT;
			break;
		default:
			break;
		}
	}

	while (1) {
		sleep10(HELLOINTV*10 + rnd);
		if (++rnd == OSPFDELTA)
			rnd = -OSPFDELTA;

		for (ifn=0; ifn<Net.nif; ++ifn) {
			if (ifn == NI_LOCAL)
				continue;
			if (nif[ifn].ni_state != NIS_UP)
				continue;
			ospf_hsend(ifn);
		}
	}
}
/*------------------------------------------------------------------------
 *  tcptimer -  TCP timer process
 *------------------------------------------------------------------------
 */
PROCESS
tcptimer(void)
{
	long	now, lastrun;		/* times from system clock	*/
	int	delta;			/* time since last iteration	*/
	struct	tqent	*tq;		/* temporary delta list ptr	*/

	lastrun = ctr100;		/* initialize to "now"		*/
	tqmutex = screate(1);		/* mutual exclusion semaphore	*/
	tqpid = getpid();		/* record timer process id	*/
	signal(Net.sema);		/* start other network processes*/

	while (TRUE) {
		sleep10(TIMERGRAN);	/* real-time delay		*/
		if (tqhead == 0)	/* block timer process if delta	*/
			suspend(tqpid);	/*   list is empty		*/

		wait(tqmutex);
		now = ctr100;
		delta = now - lastrun;	/* compute elapsed time		*/

		/* Note: check for possible clock reset (time moved	*/
		/* backward or delay was over an order of magnitude too	*/
		/* long)						*/

		if (delta < 0 || delta > TIMERGRAN*100)
			delta = TIMERGRAN*10;	/* estimate the delay	*/
		lastrun = now;
		while (tqhead != 0  &&  tqhead->tq_timeleft <= delta) {
			delta -= tqhead->tq_timeleft;
			if (pcount(tqhead->tq_port) <= tqhead->tq_portlen)
				psend(tqhead->tq_port,
					(int)tqhead->tq_msg);
			tq = tqhead;
			tqhead = tqhead->tq_next;
			freemem(tq, sizeof(struct tqent));
		}
		if (tqhead)
			tqhead->tq_timeleft -=delta;
		signal(tqmutex);
	}
}
Exemple #12
0
/*------------------------------------------------------------------------
 *  ripout  -  do the RIP route exchange protocol, output side
 *------------------------------------------------------------------------
 */
PROCESS
ripout(void)
{
	int	rnd;

	rippid = getpid();
	dorip = TRUE;
	/* advertise our routes */

	rnd = 0;	/* "randomizer" */
	while (TRUE) {
		sleep10(RIPOUTMIN);	/* minimum time between each	*/
		if (++rnd > RIPDELTA)
			rnd = -RIPDELTA;
		recvtim(RIPINT-RIPOUTMIN+rnd);
		wait(riplock);
		ripsend(ip_maskall, UP_RIP);
		signal(riplock);
	}
}
Exemple #13
0
	//--------------------------------------------------------------------------
	// TEST BUILD MAIN
	//
	int main(void)
	{
		int rslt,i,cnt;
		double temp;
		char buf[12];
		
		
		// find ALL devices
		printf("\nFIND ALL\n");
		cnt = 0;
		rslt = OWFirst();
		while (rslt)	{
			// print device found
			for (i = 7; i >= 0; i--)
				printf("%02X", ROM_NO[i]);
			printf("  %d\n",++cnt);
			
			rslt = OWNext();
		}
		
		// find only 0x10
		printf("\nFIND ONLY 0x10\n");
		cnt = 0;
		OWTargetSetup(0x10);
		while (OWNext())	{
			// check for incorrect type
			if (ROM_NO[0] != 0x10)
				break;
			
			// print device found
			for (i = 7; i >= 0; i--)
				printf("%02X", ROM_NO[i]);
			printf("  %d\n",++cnt);
		}
		if (cnt == 1)	{
			DS1820_startConversion();
			uint8_t spdata[10];
			sleep10(7);
			DS1820_readScratchPad(spdata);
			temp = DS1820_getTemperature(spdata);
			temp = temp*9.0/5.0 +32.0;
			printf("TEMP(F) = %s\n\n",dtostrf(temp,7,2,(char *)buf));
		}
		
		// find all but 0x04, 0x1A, 0x23, and 0x01
		printf("\nFIND ALL EXCEPT 0x10, 0x04, 0x0A, 0x1A, 0x23, 0x01\n");
		cnt = 0;
		rslt = OWFirst();
		while (rslt)	{
			// check for incorrect type
			if ((ROM_NO[0] == 0x04) || (ROM_NO[0] == 0x1A) ||
				(ROM_NO[0] == 0x01) || (ROM_NO[0] == 0x23) ||
				(ROM_NO[0] == 0x0A) || (ROM_NO[0] == 0x10))
				OWFamilySkipSetup();
			else	{
				// print device found
				for (i = 7; i >= 0; i--)
					printf("%02X", ROM_NO[i]);
				printf("  %d\n",++cnt);
			}
			
			rslt = OWNext();
		}
		////////////////////////////////////////////////////////////////////////////////////////////////
		// find ALL DS2438
		double voltage = 0.0;
		int myDS2438 = 0;
		uint8_t DS2438deviceNumber[8];
		double bigT = -1.;
		int micro10voltage = 0;
		
		printf("\nFind all DS2438; Read Temperature and Voltage\n");
		for (rslt=OWFirstType(0x26); rslt; rslt=OWNextType(0x26))	{
			// print device found
			for (i = 7; i >= 0; i--)
				printf("%02X", ROM_NO[i]);
			printf("\n");
			
			// Save the first ROM
			if (myDS2438 == 0)	{
				myDS2438++;
				for (i = 0; i < 8; i++)	{
					DS2438deviceNumber[i] = ROM_NO[i];
				}
			}
			
			if (myDS2438 > 0)	{
				// (default) Read Vdd
				SetupAtoD(0x0F, DS2438deviceNumber);
				
				bigT = Get_Temperature(DS2438deviceNumber);
				printf("TEMP = %s\n\n",dtostrf(bigT,7,3,(char *)buf));
				
				voltage = ReadAtoD(DS2438deviceNumber);
				printf("VDD = %s\n",dtostrf(voltage,6,2,(char *)buf));
			}
			if (myDS2438 > 0)	{
				// (default) Read Vad
				SetupAtoD(0x07, DS2438deviceNumber);
				voltage = ReadAtoD(DS2438deviceNumber);
				micro10voltage = getDS2438Voltage(DS2438deviceNumber);
				printf("VAD = %s\n",dtostrf(voltage,6,2,(char *)buf));
				printf("Micro V = %d\n", micro10voltage);
			}
		}
		
		sleep(1);
	return 0 ;
	}
Exemple #14
0
robot()
{
    int oldx, oldy;
    int direc;
    int diffx;
    int diffy;
    
    robotx = rand()%(XMAXFIELD-3)+2;
    roboty = rand()%(YMAXFIELD-3)+2;
    
    direc = EAST;

    oldx=robotx;
    oldy=roboty;

    while (TRUE) {
	sleep10(1);
	diffx = targetx-robotx;
	diffy = targety-roboty;
	if (diffy<0) {			/* NORTH */
	    if (diffx>0)
		direc = NE;
	    else if (diffx<0)
		direc = NW;
	    else
		direc = NORTH;
	}
	
	else if (diffy>0) {		/* SOUTH */
	    if (diffx>0)
		direc = SE;
	    else if (diffx<0)
		direc = SW;
	    else
		direc = SOUTH;
	}
	else {				/* HORIZONTAL */
	    if (diffx>0)
		direc = EAST;
	    else if (diffx<0)
		direc = WEST;
	    else
		direc = SIT;
	}

	switch (direc) {
	  case SIT:	continue;
	  case NORTH:	if (roboty > 1)     --roboty; break;
	  case SOUTH:	if (roboty < YMAXFIELD)  ++roboty; break;
	  case WEST:	if (robotx > 1)     --robotx; break;
	  case EAST:	if (robotx < XMAXFIELD)  ++robotx; break;
	  case NE:	if (roboty>1 && robotx<XMAXFIELD) {
	                    --roboty; ++robotx;  }    break;
	  case NW:	if (roboty>1 && robotx>1) {
	                    --roboty; --robotx;  }    break;
	  case SE:	if (roboty<YMAXFIELD && robotx<XMAXFIELD) {
	                    ++roboty; ++robotx;  }    break;
	  case SW:	if (roboty<YMAXFIELD && robotx>1) {
	                    ++roboty; --robotx;  }    break;
	}
	newsend(pidplotter,3,oldx,oldy,' ');
	newsend(pidplotter,3,robotx,roboty,'R');
	oldx=robotx;
	oldy=roboty;
    }
}