37
37
#define RTC_DEFAULT_DEVIATION 10
38
38
#define DEFAULT_TIME_OUT 2
39
39
#define SLEEPSECONDS 10
40
- #define COMEINCALLBACK 0
41
40
42
41
#define OPTARG_TO_VALUE (value , type , base ) \
43
42
do \
58
57
struct posix_timer_state_s
59
58
{
60
59
struct itimerspec it ;
61
- };
62
-
63
- struct sigev_para_s
64
- {
65
- int tim ;
66
- int interval ;
60
+ uint32_t tim ;
61
+ uint32_t deviation ;
67
62
};
68
63
69
64
/****************************************************************************
@@ -80,8 +75,9 @@ struct sigev_para_s
80
75
81
76
static void show_usage (FAR const char * progname , int exitcode )
82
77
{
83
- printf ("Usage: %s"
84
- " -s <timeout seconds>\n" ,
78
+ printf ("Usage: %s\n"
79
+ " -s <timeout seconds>\n"
80
+ " -a <timeout deviation>\n" ,
85
81
progname );
86
82
87
83
exit (exitcode );
@@ -98,7 +94,7 @@ static void parse_commandline(
98
94
int ch ;
99
95
int converted ;
100
96
101
- while ((ch = getopt (argc , argv , "s:" )) != ERROR )
97
+ while ((ch = getopt (argc , argv , "s:a: " )) != ERROR )
102
98
{
103
99
switch (ch )
104
100
{
@@ -114,6 +110,17 @@ static void parse_commandline(
114
110
posix_timer_state -> it .it_interval .tv_sec = (uint32_t )converted ;
115
111
break ;
116
112
113
+ case 'a' :
114
+ OPTARG_TO_VALUE (converted , uint32_t , 10 );
115
+ if (converted < 0 || converted > INT_MAX )
116
+ {
117
+ printf ("deviation out of range: %d\n" , converted );
118
+ show_usage (argv [0 ], EXIT_FAILURE );
119
+ }
120
+
121
+ posix_timer_state -> deviation = (uint32_t )converted ;
122
+ break ;
123
+
117
124
case '?' :
118
125
printf ("Unsupported option: %s\n" , optarg );
119
126
show_usage (argv [0 ], EXIT_FAILURE );
@@ -141,11 +148,14 @@ static uint32_t get_timestamp(void)
141
148
142
149
static void posix_timer_callback (union sigval arg )
143
150
{
144
- FAR struct sigev_para_s * sigev_para = (struct sigev_para_s * )arg .sival_ptr ;
151
+ FAR struct posix_timer_state_s * sigev_para =
152
+ (FAR struct posix_timer_state_s * )arg .sival_ptr ;
145
153
int range = get_timestamp () - (* sigev_para ).tim ;
154
+
146
155
assert_in_range (range ,
147
- (* sigev_para ).interval * 1000 - RTC_DEFAULT_DEVIATION ,
148
- (* sigev_para ).interval * 1000 + RTC_DEFAULT_DEVIATION );
156
+ sigev_para -> it .it_interval .tv_sec * 1000 - sigev_para -> deviation ,
157
+ sigev_para -> it .it_interval .tv_sec * 1000 + sigev_para -> deviation );
158
+
149
159
syslog (LOG_DEBUG , "callback trigger!!!\n" );
150
160
(* sigev_para ).tim = get_timestamp ();
151
161
}
@@ -159,7 +169,6 @@ static void test_case_posix_timer(FAR void **state)
159
169
int ret ;
160
170
timer_t timerid ;
161
171
struct sigevent event ;
162
- struct sigev_para_s sigev_para ;
163
172
164
173
FAR struct posix_timer_state_s * posix_timer_state ;
165
174
struct itimerspec it ;
@@ -170,7 +179,7 @@ static void test_case_posix_timer(FAR void **state)
170
179
event .sigev_notify = SIGEV_THREAD ;
171
180
event .sigev_notify_function = posix_timer_callback ;
172
181
event .sigev_notify_attributes = NULL ;
173
- event .sigev_value .sival_ptr = ( struct sigev_para_s * ) & sigev_para ;
182
+ event .sigev_value .sival_ptr = posix_timer_state ;
174
183
175
184
/* Create the timer */
176
185
@@ -182,8 +191,7 @@ static void test_case_posix_timer(FAR void **state)
182
191
ret = timer_settime (timerid , 0 , & (posix_timer_state -> it ), NULL );
183
192
assert_return_code (ret , OK );
184
193
185
- sigev_para .interval = posix_timer_state -> it .it_interval .tv_sec ;
186
- sigev_para .tim = get_timestamp ();
194
+ posix_timer_state -> tim = get_timestamp ();
187
195
188
196
/* Get the timer status */
189
197
@@ -209,7 +217,8 @@ int main(int argc, FAR char *argv[])
209
217
.it .it_value .tv_sec = DEFAULT_TIME_OUT ,
210
218
.it .it_value .tv_nsec = 0 ,
211
219
.it .it_interval .tv_sec = DEFAULT_TIME_OUT ,
212
- .it .it_interval .tv_nsec = 0
220
+ .it .it_interval .tv_nsec = 0 ,
221
+ .deviation = RTC_DEFAULT_DEVIATION
213
222
};
214
223
215
224
const struct CMUnitTest tests [] =
0 commit comments