-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoscaInit.c
102 lines (90 loc) · 2.61 KB
/
toscaInit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <epicsThread.h>
#include <initHooks.h>
#include <epicsExit.h>
#include "toscaIntr.h"
#include "toscaDma.h"
#include <epicsExport.h>
#include "toscaInit.h"
#define TOSCA_DEBUG_NAME toscaInit
#include "toscaDebug.h"
epicsExportAddress(int, toscaInitDebug);
int toscaIntrPrio = 80;
epicsExportAddress(int, toscaIntrPrio);
int toscaDmaPrio = 80;
epicsExportAddress(int, toscaDmaPrio);
int toscaIntrLoopStart(void)
{
epicsThreadId tid;
debug("starting interrupt handler thread");
tid = epicsThreadCreate("irq-TOSCA", toscaIntrPrio,
epicsThreadGetStackSize(epicsThreadStackMedium),
(EPICSTHREADFUNC)toscaIntrLoop, NULL);
if (!tid) {
debugErrno("starting irq-TOSCA thread");
return -1;
}
debug("irq-TOSCA tid = %p", tid);
return 0;
}
int toscaDmaLoopsStart(unsigned int n)
{
epicsThreadId tid;
unsigned int i;
int status = 0;
debug("starting dma handler threads");
for (i = 1; i <= n; i++)
{
char name[32];
sprintf(name, "dma%d-TOSCA", i);
tid = epicsThreadCreate(name, toscaDmaPrio,
epicsThreadGetStackSize(epicsThreadStackMedium),
(EPICSTHREADFUNC)toscaDmaLoop, NULL);
if (!tid) {
debugErrno("starting %s thread", name);
status = -1;
}
else debug("%s tid = %p", name, tid);
}
return status;
}
void toscaInitHook(initHookState state)
{
unsigned int n;
switch (state) {
case initHookAfterInitDrvSup:
n = toscaNumDevices();
if (n == 0)
{
fprintf(stderr,
"No Tosca device found. Kernel driver not loaded?\n");
return;
}
if (toscaInitDebug > 0)
{
unsigned int device, type;
for (device = 0; device < n; device++)
{
type = toscaDeviceType(device);
printf("Tosca device %u: %04x\n", device, type);
}
}
toscaInstallSpuriousVMEInterruptHandler();
break;
case initHookAfterInterruptAccept:
toscaIntrLoopStart();
toscaDmaLoopsStart(toscaDeviceType(0) == 0x1210 ? 2 : 4);
break;
case initHookAtEnd:
/* register as late as possible to run as early as possible */
epicsAtExit(toscaDmaLoopsStop,NULL);
epicsAtExit(toscaIntrLoopStop,NULL);
break;
default:
break;
}
}
static void toscaInitRegistrar ()
{
initHookRegister(toscaInitHook);
}
epicsExportRegistrar(toscaInitRegistrar);