📄 root.c
字号:
/* root.c */#include "sys_conf.h"#include <psos.h>#include <prepc.h>#include <stdio.h>#include "misc.h"#include "appl.h"ULONG qid1, qid2, qid3;ULONG tid;voiddrain(char * me, ULONG qid, char * qname){ ULONG rc; struct message in; char str[256]; int some = FALSE; bprintf("Draining %s:", qname); do { /* Drain Queue */ rc = q_receive(qid, Q_NOWAIT, 0, (ULONG *) &in); if (rc == 0) { some = TRUE; str[0] = '\0'; strncat(str, (char *) &(in.data), sizeof(in.data)); bprintf(" %s", str); } } while (rc == 0); if (rc != ERR_NOMSG) fail(rc, "%s q_receive(%s)", me, qname); if (some) bprintf("\n"); else bprintf(" EMPTY\n");}/* ROOT task */voidroot(){ void *dummy; ULONG ioretval, iopb[4], rc, args[4], other_tid, ignored, ev; char * me = "ROOT"; /* Initialize all drivers */ de_init(DEV_TIMER, 0, &ioretval, &dummy); de_init(DEV_SERIAL, 0, &ioretval, &dummy); bpinit(128*100); bprintf("\nRoot task begin\n"); /* Initialize the random number generator */ srand(123456781L); /* Create the three queues */ if (0 != (rc = q_create(Q1_NAM, 10, Q_LIMIT, & qid1))) fail(rc, "%s q_create(%s)", me, Q1_NAM); if (0 != (rc = q_create(Q2_NAM, 10, Q_LIMIT, & qid2))) fail(rc, "%s q_create(%s)", me, Q2_NAM); if (0 != (rc = q_create(Q3_NAM, 10, Q_LIMIT, & qid3))) fail(rc, "%s q_create(%s)", me, Q3_NAM); /* Store my Task ID */ t_ident(0, 0, &tid); /* Create and start the other task */ args[1] = args[2] = args[3] = 0; args[0] = (ULONG) T1_NAM; /* His name */ if (rc = t_create(T1_NAM, 128, 1024, 1024, 0, &other_tid)) fail(rc, "root t_create(%s)", T1_NAM); if (rc = t_start(other_tid, 0, (void(*)()) tsk1, args)) fail(rc, "root t_start(%s)", T1_NAM); /* Lower root's priority to be same as other task */ t_setpri(0, 128, &ignored); /* Main loop */ do { bprintf("%s looking for events\n", me); if (0 != (rc = ev_receive(SOMETHING, EV_WAIT | EV_ANY, 0, &ev))) fail(rc, "%s ev_receive()", me); bprintf("%s Events 0x%08x received\n", me, ev); if (ev & Q1_EV) drain(me, qid1, Q1_NAM); if (ev & Q2_EV) drain(me, qid2, Q2_NAM); if (ev & Q3_EV) drain(me, qid3, Q3_NAM); } while (!(ev & FINAL_EV)); /* Clean up */ if (0 != (rc = q_delete(qid1))) fail(rc, "%s q_delete(%s) failed", me, Q1_NAM); if (0 != (rc = q_delete(qid2))) fail(rc, "%s q_delete(%s) failed", me, Q2_NAM); if (0 != (rc = q_delete(qid3))) fail(rc, "%s q_delete(%s) failed", me, Q3_NAM); /* Example finished */ bprintf("Root task end\n"); bpflush(); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -