www.pudn.com > pebble.zip > hello.c


/*  
 * Copyright 1999, 2000, 2001, 2002 Lucent Technologies Inc. 
 * All Rights Reserved. 
 * Information Sciences Research Center, Bell Labs. 
 * 
 * LUCENT TECHNOLOGIES DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE  
 * OR THE SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The 
 * software is provided "as is" without expressed or implied warranty  
 * of any kind. 
 * 
 * These notices must be retained in any copies of any part of this 
 * software. 
 * 
 */ 
 
#include "unistd.h" 
#include "types.h" 
#include "pebble.h" 
#include "diag.h" 
#include "time.h" 
#include "nucleus.h" 
 
Time now; 
 
/* every one second */ 
static void 
watchdog_handler(void *val) 
{ 
	now = hrtime(); 
 
	if (0) 
	   printf("thread %p hello, world, time = %u %u!\n", 
		       get_thread(), (uint)(now>>32), (uint)now); 
	if (0) 
	   printf("psw = %08x\n", (int)get_psw()); 
 
	timeout(watchdog_handler, 0, hrtime() + 500000000); 
	return; 
} 
 
#define SPAWN		0	/* test semaphore */ 
#define TIMEOUT		1	/* test timeout */ 
 
int s; 
 
void 
thread_handler(int foo) 
{ 
	printf("will block\n"); 
	sem_wait(s); 
	printf("woke up!\n"); 
} 
 
Time start; 
uint startcount; 
 
int 
main(int arg, char *argv[]) 
{ 
	int c, asid; 
	volatile int *cp, v; 
 
	asid = get_asid(); 
 
	now = hrtime(); 
 
	printf("main %p hello, world, time = %u %u, count = %u," 
		"compare = %u!\n", get_thread(), 
		(uint)(now>>32), (uint)now, (uint)get_count, 
		(uint)get_compare()); 
 
	if (TIMEOUT) 
	if (timeout(watchdog_handler, 0, 500000000) < 0) 
		panic("timeout() for watchdog handler failed"); 
 
	s = sem_create(0); 
 
	if (SPAWN) if (0 > thr_spawn(thread_handler, 0)) 
		panic("spawn failed"); 
 
	yield(); 
 
	if (SPAWN) sem_post(s); 
 
	yield(); 
 
	while(0) { 
		 c++; 
		 if ((c % 4000000) == 0) { 
			now = hrtime(); 
			printf("now = %u %u, count = %u, compare = " 
				    "%u\n",  
				    (uint)(now>>32), (uint)now, 
				    (uint)get_count(), (uint)get_compare()); 
			yield(); 
		 } 
	} 
 
	cp = (int *) call_portal(SYS_TRANSMEM, 8192); 
 
	/* we should now be ready to take page faults */ 
 
	printf("about to touch %p\n", cp); 
 
	v = *cp;	/* will cause a page fault but no protection fault */ 
 
	start = hrtime(); 
	startcount = get_count(); 
	*cp = 44; 
 
	printf("*cp = %d, start = %u %u, startcount = %d\n", *cp, (uint)(start>>32), (uint)start, startcount); 
 
	printf ("TEST ENDING HERE\n"); 
 
	task_exit(0); 
 
	return(0);	/* to make GCC happy */ 
}