4 * @brief DataBase access to get hw module description is here.
6 * @author Copyright (C) 2002 CERN. Stuart Baird
7 * @author Copyright (C) 2003 - 2010 CERN. Georgievskiy Yury <ygeorgie@cern.ch>
9 * @date Created on 27/02/2004
11 * @section license_sec License
12 * Released under the GPL
18 #include <dbrt/dbrt.h>
19 #include "driverGen.h"
20 #include "utilities.h"
22 static void PrintOutVmeInfo(VmeInfo_t
*);
23 static void dbrt_error_printout();
26 * @brief Get register description from the DataBase.
28 * @param moduleName -- DataBase Module Name
29 * @param defs -- register description to put
30 * @param blks -- block description
31 * @param numBlks -- number of blocks
32 * @param prog -- program name
34 * Registers are prepared for the further use. If MAX allowed register amount
35 * reached - printout error message and exits.
37 * @return number of registers, defined in the DB.
39 int DBGetRegisterConfig(char *moduleName
, RegisterDef_t
*defs
,
40 BlockDef_t
*blks
, int numBlks
, char *prog
)
43 int idx
= 0; /* register counter */
46 DbrtRegData
*record
; /* */
48 maxReg
= MAX_REG
- GetSrvRegNum(); /* how many reg descr we can have */
50 /* pass through all register records */
51 while ((record
= DbrtBiscotoRD(moduleName
, ++seqno
)) != NULL
) {
53 /* setup pointer to block information that
54 register belongs to */
55 for (cntr
= 0; cntr
< numBlks
; cntr
++) {
56 if (blks
[cntr
].blockID
== record
->blockno
) {
57 defs
[idx
].blockP
= &blks
[cntr
];
62 defs
[idx
].timeLoop
= record
->timeloop
;
63 defs
[idx
].offset
= record
->regoffset
;
64 defs
[idx
].depth
= record
->regdepth
;
66 snprintf(defs
[idx
].size
, SIZE_LEN
, "%s",
68 snprintf(defs
[idx
].mode
, MODE_LEN
, "%s",
70 snprintf(defs
[idx
].name
, NAME_LEN
, "%s",
72 snprintf(defs
[idx
].comment
, COMMENT_LEN
, "%s",
75 idx
++; /* increase register counter */
78 dbrt_error_printout(__FUNCTION__
);
80 if (idx
>= maxReg
) { /* check if within range */
82 "%sFATAL%s %s Module %s has too many registers.\n",
83 RED_CLR
, END_CLR
, ERROR_MSG
, moduleName
);
84 fprintf(stderr
, "\t'%s' supports MAX %d registers (including"
85 " service registers).\n\tYour module has %d register"
86 " definitions (plus %d service registers)\n\t'MAX_REG'"
87 " should be changed.\n\tPlease report this problem to"
88 " the DriverGen support!\n",
89 prog
, MAX_REG
, idx
, GetSrvRegNum());
90 exit(EXIT_FAILURE
); /* 1 */
93 defs
[idx
-1].last
= 1; /* mark last register */
98 * @brief Get block configuration from the DataBase.
100 * @param moduleName -- DataBase Module Name
101 * @param defs -- results will go here
102 * @param prog -- program name
104 * prepare results for the further use. If MAX allowed block amount
105 * reached - printout error message and exits.
107 * @return number of defined blocks
109 int DBGetBlockConfig(char *moduleName
, BlockDef_t
* defs
, char *prog
)
111 int currentBlock
= -1;
113 int idx
= 0; /* block counter */
116 /* pass through all register records */
117 while ((record
= DbrtBiscotoRD(moduleName
, ++seqno
)) != NULL
) {
118 if (currentBlock
!= record
->blockno
) {
119 currentBlock
= record
->blockno
;
121 defs
[idx
].blockID
= (short)record
->blockno
;
122 defs
[idx
].blkBaseAddr
= (short)record
->address
;
123 defs
[idx
].offset
= (long)record
->blockoffset
;
125 idx
++; /* increase block counter */
129 dbrt_error_printout(__FUNCTION__
);
131 if (idx
>= MAX_BLK
) { /* check if within range */
132 fprintf(stderr
, "%sFATAL%s %s Module %s has too many blocks.\n",
133 RED_CLR
, END_CLR
, ERROR_MSG
, moduleName
);
134 fprintf(stderr
, "\t'%s' supports MAX %d blocks.\n\tYour module"
135 " has %d block definitions\n\t'MAX_BLK' should be"
136 " changed.\n\tPlease report this problem to the"
137 " DriverGen support!\n", prog
, MAX_BLK
, idx
);
138 exit(EXIT_FAILURE
); /* 1 */
145 * @brief Get PCI board information from the database.
147 * @param moduleName -- DataBase Module Name
148 * @param pciInfo -- results will go here
150 * @return DRIVER_GEN_OK - if PCI board info is obtained.
151 * @return DRIVER_GEN_BAD - othervise.
153 rstat
DBGetPciInfo(char *moduleName
, PciInfo_t
* pciInfo
)
155 rstat rtnStatus
= DRIVER_GEN_OK
;
156 DbrtModTypData
*record
= NULL
;
158 record
= DbrtModulType(moduleName
);
160 if (record
!= NULL
) {
161 sscanf(record
->vendorid
, "%lx", &(pciInfo
->vendorId
));
162 sscanf(record
->deviceid
, "%lx", &(pciInfo
->deviceId
));
164 pciInfo
->vendorId
= ASSERT_MSB(pciInfo
->vendorId
);
165 pciInfo
->deviceId
= ASSERT_MSB(pciInfo
->deviceId
);
171 fprintf(stderr
, "Failed to read pci config data.\n");
173 "DbrtBiscotoRD failed with error %d: %s\n",
174 DbrtError
, DbrtErr(DbrtError
));
175 rtnStatus
= DRIVER_GEN_BAD
;
188 * @brief Get VME board information from the database.
190 * @param moduleName -- DataBase Module Name
191 * @param vmeInfo -- results will go here
193 * @return DRIVER_GEN_OK - if VME board info is obtained.
194 * @return DRIVER_GEN_BAD - othervise.
196 rstat
DBGetVmeInfo(char *moduleName
, VmeInfo_t
*vmeInfo
)
198 rstat rtnStatus
= DRIVER_GEN_OK
;
199 DbrtModTypData
*record
= NULL
;
201 record
= DbrtModulType(moduleName
);
203 if (record
!= NULL
) { /* DB record hit */
204 /* setup first address space */
205 vmeInfo
->addr1
.baseAddr
= (record
->initbasaddr
) ?
206 record
->initbasaddr
: NO_ADDRESS
;
207 vmeInfo
->addr1
.range
= record
->initrange
;
208 vmeInfo
->addr1
.increment
= record
->initincrement
;
209 vmeInfo
->addr1
.dpSize
= record
->initdsize
;
212 Supported Addresses are:
214 => STANDART - [A24D16]
215 => EXTENDED - [A32D32]
216 => CONFIG SPACE - [A24D08O]
218 if (!strcmp(record
->initasize
, "SH"))
219 vmeInfo
->addr1
.addressModifier
= DG_AM_SH
;
220 else if (!strcmp(record
->initasize
, "ST"))
221 vmeInfo
->addr1
.addressModifier
= DG_AM_ST
;
222 else if (!strcmp(record
->initasize
, "EX"))
223 vmeInfo
->addr1
.addressModifier
= DG_AM_EX
;
224 else if (!strcmp(record
->initasize
, "CR"))
225 vmeInfo
->addr1
.addressModifier
= DG_AM_CR
;
226 else if (!strcmp(record
->initasize
, "-")) ; /* not defined */
228 fprintf(stderr
, "Unsupported AM (%s) detected for"
229 " addr1. Check DB configuration!\n",
231 return DRIVER_GEN_BAD
;
234 /* setup second address space */
235 vmeInfo
->addr2
.baseAddr
= (record
->nextbasaddr
) ?
236 record
->nextbasaddr
: NO_ADDRESS
;
237 vmeInfo
->addr2
.range
= record
->nextrange
;
238 vmeInfo
->addr2
.increment
= record
->nextincrement
;
239 vmeInfo
->addr2
.dpSize
= record
->nextdsize
;
241 if (!strcmp(record
->nextasize
, "SH"))
242 vmeInfo
->addr2
.addressModifier
= DG_AM_SH
;
243 else if (!strcmp(record
->nextasize
, "ST"))
244 vmeInfo
->addr2
.addressModifier
= DG_AM_ST
;
245 else if (!strcmp(record
->nextasize
, "EX"))
246 vmeInfo
->addr2
.addressModifier
= DG_AM_EX
;
247 else if (!strcmp(record
->nextasize
, "CR"))
248 vmeInfo
->addr2
.addressModifier
= DG_AM_CR
;
249 else if (!strcmp(record
->nextasize
, "-")) ; /* not defined */
251 fprintf(stderr
, "Unsupported AM (%s) detected for"
252 " addr2. Check DB configuration!\n",
254 return DRIVER_GEN_BAD
;
257 /* info, common to both address spaces */
258 vmeInfo
->mtn
= record
->typeno
;
259 vmeInfo
->chCntr
= record
->channelcount
;
260 vmeInfo
->irq
= record
->ilevel
;
261 vmeInfo
->vector
= record
->ivector
;
262 vmeInfo
->vectorInc
= record
->ivectorinc
;
264 if (verboseMode
) /* verbose driverGen */
265 PrintOutVmeInfo(vmeInfo
);
266 } else { /* DB record miss */
271 fprintf(stderr
, "Failed to read VME config data.\n"
272 "DbrtBiscotoRD failed with error %d: %s\n",
273 DbrtError
, DbrtErr(DbrtError
));
274 rtnStatus
= DRIVER_GEN_BAD
;
286 * @brief Printout VME configuration info.
288 * @param vmeInfo -- data to print
292 static void PrintOutVmeInfo(VmeInfo_t
* vmeInfo
)
298 printf("General information\n");
299 printf("-------------------\n");
300 printf("Module type number => %d\n", vmeInfo
->mtn
);
301 printf("Number of data channels => %s\n",
302 (vmeInfo
->chCntr
== -1) ? "NOT_DEFINED" : itoa(vmeInfo
->chCntr
,
304 printf("Interrupt processing hardware level => %s\n",
305 (vmeInfo
->irq
== -1) ? "NOT_DEFINED" : itoa(vmeInfo
->irq
, 10));
306 printf("Interrupt vector => %s\n",
307 (vmeInfo
->vector
== -1) ? "NOT_DEFINED" : itoa(vmeInfo
->vector
,
309 printf("Interrupt vector increment => %ld\n",
313 /* address space specific information */
314 printf("Address space information\n");
315 printf("-------------------------\n");
316 ptr
= &(vmeInfo
->addr1
);
317 for (cntr
= 0; cntr
< 2; cntr
++, ptr
++) {
318 if (ptr
->baseAddr
== NO_ADDRESS
) {
319 printf("\nAddress space 'Addr%d' not defined.\n",
323 printf("Address space 'Addr%d' info:\n", cntr
+ 1);
324 printf("\tBase address => 0x%lx\n", ptr
->baseAddr
);
325 printf("\tAddress range => 0x%x\n", ptr
->range
);
326 printf("\tAddress increment => 0x%lx\n",
328 printf("\tDataport size => %ld\n", ptr
->dpSize
);
329 printf("\tAddress modifier => %s\n",
330 (ptr
->addressModifier
==
331 16) ? "SH - short" : (ptr
->addressModifier
==
332 24) ? "ST - standard" :
339 * @brief Printout DBRT error.
341 * @param dbrtFN -- function name
345 static void dbrt_error_printout(char *dbrtFN
)
347 /* see '/ps/local/Linux/dbrt/dbrt.h' file for more info about possible
348 errors and their meaning */
353 fprintf(stderr
, "%s() failed to read Module config data from"
354 " the DB with error [%d] => '%s'\n",
355 dbrtFN
, DbrtError
, DbrtErr(DbrtError
));