[driver-gen-git] Add git library files.
[driver-gen.git] / vmeGeneration.c
blobf04cc97115f472ee1f5bb3d9892ed6d150c6ae1f
1 /**
2 * @file vmeGeneration.c
4 * @brief Generates a specific VME device Driver/Simulator code
6 * @author Copyright (c) 2004 - 2009 CERN. Georgievskiy Yury, Alain Gagnaire
8 * @date Created on 27/02/2004
10 * Generates a device driver based on a VME implementation of the
11 * given hardware configuration.
13 #include "driverGen.h"
14 #include "dg-version.h"
16 static void BuildVmeHeaderFile(int, RegisterDef_t *, int, BlockDef_t *, int);
17 static void BuildVmeStatics(BlockDef_t *, int, FILE *, int);
18 static void BuildVmeDrvrFile(RegisterDef_t *, int, BlockDef_t *, int);
19 static void BuildVmeSimFile(RegisterDef_t *, int, BlockDef_t *, int);
21 /**
22 * @brief Generates the entire driver source code from scratch, including
23 * user-defined files.
25 * @param registers -- register description
26 * @param numRegisters -- register amount
27 * @param blocks -- block description
28 * @param numBlocks -- block amount
29 * @param vmeInfo -- @e VME description
31 * @return void
33 void GenerateVmeDriver(RegisterDef_t * registers, int numRegisters,
34 BlockDef_t * blocks, int numBlocks, VmeInfo_t * vmeInfo)
36 char *system = TranslationGetModName();
38 /* First, build-up major source code of the driver */
39 GenerateVmeCore(registers, numRegisters, blocks, numBlocks, vmeInfo);
41 /* Now build-up user-defined driver files for the current module */
42 printf("Building %s user entry points.\n", system);
43 BuildUserPartDrvrCode();
46 /**
47 * @brief Generates major source code of the driver, excluding the generation
48 * of user-defined files.
50 * @param registers -- register description
51 * @param numRegisters -- register amount
52 * @param blocks -- block description
53 * @param numBlocks -- block amount
54 * @param vmeInfo -- @e VME description
56 * @return void
58 void GenerateVmeCore(RegisterDef_t * registers, int numRegisters,
59 BlockDef_t * blocks, int numBlocks, VmeInfo_t * vmeInfo)
61 char *system = TranslationGetModName();
63 /*-=-=-=-=-=-=-=-=-=-=-=-=- VME driver. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
64 printf("Generating %s driver's source code.\n", system);
65 /* Header file for driver. */
66 BuildVmeHeaderFile(DRIVER_FT, registers, numRegisters, blocks,
67 numBlocks);
68 /* Driver source. */
69 BuildVmeDrvrFile(registers, numRegisters, blocks, numBlocks);
71 /*-=-=-=-=-=-=-=-=-=-=-=- VME simulator. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
72 printf("Generating %s driver's simulator source code.\n", system);
73 /* Header file for simulator. */
74 BuildVmeHeaderFile(SIM_FT, registers, numRegisters, blocks, numBlocks);
75 /* Simulator source. */
76 BuildVmeSimFile(registers, numRegisters, blocks, numBlocks);
78 /*-=-=-=-=-=-=-=-=- Driver/Simulator registers r/w operations. -=-=-=-=-=-*/
79 BuildGetSetRegCH(registers, numRegisters, vmeInfo);
81 /*-=-=-=-=-=-=-=-=- Driver-specific Library. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
82 printf("Generating %s IoctlAccess library.\n", system);
83 BuildIoctlLibrary(registers, numRegisters, blocks, numBlocks);
85 /*-=-=-=-=-=-=-=-=-=- Test program. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
86 printf("Generating %s test program.\n", system);
87 BuildTestProgram(registers, numRegisters, blocks, numBlocks);
89 /*-=-=-=-=-=-=-=- Info file that holds 'DevInfo_t' structure. -=-=-=-=-=-=-*/
90 printf("Generating %s '.info' file.\n", system);
91 GenerateVmeInfoFile(registers, numRegisters, blocks, numBlocks,
92 vmeInfo);
94 /*-=-=-=-=-=-=-=- Register ID of currently processed module. -=-=-=-=-=-=-=*/
95 printf("Generating %s registers ID.\n", system);
96 BuildRegIdEnum(blocks, registers, numRegisters);
98 /*-=-=-=-=-=-=-=-=-=-=-=-=-=- Makefiles. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
99 printf("Generating %s makefiles.\n", system);
100 BuildMakefiles();
104 * @brief Create .info file for current module.
106 * @param registers -- register description
107 * @param numRegisters -- register amount
108 * @param blocks -- block description
109 * @param numBlocks -- block amount
110 * @param vmeInfo -- @e vme description
112 * Info file contains structure @e DevInfo_t that will be passed to the
113 * module device driver during installation. All parameters that are already
114 * known are set here. The rest of them will be set (or redefined) by the user
115 * during installation procedure as a parameter in the command line,
116 * or will be left unchanged.
118 * @return void
120 void GenerateVmeInfoFile(RegisterDef_t * registers, int numRegisters,
121 BlockDef_t * blocks, int numBlocks,
122 VmeInfo_t * vmeInfo)
124 long longVal;
125 uint uintVal;
126 int intVal;
127 short shortVal;
128 char charVal[MAX_STR];
129 int cntr;
130 int regCntr = 0; /* register ID counter. Starts from zero */
131 int ioctlCntr = 0; /* ioctl number counter */
133 int totalReg;
134 int tmpBiggest, biggest = 0; /* size in bytes of the
135 biggest register */
136 FILE *infoF = OpenFile(COMMON_FT, LOC_MODSRC, "object_%s/.info",
137 TranslationGetSysLower());
139 memset(charVal, 0, sizeof(charVal));
141 /*---Fill in data of the first address space. 'addr1' member.------*/
142 /* base address (NO_ADDRESS means that address space NOT defined) */
143 longVal = vmeInfo->addr1.baseAddr;
144 longVal = ASSERT_MSB(longVal);
146 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'baseAddr' member */
148 /* address range */
149 uintVal = vmeInfo->addr1.range;
150 uintVal = ASSERT_MSB(uintVal);
152 fwrite(&uintVal, sizeof(uintVal), 1, infoF); /* 'range' member */
154 /* address increment */
155 longVal = vmeInfo->addr1.increment;
156 longVal = ASSERT_MSB(longVal);
158 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'increment' member */
160 /* dataport size (16 or 32) */
161 longVal = vmeInfo->addr1.dpSize;
162 longVal = ASSERT_MSB(longVal);
164 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'dpSize' member */
166 /* address modifier (16-SH, 24-ST, 32-EX) */
167 longVal = vmeInfo->addr1.addressModifier;
168 longVal = ASSERT_MSB(longVal);
170 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'addrModif' member */
171 /*----------- Done for the first address space ----------------------*/
173 /*----- Fill in data of the second address space. 'addr2' member ----*/
174 /* base address (NO_ADDRESS - address space NOT defined) */
175 longVal = vmeInfo->addr2.baseAddr;
176 longVal = ASSERT_MSB(longVal);
178 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'baseAddr' member */
180 /* address range */
181 uintVal = vmeInfo->addr2.range;
182 uintVal = ASSERT_MSB(uintVal);
184 fwrite(&uintVal, sizeof(uintVal), 1, infoF); /* 'range' member */
186 /* address increment */
187 longVal = vmeInfo->addr2.increment;
188 longVal = ASSERT_MSB(longVal);
190 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'increment' member */
192 /* dataport size (16 or 32) */
193 longVal = vmeInfo->addr2.dpSize;
194 longVal = ASSERT_MSB(longVal);
196 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'dpSize' member */
198 /* address modifier (16-SH, 24-ST, 32-EX) */
199 longVal = vmeInfo->addr2.addressModifier;
200 longVal = ASSERT_MSB(longVal);
202 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'addrModif' member */
203 /*----------- Done for the second address space ---------------------*/
205 /*---------- Fill in General Module Information ---------------------*/
206 /* DataBase Module Type Number */
207 intVal = vmeInfo->mtn;
208 intVal = ASSERT_MSB(intVal);
209 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'mtn' member */
211 /* module Logical Unit Number. Will be set by user during
212 installation. */
213 intVal = NO_LUN;
214 intVal = ASSERT_MSB(intVal);
215 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'mlun' member */
217 /* bit field. Will be set by user during installation. */
218 intVal = 0;
219 intVal = ASSERT_MSB(intVal);
220 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'debugFlag' member */
222 /* opaque param. Will be set by user during installation. */
223 /* 'opaque' member */
224 fwrite(charVal, sizeof(char), sizeof(charVal), infoF);
226 /* interrupt processing hardware level */
227 intVal = vmeInfo->irq;
228 intVal = ASSERT_MSB(intVal);
229 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'iLevel' member */
231 /* interrupt vector */
232 intVal = vmeInfo->vector;
233 intVal = ASSERT_MSB(intVal);
234 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'iVector' member */
236 /* interrupt vector increment */
237 intVal = vmeInfo->vectorInc;
238 intVal = ASSERT_MSB(intVal);
239 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'iVectorInc' member */
241 /* minor devices amount */
242 intVal = vmeInfo->chCntr;
243 intVal = ASSERT_MSB(intVal);
244 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'chan' member */
246 /* check register index */
247 intVal = (vmeInfo->CheckRegister == -1)
248 ? (-1) /* no checking register */
249 : vmeInfo->CheckRegister + GetSrvRegNum(); /* check reg is present */
250 intVal = ASSERT_MSB(intVal);
251 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'chrindex' member */
253 /* TODO! Set good values. */
254 longVal = -1;
255 longVal = ASSERT_MSB(longVal);
256 fwrite(&longVal, sizeof(longVal), 1, infoF); /* 'gen_date' member */
257 fwrite(charVal, sizeof(char), NAME_LEN, infoF); /* 'dg_vers' member */
259 /* actual register amount of the module */
260 totalReg = intVal = GetSrvRegNum() + numRegisters;
261 intVal = ASSERT_MSB(intVal);
262 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regAmount' member */
263 /*---------- Done for General Module Information --------------------*/
265 /*---------- Description of each register ('regDesc' member) --------*/
266 /* -----------------------------
267 00. First - Service registers
268 ----------------------------- */
269 for (cntr = 0; cntr < GetSrvRegNum(); cntr++, regCntr++) {
270 /* register ID */
271 intVal = regCntr;
272 intVal = ASSERT_MSB(intVal);
273 /* 'regId' member */
274 fwrite(&intVal, sizeof(intVal), 1, infoF);
276 /* register name */
277 memset(charVal, 0, sizeof(charVal));
278 strncpy(charVal, srv_ioctl[cntr].name, NAME_LEN);
279 charVal[NAME_LEN] = 0;
280 /* 'regName' member */
281 fwrite(charVal, sizeof(char), NAME_LEN, infoF);
283 /* bus type */
284 memset(charVal, 0, sizeof(charVal));
285 strcpy(charVal, "VME");
286 /* 'busType' member */
287 fwrite(charVal, sizeof(char), MIN_STR, infoF);
289 /* service register */
290 intVal = RT_SRVS;
291 intVal = ASSERT_MSB(intVal);
293 /* 'regType' member */
294 fwrite(&intVal, sizeof(intVal), 1, infoF);
296 /* register size in bytes */
297 intVal = srv_ioctl[cntr].regSize;
298 intVal = ASSERT_MSB(intVal);
300 /* 'regSize' member */
301 fwrite(&intVal, sizeof(intVal), 1, infoF);
303 /* 'addr1' or 'addr2' */
304 memset(charVal, 0, sizeof(charVal));
305 strcpy(charVal, "none");
306 /* 'b_a' member */
307 fwrite(charVal, sizeof(char), MIN_STR, infoF);
309 /* block, to which register belongs */
310 shortVal = -1;
311 shortVal = ASSERT_MSB(shortVal);
312 /* 'bid' member */
313 fwrite(&shortVal, sizeof(shortVal), 1, infoF);
315 /* reg offset from the base addr */
316 intVal = 0;
317 /* 'regOffset' member */
318 fwrite(&intVal, sizeof(intVal), 1, infoF);
320 /* register depth */
321 intVal = srv_ioctl[cntr].depth;
322 intVal = ASSERT_MSB(intVal);
323 /* 'regDepth' member */
324 fwrite(&intVal, sizeof(intVal), 1, infoF);
326 /* register timing loop */
327 intVal = 0;
328 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regtl' member */
330 /* register access mode */
331 intVal = srv_ioctl[cntr].rar;
332 intVal = ASSERT_MSB(intVal);
333 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regar' member */
335 /* service ioctl w/r numbers */
336 intVal = PackIoctlNum(&ioctlCntr, srv_ioctl[cntr].rar,
337 TRUE/*service register */);
338 intVal = ASSERT_MSB(intVal);
340 /* 'rwIoctlOpNum' member */
341 fwrite(&intVal, sizeof(intVal), 1, infoF);
343 /* control biggest register size in bytes */
344 tmpBiggest = srv_ioctl[cntr].depth * srv_ioctl[cntr].regSize;
345 if (tmpBiggest > biggest)
346 biggest = tmpBiggest;
349 /* --------------------------
350 01. Now - Module registers
351 -------------------------- */
352 for (cntr = 0; cntr < numRegisters; cntr++, regCntr++) {
353 int realDepth;
354 /* register ID */
355 intVal = regCntr;
356 intVal = ASSERT_MSB(intVal);
357 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regId' member */
359 /* register name */
360 memset(charVal, 0, sizeof(charVal));
361 strncpy(charVal, registers[cntr].name, NAME_LEN);
362 charVal[NAME_LEN] = 0;
363 /* 'regName' member */
364 fwrite(charVal, sizeof(char), NAME_LEN, infoF);
366 /* bus type */
367 memset(charVal, 0, sizeof(charVal));
368 strcpy(charVal, "VME");
369 /* 'busType' member */
370 fwrite(charVal, sizeof(char), MIN_STR, infoF);
372 /* if register is Extraneous or Real */
373 if (strchr(registers[cntr].mode, 'e'))
374 intVal = RT_EXTR; /* extraneous register */
375 else
376 intVal = RT_REAL; /* normal register */
377 intVal = ASSERT_MSB(intVal);
378 /* 'regType' member */
379 fwrite(&intVal, sizeof(intVal), 1, infoF);
381 /* register size in bytes */
382 intVal = registers[cntr].regSize;
383 intVal = ASSERT_MSB(intVal);
384 /* 'regSize' member */
385 fwrite(&intVal, sizeof(intVal), 1, infoF);
387 /* 'addr1' or 'addr2' */
388 memset(charVal, 0, sizeof(charVal));
389 strcpy(charVal, ((registers[cntr].blockP->blkBaseAddr == 1) ?
390 "addr1" : "addr2"));
391 /* 'b_a' member */
392 fwrite(charVal, sizeof(char), MIN_STR, infoF);
394 /* block, to which register belongs */
395 shortVal = registers[cntr].blockP->blockID;
396 shortVal = ASSERT_MSB(shortVal);
397 /* 'bid' member */
398 fwrite(&shortVal, sizeof(shortVal), 1, infoF);
400 /* reg offset from the base addr */
401 intVal = registers[cntr].offset;
402 intVal = ASSERT_MSB(intVal);
403 /* 'regOffset' member */
404 fwrite(&intVal, sizeof(intVal), 1, infoF);
406 /* register depth */
407 intVal = registers[cntr].depth;
408 intVal = ASSERT_MSB(intVal);
409 /* 'regDepth' member */
410 fwrite(&intVal, sizeof(intVal), 1, infoF);
412 /* register timing loop */
413 intVal = registers[cntr].timeLoop;
414 intVal = ASSERT_MSB(intVal);
415 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regtl' member */
417 /* register access mode */
418 intVal = registers[cntr].rar;
419 intVal = ASSERT_MSB(intVal);
420 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regar' member */
422 /* ioctl w/r numbers */
423 intVal = PackIoctlNum(&ioctlCntr, registers[cntr].rar,
424 FALSE /*not service register */ );
425 intVal = ASSERT_MSB(intVal);
426 /* 'rwIoctlOpNum' member */
427 fwrite(&intVal, sizeof(intVal), 1, infoF);
429 /* control biggest register size in bytes */
430 if (registers[cntr].depth == 0 || registers[cntr].depth == -1)
431 realDepth = 1;
432 else
433 realDepth = registers[cntr].depth;
434 tmpBiggest = realDepth * registers[cntr].regSize;
435 if (tmpBiggest > biggest)
436 biggest = tmpBiggest;
439 /* -------------------------------------------------------------
440 02. fill in the rest (i.e. unused register slots) with zeroes
441 ------------------------------------------------------------- */
442 intVal = 0;
443 for (cntr = 0; cntr < MAX_REG - totalReg; cntr++) {
444 /* set register ID to zero. Indicates the last one */
445 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'regId' member */
447 /* register name */
448 /* 'regName' member */
449 fwrite(&intVal, sizeof(char), NAME_LEN, infoF);
451 /* bus type */
452 /* 'busType' member */
453 fwrite(&intVal, sizeof(char), MIN_STR, infoF);
455 /* if register is Real, Extraneous or Service */
456 /* 'regType' member */
457 fwrite(&intVal, sizeof(intVal), 1, infoF);
459 /* register size in bytes */
460 /* 'regSize' member */
461 fwrite(&intVal, sizeof(intVal), 1, infoF);
463 /* 'addr1' or 'addr2' */
464 /* 'b_a' member */
465 fwrite(&intVal, sizeof(char), MIN_STR, infoF);
467 /* block, to which register belongs */
468 /* 'bid' member */
469 fwrite(&intVal, sizeof(short), 1, infoF);
471 /* reg offset from the base addr */
472 /* 'regOffset' member */
473 fwrite(&intVal, sizeof(intVal), 1, infoF);
475 /* register depth */
476 /* 'regDepth' member */
477 fwrite(&intVal, sizeof(intVal), 1, infoF);
479 /* register timing loop */
480 /* 'regtl' member */
481 fwrite(&intVal, sizeof(intVal), 1, infoF);
483 /* register access mode */
484 /* 'regar' member */
485 fwrite(&intVal, sizeof(intVal), 1, infoF);
487 /* ioctl w/r numbers */
488 /* 'rwIoctlOpNum' member */
489 fwrite(&intVal, sizeof(intVal), 1, infoF);
491 /*------------ End of each register description -------------------*/
493 /* set size in bytes of the biggest register in the module */
494 biggest = ASSERT_MSB(biggest);
495 fwrite(&biggest, sizeof(biggest), 1, infoF); /* 'maxRegSz' member */
497 /* actual block amount of the moudule */
498 intVal = numBlocks;
499 intVal = ASSERT_MSB(intVal);
500 fwrite(&intVal, sizeof(intVal), 1, infoF); /* 'blkAmount' member */
502 /*-------- Description of each block 'blkDesc' member -------------*/
503 /* ----------------------------
504 00. actual block description
505 ---------------------------- */
506 for (cntr = 0; cntr < numBlocks; cntr++) {
507 /* block sequence number, starting from 0 */
508 shortVal = blocks[cntr].blockID;
509 shortVal = ASSERT_MSB(shortVal);
510 /* 'block' member */
511 fwrite(&shortVal, sizeof(shortVal), 1, infoF);
513 /* 1 for INIT and 2 for NEXT base address */
514 shortVal = blocks[cntr].blkBaseAddr;
515 shortVal = ASSERT_MSB(shortVal);
516 /* 'blkBaseAddr' member */
517 fwrite(&shortVal, sizeof(shortVal), 1, infoF);
519 /* block offset from the base address */
520 longVal = blocks[cntr].offset;
521 longVal = ASSERT_MSB(longVal);
522 /* 'offset' member */
523 fwrite(&longVal, sizeof(longVal), 1, infoF);
525 /* driver block size in bytes */
526 intVal = blocks[cntr].blksz_drvr;
527 intVal = ASSERT_MSB(intVal);
528 /* 'blksz_drvr' member */
529 fwrite(&intVal, sizeof(intVal), 1, infoF);
531 /* simulator block size in bytes */
532 intVal = blocks[cntr].blksz_sim;
533 intVal = ASSERT_MSB(intVal);
534 /* 'blksz_sim' member */
535 fwrite(&intVal, sizeof(intVal), 1, infoF);
537 /* register amount in the block */
538 intVal = blocks[cntr].reg_am;
539 intVal = ASSERT_MSB(intVal);
540 /* 'reg_am' member */
541 fwrite(&intVal, sizeof(intVal), 1, infoF);
545 /* --------------------------------
546 01. fill in the rest with zeroes
547 -------------------------------- */
548 shortVal = longVal = intVal = 0;
549 for (cntr = 0; cntr < MAX_BLK - numBlocks; cntr++) {
550 /* block sequence number, starting from 0 */
551 /* 'block' member */
552 fwrite(&shortVal, sizeof(shortVal), 1, infoF);
554 /* 1 for INIT and 2 for NEXT base address */
555 /* 'blkBaseAddr' member */
556 fwrite(&shortVal, sizeof(shortVal), 1, infoF);
558 /* block offset from the base address */
559 /* 'offset' member */
560 fwrite(&longVal, sizeof(longVal), 1, infoF);
562 /* driver block size in bytes */
563 /* 'blksz_drvr' member */
564 fwrite(&intVal, sizeof(intVal), 1, infoF);
566 /* simulator block size in bytes */
567 /* 'blksz_sim' member */
568 fwrite(&intVal, sizeof(intVal), 1, infoF);
570 /* register amount in the block */
571 /* 'reg_am' member */
572 fwrite(&intVal, sizeof(intVal), 1, infoF);
574 /*-----------------End of each block description-------------------*/
576 /* TODO! compute checksum */
577 memset(charVal, 0, sizeof(charVal));
578 fwrite(charVal, sizeof(char), 1, infoF); /* 'checksum' member */
579 fclose(infoF);
583 * @brief Construct driver/simulator header files.
585 * @param type -- driver or simulator
586 * @param registers -- register description
587 * @param numRegisters -- register amount
588 * @param blocks -- block description
589 * @param numBlocks -- block amount
591 static void BuildVmeHeaderFile(int type, RegisterDef_t * registers,
592 int numRegisters, BlockDef_t * blocks,
593 int numBlocks)
595 FILE *headerFile;
596 char *bus = TranslationGetBus();
598 TranslationReset();
599 headerFile = OpenFile(type, LOC_INCL, ".h");
601 /* Generate the header file's head and then go to generate the rest */
602 TranslationSetDriverType((type == DRIVER_FT) ? "DRVR" : "SIM");
603 TranslationSetChar(*(TranslationGetModName()));
604 TranslationSetFreeFormat("%s", DG_INC_DIR);
605 Translate(headerFile, bus, "header/DrvrSimHeader.h");
607 /* Generate the constants used for the IOCTL function */
608 BuildIoctlConsts(registers, numRegisters, headerFile);
610 /* Generate the statics, info and block structures */
611 BuildCommonBlocks(type, registers, numRegisters, headerFile);
612 BuildVmeStatics(blocks, numBlocks, headerFile, type);
614 fclose(headerFile);
618 * @brief Construct the driver's statics and info structures.
620 * @param blocks -- block description
621 * @param numBlocks -- block amount
622 * @param headerFile -- open file descriptor
623 * @param type -- driver or simulator
625 * @return void
627 static void BuildVmeStatics(BlockDef_t * blocks, int numBlocks,
628 FILE * headerFile, int type)
630 int cntr;
631 char *bus = TranslationGetBus();
633 TranslationReset();
635 /* Generate the topographic structure's head */
636 Translate(headerFile, bus, "header/topologyHead.h");
638 /* For each block that's been defined, put a field in the topology
639 structure. */
640 for (cntr = 0; cntr < numBlocks; cntr++) {
641 TranslationSetFancyNum(blocks[cntr].blockID);
642 Translate(headerFile, "common", "header/blockDef.h");
645 /* Close the statics structure and generate the info one. */
646 TranslationSetDriverType((type == DRIVER_FT) ? "DRVR" : "SIM");
647 Translate(headerFile, "common", "header/topologyFoot.h");
651 * @brief Generate the driver's source file.
653 * @param registers -- register description
654 * @param numRegisters -- register amount
655 * @param blocks -- block description
656 * @param numBlocks -- block amount
658 * @return void
660 static void BuildVmeDrvrFile(RegisterDef_t * registers, int numRegisters,
661 BlockDef_t * blocks, int numBlocks)
663 char *bus = TranslationGetBus();
664 FILE *dfd = OpenFile(DRIVER_FT, LOC_DRVR, ".c");
665 int cntr;
666 char *tstr = ctime(&mod_creation_time); /* time string */
668 tstr[strlen(tstr) - 1] = 0; /* get rid of '\n' */
670 TranslationReset();
672 TranslationSetDriverType("Drvr");
673 TranslationSetFancyString("DRVR");
674 TranslationSetDummyString("Driver");
675 TranslationSetFreeFormat("%s", DG_INC_DIR);
676 /* set driver generation time */
677 TranslationSetHexNum(mod_creation_time);
678 TranslationSetComment(tstr);
679 TranslationSetString((char *)dg_version);
680 Translate(dfd, "common", "driver/driverHead.c");
682 /* Generate driver's OPEN routine */
683 Translate(dfd, bus, "driver/open/head.c");
685 /* Generate driver's CLOSE routine. */
686 Translate(dfd, "common", "driver/close/head.c");
688 /* Generate driver's READ routine. */
689 Translate(dfd, "common", "driver/read/head.c");
691 /* Generate driver's WRITE routine. */
692 Translate(dfd, "common", "driver/write/head.c");
694 /* Generate driver's SELECT routine */
695 Translate(dfd, "common", "driver/select/head.c");
697 /* Generate driver's IOCTL routine. */
698 BuildDrvrSimIoctl(registers, numRegisters, dfd);
700 /* generate statics table cleanup routine */
701 TranslationSetDriverType("Driver");
702 Translate(dfd, "common", "driver/uninstall/cleanupHead.c");
703 Translate(dfd, "common", "driver/uninstall/cleanupFoot.c");
705 /* Generate driver's INSTALL routine */
706 /* device checking should be done in case of the real driver */
707 Translate(dfd, bus, "driver/install/checkDev.c");
708 Translate(dfd, bus, "driver/install/head.c");
710 Translate(dfd, bus, "driver/install/infoPrnt.c");
711 Translate(dfd, bus, "driver/install/doCheck.c"); /* device checking */
713 Translate(dfd, bus, "driver/install/body.c");
714 for (cntr = 0; cntr < numBlocks; cntr++) {
715 TranslationSetPlainNum(blocks[cntr].blockID);
716 TranslationSetFancyNum(blocks[cntr].blockID);
717 TranslationSetIntNum(cntr);
719 if (blocks[cntr].blkBaseAddr == 1)
720 TranslationSetBaseAddr("addr1");
721 else
722 TranslationSetBaseAddr("addr2");
724 Translate(dfd, bus, "driver/install/assignBlock.c");
726 Translate(dfd, bus, "driver/install/foot.c");
728 /* Generate driver's UNINSTALL routine */
729 Translate(dfd, bus, "driver/uninstall/head.c");
730 Translate(dfd, bus, "driver/uninstall/unmap.c");
731 Translate(dfd, bus, "driver/uninstall/foot.c");
733 /* Build-up dldd structure (driver entry points) */
734 TranslationSetDriverType("Drvr");
735 Translate(dfd, "common", "driver/entryPoints.c");
737 fclose(dfd);
741 * @brief Generate the simulator's source file.
743 * @param registers -- register description
744 * @param numRegisters -- register amount
745 * @param blocks -- block description
746 * @param numBlocks -- block amount
748 * @return void
750 static void BuildVmeSimFile(RegisterDef_t * registers, int numRegisters,
751 BlockDef_t * blocks, int numBlocks)
753 char *bus = TranslationGetBus();
754 FILE *sfd = OpenFile(SIM_FT, LOC_DRVR, ".c");
755 int cntr;
756 char *tstr = ctime(&mod_creation_time); /* time string */
758 tstr[strlen(tstr) - 1] = 0; /* get rid of '\n' */
760 TranslationReset();
762 TranslationSetDriverType("Sim");
763 TranslationSetFancyString("SIM");
764 TranslationSetDummyString("Simulator");
765 TranslationSetFreeFormat("%s", DG_INC_DIR);
766 /* set driver generation time */
767 TranslationSetHexNum(mod_creation_time);
768 TranslationSetComment(tstr);
769 TranslationSetString((char *)dg_version);
770 Translate(sfd, "common", "driver/driverHead.c");
772 /* Generate simulator's OPEN routine. */
773 Translate(sfd, bus, "driver/open/head.c");
775 /* Generate simulator's CLOSE routine. */
776 Translate(sfd, "common", "driver/close/head.c");
778 /* Generate simulator's READ routine. */
779 Translate(sfd, "common", "driver/read/head.c");
781 /* Generate simulator's WRITE routine. */
782 Translate(sfd, "common", "driver/write/head.c");
784 /* Generate simulator's SELECT routine */
785 Translate(sfd, "common", "driver/select/head.c");
787 /* Generate simulator's IOCTL routine */
788 BuildDrvrSimIoctl(registers, numRegisters, sfd);
790 /* generate statics table cleanup routine */
791 TranslationSetDriverType("Simulator");
792 Translate(sfd, "common", "driver/uninstall/cleanupHead.c");
793 for (cntr = 0; cntr < numBlocks; cntr++) {
794 TranslationSetFancyNum(blocks[cntr].blockID);
795 TranslationSetPlainNum(blocks[cntr].blockID);
796 Translate(sfd, "common", "driver/uninstall/uninstallBlocks.c");
798 Translate(sfd, "common", "driver/uninstall/cleanupFoot.c");
800 /* Generate simulator's INSTALL routine */
801 Translate(sfd, bus, "driver/install/head.c");
802 Translate(sfd, bus, "driver/install/infoPrnt.c");
804 Translate(sfd, bus, "driver/install/body.c");
805 for (cntr = 0; cntr < numBlocks; cntr++) {
806 TranslationSetFancyNum(blocks[cntr].blockID);
807 TranslationSetPlainNum(blocks[cntr].blockID);
808 Translate(sfd, "common", "driver/install/allocateBlock.c");
810 Translate(sfd, bus, "driver/install/foot.c");
812 /* Generate simulator's UNINSTALL routine */
813 Translate(sfd, bus, "driver/uninstall/head.c");
814 Translate(sfd, bus, "driver/uninstall/foot.c");
816 /* Build-up dldd structure (simulator entry points) */
817 TranslationSetDriverType("Sim");
818 Translate(sfd, "common", "driver/entryPoints.c");
820 fclose(sfd);