Beispiel #1
0
static void kernel_evt_hdr(const T_EVTINF *evtinf) {
	static SYSTIM back_press_time;

    switch(evtinf->evtcd) {

    case EVTCD_BUTTON_CLICKED:
    	break;

    case EVTCD_BUTTON_PRESSED:
    	assert(evtinf->arg[0] >= 0 || evtinf->arg[0] < TNUM_BUTTON);
    	if(evtinf->arg[0] == BACK_BUTTON && status == STATUS_RUNNING)
    		get_tim(&back_press_time);
    	syslog(LOG_NOTICE, "HERE EVTCD_BUTTON_PRESSED");
    	break;

    case EVTCD_BUTTON_RELEASED:
    	assert(evtinf->arg[0] >= 0 || evtinf->arg[0] < TNUM_BUTTON);
    	if(evtinf->arg[0] == BACK_BUTTON && status == STATUS_RUNNING) {
    		SYSTIM now;
    		get_tim(&now);

    		if(now - back_press_time >= 500) {
    			syslog(LOG_NOTICE, "HERE sig_sem(APP_TER_SEM)");
    			sig_sem(APP_TER_SEM);
    		}
    	}
    	break;

    default:
    	syslog(LOG_NOTICE, "Unhandled evtinf->evtcd %d", evtinf->evtcd);
    }
}
Beispiel #2
0
void
tcp_init_iss (void)
{
	SYSTIM now;

#ifdef SUPPORT_ETHER

	T_IF_SOFTC	*ic;

	ic = IF_ETHER_NIC_GET_SOFTC();
	syscall(get_tim(&now));
	net_srand(now + (ic->ifaddr.lladdr[2] << 24)
	              + (ic->ifaddr.lladdr[3] << 16)
	              + (ic->ifaddr.lladdr[4] <<  8)
	              + (ic->ifaddr.lladdr[5]      ));

#else	/* of #ifdef SUPPORT_ETHER */

	syscall(get_tim(&now));
	net_srand(now);

#endif	/* of #ifdef SUPPORT_ETHER */

	tcp_iss = net_rand();
	}
Beispiel #3
0
static ER
tcp_discard_srv (ID cepid, ID repid)
{
	static char buffer[BUF_SIZE];

	T_IPEP		dst;
	ER_UINT		rlen;
	ER		error;
	SYSTIM		time;
	uint32_t	total;
	uint16_t	count;
	uint8_t		*buf = buffer;

	if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) {
		syslog(LOG_NOTICE, "[TDS:%02d RCV] accept error: %s", cepid, itron_strerror(error));
		return error;
		}

#ifdef USE_TCP_EXTENTIONS
	if ((error = free_tcp_rep(repid, true)) != E_OK) {
		syslog(LOG_NOTICE, "[TDS:%02d DEL] REP delete error: %s", cepid, itron_strerror(error));
		return error;
		}
#endif	/* of #ifdef USE_TCP_EXTENTIONS */

	count = total = 0;
	get_tim(&time);
	syslog(LOG_NOTICE, "[TDS:%02d RCV] connected:  %6ld, from: %s.%d",
	                   cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
	while ((rlen = tcp_rcv_dat(cepid, buf, BUF_SIZE - 1, TMO_FEVR)) > 0) {
		count ++;

#ifdef SHOW_RCV_RANGE
		syslog(LOG_NOTICE, "[TDS:%02d RCV] count: %4d, len: %4d, data: %02x -> %02x",
		       cepid, count, (uint16_t)rlen, *buf, *(buf + rlen - 1));
#endif	/* of #ifdef SHOW_RCV_RANGE */

		total += rlen;
		}
	if (rlen != 0)
		syslog(LOG_NOTICE, "[TDS:%02d RCV] recv error: %s", cepid, itron_strerror(rlen));

	if ((error = tcp_sht_cep(cepid)) != E_OK)
		syslog(LOG_NOTICE, "[TDS:%02d RCV] shutdown error: %s", cepid, itron_strerror(error));

	if ((error = tcp_cls_cep(cepid, TMO_FEVR)) != E_OK)
		syslog(LOG_NOTICE, "[TDS:%02d RCV] close error: %s", cepid, itron_strerror(error));

	get_tim(&time);
	syslog(LOG_NOTICE, "[TDS:%02d RCV] finished:   %6ld,            rcv: %4d, len: %ld",
	                   cepid, time / SYSTIM_HZ, count, total);

	return error;
	}
Beispiel #4
0
ER load_application(const void *mod_data, SIZE mod_data_sz) {
	ER ercd;

//	ev3_led_set_color(LED_GREEN);
//	chg_status(STATUS_RUNNING);

#if 0
	// Wait for pressing center button
    SYSTIM time = 0;
    uint32_t ledcolor = 0;
	syslog(LOG_NOTICE, "Press center button to run the application.");
	while(!global_brick_info.button_pressed[BRICK_BUTTON_ENTER]) {
		SYSTIM newtime;
		get_tim(&newtime);
		if (newtime - time > 500) { // Blink LED
			brick_misc_command(MISCCMD_SET_LED, ledcolor);
			ledcolor ^= TA_LED_RED | TA_LED_GREEN;
			time = newtime;
		}
	}
	while(global_brick_info.button_pressed[BRICK_BUTTON_ENTER]) {
		SYSTIM newtime;
		get_tim(&newtime);
		if (newtime - time > 500) { // Blink LED
			brick_misc_command(MISCCMD_SET_LED, ledcolor);
			ledcolor ^= TA_LED_RED | TA_LED_GREEN;
			time = newtime;
		}
	}
#endif

	brick_misc_command(MISCCMD_SET_LED, TA_LED_GREEN);
	platform_soft_reset();
	ercd = dmloader_ins_ldm(mod_data, mod_data_sz, 1);
	if (ercd != E_OK) {
		syslog(LOG_ERROR, "Failed to load application, ercd: %d", ercd);
	} else {
		app_loaded = true;
		SVC_PERROR(sta_alm(APP_TER_BTN_ALM, 0));
		SVC_PERROR(wai_sem(APP_TER_SEM));
		syslog(LOG_NOTICE, "Terminate application.");
		SVC_PERROR(dmloader_rmv_ldm(1));
		brick_misc_command(MISCCMD_SET_LED, TA_LED_GREEN);
	}
//	chg_status(STATUS_IDLE);
	platform_soft_reset();
	tslp_tsk(500);

	return ercd;
}
Beispiel #5
0
static void
test_empty(void)
{
	SYSTIM	stime, etime;
	volatile ulong_t	i;

	get_tim(&stime);
	for (i = 0; i < NO_LOOP; i++) {
	}
	get_tim(&etime);
	empty_time = etime - stime;
	syslog(LOG_NOTICE, "empty loop: %u", empty_time);
	syslog_flush();
}
Beispiel #6
0
ER
nd6_output_hold (T_IFNET *ifp, T_LLINFO_ND6 *ln)
{
	SYSTIM now;

	/* アドレス解決待ちのデータグラムがあれば送信する。*/
	if (ln->hold) {

		/* タイムアウトの処理 */
		if (ln->tmout != TMO_FEVR) {

			/*
			 *  タイムアウトの指定が永久でなく、時間を過ぎていれば、
			 *  出力しないで終了する。
			 */
			syscall(get_tim(&now));
			if ((int32_t)(ln->tmout - now) < 0) {
			           /* ln->tmout < now */
				syscall(rel_net_buf(ln->hold));
				ln->hold = NULL;
				return E_TMOUT;
				}
			}
				
		nd6_output(ifp, ln->hold, &ln->addr, ln, TMO_FEVR);
		ln->hold = NULL;
		}
	return E_OK;
	}
Beispiel #7
0
static mrb_int
getTim()
{
	SYSTIM time;
	get_tim(&time);
	return time;
}
/**
 * Execute run_loop once
 */
void embedded_execute_once(void) {
    // refresh system_ticks
    get_tim(&system_ticks);

    data_source_t *ds;

    // process data sources
    data_source_t *next;
    for (ds = (data_source_t *) data_sources; ds != NULL ; ds = next){
        next = (data_source_t *) ds->item.next; // cache pointer to next data_source to allow data source to remove itself
        ds->process(ds);
    }
    
#ifdef HAVE_TICK
    // process timers
    while (timers) {
        timer_source_t *ts = (timer_source_t *) timers;
        if (ts->timeout > system_ticks) break;
        run_loop_remove_timer(ts);
        ts->process(ts);
    }
#endif
    
    // disable IRQs and check if run loop iteration has been requested. if not, go to sleep
//    hal_cpu_disable_irqs();
//    if (trigger_event_received){
//        trigger_event_received = 0;
//        hal_cpu_enable_irqs();
//    } else {
//        hal_cpu_enable_irqs_and_sleep();
//    }
}
Beispiel #9
0
static void
test_dly_nse(ulong_t dlytim)
{
	SYSTIM	stime, etime, delay_time;
	volatile ulong_t	i;

	get_tim(&stime);
	for (i = 0; i < NO_LOOP; i++) {
		sil_dly_nse(dlytim);
	}
	get_tim(&etime);
	delay_time = (etime - stime) - empty_time;
	syslog(LOG_NOTICE, "sil_dly_nse(%u): %u %s", (uint_t)(dlytim),
				(uint_t)(delay_time), delay_time > dlytim ? "OK" : "NG");
	syslog_flush();
}
Beispiel #10
0
void embedded_init(void){

    data_sources = NULL;

#ifdef HAVE_TICK
    timers = NULL;
    get_tim(&system_ticks);
    //system_ticks = 0;
    //hal_tick_init();
    //hal_tick_set_handler(&embedded_tick_handler);
#endif
}
Beispiel #11
0
void init_task(intptr_t exinf)
{
#ifndef TASK_LOOP
    volatile ulong_t	i;
    SYSTIM	stime1, stime2;
#endif /* TASK_LOOP */

    /* シリアルポートのオープン */
    SVC(serial_opn_por(SIO_PORTID));
    SVC(serial_ctl_por(SIO_PORTID , IOCTL_CRLF));

    /* 起動メッセージの出力 */
    syslog(LOG_INFO , "Sample program starts.");

    /* 周期ハンドラの起動 */
    SVC(sta_cyc(MAIN_CYC));


    /*
     *  ループ回数の設定
     *
     *  TASK_LOOPがマクロ定義されている場合,測定せずに,TASK_LOOPに定
     *  義された値を,タスク内でのループ回数とする.
     *
     *  MEASURE_TWICEがマクロ定義されている場合,1回目の測定結果を捨て
     *  て,2回目の測定結果を使う.1回目の測定は長めの時間が出るため.
     */
#ifdef TASK_LOOP
    task_loop = TASK_LOOP;
#else /* TASK_LOOP */

    task_loop = LOOP_REF;
    SVC(get_tim(&stime1));
    for (i = 0; i < task_loop; i++);
    SVC(get_tim(&stime2));
    task_loop = LOOP_REF * 400UL / (stime2 - stime1);

#endif /* TASK_LOOP */

}
Beispiel #12
0
static void
in6_hostcache_timer (void)
{
	static int_t interval = IN6_HOSTCACHE_PRUNE / SYSTIM_HZ;

	SYSTIM	now;

	interval --;
	if (interval <= 0) {
		syscall(get_tim(&now));
		interval = IN6_HOSTCACHE_PRUNE / SYSTIM_HZ;
		}
	}
Beispiel #13
0
knh_uint_t knh_initseed(void)
{
#if defined(KNH_USING_WINDOWS)
  return (knh_uint_t)time(NULL) + GetCurrentProcessId();
#elif defined(KNH_USING_POSIX)
	return (knh_uint_t)time(NULL) + getpid();
#elif defined(KNH_USING_BTRON)
        STIME st;
        get_tim(&st, NULL);
        return (knh_uint_t)st;
#else
	return 0;
#endif
}
Beispiel #14
0
void
in6_hostcache_update (T_IN6_ADDR *dst, uint32_t mtu)
{
	T_IN6_HOSTCACHE_ENTRY	*hc;
	SYSTIM	now, old;
	int_t	ix, oix;

	syscall(get_tim(&now));

	/* 既に登録されているか探索する。*/
	if ((hc = in6_hostcache_lookup (dst)) == NULL) {

		/* 空きのホストキャッシュを探す。*/
		for (ix = NUM_IN6_HOSTCACHE_ENTRY; ix -- > 0; ) {
			if (IN6_IS_HOSTCACHE_FREE(&in6_hostcache[ix]))
				break;
			}

		if (ix < 0) {
			/*
			 *  空きが無い時は、有効時間の切れる時間が、
			 *  最も短いホストキャッシュを置換する。
			 */
			old = now - 1;
			oix = 0;
			for (ix = NUM_IN6_HOSTCACHE_ENTRY; ix -- > 0; ) {
				hc = &in6_hostcache[ix];
				if (IN6_IS_HOSTCACHE_BUSY(hc) && (int32_t)(hc->expire - old) < 0) {
				                                        /* hc->expire < old */
					oix = ix;
					old = hc->expire;
					}
				}
			ix = oix;
			}
		hc = &in6_hostcache[ix];
		}
	else if (mtu > hc->mtu &&
	         (int32_t)(hc->expire - now) >= (IN6_HOSTCACHE_EXPIRE - IN6_HOSTCACHE_INCREASE)) {

		/*
		 *  既に登録されていて、新しい MTU が、登録されている MTU より大きいとき、
		 *  IN6_HOSTCACHE_INCREASE(推奨 10 分)間は更新しない。
		 */
		return;
		}
	hc->dst    = *dst;
	hc->expire = now + IN6_HOSTCACHE_EXPIRE;
	hc->mtu    = mtu;
	}
Beispiel #15
0
/** ウォッチドッグのクリア
 ****************************************************************************** */
void	WDT_Clear( void )
{
#if	WDT_LONG_TIME_CLEAR_INTERVAL
SYSTIM	stm;

	get_tim( &stm );

	if( mWdtWork.LongWatchdogTimer > stm )
		mWdtWork.LongWatchdogTimer = stm;

	if( PARA_IsHost() ||
		( stm - mWdtWork.LongWatchdogTimer < WDT_LONG_TIME_CLEAR_INTERVAL ) )
#endif	// WDT_LONG_TIME_CLEAR_INTERVAL
		WDT_TCNT = 0x5A00;
}
Beispiel #16
0
/*
 *  日付・時刻の取得
 *    ToDo:未実装
 */
DWORD
get_fattime(void)
{
	SYSTIM systim;
	DWORD  fdate = ((1980-1980)<<25)+(1<<21)+(1<<16);
	DWORD  ftime;

	if(SDeviceHead._get_datetime != 0)
		return (DWORD)SDeviceHead._get_datetime();
	else{
		get_tim(&systim);
		systim = (systim+1000L) /2000L;
		ftime  = systim % 30;
		ftime += ((systim/30) % 60)<<5;
		ftime += ((systim/(60*30))<<11);
		return (fdate+ftime);
	}
}
void
alarm1_handler(intptr_t exinf)
{
	ER_UINT	ercd;
	SYSTIM	systim;

	switch (++alarm1_count) {
	case 1:
		check_point(36);
		ercd = set_tim(1LLU << 32);
		check_ercd(ercd, E_CTX);

		ercd = get_tim(&systim);
		check_ercd(ercd, E_CTX);

		return;

		check_point(0);

	case 2:
		check_point(74);
		ercd = adj_tim(+1000000);
		check_ercd(ercd, E_OK);

		check_point(76);
		ercd = adj_tim(+1000000);
		check_ercd(ercd, E_OBJ);

		check_point(78);
		return;

		check_point(0);

	default:
		check_point(0);
	}
	check_point(0);
}
Beispiel #18
0
T_LLINFO_ND6 *
nd6_lookup (T_IN6_ADDR *addr, bool_t create)
{
	SYSTIM	min = 0xffffffff;
	int_t	ix, fix = -1, mix = -1;

	for (ix = NUM_ND6_CACHE_ENTRY; ix -- > 0; ) {
		if (nd6_cache[ix].state == 0) {
			/* 未使用エントリのインデックスを記録する。*/
			if (fix == -1)
				fix = ix;
			}
		else if (IN6_ARE_ADDR_EQUAL(addr, &nd6_cache[ix].addr)) {
			return &nd6_cache[ix];
			}
		else if ((int32_t)(nd6_cache[ix].expire - min) < 0) {	/* nd6_cache[ix].expire < min */
			/* 有効期限が最短エントリのインデックスを記録する。*/
			min = nd6_cache[ix].expire;
			mix = ix;
			}
		}

	if (create) {
		if (fix == -1)  {
			if (nd6_cache[mix].hold != NULL) {
				syscall(rel_net_buf(nd6_cache[mix].hold));
				}
			fix = mix;
			}
		syscall(get_tim(&nd6_cache[fix].expire));
		nd6_cache[fix].addr   = *addr;
		nd6_cache[fix].state  = ND6_LLINFO_NO_STATE;
		return &nd6_cache[fix];
		}
	else
		return NULL;
	}
Beispiel #19
0
T_IN6_ADDR *
in6_rtalloc (T_IFNET *ifp, T_IN6_ADDR *dst)
{
	if (IN6_IS_ADDR_LINKLOCAL(dst) || IN6_IS_ADDR_MULTICAST(dst))
		return dst;
	else {
		T_IN6_IFADDR	*ia;
		SYSTIM		now;
		int_t		ix;

		/*
		 *  サイトローカルアドレスか集約可能(グローバル)アドレスの場合は、
		 *  同一リンク内のノードであるかをチェックする。
		 */

		syscall(get_tim(&now));
		now /= SYSTIM_HZ;

		/* 推奨有効時間内のアドレスを探索する。*/
		for (ix = NUM_IN6_IFADDR_ENTRY; ix -- > 0; ) {
			ia = &ifp->in_ifaddrs[ix];
			if (IFA6_IS_READY(ia) &&
			    in6_are_prefix_equal(dst, &ia->addr, ia->prefix_len) &&
			    (int32_t)(ia->lifetime.preferred - now) > 0) {
		                   /* ia->lifetime.preferred > now */
				return dst;
				}
			}

		/* 有効時間内のアドレスを探索する。*/
		for (ix = NUM_IN6_IFADDR_ENTRY; ix -- > 0; ) {
			ia = &ifp->in_ifaddrs[ix];
			if (IFA6_IS_READY(ia) &&
			    in6_are_prefix_equal(dst, &ia->addr, ia->prefix_len) &&
			    (int32_t)(ia->lifetime.expire - now) > 0)
		                   /* ia->lifetime.expire > now */
				return dst;
			}

		/*
		 *  プレフィックスを探索する。
		 */
		if (nd6_onlink_prefix_lookup (dst) != NULL)
			return dst;

		/*
		 *  静的経路表を探索する。
		 */

#if NUM_ROUTE_ENTRY > 0

		syscall(wai_sem(SEM_IN_ROUTING_TBL));
		for (ix = NUM_ROUTE_ENTRY; ix --; ) {
			if ((routing_tbl[ix].flags & IN_RTF_DEFINED) &&
			    in6_are_prefix_equal(dst, &routing_tbl[ix].target,
			                               routing_tbl[ix].prefix_len)) {

				/*
				 *  向け直しによるエントリは、有効時間が切れる時刻を延長する。
				 *  expire の単位は [s]。
				 *  TMO_IN_REDIRECT の単位は [ms]。
				 */
				if (ix > NUM_STATIC_ROUTE_ENTRY) {
					SYSTIM	now;

					syscall(get_tim(&now));
					routing_tbl[ix].expire = now / SYSTIM_HZ + TMO_IN_REDIRECT / 1000;
					}

				syscall(sig_sem(SEM_IN_ROUTING_TBL));
				return &routing_tbl[ix].gateway;
				}
			}
		syscall(sig_sem(SEM_IN_ROUTING_TBL));

#endif	/* of #if NUM_ROUTE_ENTRY > 0 */

		/*
		 *  ディフォルトルータ・リストを探索する。
		 */
		return nd6_router_lookup();
		}
	}
Beispiel #20
0
static ER
tcp_echo_srv (ID cepid, ID repid)
{
	ER_UINT		rlen, slen;
	ER		error = E_OK;
	SYSTIM		now;
	uint32_t	total;
	uint16_t	soff, scount, rcount;

	if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) {
		syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(error));
		return error;
		}

#ifdef USE_TCP_EXTENTIONS
	if ((error = free_tcp_rep(repid, true)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_EXTENTIONS */

	scount = rcount = total = 0;
	syscall(get_tim(&now));
	syslog(LOG_NOTICE, "[TES:%02d ACP] connected:  %6lu, from: %s.%u",
	                   cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
	while (true) {
		if ((rlen = tcp_rcv_dat(cepid, buffer, BUF_SIZE - 1, RCV_TMO)) <= 0) {
			if (rlen != E_OK)
				syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s",
				                   cepid, itron_strerror(rlen));
			break;
			}

		rcount ++;
#ifdef SHOW_RCV_RANGE
		syslog(LOG_NOTICE, "[TES:%02d RCV] rcount: %4d, len: %4d, data %02x -> %02x",
		       cepid, rcount, (uint16_t)rlen, *buffer, *(buffer + rlen - 1));
#endif	/* of #ifdef SHOW_RCV_RANGE */

		total += rlen;
		soff = 0;
		while (rlen > 0) {
			scount ++;
			if ((slen = tcp_snd_dat(cepid, &buffer[soff], rlen, SND_TMO)) < 0) {
				syslog(LOG_NOTICE, "[TES:%02d SND] error: %s",
				                   cepid, itron_strerror(slen));
				goto err_fin;
				}
#ifdef SHOW_RCV_RANGE
			syslog(LOG_NOTICE, "[TES:%02d SND] scount: %4d, len: %4d", cepid, scount, (uint16_t)slen);
#endif	/* of #ifdef SHOW_RCV_RANGE */

			rlen -= slen;
			soff += slen;
			}
		}
err_fin:

#ifdef USE_TCP_SHT_CEP
	if ((error = tcp_sht_cep(cepid)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d SHT] error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_SHT_CEP */

	if ((error = tcp_cls_cep(cepid, CLS_TMO)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d CLS] error: %s", cepid, itron_strerror(error));

	syscall(get_tim(&now));
	syslog(LOG_NOTICE, "[TES:%02d FIN] finished:   %6lu, snd: %4u, rcv: %4u, len: %lu",
	                   cepid, now / SYSTIM_HZ, scount, rcount, total);

	return error;
	}
Beispiel #21
0
static ER
tcp_echo_srv (ID cepid, ID repid)
{
	ER_UINT		rblen, sblen;
	SYSTIM		now;
	ER		error;
	uint32_t	total;
	uint16_t	rlen, slen, soff, scount, rcount;
	char		*rbuf, *sbuf, head, tail;

	if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) {
		syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(error));
		return error;
		}

#ifdef USE_TCP_EXTENTIONS
	if ((error = free_tcp_rep(repid, true)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_EXTENTIONS */

	scount = rcount = total = 0;
	syscall(get_tim(&now));
	syslog(LOG_NOTICE, "[TES:%02d ACP] connected:  %6lu, from: %s.%u",
	                   cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
	while (true) {
		if ((rblen = tcp_rcv_buf(cepid, (void**)&rbuf, RCV_TMO)) <= 0) {
			if (rblen != E_OK)
				syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s",
				                   cepid, itron_strerror(rblen));
			break;
			}

		head = *rbuf;
		tail = *(rbuf + rblen - 1);
		rcount ++;

		//syslog(LOG_NOTICE, "[TES:%02d RCV] len: %4d", cepid, (uint16_t)rblen);
#ifdef SHOW_RCV_RANGE
		syslog(LOG_NOTICE, "[TES:%02d RCV] rcount: %4d, len: %4d, data %02x -> %02x",
		       cepid, rcount, (uint16_t)rblen, head, tail);
#endif	/* of #ifdef SHOW_RCV_RANGE */

		rlen   = (uint16_t)rblen;
		total +=     rblen;
		soff = 0;
		while (rlen > 0) {

			if ((sblen = tcp_get_buf(cepid, (void**)&sbuf, SND_TMO)) < 0) {
				syslog(LOG_NOTICE, "[TES:%02d GET] error: %s",
				                   cepid, itron_strerror(sblen));
				goto err_fin;
				}

			//syslog(LOG_NOTICE, "[TES:%02d SND] len: %4d", cepid, (uint16_t)sblen);
			scount ++;
			slen = rlen < (uint16_t)sblen ? rlen : (uint16_t)sblen;
			memcpy(sbuf, rbuf + soff, slen);
			if ((error = tcp_snd_buf(cepid, slen)) != E_OK) {
				syslog(LOG_NOTICE, "[TES:%02d SND] error: %s",
				                   cepid, itron_strerror(error));
				goto err_fin;
				}
#ifdef SHOW_RCV_RANGE
			syslog(LOG_NOTICE, "[TES:%02d SND] scount: %4d, len: %4d", cepid, scount, slen);
#endif	/* of #ifdef SHOW_RCV_RANGE */

			rlen -= slen;
			soff += slen;
			}

		if ((error = tcp_rel_buf(cepid, rblen)) < 0) {
			syslog(LOG_NOTICE, "[TES:%02d REL] error: %s", cepid, itron_strerror(error));
			break;
			}
		}
err_fin:

#ifdef USE_TCP_SHT_CEP
	if ((error = tcp_sht_cep(cepid)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d SHT] error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_SHT_CEP */

	if ((error = tcp_cls_cep(cepid, CLS_TMO)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d CLS] error: %s", cepid, itron_strerror(error));

	syscall(get_tim(&now));
	syslog(LOG_NOTICE, "[TES:%02d FIN] finished:   %6lu, snd: %4u, rcv: %4u, len: %lu",
	                   cepid, now / SYSTIM_HZ, scount, rcount, total);

	return error;
	}
Beispiel #22
0
static ER
tcp_echo_srv (ID cepid, ID repid)
{
	SYSTIM		now;
	ER		error;
	uint32_t	total;
	uint16_t	rlen, slen, soff, scount, rcount;
	char		head, tail;

	if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_NBLK)) != E_WBLK) {
		syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(error));
		return error;
		}

	/* 相手から接続されるまで待つ。*/
	syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

	if (nblk_error == E_OK) {
		syscall(get_tim(&now));
		syslog(LOG_NOTICE, "[TES:%02d ACP] connected:  %6lu, from: %s.%u",
		                   cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
		}
	else {
		syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(nblk_error));
		return nblk_error;
		}

#ifdef USE_TCP_EXTENTIONS
	if ((error = free_tcp_rep(repid, true)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_EXTENTIONS */

	scount = rcount = total = 0;
	while (true) {
		if ((error = tcp_rcv_dat(cepid, buffer, BUF_SIZE - 1, TMO_NBLK)) != E_WBLK) {
			syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s",
			                   cepid, itron_strerror(error));
			break;
			}

		/* 受信完了まで待つ。*/
		syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

		if (nblk_rlen < 0) {
			syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s",
			                   cepid, itron_strerror(nblk_rlen));
			break;
			}
		else if (nblk_rlen == 0)
			break;

		rlen = nblk_rlen;
		head = *buffer;
		tail = *(buffer + rlen - 1);
		rcount ++;

#ifdef SHOW_RCV_RANGE
		syslog(LOG_NOTICE, "[TES:%02d RCV] rcount: %4d, len: %4d, data %02x -> %02x",
		                   cepid, rcount, rlen, head, tail);
#endif	/* of #ifdef SHOW_RCV_RANGE */

		total += rlen;
		soff = 0;
		while (rlen > 0) {
			scount ++;
			if ((error = tcp_snd_dat(cepid, &buffer[soff], rlen, TMO_NBLK)) != E_WBLK) {
				syslog(LOG_NOTICE, "[TES:%02d SND] error: %s",
				                   cepid, itron_strerror(error));
				goto err_fin;
				}

			/* 送信完了まで待つ。*/
			syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

			if (nblk_slen < 0) {
				syslog(LOG_NOTICE, "[TES:%02d SND] error: %s",
				                   cepid, itron_strerror(nblk_slen));
				goto err_fin;
				}

			slen = nblk_slen;

#ifdef SHOW_RCV_RANGE
			syslog(LOG_NOTICE, "[TES:%02d SND] scount: %4d, len: %4d",
			                   cepid, scount, slen);
#endif	/* of #ifdef SHOW_RCV_RANGE */

			rlen -= slen;
			soff += slen;
			}
		}
err_fin:

#ifdef USE_TCP_SHT_CEP
	if ((error = tcp_sht_cep(cepid)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d SHT] error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_SHT_CEP */

	if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK)
		syslog(LOG_NOTICE, "[TES:%02d CLS] error: %s", cepid, itron_strerror(error));

	/* 開放が完了するまで待つ。*/
	syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

	syscall(get_tim(&now));
	syslog(LOG_NOTICE, "[TES:%02d FIN] finished:   %6lu, snd: %4u, rcv: %4u, len: %lu",
	                   cepid, now / SYSTIM_HZ, scount, rcount, total);

	return error == E_WBLK ? E_OK : error;
	}
Beispiel #23
0
static ER
tcp_echo_srv (ID cepid, ID repid)
{
	ER		error;
	SYSTIM		now;
	uint32_t	total;
	uint16_t	rblen, sblen, rlen, slen, soff, scount, rcount;
	char		*rbuf, *sbuf, head, tail;

	if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_NBLK)) != E_WBLK) {
		syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(error));
		return error;
		}

	/* 相手から接続されるまで待つ。*/
	syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

	if (nblk_error == E_OK) {
		syscall(get_tim(&now));
		syslog(LOG_NOTICE, "[TES:%02d ACP] connected:  %6lu, from: %s.%u",
		                   cepid, now / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
		}
	else {
		syslog(LOG_NOTICE, "[TES:%02d ACP] error: %s", cepid, itron_strerror(nblk_error));
		return nblk_error;
		}

#ifdef USE_TCP_EXTENTIONS
	if ((error = free_tcp_rep(repid, true)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d DEL] REP delete error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_EXTENTIONS */

	rlen = scount = rcount = total = 0;
	while (true) {
		if ((error = tcp_rcv_buf(cepid, (void**)&rbuf, TMO_NBLK)) != E_WBLK) {
			syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s", cepid, itron_strerror(error));
			break;
			}

		/* 受信するまで待つ。*/
		syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

		if (nblk_rlen < 0) {	/* エラー */
			syslog(LOG_NOTICE, "[TES:%02d RCV] error: %s", 
			                   cepid, itron_strerror(nblk_rlen));
			break;
			}
		else if (nblk_rlen == 0)	/* 受信終了 */
			break;

		rblen = nblk_rlen;

		/* バッファの残りにより、受信長を調整する。*/
		if (rblen > BUF_SIZE - rlen)
			rblen = BUF_SIZE - rlen;
		total += rblen;
		rlen   = rblen;

		head = *rbuf;
		tail = *(rbuf + rblen - 1);
		rcount ++;

#ifdef SHOW_RCV_RANGE
		syslog(LOG_NOTICE, "[TES:%02d RCV] "
		                   "rcount: %4d, len: %4d, data %02x -> %02x",
		                   cepid, rcount, rblen, head, tail);
#endif	/* of #ifdef SHOW_RCV_RANGE */

		memcpy(buffer, rbuf, rblen);

		if ((error = tcp_rel_buf(cepid, rlen)) < 0) {
			syslog(LOG_NOTICE, "[TES:%02d REL] error: %s",
			                   cepid, itron_strerror(error));
			break;
			}

		soff = 0;
		while (rlen > 0) {

			if ((error = tcp_get_buf(cepid, (void**)&sbuf, TMO_NBLK)) != E_WBLK) {
				syslog(LOG_NOTICE, "[TES:%02d GET] error: %s",
				                   cepid, itron_strerror(error));
				goto err_fin;
				}

			/* 送信バッファの獲得が完了するまで待つ。*/
			syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

			if (nblk_slen < 0) {
				syslog(LOG_NOTICE, "[TES:%02d GET] error: %s",
				                   cepid, itron_strerror(nblk_slen));
				goto err_fin;
				}

			sblen = nblk_slen;
			scount ++;
			slen = sblen < rlen ? sblen : rlen;
			memcpy(sbuf, buffer + soff, slen);

			if ((error = tcp_snd_buf(cepid, slen)) != E_OK) {
				syslog(LOG_NOTICE, "[TES:%02d SND] error: %s",
				                   cepid, itron_strerror(error));
				goto err_fin;
				}
#ifdef SHOW_RCV_RANGE
			syslog(LOG_NOTICE, "[TES:%02d SND] scount: %4d, len: %4d",
			                   cepid, scount, slen);
#endif	/* of #ifdef SHOW_RCV_RANGE */

			rlen -= slen;
			soff += slen;
			}
		}
err_fin:

#ifdef USE_TCP_SHT_CEP
	if ((error = tcp_sht_cep(cepid)) != E_OK)
		syslog(LOG_NOTICE, "[TES:%02d SHT] error: %s", cepid, itron_strerror(error));
#endif	/* of #ifdef USE_TCP_SHT_CEP */

	if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK)
		syslog(LOG_NOTICE, "[TES:%02d CLS] error: %s", cepid, itron_strerror(error));

	/* 開放が完了するまで待つ。*/
	syscall(wai_sem(SEM_TCP_ECHO_SRV_NBLK_READY));

	syscall(get_tim(&now));
	syslog(LOG_NOTICE, "[TES:%02d FIN] finished:   %6lu, snd: %4u, rcv: %4u, len: %lu",
	                   cepid, now / SYSTIM_HZ, scount, rcount, total);

	return error == E_WBLK ? E_OK : error;
	}
Beispiel #24
0
char *cg_http_getdate(CgSysTime sysTime, char *buf, int bufSize)
{
	SYSTIM systim;
	long uxtime;
	int year, month, day, hour, min, sec, week;

	cg_log_debug_l4("Entering...\n");

	get_tim(&systim);

	uxtime = (systim.ltime / 1000) + ((systim.utime / 1000) << 32);

	sec = uxtime % 60;
	uxtime -= sec;
	uxtime /= 60;

	min = uxtime % 60;
	uxtime -= min;
	uxtime /= 60;

	hour = uxtime % 24;
	uxtime -= hour;
	uxtime /= 24;

	week = uxtime % 7;

	year = 1970;
	day = uxtime;
	while (day > 366) {
		if (IsLeapYear(year))
			day -= 366;
		else
			day -= 365;
		year++;
    }
	day++;

	month = 0;
	while (1) {					
		if (IsLeapYear(year)) {
			if (day <= dayLearYear[month])
				break;
			day -= dayLearYear[month];
			month++;
		} else {
			if (day <= dayYear[month])
				break;
			day -= dayYear[month];
			month++;
		}
	}

#if defined(HAVE_SNPRINTF)
	snprintf(buf, bufSize,
#else
	sprintf(buf,
#endif
		"%s, %02d %s %04d %02d:%02d:%02d GMT",
		to_week_string(week),
		day,
		to_month_string(month),
		year,
		hour,
		min,
		sec);

	return buf;

	cg_log_debug_l4("Leaving...\n");
}
Beispiel #25
0
void
nd6_timer (void)
{
	T_IFNET		*ifp = IF_GET_IFNET();
	T_LLINFO_ND6	*ln;
	SYSTIM		now;
	int_t		ix;

	/* 近隣キャッシュの処理 */
	syscall(wai_sem(SEM_ND6_CACHE));
	syscall(get_tim(&now));
	for (ix = NUM_ND6_CACHE_ENTRY; ix -- > 0; ) {
		ln = &nd6_cache[ix];
		if (ln->state >= ND6_LLINFO_NO_STATE && (int32_t)(ln->expire - now) < 0) {
		                                               /* ln->expire < now */

			switch (ln->state) {

			case ND6_LLINFO_INCOMPLETE:	/* 未解決		*/
				if (ln->asked < ND6_MAX_MCAST_QUERY) {
					/*
					 *  マルチキャストアドレス要請の再送回数以下の場合の処理
					 */
					ln->asked ++;
					ln->expire = now + ND6_RETRANS_TIME;	/* 近隣探索送信間隔 */
					nd6_ns_output(ifp, &in6_addr_unspecified, &ln->addr, ln, false);
					}
				else  {
					if (ln->hold != NULL) {
						/*
						 *  最終的には、保留されているネットワークバッファが
						 *  あれば、ICMP6 ERROR を自分自身に返したあと、
						 *  ネットワークバッファを開放する。
						 *  しかし、現在、icmp6_error の実装が不完全のため、
						 *  ネットワークバッファの開放のみ行う。
						 */
#if 0	/* 保留 */
						icmp6_error(ln->hold, ICMP6_DST_UNREACH,
						                      ICMP6_DST_UNREACH_ADDR, 0);
#endif	/* #if 0 */
						syscall(rel_net_buf(ln->hold));
						ln->hold = NULL;
						}
					nd6_free(ln);
					memset((void*)ln, 0, sizeof(*ln));
					}
				break;

			case ND6_LLINFO_REACHABLE:	/* 到達可能		*/
				if (ln->expire) {
					ln->expire = now + ND6_GCOLLECTION_TIME;
					ln->state = ND6_LLINFO_STALE;
					}
				break;

			case ND6_LLINFO_STALE:		/* 到達可能性は未確認	*/
				if (ln->expire) {
					if (ln->hold != NULL) {
						syscall(rel_net_buf(ln->hold));
						ln->hold = NULL;
						}
					nd6_free(ln);
					memset((void*)ln, 0, sizeof(*ln));
					}
				break;

			case ND6_LLINFO_DELAY:		/* 到達可能性の確認待機	*/
				ln->asked = 1;
				ln->expire = now + ND6_RETRANS_TIME;		/* 近隣探索送信間隔 */
				ln->state = ND6_LLINFO_PROBE;
				nd6_ns_output(ifp, &ln->addr, &ln->addr, ln, false);
				break;

			case ND6_LLINFO_PROBE:		/* 到達可能性を確認中	*/
				if (ln->asked < ND6_MAX_UCAST_QUERY) {
					/*
					 *  ユニキャストアドレス要請の再送回数以下の場合の処理
					 */
					ln->asked ++;
					ln->expire += ND6_RETRANS_TIME;	/* 近隣探索送信間隔 */
					nd6_ns_output(ifp, &ln->addr, &ln->addr, ln, false);
					}
				else {
					if (ln->hold != NULL) {
						syscall(rel_net_buf(ln->hold));
						ln->hold = NULL;
						}
					nd6_free(ln);
					memset((void*)ln, 0, sizeof(*ln));
					}
				break;

				}
			}
		}
	syscall(sig_sem(SEM_ND6_CACHE));

	/* ディフォルトルータ・リストの処理 */
	nd6_defrtrlist_timer();

	/* プレフィックス・リストの処理 */
	nd6_prelist_timer();

	/* ネットワークインタフェースのアドレスの処理 */
	in6_ifaddr_timer(ifp);

	/*
	 *  到達可能状態の有効時間の更新
	 */
	if ((int32_t)(nd6_recalc_reachtm_interval - now) < 0) {
	           /* nd6_recalc_reachtm_interval < now */
		nd6_recalc_reachtm_interval	= now + ND6_RECALC_REACHTM_INTERVAL;
		nd6_reachable_time		= ND6_CALC_REACH_TIME(nd6_base_reachable_time);
		}
	timeout((callout_func)nd6_timer, NULL, ND6_TIMER_TMO);
	}
/*
 *  メインタスク
 */
void main_task(intptr_t exinf)
{
	char	c;
	ID		tskid = TASK1;
	int_t	tskno = 1;
	ER_UINT	ercd;
	PRI		tskpri;
#ifndef TASK_LOOP
	volatile ulong_t	i;
	SYSTIM	stime1, stime2;
#endif /* TASK_LOOP */
	HRTCNT	hrtcnt1, hrtcnt2;

	SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)));
	syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf);

	/*
	 *  シリアルポートの初期化
	 *
	 *  システムログタスクと同じシリアルポートを使う場合など,シリアル
	 *  ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は
	 *  ない.
	 */
	ercd = serial_opn_por(TASK_PORTID);
	if (ercd < 0 && MERCD(ercd) != E_OBJ) {
		syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.",
									itron_strerror(ercd), SERCD(ercd));
	}
	SVC_PERROR(serial_ctl_por(TASK_PORTID,
							(IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));

	/*
 	 *  ループ回数の設定
	 *
	 *  並行実行されるタスク内での空ループの回数(task_loop)は,空ルー
	 *  プの実行時間が約0.4秒になるように設定する.この設定のために,
	 *  LOOP_REF回の空ループの実行時間を,その前後でget_timを呼ぶことで
	 *  測定し,その測定結果から空ループの実行時間が0.4秒になるループ回
	 *  数を求め,task_loopに設定する.
	 *
	 *  LOOP_REFは,デフォルトでは1,000,000に設定しているが,想定したよ
	 *  り遅いプロセッサでは,サンプルプログラムの実行開始に時間がかか
	 *  りすぎるという問題を生じる.逆に想定したより速いプロセッサでは,
	 *  LOOP_REF回の空ループの実行時間が短くなり,task_loopに設定する値
	 *  の誤差が大きくなるという問題がある.
	 *
	 *  そこで,そのようなターゲットでは,target_test.hで,LOOP_REFを適
	 *  切な値に定義するのが望ましい.
	 *
	 *  また,task_loopの値を固定したい場合には,その値をTASK_LOOPにマ
	 *  クロ定義する.TASK_LOOPがマクロ定義されている場合,上記の測定を
	 *  行わずに,TASK_LOOPに定義された値を空ループの回数とする.
	 *
	 * ターゲットによっては,空ループの実行時間の1回目の測定で,本来よ
	 * りも長めになるものがある.このようなターゲットでは,MEASURE_TWICE
	 * をマクロ定義することで,1回目の測定結果を捨てて,2回目の測定結果
	 * を使う.
	 */
#ifdef TASK_LOOP
	task_loop = TASK_LOOP;
#else /* TASK_LOOP */

#ifdef MEASURE_TWICE
	task_loop = LOOP_REF;
	SVC_PERROR(get_tim(&stime1));
	for (i = 0; i < task_loop; i++);
	SVC_PERROR(get_tim(&stime2));
#endif /* MEASURE_TWICE */

	task_loop = LOOP_REF;
	SVC_PERROR(get_tim(&stime1));
	for (i = 0; i < task_loop; i++);
	SVC_PERROR(get_tim(&stime2));
	task_loop = LOOP_REF * 400LU / (ulong_t)(stime2 - stime1) * 1000LU;

#endif /* TASK_LOOP */

	/*
 	 *  タスクの起動
	 */
	SVC_PERROR(act_tsk(TASK1));
	SVC_PERROR(act_tsk(TASK2));
	SVC_PERROR(act_tsk(TASK3));

	/*
 	 *  メインループ
	 */
	do {
		SVC_PERROR(serial_rea_dat(TASK_PORTID, &c, 1));
		switch (c) {
		case 'e':
		case 's':
		case 'S':
		case 'd':
		case 'y':
		case 'Y':
		case 'z':
		case 'Z':
			message[tskno-1] = c;
			break;
		case '1':
			tskno = 1;
			tskid = TASK1;
			break;
		case '2':
			tskno = 2;
			tskid = TASK2;
			break;
		case '3':
			tskno = 3;
			tskid = TASK3;
			break;
		case 'a':
			syslog(LOG_INFO, "#act_tsk(%d)", tskno);
			SVC_PERROR(act_tsk(tskid));
			break;
		case 'A':
			syslog(LOG_INFO, "#can_act(%d)", tskno);
			SVC_PERROR(ercd = can_act(tskid));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "can_act(%d) returns %d", tskno, ercd);
			}
			break;
		case 't':
			syslog(LOG_INFO, "#ter_tsk(%d)", tskno);
			SVC_PERROR(ter_tsk(tskid));
			break;
		case '>':
			syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno);
			SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY));
			break;
		case '=':
			syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno);
			SVC_PERROR(chg_pri(tskid, MID_PRIORITY));
			break;
		case '<':
			syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno);
			SVC_PERROR(chg_pri(tskid, LOW_PRIORITY));
			break;
		case 'G':
			syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno);
			SVC_PERROR(ercd = get_pri(tskid, &tskpri));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "priority of task %d is %d", tskno, tskpri);
			}
			break;
		case 'w':
			syslog(LOG_INFO, "#wup_tsk(%d)", tskno);
			SVC_PERROR(wup_tsk(tskid));
			break;
		case 'W':
			syslog(LOG_INFO, "#can_wup(%d)", tskno);
			SVC_PERROR(ercd = can_wup(tskid));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "can_wup(%d) returns %d", tskno, ercd);
			}
			break;
		case 'l':
			syslog(LOG_INFO, "#rel_wai(%d)", tskno);
			SVC_PERROR(rel_wai(tskid));
			break;
		case 'u':
			syslog(LOG_INFO, "#sus_tsk(%d)", tskno);
			SVC_PERROR(sus_tsk(tskid));
			break;
		case 'm':
			syslog(LOG_INFO, "#rsm_tsk(%d)", tskno);
			SVC_PERROR(rsm_tsk(tskid));
			break;
		case 'x':
			syslog(LOG_INFO, "#ras_ter(%d)", tskno);
			SVC_PERROR(ras_ter(tskid));
			break;
		case 'r':
			syslog(LOG_INFO, "#rot_rdq(three priorities)");
			SVC_PERROR(rot_rdq(HIGH_PRIORITY));
			SVC_PERROR(rot_rdq(MID_PRIORITY));
			SVC_PERROR(rot_rdq(LOW_PRIORITY));
			break;
		case 'c':
			syslog(LOG_INFO, "#sta_cyc(1)");
			SVC_PERROR(sta_cyc(CYCHDR1));
			break;
		case 'C':
			syslog(LOG_INFO, "#stp_cyc(1)");
			SVC_PERROR(stp_cyc(CYCHDR1));
			break;
		case 'b':
			syslog(LOG_INFO, "#sta_alm(1, 5000000)");
			SVC_PERROR(sta_alm(ALMHDR1, 5000000));
			break;
		case 'B':
			syslog(LOG_INFO, "#stp_alm(1)");
			SVC_PERROR(stp_alm(ALMHDR1));
			break;

		case 'V':
			hrtcnt1 = fch_hrt();
			hrtcnt2 = fch_hrt();
			syslog(LOG_NOTICE, "hrtcnt1 = %tu, hrtcnt2 = %tu",
										hrtcnt1, hrtcnt2);
			break;

		case 'o':
#ifdef TOPPERS_SUPPORT_OVRHDR
			syslog(LOG_INFO, "#sta_ovr(%d, 2000000)", tskno);
			SVC_PERROR(sta_ovr(tskid, 2000000));
#else /* TOPPERS_SUPPORT_OVRHDR */
			syslog(LOG_NOTICE, "sta_ovr is not supported.");
#endif /* TOPPERS_SUPPORT_OVRHDR */
			break;
		case 'O':
#ifdef TOPPERS_SUPPORT_OVRHDR
			syslog(LOG_INFO, "#stp_ovr(%d)", tskno);
			SVC_PERROR(stp_ovr(tskid));
#else /* TOPPERS_SUPPORT_OVRHDR */
			syslog(LOG_NOTICE, "stp_ovr is not supported.");
#endif /* TOPPERS_SUPPORT_OVRHDR */
			break;

		case 'v':
			SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO),
										LOG_UPTO(LOG_EMERG)));
			break;
		case 'q':
			SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE),
										LOG_UPTO(LOG_EMERG)));
			break;

#ifdef BIT_KERNEL
		case ' ':
			SVC_PERROR(loc_cpu());
			{
				extern ER	bit_kernel(void);

				SVC_PERROR(ercd = bit_kernel());
				if (ercd >= 0) {
					syslog(LOG_NOTICE, "bit_kernel passed.");
				}
			}
			SVC_PERROR(unl_cpu());
			break;
#endif /* BIT_KERNEL */

		default:
			break;
		}
	} while (c != '\003' && c != 'Q');

	syslog(LOG_NOTICE, "Sample program ends.");
	SVC_PERROR(ext_ker());
	assert(0);
}
Beispiel #27
0
/*
 *  メインタスク
 */
void main_task(intptr_t exinf)
{
	char_t	c;
	ER_UINT	ercd;
	PRI		tskpri;
	ID		prcid = exinf;
	ID		tskid = sample_tskid[(exinf - 1) * 3 ];
	int_t	        tskno = (exinf-1) * 3 + 1;
	ID		cycid = sample_cycid[(int_t)exinf-1];
	ID		almid = sample_almid[(int_t)exinf-1];
	bool_t  update_select = true;
	uint_t  tme_select    = exinf;
	uint_t  prc_select    = exinf;
	uint32_t server_req;

#ifndef TASK_LOOP
	volatile ulong_t	i;
	SYSTIM	stime1, stime2;
#endif /* TASK_LOOP */
#ifdef G_SYSLOG
	uint_t e;
#endif /* G_SYSLOG */

	SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)));
	syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf);

	/*
	 *  シリアルポートの初期化
	 *
	 *  システムログタスクと同じシリアルポートを使う場合など,シリアル
	 *  ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は
	 *  ない.
	 */
	ercd = serial_opn_por(((int_t)serial_port[exinf-1]));
	if (ercd < 0 && MERCD(ercd) != E_OBJ) {
		syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.",
									itron_strerror(ercd), SERCD(ercd));
	}
	SVC_PERROR(serial_ctl_por(serial_port[exinf-1],
							(IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));

	/*
	 *  ループ回数の設定
	 *
	 *  TASK_LOOPがマクロ定義されている場合,測定せずに,TASK_LOOPに定
	 *  義された値を,タスク内でのループ回数とする.
	 *
	 *  MEASURE_TWICEがマクロ定義されている場合,1回目の測定結果を捨て
	 *  て,2回目の測定結果を使う.1回目の測定は長めの時間が出るため.
	 */
#ifdef TASK_LOOP
	task_loop = TASK_LOOP;
#else /* TASK_LOOP */

#ifdef MEASURE_TWICE
	task_loop = LOOP_REF;
	SVC_PERROR(get_tim(&stime1));
	for (i = 0; i < task_loop; i++);
	SVC_PERROR(get_tim(&stime2));
#endif /* MEASURE_TWICE */

	task_loop = LOOP_REF;
	SVC_PERROR(get_tim(&stime1));
	for (i = 0; i < task_loop; i++);
	SVC_PERROR(get_tim(&stime2));
	task_loop = LOOP_REF * 400UL / (stime2 - stime1);
#endif /* TASK_LOOP */

	/*
	 *  タスクの起動
	 */
	SVC_PERROR(act_tsk(tskid));

	/*
 	 *  メインループ
	 */
	do {
		if (update_select) {
			prcid = prc_select;
			cycid = sample_cycid[tme_select-1];
			almid = sample_almid[tme_select-1];
                        tsk_mig_prc = prcid;
			update_select = false;
			syslog(LOG_INFO, "select tskno 0x%x", tskno);
			syslog(LOG_INFO, "select cycid %d", cycid);
			syslog(LOG_INFO, "select almid %d", almid);
			syslog(LOG_INFO, "select processor %d", prcid);
		}
		
		SVC_PERROR(serial_rea_dat(serial_port[exinf-1], &c, 1));
		
		switch (c) {
		case 'e':
		case 's':
		case 'S':
		case 'd':
                case 'g':
			message[tskno - 1] = c;
			break;
		case '1':
			tskno = 1;
                        tskid = TASK1;
			update_select = true;
			break;
		case '2':
			tskno = 2;
                        tskid = TASK2;
			update_select = true;
			break;
		case '3':
			tskno = 3;
                        tskid = TASK3;
			update_select = true;
			break;
		case '4':
			tskno = 4;
                        tskid = TASK4;
			update_select = true;
			break;
		case '5':
			tskno = 5;
                        tskid = TASK5;
			update_select = true;
			break;
		case '6':
			tskno = 6;
                        tskid = TASK6;
			update_select = true;
			break;
		case '8':
			prc_select = 1;
			update_select = true;
			break;
		case '9':
			prc_select = 2;
			update_select = true;
			break;
		case 'a':
			syslog(LOG_INFO, "#act_tsk(0x%x)", tskno);
			SVC_PERROR(act_tsk(tskid));
			break;
		case 'A':
			syslog(LOG_INFO, "#can_act(0x%x)", tskno);
			SVC_PERROR(ercd = can_act(tskid));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "can_act(0x%x) returns %d", tskno, ercd);
			}
			break;
		case '>':
			syslog(LOG_INFO, "#chg_pri(0x%x, HIGH_PRIORITY)", tskno);
			SVC_PERROR(chg_pri(tskid, HIGH_PRIORITY));
			break;
		case '=':
			syslog(LOG_INFO, "#chg_pri(0x%x, MID_PRIORITY)", tskno);
			SVC_PERROR(chg_pri(tskid, MID_PRIORITY));
			break;
		case '<':
			syslog(LOG_INFO, "#chg_pri(0x%x, LOW_PRIORITY)", tskno);
			SVC_PERROR(chg_pri(tskid, LOW_PRIORITY));
			break;
		case 'G':
			syslog(LOG_INFO, "#get_pri(0x%x, &tskpri)", tskno);
			SVC_PERROR(ercd = get_pri(tskid, &tskpri));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "priority of task 0x%x is %d", tskno, tskpri);
			}
			break;
		case 'w':
			syslog(LOG_INFO, "#wup_tsk(0x%x)", tskno);
			SVC_PERROR(wup_tsk(tskid));
			break;
		case 'W':
			syslog(LOG_INFO, "#can_wup(0x%x)", tskno);
			SVC_PERROR(ercd = can_wup(tskid));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "can_wup(0x%x) returns %d", tskno, ercd);
			}
			break;
		case 'c':
			syslog(LOG_INFO, "#sta_cyc(%d)", cycid);
			SVC_PERROR(sta_cyc(cycid));
			break;
		case 'C':
			syslog(LOG_INFO, "#stp_cyc(%d)", cycid);
			SVC_PERROR(stp_cyc(cycid));
			break;
		case 'b':
			syslog(LOG_INFO, "#sta_alm(%d, %d)", almid, ALM_TIME);
			SVC_PERROR(sta_alm(almid, ALM_TIME));
			break;
		case 'B':
			syslog(LOG_INFO, "#stp_alm(%d)", almid);
			SVC_PERROR(stp_alm(almid));
			break;
		case 'f':
			syslog(LOG_INFO, "#mact_tsk(%d, %d)", tskid, prcid);
			SVC_PERROR(mact_tsk(tskid, prcid));
			break;                  
		default:
			break;
		}
	} while (c != '\003' && c != 'Q');

	syslog(LOG_NOTICE, "Sample program ends.");
	SVC_PERROR(ext_ker());
	assert(0);
}
Beispiel #28
0
T_LLINFO_ND6 *
nd6_cache_lladdr (T_IFNET *ifp, T_IN6_ADDR *from,
                  T_IF_ADDR *lladdr, uint8_t type, uint8_t code)
{
	T_LLINFO_ND6	*ln;
	SYSTIM		now;
	bool_t		newentry, olladdr, llchange, doupdate;
	int_t		newstate = ND6_LLINFO_INCOMPLETE;

	/* アドレスが無指定なら何もしない。*/
	if (IN6_IS_ADDR_UNSPECIFIED(from))
		return NULL;

	/* 近隣キャッシュに登録する。*/
	syscall(wai_sem(SEM_ND6_CACHE));
	if ((ln = nd6_lookup(from, false)) == NULL) {
		ln = nd6_lookup(from, true);
		newentry = true;
		}
	else
		newentry = false;

	olladdr = ln->state > ND6_LLINFO_INCOMPLETE;
	if (!olladdr || lladdr == NULL)
		llchange = false;
	else if (memcmp(lladdr, &ln->ifaddr, sizeof(T_IF_ADDR)))
		llchange = true;
	else
		llchange = false;

	/*
	 *  状態遷移表
	 *
	 *  nd_na_flags
	 *  newnetry olladdr lladdr llchange 処理 (L: lladdr を登録する)
	 *
	 *      F       F       N       -    (1)
	 *      F       T       N       -    (2)
	 *      F       F       Y       -    (3) L * -> STALE
	 *      F       T       Y       F    (4) L
	 *      F       T       Y       T    (5) L * -> STALE
	 *      T       -       N       -    (6)   * -> NO_STATE
	 *      T       -       Y       -    (7) L * -> STALE
	 */

	/* データリンク層のアドレスが通知されていれば更新する。*/
	if (lladdr != NULL) {
		ln->ifaddr = *(T_IF_ADDR *)lladdr;
		}

	if (newentry) {
		if (lladdr != NULL)					/* (7) */
			newstate = ND6_LLINFO_STALE;
		else							/* (6) */
			newstate = ND6_LLINFO_NO_STATE;
		doupdate = true;
		}
	else {
		if ((!olladdr && lladdr != NULL) ||			/* (3) */
		    ( olladdr && lladdr != NULL && llchange)) {		/* (5) */
			newstate = ND6_LLINFO_STALE;
			doupdate = true;
			}
		else							/* (1),(2),(4) */
			doupdate = false;
		}

	/* 近隣キャッシュエントリを更新する。*/
	if (doupdate) {
		ln->state = newstate;

		syscall(get_tim(&now));
		if (ln->state == ND6_LLINFO_STALE) {
			ln->expire = now + ND6_GCOLLECTION_TIME;

			/* アドレス解決待ちのデータグラムがあれば送信する。*/
			nd6_output_hold(ifp, ln);
			}
		else if (ln->state == ND6_LLINFO_INCOMPLETE)
			ln->expire = now;
		}
	syscall(sig_sem(SEM_ND6_CACHE));


	/* ルータ通知の処理 */
	switch (type) {

	case ND_NEIGHBOR_SOLICIT:
		if (newentry)
			ln->flags &= ~ND6_LLIF_ROUTER;
		break;

	case ND_REDIRECT:
		if (code == ND_REDIRECT_ROUTER)
			ln->flags |=  ND6_LLIF_ROUTER;
		else if (newentry)
			ln->flags &= ~ND6_LLIF_ROUTER;
		break;

	case ND_ROUTER_SOLICIT:
		ln->flags &= ~ND6_LLIF_ROUTER;
		break;

	case ND_ROUTER_ADVERT:
		if ((!newentry && (olladdr || lladdr != NULL)) ||
		    ( newentry && lladdr))
			ln->flags |=  ND6_LLIF_ROUTER;
		break;
		}

	return ln;
	}
Beispiel #29
0
/*
 *  メインタスク
 */
void main_task(VP_INT exinf)
{
	char	c;
	ID	tskid = TASK1;
	volatile UW	i;
	INT	tskno = 1;
	ER_UINT	ercd;	
	PRI	tskpri;
	SYSTIM	stime1, stime2;
#ifndef OMIT_VGET_TIM
	SYSUTIM	utime1, utime2;
#endif /* OMIT_VGET_TIM */

	vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG));
	syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int)exinf);
	syscall(serial_ctl_por(TASK_PORTID,
			(IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));

	/*
 	 *  ループ回数の設定
	 */
	task_loop = LOOP_REF;
	get_tim(&stime1);
	for (i = 0; i < task_loop; i++);
	get_tim(&stime2);
	task_loop = LOOP_REF * 400 / (stime2 - stime1);
	tex_loop = task_loop / 5;

	/*
 	 *  タスクの起動
	 */
	act_tsk(TASK1);
	act_tsk(TASK2);
	act_tsk(TASK3);

	/*
 	 *  メインループ
	 */
	do {
		syscall(serial_rea_dat(TASK_PORTID, &c, 1));
		switch (c) {
		case 'e':
		case 's':
		case 'S':
		case 'd':
		case 'y':
		case 'Y':
		case 'z':
		case 'Z':
			message[tskno-1] = c;
			break;
		case '1':
			tskno = 1;
			tskid = TASK1;
			break;
		case '2':
			tskno = 2;
			tskid = TASK2;
			break;
		case '3':
			tskno = 3;
			tskid = TASK3;
			break;
		case 'a':
			syslog(LOG_INFO, "#act_tsk(%d)", tskno);
			syscall(act_tsk(tskid));
			break;
		case 'A':
			syslog(LOG_INFO, "#can_act(%d)", tskno);
			syscall(ercd = can_act(tskid));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "can_act(%d) returns %d",
						tskno, ercd);
			}
			break;
		case 't':
			syslog(LOG_INFO, "#ter_tsk(%d)", tskno);
			syscall(ter_tsk(tskid));
			break;
		case '>':
			syslog(LOG_INFO, "#chg_pri(%d, HIGH_PRIORITY)", tskno);
			chg_pri(tskid, HIGH_PRIORITY);
			break;
		case '=':
			syslog(LOG_INFO, "#chg_pri(%d, MID_PRIORITY)", tskno);
			chg_pri(tskid, MID_PRIORITY);
			break;
		case '<':
			syslog(LOG_INFO, "#chg_pri(%d, LOW_PRIORITY)", tskno);
			chg_pri(tskid, LOW_PRIORITY);
			break;
		case 'G':
			syslog(LOG_INFO, "#get_pri(%d, &tskpri)", tskno);
			syscall(ercd = get_pri(tskid, &tskpri));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "priority of task %d is %d",
						tskno, tskpri);
			}
			break;
		case 'w':
			syslog(LOG_INFO, "#wup_tsk(%d)", tskno);
			syscall(wup_tsk(tskid));
			break;
		case 'W':
			syslog(LOG_INFO, "#can_wup(%d)", tskno);
			syscall(ercd = can_wup(tskid));
			if (ercd >= 0) {
				syslog(LOG_NOTICE, "can_wup(%d) returns %d",
						tskno, ercd);
			}
			break;
		case 'l':
			syslog(LOG_INFO, "#rel_wai(%d)", tskno);
			syscall(rel_wai(tskid));
			break;
		case 'u':
			syslog(LOG_INFO, "#sus_tsk(%d)", tskno);
			syscall(sus_tsk(tskid));
			break;
		case 'm':
			syslog(LOG_INFO, "#rsm_tsk(%d)", tskno);
			syscall(rsm_tsk(tskid));
			break;
		case 'M':
			syslog(LOG_INFO, "#frsm_tsk(%d)", tskno);
			syscall(frsm_tsk(tskid));
			break;
		case 'x':
			syslog(LOG_INFO, "#ras_tex(%d, 0x0001)", tskno);
			syscall(ras_tex(tskid, 0x0001));
			break;
		case 'X':
			syslog(LOG_INFO, "#ras_tex(%d, 0x0002)", tskno);
			syscall(ras_tex(tskid, 0x0002));
			break;
		case 'r':
			syslog(LOG_INFO, "#rot_rdq(three priorities)");
			rot_rdq(HIGH_PRIORITY);
			rot_rdq(MID_PRIORITY);
			rot_rdq(LOW_PRIORITY);
			break;
		case 'c':
			sta_cyc(CYCHDR1);
			break;
		case 'C':
			stp_cyc(CYCHDR1);
			break;
#ifndef OMIT_VGET_TIM
		case 'V':
			syscall(vxget_tim(&utime1));
			syscall(vxget_tim(&utime2));
			syslog(LOG_NOTICE, "utime1 = %d, utime2 = %d",
						(UINT) utime1, (UINT) utime2);
			break;
#endif /* OMIT_VGET_TIM */
		case 'v':
			vmsk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG));
			break;
		case 'q':
			vmsk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG));
			break;
		default:
			break;
		}
	} while (c != '\003' && c != 'Q');

	syslog(LOG_NOTICE, "Sample program ends.");
	kernel_exit();
}
Beispiel #30
0
ER
nd6_output (T_IFNET *ifp, T_NET_BUF *output, T_IN6_ADDR *dst, T_LLINFO_ND6 *ln, TMO tmout)
{
	ER	error = E_OK;
	SYSTIM	now;

	/*
	 *  あて先アドレスがマルチキャストか、近隣キャッシュが
	 *  不要の場合は直ちに送信する。
	 */
	if (!(IN6_IS_ADDR_MULTICAST(dst) || !IF_IN6_NEED_CACHE(ifp))) {
		if (ln == NULL) {
			/* 近隣キャッシュが未定義の場合 */
			if (nd6_is_addr_neighbor(ifp, dst)) {
				/*
				 *  指定されたアドレスのノードが同一リンクにある時は、
				 *  近隣キャッシュを探索し、未定義の場合は登録する。
				 */
				ln = nd6_lookup(dst, true);
				}
			else {
				error = E_CLS;
				goto err_ret;
				}
			}

		/*
		 *  近隣キャッシュの状態が、データリンク層のアドレスが分かっていても、
		 *  到達可能性が確認されていないときは、到達不能通知を開始する。
		 */
		if (ln->state == ND6_LLINFO_STALE) {
			syscall(get_tim(&now));
			ln->expire = now + ND6_DELAY_TIME;
			ln->asked = 0;
			ln->state = ND6_LLINFO_DELAY;
			}

		/*
		 *  近隣キャッシュの状態が、データリンク層のアドレス未解決の場合は
		 *  近隣探索を行う。
		 */
		if (ln->state <= ND6_LLINFO_INCOMPLETE) {

			/* タイムアウトの指定がポーリングならタイムアウトで終了する。*/
			if (tmout == TMO_POL) {
				error = E_TMOUT;
				goto err_ret;
				}

			if (ln->state == ND6_LLINFO_NO_STATE)
				ln->state = ND6_LLINFO_INCOMPLETE;

			/* すでに、未解決のネットワークバッファがあれば、開放する。*/
			if (ln->hold != NULL) {
				syscall(rel_net_buf(ln->hold));
				}

			/*
			 *  送信をペンディングする。
			 *  IF でネットワークバッファを開放しないフラグが設定されているときは、
			 *  送信をペンディングしない。
			 */
			if ((output->flags & NB_FLG_NOREL_IFOUT) == 0) {
				ln->hold = output;

				/* タイムアウトの設定 */
				if (tmout == TMO_FEVR)
					ln->tmout = tmout;
				else {
					syscall(get_tim(&now));
					ln->tmout = now + tmout;
					}
				}
			else {
				output->flags &= ~NB_FLG_NOREL_IFOUT;
				syscall(get_tim(&now));
				ln->tmout = now + tmout;
				}

			if (ln->expire) {
				if (ln->asked < ND6_MAX_MCAST_QUERY) {
					syscall(get_tim(&now));
					if ((int32_t)(ln->expire - now) < 0) {
					           /* ln->expire < now */
						ln->expire += ND6_RETRANS_TIME;	/* 近隣探索送信間隔 */
						ln->asked ++;
						nd6_ns_output(ifp, &in6_addr_unspecified, dst, ln, false);
						}
					}
				}
			return error;
			}
		}

	/*
	 *  重複が検出されたインタフェースには出力しない。
	 */
	if ((ifp->flags & ND6_IFF_IFDISABLED) != 0) {
		return E_OK;
		}

	IF_SET_PROTO(output, IF_PROTO_IPV6);
	error = IF_OUTPUT(output, dst, ln ? & ln->ifaddr : NULL, tmout);
	return error;

err_ret:
	syscall(rel_net_buf(output));
	return error;
	}