Esempio n. 1
0
void supervisor_init(void)
{
	trace_init();

	thinkos_thread_create_inf((void *)supervisor_task, (void *)NULL,
							  &supervisor_inf);
}
Esempio n. 2
0
struct telnet_svc * telnet_svc_init(int port)
{  
	struct telnet_svc * tn = &telnet_svc;
	int th;

	if (port == 0)
		port = 23; /* use default TELNET srvice port */

	tn->svc = tcp_alloc();
	tn->tp = NULL;
	tcp_bind(tn->svc, INADDR_ANY, htons(port));

	if (tcp_listen(tn->svc, 1) != 0) {
		INF("Can't register the TCP listner!");
		return NULL;
	}

	tn->rx.nonempty_flag = thinkos_flag_alloc();
	tn->rx.nonfull_flag = thinkos_flag_alloc();
	tn->rx.head = 0;
	tn->rx.tail = 0;

	th = thinkos_thread_create_inf((void *)telnet_input_task, (void *)tn, 
								   &telnet_srv_inf);
	(void)th;
								
	INF("TELNET TCP input thread=%d", th);

	return tn;
}
Esempio n. 3
0
int ifnet_init(void)
{
	__ifnet__.evset = thinkos_ev_alloc();

	DCC_LOG(LOG_TRACE, "thinkos_thread_create_inf()");
	thinkos_thread_create_inf((void *)ifnet_input_task, NULL, &ifnet_input_inf);

	return 0;
}
Esempio n. 4
0
int webserver_start(void)
{
	struct httpd * httpd;

	httpd = httpd_alloc();

	httpd_init(httpd, 80, 4, httpd_dir, NULL);

	return thinkos_thread_create_inf((void *)http_server_task,
			(void *)httpd, &httpd_inf);
}
Esempio n. 5
0
File: usb.c Progetto: k0059/yard-ice
int usb_shell(void)
{
	int th;

	th = thinkos_thread_create_inf((void *)usb_task, NULL, 
								   &usb_shell_inf);

	tracef("USB CDC-ACM shell thread=%d", th);

	return th;
}
Esempio n. 6
0
int tftpd_start(void)
{
	int th;

	th = thinkos_thread_create_inf((void *)tftp_daemon_task, 
								   (void *)&debugger, &tftpd_inf);

	tracef("TFTPD started th=%d", th);

	return 0;
}
Esempio n. 7
0
void supervisor_init(void)
{
	monitor_stream = stdout;
	thinkos_thread_create_inf((void *)supervisor_task, (void *)NULL,
							  &supervisor_inf);
}
Esempio n. 8
0
void supervisor_init(void)
{
	static uint32_t supervisor_stack[256];

	static const struct thinkos_thread_inf supervisor_inf = {
		.stack_ptr = supervisor_stack,
		.stack_size = sizeof(supervisor_stack),
		.priority = 8,
		.thread_id = 2,
		.paused = false,
		.tag = "SUPV"
	};

	trace_init();

	thinkos_thread_create_inf((void *)supervisor_task, (void *)NULL,
							  &supervisor_inf);
}

/* -------------------------------------------------------------------------
 * MS/TP 
 * ------------------------------------------------------------------------- */

int mstp_lnk_task(void * arg)
{
	struct mstp_lnk * mstp = (struct mstp_lnk *)arg;

	printf("MS/TP link task started...\n");

	mstp_lnk_loop(mstp);

	return 0;
}

struct net_stats {
	struct {
		unsigned int octet_cnt;
		unsigned int bcast_cnt;
		unsigned int unicast_cnt;
	} rx;
	struct {
		unsigned int octet_cnt;
		unsigned int bcast_cnt;
		unsigned int unicast_cnt;
	} tx;
};

struct {
	struct mstp_lnk * mstp;
	struct net_stats stats;
} net;

int net_recv_task(void * arg)
{
	struct mstp_lnk * mstp = (struct mstp_lnk *)arg;
	struct mstp_frame_inf inf;
	uint8_t pdu[502];
	int len;
	unsigned int seconds = 10;
	uint32_t clk;

	INF("MS/TP receive task started...");

	clk = thinkos_clock() + seconds * 1000;
	for (;;) {
		len = mstp_lnk_recv(mstp, pdu, sizeof(pdu), &inf);
		net.stats.rx.octet_cnt += len;
		if (inf.daddr == MSTP_ADDR_BCAST)
			net.stats.rx.bcast_cnt++;
		else
			net.stats.rx.unicast_cnt++;

//		printf("RCV: %d->%d (%d) \"%s\"\n", inf.saddr, inf.daddr,
//				len, (char*)pdu);
//		DBG("RCV: %d->%d (%d)", inf.saddr, inf.daddr, len);
		/* Log summary each 5 seconds */
		if ((int32_t)(clk - thinkos_clock()) <= 0) {
			unsigned int rate;
			rate = net.stats.rx.octet_cnt / seconds;

			INF("Receive: %d bcast, %d unicast, %d octets, %d.%03d KBps.",
					net.stats.rx.bcast_cnt, net.stats.rx.unicast_cnt, net.stats.rx.octet_cnt,
					rate / 1000, rate % 1000);

			net.stats.rx.bcast_cnt = 0;
			net.stats.rx.unicast_cnt = 0;
			net.stats.rx.octet_cnt = 0;
			seconds = 10;
			clk += seconds * 1000;
		}
	}

	return 0;
}

uint32_t mstp_lnk_stack[512] __attribute__((section (".ccm")));

const struct thinkos_thread_inf mstp_lnk_inf = {
	.stack_ptr = mstp_lnk_stack,
	.stack_size = sizeof(mstp_lnk_stack),
	.priority = 1,
	.thread_id = 1,
	.paused = 0,
	.tag = "MS/TP"
};

uint32_t net_recv_stack[512];

const struct thinkos_thread_inf net_recv_inf = {
	.stack_ptr = net_recv_stack,
	.stack_size = sizeof(net_recv_stack),
	.priority = 32,
	.thread_id = 3,
	.paused = 0,
	.tag = "NET RCV"
};

struct mstp_lnk * mstp_start(int addr)
{
	struct serial_dev * ser;
	struct mstp_lnk * mstp;

	INF("1. serial port init");
	ser = stm32f_uart1_serial_dma_init(500000, SERIAL_8N1);

	INF("2. mstp_lnk_alloc()");
	mstp = mstp_lnk_alloc();

	INF("3. MS/TP link addr: %d", addr);
	mstp_lnk_init(mstp, "MS/TP1", addr, ser);

	INF("4. thinkos_thread_create_inf()");
	thinkos_thread_create_inf(mstp_lnk_task, mstp, &mstp_lnk_inf);

	thinkos_thread_create_inf(net_recv_task, mstp, &net_recv_inf);

	thinkos_sleep(100);

	printf("5. mstp_lnk_resume()");
	mstp_lnk_resume(mstp);

	return mstp;
}

/* -------------------------------------------------------------------------
 * Test
 * ------------------------------------------------------------------------- */
int test_mode = 0;

int mstp_test_task(void * arg)
{
	struct mstp_lnk * mstp = (struct mstp_lnk *)arg;
	struct mstp_frame_inf inf;
	uint8_t pdu[502];
	uint32_t clk;
	uint32_t tmo;
	unsigned int itval = 5;
	int len;
	int i;

	INF("MS/TP test task started...\n");

	clk = thinkos_clock();
	tmo = clk + itval * 1000;

	for (i = 0;; ++i) {
		if (test_mode != 0) {
			inf.daddr = MSTP_ADDR_BCAST;
			inf.type = FRM_DATA_NO_REPLY;
			len = snprintf((char *)pdu, 501, "%6d"
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog."
					" The quick brown fox jumps over the lazy dog.",
					i);
			if (mstp_lnk_send(mstp, pdu, len, &inf) < 0) {
				ERR("mstp_lnk_send() failed!");
			}
			net.stats.tx.octet_cnt += len;
			net.stats.tx.bcast_cnt++;

			/* Log summary each 10 seconds */
			if ((int32_t)(tmo - clk) <= 0) {
				unsigned int rate;

				rate = net.stats.tx.octet_cnt / itval;

				DBG("Send: %d bcasts, %d octets, %d.%03d KBps.",
						net.stats.tx.bcast_cnt, net.stats.tx.octet_cnt,
						rate / 1000, rate % 1000);

				net.stats.tx.octet_cnt = 0;
				net.stats.tx.bcast_cnt = 0;
				itval = 10;
				tmo += itval * 1000;
			}

			if (test_mode > 1) {
				thinkos_alarm(clk + test_mode * 100);
			}
		} else {
			thinkos_alarm(clk + 100);
		}
		clk = thinkos_clock();
	}

	return 0;
}

uint32_t test_stack[512];

const struct thinkos_thread_inf test_inf = {
	.stack_ptr = test_stack,
	.stack_size = sizeof(test_stack),
	.priority = 32,
	.thread_id = 32,
	.paused = 0,
	.tag = "TEST"
};

void  mstp_test_start(struct mstp_lnk * mstp)
{
	thinkos_thread_create_inf(mstp_test_task, mstp, &test_inf);
}

struct board_cfg {
    uint32_t magic;
    uint32_t mstp_addr;
    uint32_t ip_addr;
};

#define CFG_MAGIC 0x01020304
#define CFG_ADDR  0x0800ff00

void show_netmap(struct mstp_lnk * mstp)
{
	uint8_t map[16];
	unsigned int cnt;
	int i;

	cnt = mstp_lnk_getnetmap(mstp, map, sizeof(map));
	printf("\n---- Network Map ----\n");

	for (i = 0; i < cnt; ++i) {
		printf("%2d - Node %2d\n", i, map[i]);
	}

	printf("\n");
}



void show_menu(void)
{
	printf("\n===== MS/TP test =====\n");
	printf("[s] stop sending\n");
	printf("[1..9] set sending mode\n");
	printf("[n] show network map\n");
	printf("\n");
}

void motd(void)
{
	printf("\n--------- Test Application -------\n");
	printf("\n");
}