📄 root.c
字号:
/*
* COPYRIGHT (c) 1995,2000 TriMedia Technologies Inc.
*
* +-----------------------------------------------------------------+
* | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
* | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH |
* | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
* | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE |
* | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE |
* | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. |
* +-----------------------------------------------------------------+
*
* Module name : root.c 1.12
*
* Module type : IMPLEMENTATION
*
* Title :
*
* Author : Juul van der Spek
*
* Last update : 15:03:06 - 00/06/19
*
* Reviewed :
*
* Revision history :
*
* Description :
*
*/
/*----------------------------includes----------------------------------------*/
#include "sys_conf.h"
#include <stdio.h>
#include <psos.h>
#include <probe.h>
/*---------------------------- Functions -------------------------------------*/
ULONG sem_enter;
ULONG sem_exit;
void handler()
{
fprintf(stderr,"******************BOEM\n");
as_return();
}
void catch() {
printf("catcher active\n");
as_catch( handler, T_PREEMPT | T_TSLICE | T_ASR | T_ISR );
t_suspend(0L);
}
void aaaa()
{
int err;
printf("aaaaaaa\n");
as_catch( handler, T_PREEMPT | T_TSLICE | T_ASR | T_ISR );
do {
err = sm_v( sem_enter );
err |= sm_p( sem_exit, SM_WAIT, 0 );
printf("TOKEN SENT\n");
} while (!err);
printf("bbbbbbb\n");
_psos_exit(0);
}
/*
* At initialistion, pSOS starts two tasks, the IDLE
* task, which does nothing but spinning at the lowest
* possible priority, and the ROOT task, which starts
* executing at the highest possible priority with
* a user provided function with prescribed name 'root'
* Root should bring up your tasking systm.
* NOTE that task functions in pSOS are not allowed
* to terminate other than with a t_suspend(0) or a
* t_delete(0):
*/
void root(void)
{
int i;
ULONG task1, task2;
printf("Hello, world at time= %d us\n", clock());
t_create( "aaaa",
4,
10000,
10000,
0,
&task1
);
t_create( "catc",
100,
10000,
10000,
0,
&task2
);
sm_create(
"semp",
1,
SM_PRIOR,
&sem_enter
);
sm_create(
"semv",
1,
SM_PRIOR,
&sem_exit
);
sm_p( sem_exit, SM_WAIT, 0 );
sm_p( sem_enter, SM_WAIT, 0 );
t_start( task1, T_PREEMPT | T_TSLICE | T_ASR | T_ISR, aaaa, 0 );
t_start( task2, T_PREEMPT | T_TSLICE | T_ASR | T_ISR, catch, 0 );
for (i=1; i<10; i++) {
sm_p( sem_enter, SM_WAIT, 0 );
sm_v( sem_exit );
printf("TOKEN RECEIVED\n");
as_send(task1,1);
as_send(task2,1);
}
sm_delete(sem_enter);
sm_delete(sem_exit);
printf("Goodbye, world\n");
t_suspend(0L);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -