/*
 *  並行実行されるタスク
 */
void task(intptr_t exinf)
{
	volatile ulong_t	i;
	int_t		n = 0;
	int_t		tskno = (int_t) exinf;
	const char	*graph[] = { "|", "  +", "    *" };
	char		c;

	while (true) {
		syslog(LOG_NOTICE, "task%d is running (%03d).   %s",
										tskno, ++n, graph[tskno-1]);
		for (i = 0; i < task_loop; i++);
		c = message[tskno-1];
		message[tskno-1] = 0;
		switch (c) {
		case 'e':
			syslog(LOG_INFO, "#%d#ext_tsk()", tskno);
			SVC_PERROR(ext_tsk());
			assert(0);
		case 's':
			syslog(LOG_INFO, "#%d#slp_tsk()", tskno);
			SVC_PERROR(slp_tsk());
			break;
		case 'S':
			syslog(LOG_INFO, "#%d#tslp_tsk(10000000)", tskno);
			SVC_PERROR(tslp_tsk(10000000));
			break;
		case 'd':
			syslog(LOG_INFO, "#%d#dly_tsk(10000000)", tskno);
			SVC_PERROR(dly_tsk(10000000));
			break;
		case 'y':
			syslog(LOG_INFO, "#%d#dis_ter()", tskno);
			SVC_PERROR(dis_ter());
			break;
		case 'Y':
			syslog(LOG_INFO, "#%d#ena_ter()", tskno);
			SVC_PERROR(ena_ter());
			break;
#ifdef CPUEXC1
		case 'z':
			syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno);
			RAISE_CPU_EXCEPTION;
			break;
		case 'Z':
			SVC_PERROR(loc_cpu());
			syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno);
			RAISE_CPU_EXCEPTION;
			SVC_PERROR(unl_cpu());
			break;
#endif /* CPUEXC1 */
		default:
			break;
		}
	}
}
void
task2(intptr_t exinf)
{
	ER_UINT	ercd;

	switch (++task2_count) {
	case 1:
		check_point(2);
		while(true);

		check_point(0);

	case 2:
		check_point(35);
		ercd = dis_ter();
		check_ercd(ercd, E_OK);

		ercd = wup_tsk(TASK1);
		check_ercd(ercd, E_OK);

		check_point(0);

	case 3:
		check_point(41);
		ercd = dis_ter();
		check_ercd(ercd, E_OK);

		ercd = slp_tsk();
		check_ercd(ercd, E_RASTER);

		check_point(45);
		ercd = wup_tsk(TASK1);
		check_ercd(ercd, E_OK);

		check_point(0);

	default:
		check_point(0);
	}
	check_point(0);
}
/*
 *  並行実行されるタスク
 */
void task(intptr_t exinf)
{
	volatile ulong_t	i;
	int_t		n = 0;
	int_t		tskno = (int_t) exinf;
	const char	*graph[] = { "|    ", "  +  ", "    *" };
	char		c;
#ifdef TOPPERS_SUPPORT_OVRHDR
	T_ROVR		pk_rovr;
#endif /* TOPPERS_SUPPORT_OVRHDR */

	while (true) {
#ifdef TOPPERS_SUPPORT_OVRHDR
		SVC_PERROR(ref_ovr(TSK_SELF, &pk_rovr));
		if ((pk_rovr.ovrstat & TOVR_STA) != 0) {
			syslog(LOG_NOTICE, "task%d is running (%03d).   %s  [%ld]",
								tskno, ++n, graph[tskno-1], pk_rovr.leftotm);
		}
		else {
			syslog(LOG_NOTICE, "task%d is running (%03d).   %s",
										tskno, ++n, graph[tskno-1]);
		}
#else /* TOPPERS_SUPPORT_OVRHDR */
		syslog(LOG_NOTICE, "task%d is running (%03d).   %s",
										tskno, ++n, graph[tskno-1]);
#endif /* TOPPERS_SUPPORT_OVRHDR */
		for (i = 0; i < task_loop; i++);
		c = message[tskno-1];
		message[tskno-1] = 0;
		switch (c) {
		case 'e':
			syslog(LOG_INFO, "#%d#ext_tsk()", tskno);
			SVC_PERROR(ext_tsk());
			assert(0);
		case 's':
			syslog(LOG_INFO, "#%d#slp_tsk()", tskno);
			SVC_PERROR(slp_tsk());
			break;
		case 'S':
			syslog(LOG_INFO, "#%d#tslp_tsk(10000000)", tskno);
			SVC_PERROR(tslp_tsk(10000000));
			break;
		case 'd':
			syslog(LOG_INFO, "#%d#dly_tsk(10000000)", tskno);
			SVC_PERROR(dly_tsk(10000000));
			break;
		case 'y':
			syslog(LOG_INFO, "#%d#dis_ter()", tskno);
			SVC_PERROR(dis_ter());
			break;
		case 'Y':
			syslog(LOG_INFO, "#%d#ena_ter()", tskno);
			SVC_PERROR(ena_ter());
			break;
#ifdef CPUEXC1
		case 'z':
			syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno);
			RAISE_CPU_EXCEPTION;
			break;
		case 'Z':
			SVC_PERROR(loc_cpu());
			syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno);
			RAISE_CPU_EXCEPTION;
			SVC_PERROR(unl_cpu());
			break;
#endif /* CPUEXC1 */
		default:
			break;
		}
	}
}
void
task3(intptr_t exinf)
{
	ER_UINT	ercd;
	T_RTSK	rtsk;

	switch (++task3_count) {
	case 1:
		check_point(10);
		ercd = tloc_mtx(MTX1, 3 * TEST_TIME_CP);
		check_ercd(ercd, E_OK);

		check_point(11);
		ercd = slp_tsk();
		check_ercd(ercd, E_OK);

		check_point(0);

	case 2:
		check_point(16);
		ercd = loc_mtx(MTX1);
		check_ercd(ercd, E_OK);

		check_point(17);
		ercd = slp_tsk();
		check_ercd(ercd, E_OK);

		check_point(0);

	case 3:
		check_point(29);
		ercd = slp_tsk();
		check_ercd(ercd, E_OK);

		check_point(0);

	case 4:
		check_point(33);
		ercd = ref_tsk(TASK3, &rtsk);
		check_ercd(ercd, E_OK);

		check_assert(rtsk.tskstat == TTS_RUN);

		check_assert(rtsk.actcnt == 0U);

		ercd = ext_tsk();
		check_ercd(ercd, E_OK);

		check_point(0);

	case 5:
		check_point(47);
		ercd = dis_ter();
		check_ercd(ercd, E_OK);

		ercd = slp_tsk();
		check_ercd(ercd, E_RASTER);

		check_point(50);
		ercd = ref_tsk(TASK3, &rtsk);
		check_ercd(ercd, E_OK);

		check_assert(rtsk.tskstat == TTS_RUN);

		check_assert(rtsk.raster == true);

		check_assert(rtsk.dister == true);

		check_point(51);
		ercd = slp_tsk();
		check_ercd(ercd, E_RASTER);

		ercd = ena_ter();
		check_ercd(ercd, E_OK);

		check_point(0);

	case 6:
		check_point(54);
		ercd = dis_ter();
		check_ercd(ercd, E_OK);

		ercd = sus_tsk(TSK_SELF);
		check_ercd(ercd, E_OK);

		check_point(57);
		ercd = ref_tsk(TASK3, &rtsk);
		check_ercd(ercd, E_OK);

		check_assert(rtsk.tskstat == TTS_RUN);

		check_assert(rtsk.raster == true);

		check_assert(rtsk.dister == true);

		ercd = sus_tsk(TSK_SELF);
		check_ercd(ercd, E_RASTER);

		ercd = ena_ter();
		check_ercd(ercd, E_OK);

		check_point(0);

	default:
		check_point(0);
	}
	check_point(0);
}