4 * @brief DataBase access to get hw module description is here.
6 * @author Copyright (c) 2004 - 2009 CERN. Georgievskiy Yury
8 * @date Created on 27/02/2004
11 #include <dbrt/dbrt.h>
12 #include "driverGen.h"
13 #include "utilities.h"
15 static void PrintOutVmeInfo(VmeInfo_t
*);
16 static void dbrt_error_printout();
19 * @brief Get register description from the DataBase.
21 * @param moduleName -- DataBase Module Name
22 * @param defs -- register description to put
23 * @param blks -- block description
24 * @param numBlks -- number of blocks
25 * @param prog -- program name
27 * Registers are prepared for the further use. If MAX allowed register amount
28 * reached - printout error message and exits.
30 * @return number of registers, defined in the DB.
32 int GetRegisterConfig(char *moduleName
, RegisterDef_t
*defs
,
33 BlockDef_t
*blks
, int numBlks
, char *prog
)
36 int idx
= 0; /* register counter */
39 DbrtRegData
*record
; /* */
41 maxReg
= MAX_REG
- GetSrvRegNum(); /* how many reg descr we can have */
43 /* pass through all register records */
44 while ((record
= DbrtBiscotoRD(moduleName
, ++seqno
)) != NULL
) {
46 /* setup pointer to block information that
47 register belongs to */
48 for (cntr
= 0; cntr
< numBlks
; cntr
++) {
49 if (blks
[cntr
].blockID
== record
->blockno
) {
50 defs
[idx
].blockP
= &blks
[cntr
];
55 defs
[idx
].timeLoop
= record
->timeloop
;
56 defs
[idx
].offset
= record
->regoffset
;
57 defs
[idx
].depth
= record
->regdepth
;
59 snprintf(defs
[idx
].size
, SIZE_LEN
, "%s",
61 snprintf(defs
[idx
].mode
, MODE_LEN
, "%s",
63 snprintf(defs
[idx
].name
, NAME_LEN
, "%s",
65 snprintf(defs
[idx
].comment
, COMMENT_LEN
, "%s",
68 idx
++; /* increase register counter */
71 dbrt_error_printout(__FUNCTION__
);
73 if (idx
>= maxReg
) { /* check if within range */
75 "%sFATAL%s %s Module %s has too many registers.\n",
76 RED_CLR
, END_CLR
, ERROR_MSG
, moduleName
);
77 fprintf(stderr
, "\t'%s' supports MAX %d registers (including"
78 " service registers).\n\tYour module has %d register"
79 " definitions (plus %d service registers)\n\t'MAX_REG'"
80 " should be changed.\n\tPlease report this problem to"
81 " the DriverGen support!\n",
82 prog
, MAX_REG
, idx
, GetSrvRegNum());
83 exit(EXIT_FAILURE
); /* 1 */
86 defs
[idx
-1].last
= 1; /* mark last register */
91 * @brief Get block configuration from the DataBase.
93 * @param moduleName -- DataBase Module Name
94 * @param defs -- results will go here
95 * @param prog -- program name
97 * prepare results for the further use. If MAX allowed block amount
98 * reached - printout error message and exits.
100 * @return number of defined blocks
102 int GetBlockConfig(char *moduleName
, BlockDef_t
* defs
, char *prog
)
104 int currentBlock
= -1;
106 int idx
= 0; /* block counter */
109 /* pass through all register records */
110 while ((record
= DbrtBiscotoRD(moduleName
, ++seqno
)) != NULL
) {
111 if (currentBlock
!= record
->blockno
) {
112 currentBlock
= record
->blockno
;
114 defs
[idx
].blockID
= (short)record
->blockno
;
115 defs
[idx
].blkBaseAddr
= (short)record
->address
;
116 defs
[idx
].offset
= (long)record
->blockoffset
;
118 idx
++; /* increase block counter */
122 dbrt_error_printout(__FUNCTION__
);
124 if (idx
>= MAX_BLK
) { /* check if within range */
125 fprintf(stderr
, "%sFATAL%s %s Module %s has too many blocks.\n",
126 RED_CLR
, END_CLR
, ERROR_MSG
, moduleName
);
127 fprintf(stderr
, "\t'%s' supports MAX %d blocks.\n\tYour module"
128 " has %d block definitions\n\t'MAX_BLK' should be"
129 " changed.\n\tPlease report this problem to the"
130 " DriverGen support!\n", prog
, MAX_BLK
, idx
);
131 exit(EXIT_FAILURE
); /* 1 */
138 * @brief Get PCI board information from the database.
140 * @param moduleName -- DataBase Module Name
141 * @param pciInfo -- results will go here
143 * @return DRIVER_GEN_OK - if PCI board info is obtained.
144 * @return DRIVER_GEN_BAD - othervise.
146 rstat
GetPciInfo(char *moduleName
, PciInfo_t
* pciInfo
)
148 rstat rtnStatus
= DRIVER_GEN_OK
;
149 DbrtModTypData
*record
= NULL
;
151 record
= DbrtModulType(moduleName
);
153 if (record
!= NULL
) {
154 sscanf(record
->vendorid
, "%lx", &(pciInfo
->vendorId
));
155 sscanf(record
->deviceid
, "%lx", &(pciInfo
->deviceId
));
157 pciInfo
->vendorId
= ASSERT_MSB(pciInfo
->vendorId
);
158 pciInfo
->deviceId
= ASSERT_MSB(pciInfo
->deviceId
);
164 fprintf(stderr
, "Failed to read pci config data.\n");
166 "DbrtBiscotoRD failed with error %d: %s\n",
167 DbrtError
, DbrtErr(DbrtError
));
168 rtnStatus
= DRIVER_GEN_BAD
;
181 * @brief Get VME board information from the database.
183 * @param moduleName -- DataBase Module Name
184 * @param vmeInfo -- results will go here
186 * @return DRIVER_GEN_OK - if VME board info is obtained.
187 * @return DRIVER_GEN_BAD - othervise.
189 rstat
GetVmeInfo(char *moduleName
, VmeInfo_t
*vmeInfo
)
191 rstat rtnStatus
= DRIVER_GEN_OK
;
192 DbrtModTypData
*record
= NULL
;
194 record
= DbrtModulType(moduleName
);
196 if (record
!= NULL
) { /* DB record hit */
197 /* setup first address space */
198 vmeInfo
->addr1
.baseAddr
= (record
->initbasaddr
) ?
199 record
->initbasaddr
: NO_ADDRESS
;
200 vmeInfo
->addr1
.range
= record
->initrange
;
201 vmeInfo
->addr1
.increment
= record
->initincrement
;
202 vmeInfo
->addr1
.dpSize
= record
->initdsize
;
205 Supported Addresses are:
207 => STANDART - [A24D16]
208 => EXTENDED - [A32D32]
209 => CONFIG SPACE - [A24D08O]
211 if (!strcmp(record
->initasize
, "SH"))
212 vmeInfo
->addr1
.addressModifier
= DG_AM_SH
;
213 else if (!strcmp(record
->initasize
, "ST"))
214 vmeInfo
->addr1
.addressModifier
= DG_AM_ST
;
215 else if (!strcmp(record
->initasize
, "EX"))
216 vmeInfo
->addr1
.addressModifier
= DG_AM_EX
;
217 else if (!strcmp(record
->initasize
, "CR"))
218 vmeInfo
->addr1
.addressModifier
= DG_AM_CR
;
219 else if (!strcmp(record
->initasize
, "-")) ; /* not defined */
221 fprintf(stderr
, "Unsupported AM (%s) detected for"
222 " addr1. Check DB configuration!\n",
224 return DRIVER_GEN_BAD
;
227 /* setup second address space */
228 vmeInfo
->addr2
.baseAddr
= (record
->nextbasaddr
) ?
229 record
->nextbasaddr
: NO_ADDRESS
;
230 vmeInfo
->addr2
.range
= record
->nextrange
;
231 vmeInfo
->addr2
.increment
= record
->nextincrement
;
232 vmeInfo
->addr2
.dpSize
= record
->nextdsize
;
234 if (!strcmp(record
->nextasize
, "SH"))
235 vmeInfo
->addr2
.addressModifier
= DG_AM_SH
;
236 else if (!strcmp(record
->nextasize
, "ST"))
237 vmeInfo
->addr2
.addressModifier
= DG_AM_ST
;
238 else if (!strcmp(record
->nextasize
, "EX"))
239 vmeInfo
->addr2
.addressModifier
= DG_AM_EX
;
240 else if (!strcmp(record
->nextasize
, "CR"))
241 vmeInfo
->addr2
.addressModifier
= DG_AM_CR
;
242 else if (!strcmp(record
->nextasize
, "-")) ; /* not defined */
244 fprintf(stderr
, "Unsupported AM (%s) detected for"
245 " addr2. Check DB configuration!\n",
247 return DRIVER_GEN_BAD
;
250 /* info, common to both address spaces */
251 vmeInfo
->mtn
= record
->typeno
;
252 vmeInfo
->chCntr
= record
->channelcount
;
253 vmeInfo
->irq
= record
->ilevel
;
254 vmeInfo
->vector
= record
->ivector
;
255 vmeInfo
->vectorInc
= record
->ivectorinc
;
257 if (verboseMode
) /* verbose driverGen */
258 PrintOutVmeInfo(vmeInfo
);
259 } else { /* DB record miss */
264 fprintf(stderr
, "Failed to read VME config data.\n"
265 "DbrtBiscotoRD failed with error %d: %s\n",
266 DbrtError
, DbrtErr(DbrtError
));
267 rtnStatus
= DRIVER_GEN_BAD
;
279 * @brief Printout VME configuration info.
281 * @param vmeInfo -- data to print
285 static void PrintOutVmeInfo(VmeInfo_t
* vmeInfo
)
291 printf("General information\n");
292 printf("-------------------\n");
293 printf("Module type number => %d\n", vmeInfo
->mtn
);
294 printf("Number of data channels => %s\n",
295 (vmeInfo
->chCntr
== -1) ? "NOT_DEFINED" : itoa(vmeInfo
->chCntr
,
297 printf("Interrupt processing hardware level => %s\n",
298 (vmeInfo
->irq
== -1) ? "NOT_DEFINED" : itoa(vmeInfo
->irq
, 10));
299 printf("Interrupt vector => %s\n",
300 (vmeInfo
->vector
== -1) ? "NOT_DEFINED" : itoa(vmeInfo
->vector
,
302 printf("Interrupt vector increment => %ld\n",
306 /* address space specific information */
307 printf("Address space information\n");
308 printf("-------------------------\n");
309 ptr
= &(vmeInfo
->addr1
);
310 for (cntr
= 0; cntr
< 2; cntr
++, ptr
++) {
311 if (ptr
->baseAddr
== NO_ADDRESS
) {
312 printf("\nAddress space 'Addr%d' not defined.\n",
316 printf("Address space 'Addr%d' info:\n", cntr
+ 1);
317 printf("\tBase address => 0x%lx\n", ptr
->baseAddr
);
318 printf("\tAddress range => 0x%x\n", ptr
->range
);
319 printf("\tAddress increment => 0x%lx\n",
321 printf("\tDataport size => %ld\n", ptr
->dpSize
);
322 printf("\tAddress modifier => %s\n",
323 (ptr
->addressModifier
==
324 16) ? "SH - short" : (ptr
->addressModifier
==
325 24) ? "ST - standard" :
332 * @brief Printout DBRT error.
334 * @param dbrtFN -- function name
338 static void dbrt_error_printout(char *dbrtFN
)
340 /* see '/ps/local/Linux/dbrt/dbrt.h' file for more info about possible
341 errors and their meaning */
346 fprintf(stderr
, "%s() failed to read Module config data from"
347 " the DB with error [%d] => '%s'\n",
348 dbrtFN
, DbrtError
, DbrtErr(DbrtError
));