Revision 109
Wireless library now uses the same code for timers on mac and linux.
trunk/code/lib/src/libwireless/wireless.c | ||
---|---|---|
6 | 6 |
#include "wl_defs.h" |
7 | 7 |
|
8 | 8 |
#ifndef ROBOT |
9 |
#include <time.h> |
|
9 |
#include <sys/time.h>
|
|
10 | 10 |
#include <signal.h> |
11 | 11 |
#else |
12 | 12 |
#include <time.h> |
... | ... | |
34 | 34 |
PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS]; |
35 | 35 |
|
36 | 36 |
#ifndef ROBOT |
37 |
timer_t wl_timeout_timer; |
|
38 | 37 |
|
39 | 38 |
//called when we time out, or receive interrupt |
40 | 39 |
void sig_handler(int signo) |
... | ... | |
73 | 72 |
rtc_init(HALF_SECOND, &wl_do_timeout); |
74 | 73 |
#endif |
75 | 74 |
#else |
76 |
//create a timer to trigger every half second |
|
77 |
struct sigevent evp; |
|
78 |
evp.sigev_signo = SIGALRM; |
|
79 |
evp.sigev_notify = SIGEV_SIGNAL; |
|
80 |
if (timer_create(CLOCK_REALTIME, &evp, &wl_timeout_timer) == -1) |
|
81 |
{ |
|
75 |
|
|
76 |
//create our timer |
|
77 |
struct itimerval timer_val; |
|
78 |
struct timeval interval; |
|
79 |
interval.tv_sec = 0; |
|
80 |
interval.tv_usec = 500000; |
|
81 |
struct timeval first_time; |
|
82 |
first_time.tv_sec = 0; |
|
83 |
first_time.tv_usec = 500000; |
|
84 |
timer_val.it_interval = interval; |
|
85 |
timer_val.it_value = first_time; |
|
86 |
if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1) |
|
87 |
{ |
|
82 | 88 |
WL_DEBUG_PRINT("Error creating a timer.\r\n"); |
89 |
perror("Failure's cause"); |
|
83 | 90 |
exit(1); |
84 | 91 |
} |
92 |
|
|
93 |
//create signal handler |
|
85 | 94 |
struct sigaction wl_sig_act; |
86 | 95 |
wl_sig_act.sa_handler = (void *)sig_handler; |
87 | 96 |
wl_sig_act.sa_flags = 0; |
88 | 97 |
sigemptyset(&wl_sig_act.sa_mask); |
89 | 98 |
sigaction(SIGALRM, &wl_sig_act, 0); |
90 | 99 |
sigaction(SIGINT, &wl_sig_act, 0); |
91 |
struct itimerspec wl_timeout_time; |
|
92 |
wl_timeout_time.it_interval.tv_sec = 0; |
|
93 |
wl_timeout_time.it_interval.tv_nsec = 500000000; |
|
94 |
wl_timeout_time.it_value.tv_sec = 0; |
|
95 |
wl_timeout_time.it_value.tv_nsec = 500000000; |
|
96 |
timer_settime(wl_timeout_timer, 0, |
|
97 |
&wl_timeout_time, NULL); |
|
98 | 100 |
#endif |
99 | 101 |
} |
100 | 102 |
|
... | ... | |
104 | 106 |
void wl_terminate() |
105 | 107 |
{ |
106 | 108 |
#ifndef ROBOT |
107 |
timer_delete(wl_timeout_timer); |
|
109 |
#ifdef _POSIX_TIMERS |
|
110 |
timer_delete(wl_timeout_timer); |
|
111 |
#endif |
|
108 | 112 |
#endif |
109 | 113 |
|
110 | 114 |
int i; |
trunk/code/projects/libwireless/test/test.c | ||
---|---|---|
32 | 32 |
} |
33 | 33 |
xbee_terminate();*/ |
34 | 34 |
wl_init(); |
35 |
wl_set_channel(0x1A); |
|
36 | 35 |
printf("Wireless initialized.\n"); |
37 | 36 |
wl_error_register(); |
38 | 37 |
wl_token_ring_register(); |
trunk/code/projects/libwireless/robotTest/Makefile | ||
---|---|---|
211 | 211 |
AVRDUDE_PROGRAMMER = avrisp |
212 | 212 |
|
213 | 213 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
214 |
AVRDUDE_PORT = /dev/ttyUSB1
|
|
214 |
AVRDUDE_PORT = /dev/ttyUSB0
|
|
215 | 215 |
# programmer connected to serial device |
216 | 216 |
|
217 | 217 |
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex |
trunk/code/projects/libwireless/lib/wireless.c | ||
---|---|---|
6 | 6 |
#include "wl_defs.h" |
7 | 7 |
|
8 | 8 |
#ifndef ROBOT |
9 |
#include <time.h> |
|
9 |
#include <sys/time.h>
|
|
10 | 10 |
#include <signal.h> |
11 | 11 |
#else |
12 | 12 |
#include <time.h> |
... | ... | |
34 | 34 |
PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS]; |
35 | 35 |
|
36 | 36 |
#ifndef ROBOT |
37 |
timer_t wl_timeout_timer; |
|
38 | 37 |
|
39 | 38 |
//called when we time out, or receive interrupt |
40 | 39 |
void sig_handler(int signo) |
... | ... | |
73 | 72 |
rtc_init(HALF_SECOND, &wl_do_timeout); |
74 | 73 |
#endif |
75 | 74 |
#else |
76 |
//create a timer to trigger every half second |
|
77 |
struct sigevent evp; |
|
78 |
evp.sigev_signo = SIGALRM; |
|
79 |
evp.sigev_notify = SIGEV_SIGNAL; |
|
80 |
if (timer_create(CLOCK_REALTIME, &evp, &wl_timeout_timer) == -1) |
|
81 |
{ |
|
75 |
|
|
76 |
//create our timer |
|
77 |
struct itimerval timer_val; |
|
78 |
struct timeval interval; |
|
79 |
interval.tv_sec = 0; |
|
80 |
interval.tv_usec = 500000; |
|
81 |
struct timeval first_time; |
|
82 |
first_time.tv_sec = 0; |
|
83 |
first_time.tv_usec = 500000; |
|
84 |
timer_val.it_interval = interval; |
|
85 |
timer_val.it_value = first_time; |
|
86 |
if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1) |
|
87 |
{ |
|
82 | 88 |
WL_DEBUG_PRINT("Error creating a timer.\r\n"); |
89 |
perror("Failure's cause"); |
|
83 | 90 |
exit(1); |
84 | 91 |
} |
92 |
|
|
93 |
//create signal handler |
|
85 | 94 |
struct sigaction wl_sig_act; |
86 | 95 |
wl_sig_act.sa_handler = (void *)sig_handler; |
87 | 96 |
wl_sig_act.sa_flags = 0; |
88 | 97 |
sigemptyset(&wl_sig_act.sa_mask); |
89 | 98 |
sigaction(SIGALRM, &wl_sig_act, 0); |
90 | 99 |
sigaction(SIGINT, &wl_sig_act, 0); |
91 |
struct itimerspec wl_timeout_time; |
|
92 |
wl_timeout_time.it_interval.tv_sec = 0; |
|
93 |
wl_timeout_time.it_interval.tv_nsec = 500000000; |
|
94 |
wl_timeout_time.it_value.tv_sec = 0; |
|
95 |
wl_timeout_time.it_value.tv_nsec = 500000000; |
|
96 |
timer_settime(wl_timeout_timer, 0, |
|
97 |
&wl_timeout_time, NULL); |
|
98 | 100 |
#endif |
99 | 101 |
} |
100 | 102 |
|
... | ... | |
104 | 106 |
void wl_terminate() |
105 | 107 |
{ |
106 | 108 |
#ifndef ROBOT |
107 |
timer_delete(wl_timeout_timer); |
|
109 |
#ifdef _POSIX_TIMERS |
|
110 |
timer_delete(wl_timeout_timer); |
|
111 |
#endif |
|
108 | 112 |
#endif |
109 | 113 |
|
110 | 114 |
int i; |
Also available in: Unified diff