标签:res use 空闲 image 函数调用 border 单位 返回 开始
void os_sys_init (
void (*task)(void) ); /* 操作系统启动后执行的任务 */
#include <rtl.h>
void main (void) {
os_sys_init (task1); /* start the kernel */
while(1); /* will never come here */
}
void os_sys_init_prio (
void (*task)(void), /* Task to start */
U8 priority); /* Task priority (1-254) */
#include <rtl.h>
void main (void) {
os_sys_init_prio (task1, 10);
while(1);
}
void os_sys_init_user (
void (*task)(void), /* Task to start */
U8 priority, /* Task priority (1-254) */
void* stack, /* Task stack */
U16 size); /* Stack size */
static U64 stk1[400/8]; /* 400-byte stack */
void main (void) {
os_sys_init_user (task1, 10, &stk1, sizeof(stk1));
while(1);
}
OS_TID os_tsk_create (
void (*task)(void), /* Task to create */
U8 priority ); /* Task priority (1-254) */
OS_TID tsk1, tsk2;
__task void task1 (void) {
..
tsk2 = os_tsk_create (task2, 1);
..
}
__task void task2 (void) {
..
}
OS_TID os_tsk_create_ex (
void (*task)(void *), /* Task to create */
U8 priority, /* Task priority (1-254) */
void* argv ); /* Argument to the task */
#include <rtl.h>
OS_TID tsk1, tsk2_0, tsk2_1;
int param[2] = {0, 1};
__task void task1 (void) {
..
tsk2_0 = os_tsk_create_ex (task2, 1, ¶m[0]);
tsk2_1 = os_tsk_create_ex (task2, 1, ¶m[1]);
..
}
__task void task2 (void *argv) {
..
switch (*(int *)argv) {
case 0:
printf("This is a first instance of task2.\n");
break;
case 1:
printf("This is a second instance of task2.\n");
break;
}
..
}
OS_TID os_tsk_create_user(
void (*task)(void), /* Task to create */
U8 priority, /* Task priority (1-254) */
void* stk, /* Pointer to the task‘s stack */
U16 size ); /* Number of bytes in the stack */
OS_TID tsk1,tsk2;
static U64 stk2[400/8];
__task void task1 (void) {
..
/* Create task 2 with a bigger stack */
tsk2 = os_tsk_create_user (task2, 1, &stk2, sizeof(stk2));
..
}
__task void task2 (void) {
/* We need a bigger stack here. */
U8 buf[200];
..
}
OS_TID os_tsk_create_user_ex (
void (*task)(void *), /* Task to create */
U8 priority, /* Task priority (1-254) */
void* stk, /* Pointer to the task‘s stack */
U16 size, /* Size of stack in bytes */
void* argv ); /* Argument to the task */
#include <rtl.h>
OS_TID tsk1,tsk2_0,tsk2_1;
static U64 stk2[2][400/8];
__task void task1 (void) {
..
/* Create task 2 with a bigger stack */
tsk2_0 = os_tsk_create_user_ex (task2, 1,
&stk2[0], sizeof(stk2[0]),
(void *)0);
tsk2_1 = os_tsk_create_user_ex (task2, 1,
&stk2[1], sizeof(stk2[1]),
(void *)1);
..
}
__task void task2 (void *argv) {
/* We need a bigger stack here. */
U8 buf[200];
..
switch ((int)argv) {
case 0:
printf("This is a first instance of task2.\n");
break;
case 1:
printf("This is a second instance of task2.\n");
break;
}
..
}
OS_RESULT os_tsk_delete (
OS_TID task_id ); /* Id of the task to delete */
#include <rtl.h>
OS_TID tsk3;
__task void task2 (void) {
tsk3 = os_tsk_create (task3, 0);
..
if (os_tsk_delete (tsk3) == OS_R_OK) {
printf("\n‘task 3‘ deleted.");
}
else {
printf ("\nFailed to delete ‘task 3‘.");
}
}
__task void task3 (void) {
..
}
#include <rtl.h>
void os_tsk_delete_self (void);
#include <rtl.h>
__task void task2 (void) {
..
os_tsk_delete_self();
}
#include <rtl.h>
void os_tsk_pass (void);
#include <rtl.h>
OS_TID tsk1;
__task void task1 (void) {
..
os_tsk_pass();
..
}
OS_RESULT os_tsk_prio (
OS_TID task_id, /* ID of the task */
U8 new_prio ); /* New priority of the task (1-254) */
#include <RTL.h>
OS_TID tsk1,tsk2;
__task void task1 (void) {
..
os_tsk_prio_self (5);
/* Changing the priority of task2 will cause a task switch. */
os_tsk_prio(tsk2, 10);
..
}
__task void task2 (void) {
..
/* Change priority of this task will cause task switch. */
os_tsk_prio_self (1);
..
}
#include <rtl.h>
OS_RESULT os_tsk_prio_self (
U8 new_prio ); /* New priority of task (1-254) */
#include <rtl.h>
OS_TID tsk1;
__task void task1 (void) {
..
os_tsk_prio_self(10); /* Increase its priority, for the critical section */
.. /* This is a critical section */
..
os_tsk_prio_self(2); /* Decrease its priority at end of critical section */
..
}
#include <rtl.h>
OS_TID os_tsk_self (void);
#include <rtl.h>
OS_TID tsk1;
__task void task1 (void) {
tsk1 = os_tsk_self();
..
}
#include <rtl.h>
OS_TID isr_tsk_get (void);
#include <rtl.h>
void os_error (U32 err_code) {
/* This function is called when a runtime error is detected. */
OS_TID err_task;
switch (err_code) {
case OS_ERR_STK_OVF:
/* Identify the task with stack overflow. */
err_task = isr_tsk_get();
break;
case OS_ERR_FIFO_OVF:
break;
case OS_ERR_MBX_OVF:
break;
}
for (;;);
}
标签:res use 空闲 image 函数调用 border 单位 返回 开始
原文地址:http://www.cnblogs.com/dengxiaojun/p/26b12908015343e93337e41a7dd342cf.html