2 * @file vmeGeneration.c
4 * @brief Generates a specific VME device Driver/Simulator code
6 * Generates a device driver based on a VME implementation of the
7 * given hardware configuration.
9 * @author Copyright (C) 2002 CERN. Stuart Baird
10 * @author Copyright (C) 2003 CERN. Alain Gagnaire
11 * @author Copyright (C) 2003 - 2010 CERN. Georgievskiy Yury <ygeorgie@cern.ch>
13 * @date Created on 27/02/2004
15 * @section license_sec License
16 * Released under the GPL
18 #include "driverGen.h"
19 #include "dg-version.h"
20 #include "xml-access.h"
22 static void BuildVmeHeaderFile(int, RegisterDef_t
*, int, BlockDef_t
*, int);
23 static void BuildVmeStatics(BlockDef_t
*, int, FILE *, int);
24 static void BuildVmeDrvrFile(RegisterDef_t
*, int, BlockDef_t
*, int);
25 static void BuildVmeSimFile(RegisterDef_t
*, int, BlockDef_t
*, int);
28 * @brief Generates the entire driver source code from scratch, including
31 * @param registers -- register description
32 * @param numRegisters -- register amount
33 * @param blocks -- block description
34 * @param numBlocks -- block amount
35 * @param vmeInfo -- @e VME description
39 void GenerateVmeDriver(RegisterDef_t
* registers
, int numRegisters
,
40 BlockDef_t
* blocks
, int numBlocks
, VmeInfo_t
* vmeInfo
)
42 char *system
= TranslationGetModName();
44 /* First, build-up major source code of the driver */
45 GenerateVmeCore(registers
, numRegisters
, blocks
, numBlocks
, vmeInfo
);
47 /* Now build-up user-defined driver files for the current module */
48 printf("Building %s user entry points.\n", system
);
49 BuildUserPartDrvrCode();
53 * @brief Generates major source code of the driver, excluding the generation
54 * of user-defined files.
56 * @param registers -- register description
57 * @param numRegisters -- register amount
58 * @param blocks -- block description
59 * @param numBlocks -- block amount
60 * @param vmeInfo -- @e VME description
64 void GenerateVmeCore(RegisterDef_t
* registers
, int numRegisters
,
65 BlockDef_t
* blocks
, int numBlocks
, VmeInfo_t
* vmeInfo
)
67 char *system
= TranslationGetModName();
69 /*-=-=-=-=-=-=-=-=-=-=-=-=- VME driver. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
70 printf("Generating %s driver's source code.\n", system
);
71 /* Header file for driver. */
72 BuildVmeHeaderFile(DRIVER_FT
, registers
, numRegisters
, blocks
,
75 BuildVmeDrvrFile(registers
, numRegisters
, blocks
, numBlocks
);
77 /*-=-=-=-=-=-=-=-=-=-=-=- VME simulator. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
78 printf("Generating %s driver's simulator source code.\n", system
);
79 /* Header file for simulator. */
80 BuildVmeHeaderFile(SIM_FT
, registers
, numRegisters
, blocks
, numBlocks
);
81 /* Simulator source. */
82 BuildVmeSimFile(registers
, numRegisters
, blocks
, numBlocks
);
84 /*-=-=-=-=-=-=-=-=- Driver/Simulator registers r/w operations. -=-=-=-=-=-*/
85 BuildGetSetRegCH(registers
, numRegisters
, vmeInfo
);
87 /*-=-=-=-=-=-=-=-=- Driver-specific Library. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
88 printf("Generating %s IoctlAccess library.\n", system
);
89 BuildIoctlLibrary(registers
, numRegisters
, blocks
, numBlocks
);
91 /*-=-=-=-=-=-=-=-=-=- Test program. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
92 printf("Generating %s test program.\n", system
);
93 BuildTestProgram(registers
, numRegisters
, blocks
, numBlocks
);
95 /*-=-=-=-=-=-=-=- Info file that holds 'DevInfo_t' structure. -=-=-=-=-=-=-*/
96 printf("Generating %s '.info' file.\n", system
);
97 GenerateVmeInfoFile(registers
, numRegisters
, blocks
, numBlocks
,
100 /*-=-=-=-=-=-=-=- Register ID of currently processed module. -=-=-=-=-=-=-=*/
101 printf("Generating %s registers ID.\n", system
);
102 BuildRegIdEnum(blocks
, registers
, numRegisters
);
104 /*-=-=-=-=-=-=-=-=-=-=-=-=-=- Makefiles. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
105 printf("Generating %s makefiles.\n", system
);
110 * @brief Create .info file for current module.
112 * @param registers -- register description
113 * @param numRegisters -- register amount
114 * @param blocks -- block description
115 * @param numBlocks -- block amount
116 * @param vmeInfo -- @e vme description
118 * Info file contains structure @e DevInfo_t that will be passed to the
119 * module device driver during installation. All parameters that are already
120 * known are set here. The rest of them will be set (or redefined) by the user
121 * during installation procedure as a parameter in the command line,
122 * or will be left unchanged.
126 void GenerateVmeInfoFile(RegisterDef_t
* registers
, int numRegisters
,
127 BlockDef_t
* blocks
, int numBlocks
,
134 char charVal
[MAX_STR
];
136 int regCntr
= 0; /* register ID counter. Starts from zero */
137 int ioctlCntr
= 0; /* ioctl number counter */
140 int tmpBiggest
, biggest
= 0; /* size in bytes of the
142 FILE *infoF
= OpenFile(COMMON_FT
, LOC_MODSRC
, "object_%s/.info",
143 TranslationGetSysLower());
145 memset(charVal
, 0, sizeof(charVal
));
147 /*---Fill in data of the first address space. 'addr1' member.------*/
148 /* base address (NO_ADDRESS means that address space NOT defined) */
149 longVal
= vmeInfo
->addr1
.baseAddr
;
150 longVal
= ASSERT_MSB(longVal
);
152 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'baseAddr' member */
155 uintVal
= vmeInfo
->addr1
.range
;
156 uintVal
= ASSERT_MSB(uintVal
);
158 fwrite(&uintVal
, sizeof(uintVal
), 1, infoF
); /* 'range' member */
160 /* address increment */
161 longVal
= vmeInfo
->addr1
.increment
;
162 longVal
= ASSERT_MSB(longVal
);
164 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'increment' member */
166 /* dataport size (16 or 32) */
167 longVal
= vmeInfo
->addr1
.dpSize
;
168 longVal
= ASSERT_MSB(longVal
);
170 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'dpSize' member */
172 /* address modifier (16-SH, 24-ST, 32-EX) */
173 longVal
= vmeInfo
->addr1
.addressModifier
;
174 longVal
= ASSERT_MSB(longVal
);
176 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'addrModif' member */
177 /*----------- Done for the first address space ----------------------*/
179 /*----- Fill in data of the second address space. 'addr2' member ----*/
180 /* base address (NO_ADDRESS - address space NOT defined) */
181 longVal
= vmeInfo
->addr2
.baseAddr
;
182 longVal
= ASSERT_MSB(longVal
);
184 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'baseAddr' member */
187 uintVal
= vmeInfo
->addr2
.range
;
188 uintVal
= ASSERT_MSB(uintVal
);
190 fwrite(&uintVal
, sizeof(uintVal
), 1, infoF
); /* 'range' member */
192 /* address increment */
193 longVal
= vmeInfo
->addr2
.increment
;
194 longVal
= ASSERT_MSB(longVal
);
196 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'increment' member */
198 /* dataport size (16 or 32) */
199 longVal
= vmeInfo
->addr2
.dpSize
;
200 longVal
= ASSERT_MSB(longVal
);
202 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'dpSize' member */
204 /* address modifier (16-SH, 24-ST, 32-EX) */
205 longVal
= vmeInfo
->addr2
.addressModifier
;
206 longVal
= ASSERT_MSB(longVal
);
208 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'addrModif' member */
209 /*----------- Done for the second address space ---------------------*/
211 /*---------- Fill in General Module Information ---------------------*/
212 /* DataBase Module Type Number */
213 intVal
= vmeInfo
->mtn
;
214 intVal
= ASSERT_MSB(intVal
);
215 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'mtn' member */
217 /* module Logical Unit Number. Will be set by user during
220 intVal
= ASSERT_MSB(intVal
);
221 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'mlun' member */
223 /* bit field. Will be set by user during installation. */
225 intVal
= ASSERT_MSB(intVal
);
226 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'debugFlag' member */
228 /* opaque param. Will be set by user during installation. */
229 /* 'opaque' member */
230 fwrite(charVal
, sizeof(char), sizeof(charVal
), infoF
);
232 /* interrupt processing hardware level */
233 intVal
= vmeInfo
->irq
;
234 intVal
= ASSERT_MSB(intVal
);
235 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'iLevel' member */
237 /* interrupt vector */
238 intVal
= vmeInfo
->vector
;
239 intVal
= ASSERT_MSB(intVal
);
240 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'iVector' member */
242 /* interrupt vector increment */
243 intVal
= vmeInfo
->vectorInc
;
244 intVal
= ASSERT_MSB(intVal
);
245 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'iVectorInc' member */
247 /* minor devices amount */
248 intVal
= vmeInfo
->chCntr
;
249 intVal
= ASSERT_MSB(intVal
);
250 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'chan' member */
252 /* check register index */
253 intVal
= (vmeInfo
->CheckRegister
== -1)
254 ? (-1) /* no checking register */
255 : vmeInfo
->CheckRegister
+ GetSrvRegNum(); /* check reg is present */
256 intVal
= ASSERT_MSB(intVal
);
257 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'chrindex' member */
259 /* TODO! Set good values. */
261 longVal
= ASSERT_MSB(longVal
);
262 fwrite(&longVal
, sizeof(longVal
), 1, infoF
); /* 'gen_date' member */
263 fwrite(charVal
, sizeof(char), NAME_LEN
, infoF
); /* 'dg_vers' member */
265 /* actual register amount of the module */
266 totalReg
= intVal
= GetSrvRegNum() + numRegisters
;
267 intVal
= ASSERT_MSB(intVal
);
268 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regAmount' member */
269 /*---------- Done for General Module Information --------------------*/
271 /*---------- Description of each register ('regDesc' member) --------*/
272 /* -----------------------------
273 00. First - Service registers
274 ----------------------------- */
275 for (cntr
= 0; cntr
< GetSrvRegNum(); cntr
++, regCntr
++) {
278 intVal
= ASSERT_MSB(intVal
);
280 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
283 memset(charVal
, 0, sizeof(charVal
));
284 strncpy(charVal
, srv_ioctl
[cntr
].name
, NAME_LEN
);
285 charVal
[NAME_LEN
] = 0;
286 /* 'regName' member */
287 fwrite(charVal
, sizeof(char), NAME_LEN
, infoF
);
290 memset(charVal
, 0, sizeof(charVal
));
291 strcpy(charVal
, "VME");
292 /* 'busType' member */
293 fwrite(charVal
, sizeof(char), MIN_STR
, infoF
);
295 /* service register */
297 intVal
= ASSERT_MSB(intVal
);
299 /* 'regType' member */
300 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
302 /* register size in bytes */
303 intVal
= srv_ioctl
[cntr
].regSize
;
304 intVal
= ASSERT_MSB(intVal
);
306 /* 'regSize' member */
307 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
309 /* 'addr1' or 'addr2' */
310 memset(charVal
, 0, sizeof(charVal
));
311 strcpy(charVal
, "none");
313 fwrite(charVal
, sizeof(char), MIN_STR
, infoF
);
315 /* block, to which register belongs */
317 shortVal
= ASSERT_MSB(shortVal
);
319 fwrite(&shortVal
, sizeof(shortVal
), 1, infoF
);
321 /* reg offset from the base addr */
323 /* 'regOffset' member */
324 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
327 intVal
= srv_ioctl
[cntr
].depth
;
328 intVal
= ASSERT_MSB(intVal
);
329 /* 'regDepth' member */
330 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
332 /* register timing loop */
334 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regtl' member */
336 /* register access mode */
337 intVal
= srv_ioctl
[cntr
].rar
;
338 intVal
= ASSERT_MSB(intVal
);
339 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regar' member */
341 /* service ioctl w/r numbers */
342 intVal
= PackIoctlNum(&ioctlCntr
, srv_ioctl
[cntr
].rar
,
343 TRUE
/*service register */);
344 intVal
= ASSERT_MSB(intVal
);
346 /* 'rwIoctlOpNum' member */
347 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
349 /* control biggest register size in bytes */
350 tmpBiggest
= srv_ioctl
[cntr
].depth
* srv_ioctl
[cntr
].regSize
;
351 if (tmpBiggest
> biggest
)
352 biggest
= tmpBiggest
;
355 /* --------------------------
356 01. Now - Module registers
357 -------------------------- */
358 for (cntr
= 0; cntr
< numRegisters
; cntr
++, regCntr
++) {
362 intVal
= ASSERT_MSB(intVal
);
363 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regId' member */
366 memset(charVal
, 0, sizeof(charVal
));
367 strncpy(charVal
, registers
[cntr
].name
, NAME_LEN
);
368 charVal
[NAME_LEN
] = 0;
369 /* 'regName' member */
370 fwrite(charVal
, sizeof(char), NAME_LEN
, infoF
);
373 memset(charVal
, 0, sizeof(charVal
));
374 strcpy(charVal
, "VME");
375 /* 'busType' member */
376 fwrite(charVal
, sizeof(char), MIN_STR
, infoF
);
378 /* if register is Extraneous or Real */
379 if (strchr(registers
[cntr
].mode
, 'e'))
380 intVal
= RT_EXTR
; /* extraneous register */
382 intVal
= RT_REAL
; /* normal register */
383 intVal
= ASSERT_MSB(intVal
);
384 /* 'regType' member */
385 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
387 /* register size in bytes */
388 intVal
= registers
[cntr
].regSize
;
389 intVal
= ASSERT_MSB(intVal
);
390 /* 'regSize' member */
391 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
393 /* 'addr1' or 'addr2' */
394 memset(charVal
, 0, sizeof(charVal
));
395 strcpy(charVal
, ((registers
[cntr
].blockP
->blkBaseAddr
== 1) ?
398 fwrite(charVal
, sizeof(char), MIN_STR
, infoF
);
400 /* block, to which register belongs */
401 shortVal
= registers
[cntr
].blockP
->blockID
;
402 shortVal
= ASSERT_MSB(shortVal
);
404 fwrite(&shortVal
, sizeof(shortVal
), 1, infoF
);
406 /* reg offset from the base addr */
407 intVal
= registers
[cntr
].offset
;
408 intVal
= ASSERT_MSB(intVal
);
409 /* 'regOffset' member */
410 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
413 intVal
= registers
[cntr
].depth
;
414 intVal
= ASSERT_MSB(intVal
);
415 /* 'regDepth' member */
416 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
418 /* register timing loop */
419 intVal
= registers
[cntr
].timeLoop
;
420 intVal
= ASSERT_MSB(intVal
);
421 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regtl' member */
423 /* register access mode */
424 intVal
= registers
[cntr
].rar
;
425 intVal
= ASSERT_MSB(intVal
);
426 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regar' member */
428 /* ioctl w/r numbers */
429 intVal
= PackIoctlNum(&ioctlCntr
, registers
[cntr
].rar
,
430 FALSE
/*not service register */ );
431 intVal
= ASSERT_MSB(intVal
);
432 /* 'rwIoctlOpNum' member */
433 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
435 /* control biggest register size in bytes */
436 if (registers
[cntr
].depth
== 0 || registers
[cntr
].depth
== -1)
439 realDepth
= registers
[cntr
].depth
;
440 tmpBiggest
= realDepth
* registers
[cntr
].regSize
;
441 if (tmpBiggest
> biggest
)
442 biggest
= tmpBiggest
;
445 /* -------------------------------------------------------------
446 02. fill in the rest (i.e. unused register slots) with zeroes
447 ------------------------------------------------------------- */
449 for (cntr
= 0; cntr
< MAX_REG
- totalReg
; cntr
++) {
450 /* set register ID to zero. Indicates the last one */
451 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'regId' member */
454 /* 'regName' member */
455 fwrite(&intVal
, sizeof(char), NAME_LEN
, infoF
);
458 /* 'busType' member */
459 fwrite(&intVal
, sizeof(char), MIN_STR
, infoF
);
461 /* if register is Real, Extraneous or Service */
462 /* 'regType' member */
463 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
465 /* register size in bytes */
466 /* 'regSize' member */
467 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
469 /* 'addr1' or 'addr2' */
471 fwrite(&intVal
, sizeof(char), MIN_STR
, infoF
);
473 /* block, to which register belongs */
475 fwrite(&intVal
, sizeof(short), 1, infoF
);
477 /* reg offset from the base addr */
478 /* 'regOffset' member */
479 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
482 /* 'regDepth' member */
483 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
485 /* register timing loop */
487 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
489 /* register access mode */
491 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
493 /* ioctl w/r numbers */
494 /* 'rwIoctlOpNum' member */
495 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
497 /*------------ End of each register description -------------------*/
499 /* set size in bytes of the biggest register in the module */
500 biggest
= ASSERT_MSB(biggest
);
501 fwrite(&biggest
, sizeof(biggest
), 1, infoF
); /* 'maxRegSz' member */
503 /* actual block amount of the moudule */
505 intVal
= ASSERT_MSB(intVal
);
506 fwrite(&intVal
, sizeof(intVal
), 1, infoF
); /* 'blkAmount' member */
508 /*-------- Description of each block 'blkDesc' member -------------*/
509 /* ----------------------------
510 00. actual block description
511 ---------------------------- */
512 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
513 /* block sequence number, starting from 0 */
514 shortVal
= blocks
[cntr
].blockID
;
515 shortVal
= ASSERT_MSB(shortVal
);
517 fwrite(&shortVal
, sizeof(shortVal
), 1, infoF
);
519 /* 1 for INIT and 2 for NEXT base address */
520 shortVal
= blocks
[cntr
].blkBaseAddr
;
521 shortVal
= ASSERT_MSB(shortVal
);
522 /* 'blkBaseAddr' member */
523 fwrite(&shortVal
, sizeof(shortVal
), 1, infoF
);
525 /* block offset from the base address */
526 longVal
= blocks
[cntr
].offset
;
527 longVal
= ASSERT_MSB(longVal
);
528 /* 'offset' member */
529 fwrite(&longVal
, sizeof(longVal
), 1, infoF
);
531 /* driver block size in bytes */
532 intVal
= blocks
[cntr
].blksz_drvr
;
533 intVal
= ASSERT_MSB(intVal
);
534 /* 'blksz_drvr' member */
535 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
537 /* simulator block size in bytes */
538 intVal
= blocks
[cntr
].blksz_sim
;
539 intVal
= ASSERT_MSB(intVal
);
540 /* 'blksz_sim' member */
541 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
543 /* register amount in the block */
544 intVal
= blocks
[cntr
].reg_am
;
545 intVal
= ASSERT_MSB(intVal
);
546 /* 'reg_am' member */
547 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
551 /* --------------------------------
552 01. fill in the rest with zeroes
553 -------------------------------- */
554 shortVal
= longVal
= intVal
= 0;
555 for (cntr
= 0; cntr
< MAX_BLK
- numBlocks
; cntr
++) {
556 /* block sequence number, starting from 0 */
558 fwrite(&shortVal
, sizeof(shortVal
), 1, infoF
);
560 /* 1 for INIT and 2 for NEXT base address */
561 /* 'blkBaseAddr' member */
562 fwrite(&shortVal
, sizeof(shortVal
), 1, infoF
);
564 /* block offset from the base address */
565 /* 'offset' member */
566 fwrite(&longVal
, sizeof(longVal
), 1, infoF
);
568 /* driver block size in bytes */
569 /* 'blksz_drvr' member */
570 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
572 /* simulator block size in bytes */
573 /* 'blksz_sim' member */
574 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
576 /* register amount in the block */
577 /* 'reg_am' member */
578 fwrite(&intVal
, sizeof(intVal
), 1, infoF
);
580 /*-----------------End of each block description-------------------*/
582 /* TODO! compute checksum */
583 memset(charVal
, 0, sizeof(charVal
));
584 fwrite(charVal
, sizeof(char), 1, infoF
); /* 'checksum' member */
587 /* produce .xml file */
588 dgxml_cerndb_info2xml(NULL
);
592 * @brief Construct driver/simulator header files.
594 * @param type -- driver or simulator
595 * @param registers -- register description
596 * @param numRegisters -- register amount
597 * @param blocks -- block description
598 * @param numBlocks -- block amount
600 static void BuildVmeHeaderFile(int type
, RegisterDef_t
* registers
,
601 int numRegisters
, BlockDef_t
* blocks
,
605 char *bus
= TranslationGetBus();
608 headerFile
= OpenFile(type
, LOC_INCL
, ".h");
610 /* Generate the header file's head and then go to generate the rest */
611 TranslationSetDriverType((type
== DRIVER_FT
) ? "DRVR" : "SIM");
612 TranslationSetChar(*(TranslationGetModName()));
613 TranslationSetFreeFormat("%s", DG_INC_DIR
);
614 Translate(headerFile
, bus
, "header/DrvrSimHeader.h");
616 /* Generate the constants used for the IOCTL function */
617 BuildIoctlConsts(registers
, numRegisters
, headerFile
);
619 /* Generate the statics, info and block structures */
620 BuildCommonBlocks(type
, registers
, numRegisters
, headerFile
);
621 BuildVmeStatics(blocks
, numBlocks
, headerFile
, type
);
627 * @brief Construct the driver's statics and info structures.
629 * @param blocks -- block description
630 * @param numBlocks -- block amount
631 * @param headerFile -- open file descriptor
632 * @param type -- driver or simulator
636 static void BuildVmeStatics(BlockDef_t
* blocks
, int numBlocks
,
637 FILE * headerFile
, int type
)
640 char *bus
= TranslationGetBus();
644 /* Generate the topographic structure's head */
645 Translate(headerFile
, bus
, "header/topologyHead.h");
647 /* For each block that's been defined, put a field in the topology
649 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
650 TranslationSetFancyNum(blocks
[cntr
].blockID
);
651 Translate(headerFile
, "common", "header/blockDef.h");
654 /* Close the statics structure and generate the info one. */
655 TranslationSetDriverType((type
== DRIVER_FT
) ? "DRVR" : "SIM");
656 Translate(headerFile
, "common", "header/topologyFoot.h");
660 * @brief Generate the driver's source file.
662 * @param registers -- register description
663 * @param numRegisters -- register amount
664 * @param blocks -- block description
665 * @param numBlocks -- block amount
669 static void BuildVmeDrvrFile(RegisterDef_t
* registers
, int numRegisters
,
670 BlockDef_t
* blocks
, int numBlocks
)
672 char *bus
= TranslationGetBus();
673 FILE *dfd
= OpenFile(DRIVER_FT
, LOC_DRVR
, ".c");
675 char *tstr
= ctime(&mod_creation_time
); /* time string */
677 tstr
[strlen(tstr
) - 1] = 0; /* get rid of '\n' */
681 TranslationSetDriverType("Drvr");
682 TranslationSetFancyString("DRVR");
683 TranslationSetDummyString("Driver");
684 TranslationSetFreeFormat("%s", DG_INC_DIR
);
685 /* set driver generation time */
686 TranslationSetHexNum(mod_creation_time
);
687 TranslationSetComment(tstr
);
688 TranslationSetString((char *)dg_version
);
689 Translate(dfd
, "common", "driver/driverHead.c");
691 /* Generate driver's OPEN routine */
692 Translate(dfd
, bus
, "driver/open/head.c");
694 /* Generate driver's CLOSE routine. */
695 Translate(dfd
, "common", "driver/close/head.c");
697 /* Generate driver's READ routine. */
698 Translate(dfd
, "common", "driver/read/head.c");
700 /* Generate driver's WRITE routine. */
701 Translate(dfd
, "common", "driver/write/head.c");
703 /* Generate driver's SELECT routine */
704 Translate(dfd
, "common", "driver/select/head.c");
706 /* Generate driver's IOCTL routine. */
707 BuildDrvrSimIoctl(registers
, numRegisters
, dfd
);
709 /* generate statics table cleanup routine */
710 TranslationSetDriverType("Driver");
711 Translate(dfd
, "common", "driver/uninstall/cleanupHead.c");
712 Translate(dfd
, "common", "driver/uninstall/cleanupFoot.c");
714 /* Generate driver's INSTALL routine */
715 /* device checking should be done in case of the real driver */
716 Translate(dfd
, bus
, "driver/install/checkDev.c");
717 Translate(dfd
, bus
, "driver/install/head.c");
719 Translate(dfd
, bus
, "driver/install/infoPrnt.c");
720 Translate(dfd
, bus
, "driver/install/doCheck.c"); /* device checking */
722 Translate(dfd
, bus
, "driver/install/body.c");
723 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
724 TranslationSetPlainNum(blocks
[cntr
].blockID
);
725 TranslationSetFancyNum(blocks
[cntr
].blockID
);
726 TranslationSetIntNum(cntr
);
728 if (blocks
[cntr
].blkBaseAddr
== 1)
729 TranslationSetBaseAddr("addr1");
731 TranslationSetBaseAddr("addr2");
733 Translate(dfd
, bus
, "driver/install/assignBlock.c");
735 Translate(dfd
, bus
, "driver/install/foot.c");
737 /* Generate driver's UNINSTALL routine */
738 Translate(dfd
, bus
, "driver/uninstall/head.c");
739 Translate(dfd
, bus
, "driver/uninstall/unmap.c");
740 Translate(dfd
, bus
, "driver/uninstall/foot.c");
742 /* Build-up dldd structure (driver entry points) */
743 TranslationSetDriverType("Drvr");
744 Translate(dfd
, "common", "driver/entryPoints.c");
750 * @brief Generate the simulator's source file.
752 * @param registers -- register description
753 * @param numRegisters -- register amount
754 * @param blocks -- block description
755 * @param numBlocks -- block amount
759 static void BuildVmeSimFile(RegisterDef_t
* registers
, int numRegisters
,
760 BlockDef_t
* blocks
, int numBlocks
)
762 char *bus
= TranslationGetBus();
763 FILE *sfd
= OpenFile(SIM_FT
, LOC_DRVR
, ".c");
765 char *tstr
= ctime(&mod_creation_time
); /* time string */
767 tstr
[strlen(tstr
) - 1] = 0; /* get rid of '\n' */
771 TranslationSetDriverType("Sim");
772 TranslationSetFancyString("SIM");
773 TranslationSetDummyString("Simulator");
774 TranslationSetFreeFormat("%s", DG_INC_DIR
);
775 /* set driver generation time */
776 TranslationSetHexNum(mod_creation_time
);
777 TranslationSetComment(tstr
);
778 TranslationSetString((char *)dg_version
);
779 Translate(sfd
, "common", "driver/driverHead.c");
781 /* Generate simulator's OPEN routine. */
782 Translate(sfd
, bus
, "driver/open/head.c");
784 /* Generate simulator's CLOSE routine. */
785 Translate(sfd
, "common", "driver/close/head.c");
787 /* Generate simulator's READ routine. */
788 Translate(sfd
, "common", "driver/read/head.c");
790 /* Generate simulator's WRITE routine. */
791 Translate(sfd
, "common", "driver/write/head.c");
793 /* Generate simulator's SELECT routine */
794 Translate(sfd
, "common", "driver/select/head.c");
796 /* Generate simulator's IOCTL routine */
797 BuildDrvrSimIoctl(registers
, numRegisters
, sfd
);
799 /* generate statics table cleanup routine */
800 TranslationSetDriverType("Simulator");
801 Translate(sfd
, "common", "driver/uninstall/cleanupHead.c");
802 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
803 TranslationSetFancyNum(blocks
[cntr
].blockID
);
804 TranslationSetPlainNum(blocks
[cntr
].blockID
);
805 Translate(sfd
, "common", "driver/uninstall/uninstallBlocks.c");
807 Translate(sfd
, "common", "driver/uninstall/cleanupFoot.c");
809 /* Generate simulator's INSTALL routine */
810 Translate(sfd
, bus
, "driver/install/head.c");
811 Translate(sfd
, bus
, "driver/install/infoPrnt.c");
813 Translate(sfd
, bus
, "driver/install/body.c");
814 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
815 TranslationSetFancyNum(blocks
[cntr
].blockID
);
816 TranslationSetPlainNum(blocks
[cntr
].blockID
);
817 Translate(sfd
, "common", "driver/install/allocateBlock.c");
819 Translate(sfd
, bus
, "driver/install/foot.c");
821 /* Generate simulator's UNINSTALL routine */
822 Translate(sfd
, bus
, "driver/uninstall/head.c");
823 Translate(sfd
, bus
, "driver/uninstall/foot.c");
825 /* Build-up dldd structure (simulator entry points) */
826 TranslationSetDriverType("Sim");
827 Translate(sfd
, "common", "driver/entryPoints.c");