📄 task1.cc
字号:
/* Task1 * * This task is the main line for the test. It creates other * tasks which can create * * Input parameters: * argument - task argument * * Output parameters: NONE * * COPYRIGHT (c) 1997 * Objective Design Systems Ltd Pty (ODS) * All rights reserved (R) Objective Design Systems Ltd Pty * * COPYRIGHT (c) 1989-1999. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.com/license/LICENSE. * * $Id: Task1.cc,v 1.6.8.1 2003/09/04 18:46:13 joel Exp $ */#include <stdlib.h>#include <string.h>#include "System.h"void Task1::body(rtems_task_argument argument){ rtems_test_pause_and_screen_number(1); printf(" * START Task Class test *\n"); printf("%s - test argument - ", name_string()); if (argument != 0xDEADDEAD) printf("argument is not 0xDEADDEAD\n"); else printf("argument matched\n"); screen1(); rtems_test_pause_and_screen_number(2); screen2(); rtems_test_pause_and_screen_number(3); screen3(); rtems_test_pause_and_screen_number(4); screen4(); rtems_test_pause_and_screen_number(5); screen5(); rtems_test_pause_and_screen_number(6); screen6(); // do not call exit(0) from this thread as this object is static // the static destructor call delete the task which is calling exit // so exit never completes EndTask end_task("ENDT", (rtems_task_priority) 1, RTEMS_MINIMUM_STACK_SIZE * 6); end_task.start(0); rtemsEvent block_me; rtems_event_set out; block_me.receive(RTEMS_SIGNAL_0, out); printf("**** TASK 1 did not block ????\n");}void Task1::screen1(void){ // create two local task objects to connect to this task rtemsTask local_task_1 = *this; rtemsTask local_task_2; local_task_2 = *this; // check the copy constructor works printf("%s - copy constructor - ", name_string()); if (local_task_1.id_is() == id_is()) printf("local and this id's match\n"); else printf("local and this id's do not match\n"); printf("%s - copy constructor - ", name_string()); if (local_task_1.name_is() == name_is()) printf("local and this name's match\n"); else printf("local and this name's do not match\n"); // check the copy operator works printf("%s - copy operator - ", name_string()); if (local_task_2.id_is() == id_is()) printf("local and this id's match\n"); else printf("local and this id's do not match\n"); printf("%s - copy operator - ", name_string()); if (local_task_2.name_is() == name_is()) printf("local and this name's match\n"); else printf("local and this name's do not match\n"); // check that the owner of the id cannot delete this task printf("%s - not owner destroy's task - ", local_task_1.name_string()); local_task_1.destroy(); printf("%s\n", local_task_1.last_status_string()); // connect to a valid task printf("%s - connect to a local valid task name - ", local_task_2.name_string()); local_task_2.connect("TA1 ", RTEMS_SEARCH_ALL_NODES); printf("%s\n", local_task_2.last_status_string()); // connect to an invalid task printf("%s - connect to an invalid task name - ", local_task_2.name_string()); local_task_2.connect("BADT", RTEMS_SEARCH_ALL_NODES); printf("%s\n", local_task_2.last_status_string()); // connect to a task an invalid node printf("%s - connect to a task on an invalid node - ", local_task_2.name_string()); local_task_2.connect("BADT", 10); printf("%s\n", local_task_2.last_status_string()); // restart this task printf("%s - restart from a non-owner - ", name_string()); local_task_1.restart(0); printf("%s\n", local_task_1.last_status_string());}void Task1::screen2(void){ // wake after using this object printf("%s - wake after 0 secs - ", name_string()); wake_after(0); printf("%s\n", last_status_string()); printf("%s - wake after 500 msecs - ", name_string()); wake_after(500000); printf("%s\n", last_status_string()); printf("%s - wake after 5 secs - ", name_string()); wake_after(5000000); printf("%s\n", last_status_string()); printf("%s - wake when - to do\n", name_string()); rtemsTask task_1 = *this; // wake after using a connected object printf("%s - connected object wake after 0 secs - ", task_1.name_string()); task_1.wake_after(0); printf("%s\n", task_1.last_status_string()); printf("%s - connected object wake after 500 msecs - ", task_1.name_string()); task_1.wake_after(500000); printf("%s\n", task_1.last_status_string()); printf("%s - connected object wake after 5 secs - ", task_1.name_string()); task_1.wake_after(5000000); printf("%s\n", task_1.last_status_string()); printf("%s - connected object wake when - to do\n", task_1.name_string()); rtemsTask task_2; // wake after using a self object printf("%s - self object wake after 0 secs - ", task_2.name_string()); task_2.wake_after(0); printf("%s\n", task_2.last_status_string()); printf("%s - self object wake after 500 msecs - ", task_2.name_string()); task_2.wake_after(500000); printf("%s\n", task_2.last_status_string()); printf("%s - self object wake after 5 secs - ", task_2.name_string()); task_2.wake_after(5000000); printf("%s\n", task_2.last_status_string()); printf("%s - self object wake when - to do\n", task_2.name_string()); rtems_task_priority current_priority; rtems_task_priority priority; // priorities with this object printf("%s - get priority - ", name_string()); get_priority(current_priority); printf("%s, priority is %i\n", last_status_string(), current_priority); printf("%s - set priority to 512 - ", name_string()); set_priority(512); printf("%s\n", last_status_string()); printf("%s - set priority to 25 - ", name_string()); set_priority(25); printf("%s\n", last_status_string()); printf("%s - set priority to original - ", name_string()); set_priority(current_priority, priority); printf("%s, priority was %i\n", last_status_string(), priority); // priorities with connected object printf("%s - connected object get priority - ", task_1.name_string()); task_1.get_priority(current_priority); printf("%s, priority is %i\n", task_1.last_status_string(), current_priority); printf("%s - connected object set priority to 512 - ", task_1.name_string()); task_1.set_priority(512); printf("%s\n", task_1.last_status_string()); printf("%s - connected object set priority to 25 - ", task_1.name_string()); task_1.set_priority(25); printf("%s\n", task_1.last_status_string()); printf("%s - connected object set priority to original - ", task_1.name_string()); task_1.set_priority(current_priority, priority); printf("%s, priority was %i\n", task_1.last_status_string(), priority); // priorities with self object printf("%s - self object get priority - ", task_2.name_string()); task_2.get_priority(current_priority); printf("%s, priority is %i\n", task_2.last_status_string(), current_priority); printf("%s - self object set priority to 512 - ", task_2.name_string()); task_2.set_priority(512); printf("%s\n", task_2.last_status_string()); printf("%s - self object set priority to 25 - ", task_2.name_string()); task_2.set_priority(25); printf("%s\n", task_2.last_status_string()); printf("%s - self object set priority to original - ", task_2.name_string()); task_2.set_priority(current_priority, priority); printf("%s, priority was %i\n", task_2.last_status_string(), priority); rtems_unsigned32 current_note; rtems_unsigned32 note; // notepad registers for this object printf("%s - get note - ", name_string()); get_note(0, current_note); printf("%s, note is %i\n", last_status_string(), current_note); printf("%s - get with bad notepad number - ", name_string()); get_note(100, current_note); printf("%s, note is %i\n", last_status_string(), current_note); printf("%s - set note to 0xDEADBEEF - ", name_string()); set_note(0, 0xDEADBEEF); printf("%s\n", last_status_string()); printf("%s - get note - ", name_string()); get_note(0, note); printf("%s, note is 0x%08X\n", last_status_string(), note); printf("%s - set note to original value - ", name_string()); set_note(0, current_note); printf("%s\n", last_status_string()); // notepad registers for connected object printf("%s - connected object get note - ", task_1.name_string()); task_1.get_note(0, current_note); printf("%s, notepad is %i\n", task_1.last_status_string(), current_note); printf("%s - connected object get with bad notepad number - ", task_1.name_string()); task_1.get_note(100, current_note); printf("%s, note is %i\n", task_1.last_status_string(), current_note); printf("%s - connected object set note to 0xDEADBEEF - ", task_1.name_string()); task_1.set_note(0, 0xDEADBEEF); printf("%s\n", task_1.last_status_string()); printf("%s - connected object get note - ", task_1.name_string()); task_1.get_note(0, note); printf("%s, note is 0x%08X\n", task_1.last_status_string(), note); printf("%s - connected object set note to original value - ", task_1.name_string()); task_1.set_note(0, current_note); printf("%s\n", task_1.last_status_string()); // notepad registers for self object printf("%s - self object get note - ", task_2.name_string()); task_2.get_note(0, current_note); printf("%s, note is %i\n", task_2.last_status_string(), current_note); printf("%s - self object get with bad notepad number - ", task_2.name_string()); task_2.get_note(100, current_note); printf("%s, note is %i\n", task_2.last_status_string(), current_note); printf("%s - self object set note to 0xDEADBEEF - ", task_2.name_string()); task_2.set_note(0, 0xDEADBEEF); printf("%s\n", task_2.last_status_string()); printf("%s - self object get note - ", task_2.name_string()); task_2.get_note(0, note); printf("%s, notepad is 0x%08X\n", task_2.last_status_string(), note); printf("%s - self object set note to original value - ", task_2.name_string()); task_2.set_note(0, current_note); printf("%s\n", task_2.last_status_string()); printf(" * END Task Class test *\n");}#define RTEMS_ALL_MODES (RTEMS_PREEMPT_MASK | \ RTEMS_TIMESLICE_MASK | \ RTEMS_ASR_MASK | \ RTEMS_INTERRUPT_MASK)void Task1::screen3(void){ printf(" * START TaskMode Class test *\n"); rtemsTask self; rtemsTaskMode task_mode; rtems_mode current_mode; rtems_mode mode; printf("%s - get mode - ", self.name_string()); task_mode.get_mode(current_mode); printf("%s,\n\t mode is 0x%08X, ", task_mode.last_status_string(), current_mode); print_mode(current_mode, RTEMS_ALL_MODES); printf("\n"); // PREEMPTION mode control printf("%s - get preemption state - ", self.name_string()); task_mode.get_preemption_state(mode); printf("%s,\n\t mode is 0x%08X, ", task_mode.last_status_string(), mode); print_mode(mode, RTEMS_PREEMPT_MASK); printf("\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -