Anti-Sway Capstone 1.0
Loading...
Searching...
No Matches
thread-lib.h
Go to the documentation of this file.
1
12#ifndef THREAD_LIB_H_
13#define THREAD_LIB_H_
14
15#include <stdbool.h>
16#include <pthread.h>
17
18#include "MyRio.h"
19#include "AIO.h"
20#include "NiFpga.h"
21#include "DIIRQ.h"
22#include "TimerIRQ.h"
23#include "io.h"
24
25#include "setup.h"
26
27
28/* Thread Data Structures */
29
30
36typedef struct {
37 NiFpga_IrqContext irq_context;
38 NiFpga_Bool irq_thread_rdy;
40
41
42/* Time Constants */
43
44
46#define BTI_US 5000u
48#define BTI_MS 5u
50#define BTI_S 0.005
51
52
53/* Physical Constants */
54
55
57#define g 9.81
59#define PI 3.141592653549
61#define l 0.47
63#define m_dt 2.092
65#define m_st 0.664
67#define m_p 0.765
68
69
70/* MyRio Session */
71
73extern NiFpga_Session myrio_session;
74
75
76/* Thread Construction/Destruction */
77
78
94#define START_THREAD(thread, function, resource) \
95 resource.irq_thread_rdy = true; \
96 VERIFY(error, pthread_create(&thread, NULL, function, &resource))
97
108#define REGISTER_TIMER(resource) \
109 Irq_RegisterTimerIrq(&timer, &(resource.irq_context), BTI_US)
110
126#define STOP_THREAD(thread, resource) \
127 resource.irq_thread_rdy = false; \
128 VERIFY(error, pthread_join(thread, NULL))
129
139#define UNREGISTER_TIMER(resource) \
140 Irq_UnregisterTimerIrq(&timer, resource.irq_context)
141
153#define TIMER_TRIGGER(irq_assert, resource) \
154 Irq_Wait(resource->irq_context, \
155 TIMERIRQNO, \
156 &irq_assert, \
157 (NiFpga_Bool *) &(resource->irq_thread_rdy)); \
158 NiFpga_WriteU32(myrio_session, IRQTIMERWRITE, BTI_US); \
159 NiFpga_WriteBool(myrio_session, IRQTIMERSETTIME, NiFpga_True)
160
167#define EXIT_THREAD() \
168 pthread_exit(NULL); \
169 return NULL
170
171#endif // THREAD_LIB_H_
Sensor/Actuator (Input/Output) Interfacing Library Header.
System Setup Header.
Parameter for Threading Functions.
Definition thread-lib.h:36
NiFpga_IrqContext irq_context
context
Definition thread-lib.h:37
NiFpga_Bool irq_thread_rdy
stop signal
Definition thread-lib.h:38
NiFpga_Session myrio_session
The MyRio Session.