1 | /* Tasks_Periodic |
---|
2 | * |
---|
3 | * This routine serves as a test task for the CBS scheduler |
---|
4 | * implementation. |
---|
5 | * |
---|
6 | * Input parameters: |
---|
7 | * argument - task argument |
---|
8 | * |
---|
9 | * Output parameters: NONE |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #include "system.h" |
---|
19 | |
---|
20 | rtems_task Task_Periodic( |
---|
21 | rtems_task_argument argument |
---|
22 | ) |
---|
23 | { |
---|
24 | rtems_id rmid; |
---|
25 | rtems_status_code status; |
---|
26 | |
---|
27 | time_t approved_budget, exec_time, abs_time, current_budget; |
---|
28 | |
---|
29 | int start, stop, now; |
---|
30 | |
---|
31 | qres_sid_t server_id, tsid; |
---|
32 | qres_params_t params, tparams; |
---|
33 | |
---|
34 | params.P = Period; |
---|
35 | params.Q = Execution+1; |
---|
36 | |
---|
37 | printf( "Periodic task: Create server and Attach thread\n" ); |
---|
38 | if ( qres_create_server( ¶ms, &server_id ) ) |
---|
39 | printf( "ERROR: CREATE SERVER FAILED\n" ); |
---|
40 | if ( qres_attach_thread( server_id, 0, Task_id ) ) |
---|
41 | printf( "ERROR: ATTACH THREAD FAILED\n" ); |
---|
42 | |
---|
43 | printf( "Periodic task: ID and Get parameters\n" ); |
---|
44 | if ( qres_get_sid( 0, Task_id, &tsid ) ) |
---|
45 | printf( "ERROR: GET SERVER ID FAILED\n" ); |
---|
46 | if ( tsid != server_id ) |
---|
47 | printf( "ERROR: SERVER ID MISMATCH\n" ); |
---|
48 | if ( qres_get_params( server_id, &tparams ) ) |
---|
49 | printf( "ERROR: GET PARAMETERS FAILED\n" ); |
---|
50 | if ( params.P != tparams.P || |
---|
51 | params.Q != tparams.Q ) |
---|
52 | printf( "ERROR: PARAMETERS MISMATCH\n" ); |
---|
53 | |
---|
54 | printf( "Periodic task: Detach thread and Destroy server\n" ); |
---|
55 | if ( qres_detach_thread( server_id, 0, Task_id ) ) |
---|
56 | printf( "ERROR: DETACH THREAD FAILED\n" ); |
---|
57 | if ( qres_destroy_server( server_id ) ) |
---|
58 | printf( "ERROR: DESTROY SERVER FAILED\n" ); |
---|
59 | if ( qres_create_server( ¶ms, &server_id ) ) |
---|
60 | printf( "ERROR: CREATE SERVER FAILED\n" ); |
---|
61 | |
---|
62 | printf( "Periodic task: Current budget and Execution time\n" ); |
---|
63 | if ( qres_get_curr_budget( server_id, ¤t_budget ) ) |
---|
64 | printf( "ERROR: GET REMAINING BUDGET FAILED\n" ); |
---|
65 | if ( current_budget != params.Q ) |
---|
66 | printf( "ERROR: REMAINING BUDGET MISMATCH\n" ); |
---|
67 | if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) ) |
---|
68 | printf( "ERROR: GET EXECUTION TIME FAILED\n" ); |
---|
69 | |
---|
70 | printf( "Periodic task: Set parameters\n" ); |
---|
71 | if ( qres_attach_thread( server_id, 0, Task_id ) ) |
---|
72 | printf( "ERROR: ATTACH THREAD FAILED\n" ); |
---|
73 | params.P = Period * 2; |
---|
74 | params.Q = Execution * 2 +1; |
---|
75 | if ( qres_set_params( server_id, ¶ms ) ) |
---|
76 | printf( "ERROR: SET PARAMS FAILED\n" ); |
---|
77 | if ( qres_get_params( server_id, &tparams ) ) |
---|
78 | printf( "ERROR: GET PARAMS FAILED\n" ); |
---|
79 | if ( params.P != tparams.P || |
---|
80 | params.Q != tparams.Q ) |
---|
81 | printf( "ERROR: PARAMS MISMATCH\n" ); |
---|
82 | params.P = Period; |
---|
83 | params.Q = Execution+1; |
---|
84 | if ( qres_set_params( server_id, ¶ms ) ) |
---|
85 | printf( "ERROR: SET PARAMS FAILED\n" ); |
---|
86 | if ( qres_get_appr_budget( server_id, &approved_budget ) ) |
---|
87 | printf( "ERROR: GET APPROVED BUDGET FAILED\n" ); |
---|
88 | |
---|
89 | printf( "Periodic task: Approved budget\n" ); |
---|
90 | if ( approved_budget != params.Q ) |
---|
91 | printf( "ERROR: APPROVED BUDGET MISMATCH\n" ); |
---|
92 | |
---|
93 | status = rtems_rate_monotonic_create( argument, &rmid ); |
---|
94 | directive_failed( status, "rtems_rate_monotonic_create" ); |
---|
95 | |
---|
96 | /* Starting periodic behavior of the task */ |
---|
97 | printf( "Periodic task: Starting periodic behavior\n" ); |
---|
98 | status = rtems_task_wake_after( 1 + Phase ); |
---|
99 | directive_failed( status, "rtems_task_wake_after" ); |
---|
100 | |
---|
101 | while ( FOREVER ) { |
---|
102 | if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT ) |
---|
103 | printf( "P%" PRIdPTR " - Deadline miss\n", argument ); |
---|
104 | |
---|
105 | rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start ); |
---|
106 | printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start ); |
---|
107 | if ( start > 4*Period+Phase ) break; /* stop */ |
---|
108 | /* active computing */ |
---|
109 | while(FOREVER) { |
---|
110 | rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now ); |
---|
111 | if ( now >= start + Execution ) break; |
---|
112 | |
---|
113 | if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) ) |
---|
114 | printf( "ERROR: GET EXECUTION TIME FAILED\n" ); |
---|
115 | if ( qres_get_curr_budget( server_id, ¤t_budget) ) |
---|
116 | printf( "ERROR: GET CURRENT BUDGET FAILED\n" ); |
---|
117 | if ( (current_budget + exec_time) > (Execution + 1) ) { |
---|
118 | printf( "ERROR: CURRENT BUDGET AND EXECUTION TIME MISMATCH\n" ); |
---|
119 | rtems_test_exit( 0 ); |
---|
120 | } |
---|
121 | } |
---|
122 | rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop ); |
---|
123 | printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop ); |
---|
124 | } |
---|
125 | |
---|
126 | /* delete period and SELF */ |
---|
127 | status = rtems_rate_monotonic_delete( rmid ); |
---|
128 | if ( status != RTEMS_SUCCESSFUL ) { |
---|
129 | printf("rtems_rate_monotonic_delete failed with status of %d.\n", status); |
---|
130 | rtems_test_exit( 0 ); |
---|
131 | } |
---|
132 | if ( qres_cleanup() ) |
---|
133 | printf( "ERROR: QRES CLEANUP\n" ); |
---|
134 | |
---|
135 | fflush(stdout); |
---|
136 | puts( "*** END OF TEST QRES LIBRARY ***" ); |
---|
137 | rtems_test_exit( 0 ); |
---|
138 | } |
---|