Ejemplo n.º 1
0
void CPCTimerHandler::run(){
  //Calculate time handler thread period based on TICKS_PER_SECOND parameter configured in CMake
  struct timespec stPeriod;
  stPeriod.tv_sec = 0;
  stPeriod.tv_nsec = (1000000000 / getTicksPerSecond());
  if(stPeriod.tv_nsec < 1){
	  //Time base under 1 ns is not supported
	  DEVLOG_ERROR("TICKS_PER_SECOND greater than 1000000000 are not supported");
	  stPeriod.tv_nsec = 1;
  }
  //Make this thread periodic
  unsigned long nOverRuns;
  struct timespec stAuxTime;
  clock_gettime(CLOCK_REALTIME, &stAuxTime);
  stAuxTime.tv_nsec += 100000;
  pthread_t oThreadId = pthread_self();
  if(oThreadId != 0){
	  if(pthread_make_periodic_np(oThreadId,&stAuxTime,&stPeriod)!= 0){
		  DEVLOG_ERROR("Error could not set time handler thread period! %s\n", strerror(errno));
		  return;
	  }
  }

  while(isAlive()){
	//TODO: Handle overruns
    nextTick();
    pthread_wait_np(&nOverRuns);
  }
}
Ejemplo n.º 2
0
int main() {
	uint32			pkt[32];
	uint32			sz;
	
	printf("[dconsole] initialized\n");
	
	tps = getTicksPerSecond();
	
	/* initialize v-messages structure */
	vmsg_init(&vmsgs);
	
	lh_init();
	
	lh_setdbgname("dconsole");
	lh_setoptarg(0);
	lh_setpktarrived(&main_pktarrived);
	lh_setlinkreq(&main_linkreq);
	lh_setlinkdropped(&main_linkdropped);
	lh_setlinkestablished(&main_linkestablished);
	lh_setkmsg(&main_kmsg);
	
	sz = sizeof(pkt);
	pkt[0] = KMSG_ENUMSERVICE;
	pkt[1] = 0x11223344;
	pkt[2] = KSERVICE_DIRECTORY;
	
	while (1) {
		printf("[dconsole] sleeping for enum req reply\n");
		er_waworr(&__corelib_tx, &__corelib_rx, &pkt[0], 5 * 4, 1, pkt[1], tps * 30);
		printf("	looking for reply packet - pkt[0]:%x pkt[1]:%x\n", pkt[0], pkt[1]);
		if (pkt[0] == KMSG_ENUMSERVICEREPLY && pkt[3] != 0) {
			printf("	got directory service at %x:%x\n", pkt[3], pkt[4]);
			/* establish connection to directory service */
			dirproc = pkt[3];
			dirthread = pkt[4];
			break;
		}
	}
	
	/* request link to remote directory service */
	if (!lh_establishlink(dirproc, dirthread, IPC_PROTO_ER, 2048, 2048, 16 * 4, 16 * 4, 0x12345678)) {
		printf("[dconsole] establish link failed\n");
		return -1;
	}
	
	printf("[dconsole] going into main loop\n");
	
	while (1) {
		lh_tick();
		lh_sleep(0);
	}
	
	return 1;
}