]> rtime.felk.cvut.cz Git - rtems-pluggable-edf.git/blob - src/test_edf/task.c
27a10ebcfc416d6e6112c809f388452032df2229
[rtems-pluggable-edf.git] / src / test_edf / task.c
1 #include <system_def.h>
2 #include "system.h"
3 #include "app_def.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <rtems/untar.h>
7 #include <rtems/error.h>
8 #include <rtems/mw_uid.h>
9 #include <errno.h>
10 #include <stdint.h>
11
12
13 #define TEST_DURATION 130
14
15 #define T1_DUR 400000000
16 #define T2_DUR 600000000
17 #define T1_PER 7
18 #define T2_PER 10
19
20 rtems_task Task_1(
21   rtems_task_argument argument
22 )
23 {
24   rtems_name name;
25   rtems_id period;
26   rtems_status_code status;
27   char output1[50];
28   char output2[50];
29   unsigned int start, stop, period_length, max_i, max_j;
30   unsigned int i,j,k;
31   
32   name = rtems_build_name( 'P', 'E', 'R', 'A' );
33   status = rtems_rate_monotonic_create( name, &period );
34   
35   if ( status != RTEMS_SUCCESSFUL ) {
36         printf( "rtems_monotonic_create failed with status of %d.\n", status);
37             exit( 1 );
38   }
39   
40   period_length = T1_PER; // duration 3 ticks
41   max_i = 10000; max_j = T1_DUR;
42   edf_deadline_init(period_length);
43   while ( 1 ) {
44           if (rtems_rate_monotonic_period(period,period_length)==RTEMS_TIMEOUT)
45                      puts("P1 - Deadline miss");
46           edf_next_period();
47           rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start);
48           sprintf(output1,"P1-S  ticks:%u",start);
49           puts(output1);
50           
51           if ( start >= TEST_DURATION ) break;
52           
53           /* active computing */ 
54           for ( i = 1 ; i < max_i; i++) 
55           { 
56                   j =  i/12 ; j++;
57                   for ( j = 1; j < max_j; j++) 
58                   {
59                           k = j/ 3; 
60                           k++;                    
61                  }
62           }
63          
64           rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop);
65           sprintf(output2,"P1-F  ticks:%u",stop);
66           puts(output2);
67   }
68   
69   /* missed period so delete period and SELF */
70   status = rtems_rate_monotonic_delete( period );
71   edf_deadline_cancel();
72   if ( status != RTEMS_SUCCESSFUL ) {
73           printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
74           exit( 0 );
75   }
76   
77   puts( "*** END OF TEST - edf***" );
78   exit( 0 );
79 }
80
81
82
83
84 rtems_task Task_2(
85   rtems_task_argument argument
86 )
87 {
88   rtems_name name;
89   rtems_id period;
90   rtems_status_code status;
91   char output1[50];
92   char output2[50];
93   unsigned int start, stop, period_length, max_i, max_j;
94   unsigned int i,j,k;
95           
96   name = rtems_build_name( 'P', 'E', 'R', 'B' );
97   status = rtems_rate_monotonic_create( name, &period );
98   if ( status != RTEMS_SUCCESSFUL ) {
99         printf( "rtems_monotonic_create failed with status of %d.\n", status );
100             exit( 1 );
101   }
102   
103   period_length = T2_PER; // duration 5 ticks
104   max_i = 10000; max_j = T2_DUR;
105   edf_deadline_init(period_length);
106   while ( 1 ) {
107           if (rtems_rate_monotonic_period(period,period_length)==RTEMS_TIMEOUT)
108                   puts("P2 - Deadline miss");
109           edf_next_period();
110           rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start);
111           sprintf(output1,"P2-S  ticks:%u",start);
112           puts(output1);
113           
114           if ( _Watchdog_Ticks_since_boot >= TEST_DURATION ) {
115                   break;
116           }
117   
118           /* active computing */
119           
120           for ( i = 1 ; i < max_i; i++) 
121           { 
122                   j =  i/12 ; j++;
123                   for ( j = 1; j < max_j; j++) 
124                   {
125                           k = j/ 3; 
126                           k++;                    
127                  }
128           }
129           
130           rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop);
131           sprintf(output2,"P2-F  ticks:%u",stop);
132           puts(output2); 
133   }
134
135   /* missed period so delete period and SELF */
136   status = rtems_rate_monotonic_delete( period );
137   edf_deadline_cancel();
138   if ( status != RTEMS_SUCCESSFUL ) {
139           printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
140           exit( 0 );
141   }
142   
143   puts( "*** END OF TEST - edf***" );
144   exit( 0 );
145 }
146