14 #include "../include/tscope5/timer_internal.h"
15 #include "../include/tscope5/system_internal.h"
18 #include <sys/ioctl.h>
19 #include <linux/rtc.h>
40 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_timer\n", calling_function);
57 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_timer2\n", calling_function);
58 if (_ts5_status.timer.num_active_buttons<1) {
59 ts5_fatal(
"%s: there are no active response buttons\n",
75 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_timer3\n", calling_function);
79 if (_ts5_status.timer.parport_is_trigger_device) {
82 for (i=0; i<_ts5_status.timer.num_parports; i++) {
84 if (_ts5_status.timer.parport[i].is_trigger_input_device) {
90 if (_ts5_status.timer.serialport_is_trigger_device) {
93 for (i=0; i<_ts5_status.timer.num_serialports; i++) {
95 if (_ts5_status.timer.serialport[i].is_trigger_input_device) {
102 ts5_fatal(
"%s: there are no trigger input devices\n", calling_function);
118 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_timer4\n", calling_function);
143 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 timer\n",
146 _ts5_data.timer.response_queue = al_create_event_queue();
148 if (_ts5_data.timer.response_queue==NULL) {
149 ts5_fatal(
"%s: could not install timer\n", calling_function);
152 _ts5_data.timer.trigger_queue = al_create_event_queue();
154 if (_ts5_data.timer.trigger_queue==NULL) {
155 ts5_fatal(
"%s: could not install timer\n", calling_function);
158 _ts5_data.timer.trigger_log = al_create_event_queue();
160 if (_ts5_data.timer.trigger_log==NULL) {
161 ts5_fatal(
"%s: could not install timer\n", calling_function);
183 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 timer\n");
185 al_flush_event_queue(_ts5_data.timer.response_queue);
186 al_flush_event_queue(_ts5_data.timer.trigger_queue);
187 al_flush_event_queue(_ts5_data.timer.trigger_log);
189 al_destroy_event_queue(_ts5_data.timer.response_queue);
190 al_destroy_event_queue(_ts5_data.timer.trigger_queue);
191 al_destroy_event_queue(_ts5_data.timer.trigger_log);
219 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 realtime clock\n",
223 if (geteuid() != 0) {
224 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
225 "only root can open the realtime clock");
229 if ((_ts5_data.timer.realtime_clock
230 = open(
"/dev/rtc", O_RDONLY)) < 0) {
231 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
232 "error opening realtime clock");
235 if (ioctl(_ts5_data.timer.realtime_clock, RTC_IRQP_SET, 8192) < 0) {
236 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
237 "error setting realtime clock frequency");
240 if (ioctl(_ts5_data.timer.realtime_clock, RTC_PIE_ON, 0) < 0) {
241 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
242 "error setting realtime clock interrupts");
262 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 realtime clock\n");
265 if (ioctl(_ts5_data.timer.realtime_clock, RTC_PIE_OFF, 0) < 0) {
266 ts5_fatal(
"%s: %s\n",
"ts5_uninstall_realtime_clock",
267 "error removing realtime clock interrupts");
270 close(_ts5_data.timer.realtime_clock);
287 #elif defined TS5_LINUX
289 unsigned long timedata;
290 if (read(_ts5_data.timer.realtime_clock, &timedata,
291 sizeof(
unsigned long)) < 0) {
292 ts5_fatal(
"%s: %s\n",
"ts5_realtime_clock_nap",
293 "error reading realtime clock");