driver-gen/xml-lib: Search for version header files in the correct dir
[driver-gen.git] / templates / VME / header / DrvrSimHeader.h
blobacdd7f79de511c03035203a5273117bf42c3c30e
1 #ifndef _<mod_name>_<drvr_type>_H_INCLUDE_
2 #define _<mod_name>_<drvr_type>_H_INCLUDE_
4 #ifdef __LYNXOS
5 /* only for kernel */
6 #include <dldd.h>
7 #include <kernel.h>
8 #include <kern_proto.h>
10 #include <errno.h>
11 #include <sys/types.h>
12 #include <conf.h>
13 #include <io.h>
14 #include <sys/ioctl.h>
15 #include <time.h>
16 #include <param.h>
17 #include <string.h>
18 #include <proto.h>
19 #include <proto_int.h>
20 #include <fcntl.h>
21 #include <dir.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <param.h>
25 #include <sys/stat.h>
26 #include <stdio.h>
27 #include <signal.h>
28 #include <sys/file.h>
29 #include <termio.h>
30 #include <termios.h>
31 #include <ces/vmelib.h> /* for 'pdparam_xxx' structure */
32 #include <inode.h>
34 /* system thread */
35 #include <conf.h>
36 #include <st.h>
37 #endif /* __LYNXOS */
39 #include "<dg_free_fmt>/vme_am.h" /* for VMEbus Address Modifier Codes */
40 #include "<dg_free_fmt>/ServiceRegIoctl.h"
41 #include "<dg_free_fmt>/ModuleHeader.h"
43 #if defined(__linux__) && defined (__KERNEL__)
44 #undef sel
45 #define sel poll_table_struct /* for select entry point */
46 /* only for Linux kernel */
47 #include <cdcm/cdcm.h>
48 #include "<dg_free_fmt>/swab-extra-linux.h"
49 #endif
51 /* for kernel only */
52 #if defined(__LYNXOS) || defined (__KERNEL__)
53 /* to be able to use CDCM utils inside the driver */
54 #include <cdcm/cdcmBoth.h>
55 #endif
57 /* Provides debug information printing. */
58 #define DBG_BEG(f_nm) \
59 do { \
60 if (s->info->debugFlag & DBGIOCTL) { \
61 swait(&sem_drvr, SEM_SIGIGNORE); /* lock calling thread */ \
62 cprintf("(pid %d) (tid %d) %s() ", getpid(), st_getstid(), f_nm); \
63 } \
64 } while (0)
66 /* information about the address that will be read/write */
67 #define DBG_ADDR(ra, idx, en) \
68 do { \
69 if (s->info->debugFlag & DBGIOCTL) { \
70 unsigned addr = (unsigned)ra; \
71 cprintf("[(elIdx %d) (elAm %d) @ 0x%x] ", idx, (int)en, addr); \
72 } \
73 } while (0)
75 /* ioctl completion tag */
76 #define DBG_OK() \
77 do { \
78 if (s->info->debugFlag & DBGIOCTL) { \
79 cprintf(" - OK.\n"); \
80 ssignal(&sem_drvr); /* wake up waiting thread */ \
81 } \
82 } while (0)
84 /* ioctl completion tag */
85 #define DBG_FAIL() \
86 do { \
87 if (s->info->debugFlag & DBGIOCTL) { \
88 cprintf(" - FAIL.\n"); \
89 ssignal(&sem_drvr); /* wake up waiting thread */ \
90 } \
91 } while (0)
93 /* start timing measurements. Different in case of Lynx/Linux */
94 #ifdef __Lynx__
96 #define START_TIME_STAT() \
97 do { \
98 if (s->info->debugFlag & DBGTIMESTAT) { \
99 /* because of the spatial locality reference phenomenon, fill in cache \
100 memory so that it will keep recently accessed values (in our case \
101 it is 'nanotime' sys function stuff), thus trying to avoid additional \
102 time loss induced by cache miss. \
103 Normally, '__builtin_prefetch' gcc function should be used to minimize \
104 cache-miss latency by moving data into a cache before it is accessed. \
105 But with currently used Lynx gcc (version 2.95.3 20010323 (Lynx) as \
106 of 24.04.06) it's not possible, as it's probably not supported. \
107 For more info see gcc 4.0.1 reference manual at: \
108 http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Other-Builtins.html#Other-Builtins \
109 So let's wait until newer gcc will be installed and then try the new \
110 approach. */ \
111 GlobStartN = nanotime(&GlobStartS); \
113 /* wait for the better times to implement... */ \
114 /*__builtin_prefetch(&GlobStartN, 1, 1); */ \
116 /* now we can start real timing measurements */ \
117 GlobStartN = nanotime(&GlobStartS); \
119 } while (0)
121 #else /* linux */
123 #define START_TIME_STAT() \
124 if (s->info->debugFlag & DBGTIMESTAT) getnstimeofday(&_t_beg)
126 #endif /* defined __Lynx__ */
128 /* printout measured time statistics */
129 #define FINISH_TIME_STAT() \
130 do { \
131 if (s->info->debugFlag & DBGTIMESTAT) { \
132 unsigned int retN; /* for timing measurements */ \
133 retN = ComputeTime(GlobTimeStatS); \
134 if (retN == -1) \
135 cprintf("Done in %s\n", GlobTimeStatS); \
136 else \
137 cprintf("Done in %dns (%s)\n", retN, GlobTimeStatS); \
139 } while (0)
142 #define <mod_name>_MAX_NUM_CARDS 21 /* VME crates have 21 slots max */
144 /* <mod_name> module ioctl numbers */
145 #define <mod_name>_IOCTL_MAGIC '<dg_char>'
147 #define <mod_name>_IO(nr) _IO(<mod_name>_IOCTL_MAGIC, nr)
148 #define <mod_name>_IOR(nr,sz) _IOR(<mod_name>_IOCTL_MAGIC, nr, sz)
149 #define <mod_name>_IOW(nr,sz) _IOW(<mod_name>_IOCTL_MAGIC, nr, sz)
150 #define <mod_name>_IOWR(nr,sz) _IOWR(<mod_name>_IOCTL_MAGIC, nr, sz)