4 * @brief Service register description and some register operations are here.
6 * @author Copyright (C) 2002 CERN. Stuart Baird
7 * @author Copyright (C) 2003 CERN. Alain Gagnaire
8 * @author Copyright (C) 2003 - 2010 CERN. Georgievskiy Yury <ygeorgie@cern.ch>
10 * @date Created on 27/02/2004
12 * @section license_sec License
13 * Released under the GPL
15 #include "driverGen.h"
17 /* describes all 'service' registers, provided by 'driverGen' */
18 SRVIOCTL srv_ioctl
[] = {
20 .name
= SRVREGPREF
"DEBUG_FLAG",
21 .comment
= "Flag Register. Enable/Disable various driver flags",
28 .name
= SRVREGPREF
"DEVINFO_T",
29 .comment
= "Full device information (info file)",
31 .regSize
= 0, /* irrelevant, so set it to zero */
36 /* This register consists of the driver version string plus driver version
37 number. From the user point of view - he should pass two memory
38 locations - first that will hold version number, second one that will
39 hold version string. */
40 .name
= SRVREGPREF
"DRVR_VERS",
42 "Driver version info (current version number and version info string)",
44 .regSize
= MAX_STR
+ 4, /* version string + version number */
49 .name
= SRVREGPREF
"DAL_CONSISTENT",
51 "driver/DAL consistency checking (comparision between the creation dates)",
57 /* ---------[ NOTE ON SPECIAL SERVICE REGISTERS ]-------------------
58 If you want to add a SPECIAL register, you should set reg access
59 rights (rar member) to zero. Register depth (depth member) should
60 be greater than zero. Such register will have one ioctl number */
62 /* This is a SPECIAL service register.
63 Handles repetitive register r/w access. Contains no data. */
64 .name
= SRVREGPREF
"REP_REG_RW",
65 .comment
= "Special ioctl number for repetitive register r/w access",
68 .rar
= 0, /* indicates special register type.
69 No menu entry in the test program as this register
74 /* SPECIAL service register.
75 Enable/Disable/Query r/w bounds checking in ioctl calls.
76 Write 1 - to enable, 0 - to disable, 2 - to query current state */
77 .name
= SRVREGPREF
"RW_BOUNDS",
78 .comment
= "Special ioctl number to enable/disable r/w bounds"
79 " checking during ioctl call",
82 .rar
= 0, /* indicates special register type.
83 No menu entry in the test program as this register
87 /* Add any new description before the last element!
89 All service register names should start with 'SRVREGPREF'
90 If you add any new service register, than you should modify
91 srvRegOps.c, testMainBegin.c and ioctl/head.c template files for
92 payload implementation of the newly defined service registers.
95 .name
= "LAST_SRV_REG",
96 .comment
= "first user-available register ID number",
100 .depth
= 0 /* indicates the last service reg element */
105 * @brief Pack Ioctl number
107 * @param opNum - number to pack. (see more in detailed description)
108 * @param a_r - register access rights
109 * @param isSrv - denotes register type (service or normal)
111 * First parameter should be zero for the first invocation of this function.
112 * This number will be properly change, so that next time user should pass the
113 * previously returned number. Pay attention to the fact that if you invoke
114 * this function once, then next time as a first parameter you should pass
115 * the number that was returned by the previous call. If not follow this
116 * rule - then discrepancy between defined ioctl numbers and driver ioctl
117 * numbers will occur.
118 * Two MSB are for 'r' operation number.
119 * Two LSB are for 'w' operation number.
126 * @return masked operation number.
128 int PackIoctlNum(int *opNum
, ARIGHTS a_r
, bool isSrv
)
130 int res
= -1; /* if r/w ioctl num is equal to 0xffff - then it means
131 that it's not defined for the given register */
135 res
= (*opNum
) << 16; /* move 'r' to the 'most significant' halfword */
139 if (!isSrv
) { /* because of "GET_HISTORY" is possible in this case! */
140 res
= (*opNum
) << 16; /* move 'r' to the 'most significant' halfword */
146 case AMRD
| AMWR
: /* 'wr' */
148 res
= (*opNum
) << 16; /* move 'r' to the 'most significant' halfword */
153 default: /* access rights not defined for this register */
154 if (isSrv
) { /* SPECIAL service reg. he's got one ioctl number!
155 (will be the same for read and write) */
156 res
= ((*opNum
) << 16) + *opNum
;
167 * @brief Build-up enumiration table header file for all module registers.
169 * @param blocks - block description
170 * @param registers - register description
171 * @param numRegisters - register amount
173 * Fill it in properly with the information from the database.
177 void BuildRegIdEnum(BlockDef_t
* blocks
, RegisterDef_t
* registers
,
180 char *bus
= TranslationGetBus(); /* 'VME' or 'DRM' */
184 fp
= OpenFile(COMMON_FT
, LOC_INCL
, "RegId.h");
185 TranslationSetFreeFormat("%s", DG_INC_DIR
);
186 Translate(fp
, bus
, "regDesc/regIdHead.h");
188 /* pass though all registers */
189 for (cntr
= 0; cntr
< numRegisters
; cntr
++) {
190 TranslationSetRegId(registers
[cntr
].upperName
);
191 TranslationSetRegComm(registers
[cntr
].comment
);
192 TranslationSetFancyString(registers
[cntr
].mode
);
194 /* first module register number should start
195 just after the last service register number */
196 TranslationSetDummyString(srv_ioctl
[GetSrvRegNum()].
198 Translate(fp
, "common", "header/regIdEnumIndexed.h");
200 Translate(fp
, "common", "header/regIdEnum.h");
204 Translate(fp
, bus
, "regDesc/regIdFoot.h");
209 * @brief Get number of all defined <E>Service Registers</E>
211 * @return amount of defined Service Registers.
215 SRVIOCTL
*ptr
= srv_ioctl
;
216 static int cntr
= -1;
218 if (cntr
== -1) { /* see if already defined */
219 cntr
= 0; /* reset it */
220 while (ptr
->depth
) { /* 0 means no more sevice registers left */
229 * @brief Converts register access rights into register access mode.
231 * @param rar - register access rights
233 * It converts from enum representation to char representation. Note that
234 * subsequent calls modifies previously reterned string. So you should save
235 * it in a local buffer before next call to this function.
237 * @return string pointer to register access mode.
239 char *rar2mode(ARIGHTS rar
)
241 static char ram
[4] = { 0, 0, 0, 0 }; /* register access mode (rwe) */
255 /* extraneous register */
265 * @brief Converts register access mode into register access rights.
267 * @param mode - register access mode (rwec)
269 * It converts from char representation to enum representation.
271 * @return register access rights
273 ARIGHTS
mode2rar(char *mode
)
278 if (strlen(mode
) > 4)
279 return (rar
); /* wrong access mode string format */
281 for (cntr
= 0; cntr
< 4; cntr
++) {
282 switch (mode
[cntr
]) {
293 rar
= 0; /* oops... */