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.cedrusbox_is_trigger_device) {
82 for (i=0; i<_ts5_status.timer.num_cedrusboxes; i++) {
84 if (_ts5_status.timer.cedrusbox[i].is_trigger_input_device) {
90 if (_ts5_status.timer.parport_is_trigger_device) {
93 for (i=0; i<_ts5_status.timer.num_parports; i++) {
95 if (_ts5_status.timer.parport[i].is_trigger_input_device) {
101 if (_ts5_status.timer.serialport_is_trigger_device) {
104 for (i=0; i<_ts5_status.timer.num_serialports; i++) {
106 if (_ts5_status.timer.serialport[i].is_trigger_input_device) {
113 ts5_fatal(
"%s: there are no trigger input devices\n", calling_function);
129 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_timer4\n", calling_function);
154 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 timer\n",
157 _ts5_data.timer.response_queue = al_create_event_queue();
159 if (_ts5_data.timer.response_queue==NULL) {
160 ts5_fatal(
"%s: could not install timer\n", calling_function);
163 _ts5_data.timer.trigger_queue = al_create_event_queue();
165 if (_ts5_data.timer.trigger_queue==NULL) {
166 ts5_fatal(
"%s: could not install timer\n", calling_function);
169 _ts5_data.timer.trigger_log = al_create_event_queue();
171 if (_ts5_data.timer.trigger_log==NULL) {
172 ts5_fatal(
"%s: could not install timer\n", calling_function);
189 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 timer\n");
191 al_flush_event_queue(_ts5_data.timer.response_queue);
192 al_flush_event_queue(_ts5_data.timer.trigger_queue);
193 al_flush_event_queue(_ts5_data.timer.trigger_log);
195 al_destroy_event_queue(_ts5_data.timer.response_queue);
196 al_destroy_event_queue(_ts5_data.timer.trigger_queue);
197 al_destroy_event_queue(_ts5_data.timer.trigger_log);
225 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 realtime clock\n",
229 if (geteuid() != 0) {
230 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
231 "only root can open the realtime clock");
235 if ((_ts5_data.timer.realtime_clock
236 = open(
"/dev/rtc", O_RDONLY)) < 0) {
237 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
238 "error opening realtime clock");
241 if (ioctl(_ts5_data.timer.realtime_clock, RTC_IRQP_SET, 8192) < 0) {
242 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
243 "error setting realtime clock frequency");
246 if (ioctl(_ts5_data.timer.realtime_clock, RTC_PIE_ON, 0) < 0) {
247 ts5_fatal(
"%s: %s\n",
"ts5_install_realtime_clock",
248 "error setting realtime clock interrupts");
268 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 realtime clock\n");
271 if (ioctl(_ts5_data.timer.realtime_clock, RTC_PIE_OFF, 0) < 0) {
272 ts5_fatal(
"%s: %s\n",
"ts5_uninstall_realtime_clock",
273 "error removing realtime clock interrupts");
276 close(_ts5_data.timer.realtime_clock);
293 #elif defined TS5_LINUX
295 unsigned long timedata;
296 if (read(_ts5_data.timer.realtime_clock, &timedata,
297 sizeof(
unsigned long)) < 0) {
298 ts5_fatal(
"%s: %s\n",
"ts5_realtime_clock_nap",
299 "error reading realtime clock");
int _ts5_is_tscope5_installed
Is Tscope5 installed?
int _ts5_is_timer_installed
Is the timer subsystem installed?
int _ts5_is_realtime_clock_installed
Is the realtime clock installed.
void ts5_check_timer3(char *calling_function)
Do some checks at the start of each timer function.
void ts5_realtime_clock_nap()
Give up processor time to allow other processes to run.
void ts5_check_timer4(char *calling_function)
Do some checks at the start of each timer function.
void ts5_uninstall_realtime_clock()
Uninstall the realtime clock.
void ts5_install_timer(char *calling_function)
Install the timer subsystem.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
void ts5_check_timer2(char *calling_function)
Do some checks at the start of each timer function.
void ts5_install_tscope5(char *calling_function)
Install Tscope5.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
void ts5_uninstall_timer()
Uninstall the timer subsystem.
void ts5_install_realtime_clock(char *calling_function)
Install the realtime clock.
void ts5_check_timer(char *calling_function)
Do some checks at the start of each timer function.