📄 root.c
字号:
/* root.c */#include "sys_conf.h"#include <psos.h>#include <prepc.h>#include <stdio.h>#include "misc.h"#include "appl.h"ULONG qid, pid;/* ROOT task */voidroot(){ void * dummy, * part_base; ULONG ioretval, iopb[4], rc, args[4], tid1, ignored, bufs, qid, pid; char str[256], * me = "ROOT"; struct message in; /* 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"); /* Get some memory from Region #0 */ if (0 != (rc = rn_getseg(0, PART_SIZE, RN_WAIT, 0, & part_base))) fail(rc, "%s rn_getseg() failed", me); /* Tell pSOS+ to manage it as a partition of buffers */ if (0 != (rc = pt_create(PART_NAM, part_base, 0, PART_SIZE, LINE_MAX, PT_NODEL, &pid, &bufs))) fail(rc, "%s pt_create() failed", me); bprintf("Root: partition created with %d buffers\n", bufs); /* Initialize the random number generator */ srand(123456781L); /* Create the message queue */ if (0 != (rc = q_create(Q_NAM, 10, Q_LIMIT, & qid))) fail(rc, "%s q_create(%s) failed", me, Q_NAM); /* Create and start the other task */ args[0] = (ULONG) T1_NAM; /* His name */ args[1] = qid; /* The queue to use */ args[2] = pid; /* The partition to use */ args[3] = 0; if (rc = t_create(T1_NAM, 128, 1024, 1024, 0, &tid1)) fail(rc, "root: t_create(%s)", T1_NAM); if (rc = t_start(tid1, 0, (void(*)()) tsk1, args)) fail(rc, "root: t_start(%s)", T1_NAM); /* Finally, lower root's priority to the same as the other task */ t_setpri(0, 128, &ignored); /* Main loop */ for (;;) { if (0 != (rc = q_receive(qid, Q_WAIT, 0, (ULONG *)&in))) fail(rc, "%s q_receive(%s) failed", me, Q_NAM); bprintf("%2d: ", in.leng); if (in.pbuf == ((char *) 0)) { bprintf("<EOF>\n"); break; } str[0] = '\0'; strncat(str, in.pbuf, in.leng); bprintf("%s\n", str); if (0 != (rc = pt_retbuf(in.ptid, in.pbuf))) fail(rc, "%s pt_retbuf(0x%x, 0x%x)\n", in.ptid, (ULONG) in.pbuf); } /* Delete the message queue */ if (0 != (rc = q_delete(qid))) fail(rc, "%s q_delete(%s) failed", me, Q_NAM); /* Delete the buffer partition */ if (0 != (rc = pt_delete(pid))) fail(rc, "%s pt_delete failed", me); /* Return the memory to pSOS+ Region #0 */ if (0 != (rc = rn_retseg(0, part_base))) fail(rc, "%s rn_retseg failed", me); /* Example finished */ bprintf("Root task end\n"); bpflush(); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -