![]() |
RTXI 1.3
|
00001 00024 /* 00025 00026 +-----------------------------------------------------------------------+ 00027 | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier | 00028 +-----------------------------------------------------------------------+ 00029 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | 00030 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | 00031 +-----------------------------------------------------------------------+ 00032 | Project : ADDI DATA | Compiler : GCC | 00033 | Modulname : addi_eeprom.c | Version : 2.96 | 00034 +-------------------------------+---------------------------------------+ 00035 | Project manager: Eric Stolz | Date : 02/12/2002 | 00036 +-----------------------------------------------------------------------+ 00037 | Description : ADDI EEPROM Module | 00038 +-----------------------------------------------------------------------+ 00039 | UPDATE'S | 00040 +-----------------------------------------------------------------------+ 00041 | Date | Author | Description of updates | 00042 +----------+-----------+------------------------------------------------+ 00043 | | | | 00044 | | | | 00045 +----------+-----------+------------------------------------------------+ 00046 */ 00047 00048 #define NVCMD_BEGIN_READ (0x7 << 5 ) // nvRam begin read command 00049 #define NVCMD_LOAD_LOW (0x4 << 5 ) // nvRam load low command 00050 #define NVCMD_LOAD_HIGH (0x5 << 5 ) // nvRam load high command 00051 #define EE76_CMD_LEN 13 // bits in instructions 00052 #define EE_READ 0x0180 // 01 1000 0000 read instruction 00053 00054 #define WORD unsigned short 00055 #define PWORD unsigned short * 00056 #define PDWORD unsigned int * 00057 00058 #ifndef DWORD 00059 #define DWORD unsigned int 00060 #endif 00061 00062 #define EEPROM_DIGITALINPUT 0 00063 #define EEPROM_DIGITALOUTPUT 1 00064 #define EEPROM_ANALOGINPUT 2 00065 #define EEPROM_ANALOGOUTPUT 3 00066 #define EEPROM_TIMER 4 00067 #define EEPROM_WATCHDOG 5 00068 #define EEPROM_TIMER_WATCHDOG_COUNTER 10 00069 00070 struct str_Functionality { 00071 BYTE b_Type; 00072 WORD w_Address; 00073 }; 00074 00075 typedef struct { 00076 WORD w_HeaderSize; 00077 BYTE b_Nfunctions; 00078 struct str_Functionality s_Functions[7]; 00079 } str_MainHeader; 00080 00081 typedef struct { 00082 WORD w_Nchannel; 00083 BYTE b_Interruptible; 00084 WORD w_NinterruptLogic; 00085 } str_DigitalInputHeader; 00086 00087 typedef struct { 00088 WORD w_Nchannel; 00089 } str_DigitalOutputHeader; 00090 00091 // used for timer as well as watchdog 00092 00093 typedef struct { 00094 WORD w_HeaderSize; 00095 BYTE b_Resolution; 00096 BYTE b_Mode; // in case of Watchdog it is functionality 00097 WORD w_MinTiming; 00098 BYTE b_TimeBase; 00099 } str_TimerDetails; 00100 typedef struct { 00101 00102 WORD w_Ntimer; 00103 str_TimerDetails s_TimerDetails[4]; // supports 4 timers 00104 } str_TimerMainHeader; 00105 00106 typedef struct { 00107 WORD w_Nchannel; 00108 BYTE b_Resolution; 00109 } str_AnalogOutputHeader; 00110 00111 typedef struct { 00112 WORD w_Nchannel; 00113 WORD w_MinConvertTiming; 00114 WORD w_MinDelayTiming; 00115 BYTE b_HasDma; 00116 BYTE b_Resolution; 00117 } str_AnalogInputHeader; 00118 00119 /*****************************************/ 00120 /* Read Header Functions */ 00121 /*****************************************/ 00122 00123 INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress, 00124 PCHAR pc_PCIChipInformation, comedi_device * dev); 00125 00126 INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress, 00127 PCHAR pc_PCIChipInformation, WORD w_Address, 00128 str_DigitalInputHeader * s_Header); 00129 00130 INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress, 00131 PCHAR pc_PCIChipInformation, WORD w_Address, 00132 str_DigitalOutputHeader * s_Header); 00133 00134 INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, 00135 PCHAR pc_PCIChipInformation, WORD w_Address, 00136 str_TimerMainHeader * s_Header); 00137 00138 INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress, 00139 PCHAR pc_PCIChipInformation, WORD w_Address, 00140 str_AnalogOutputHeader * s_Header); 00141 00142 INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress, 00143 PCHAR pc_PCIChipInformation, WORD w_Address, 00144 str_AnalogInputHeader * s_Header); 00145 00146 /******************************************/ 00147 /* Eeprom Specific Functions */ 00148 /******************************************/ 00149 WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress, PCHAR pc_PCIChipInformation, 00150 WORD w_EepromStartAddress); 00151 VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress); 00152 VOID v_EepromClock76(DWORD dw_Address, DWORD dw_RegisterValue); 00153 VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress); 00154 VOID v_EepromSendCommand76(DWORD dw_Address, DWORD dw_EepromCommand, 00155 BYTE b_DataLengthInBits); 00156 VOID v_EepromCs76Read(DWORD dw_Address, WORD w_offset, PWORD pw_Value); 00157 00158 /* 00159 +----------------------------------------------------------------------------+ 00160 | Function Name : WORD w_EepromReadWord | 00161 | (WORD w_PCIBoardEepromAddress, | 00162 | PCHAR pc_PCIChipInformation, | 00163 | WORD w_EepromStartAddress) | 00164 +----------------------------------------------------------------------------+ 00165 | Task : Read from eepromn a word | 00166 +----------------------------------------------------------------------------+ 00167 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 00168 | | 00169 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 00170 | | 00171 | WORD w_EepromStartAddress : Selected eeprom address | 00172 +----------------------------------------------------------------------------+ 00173 | Output Parameters : - | 00174 +----------------------------------------------------------------------------+ 00175 | Return Value : Read word value from eeprom | 00176 +----------------------------------------------------------------------------+ 00177 */ 00178 00179 WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress, PCHAR pc_PCIChipInformation, 00180 WORD w_EepromStartAddress) 00181 { 00182 00183 BYTE b_Counter = 0; 00184 00185 BYTE b_ReadByte = 0; 00186 00187 BYTE b_ReadLowByte = 0; 00188 00189 BYTE b_ReadHighByte = 0; 00190 00191 BYTE b_SelectedAddressLow = 0; 00192 00193 BYTE b_SelectedAddressHigh = 0; 00194 00195 WORD w_ReadWord = 0; 00196 00197 /**************************/ 00198 00199 /* Test the PCI chip type */ 00200 00201 /**************************/ 00202 00203 if ((!strcmp(pc_PCIChipInformation, "S5920")) || 00204 (!strcmp(pc_PCIChipInformation, "S5933"))) 00205 { 00206 00207 for (b_Counter = 0; b_Counter < 2; b_Counter++) 00208 { 00209 00210 b_SelectedAddressLow = (w_EepromStartAddress + b_Counter) % 256; //Read the low 8 bit part 00211 00212 b_SelectedAddressHigh = (w_EepromStartAddress + b_Counter) / 256; //Read the high 8 bit part 00213 00214 /************************************/ 00215 00216 /* Select the load low address mode */ 00217 00218 /************************************/ 00219 00220 outb(NVCMD_LOAD_LOW, w_PCIBoardEepromAddress + 0x3F); 00221 00222 /****************/ 00223 00224 /* Wait on busy */ 00225 00226 /****************/ 00227 00228 v_EepromWaitBusy(w_PCIBoardEepromAddress); 00229 00230 /************************/ 00231 00232 /* Load the low address */ 00233 00234 /************************/ 00235 00236 outb(b_SelectedAddressLow, 00237 w_PCIBoardEepromAddress + 0x3E); 00238 00239 /****************/ 00240 00241 /* Wait on busy */ 00242 00243 /****************/ 00244 00245 v_EepromWaitBusy(w_PCIBoardEepromAddress); 00246 00247 /*************************************/ 00248 00249 /* Select the load high address mode */ 00250 00251 /*************************************/ 00252 00253 outb(NVCMD_LOAD_HIGH, w_PCIBoardEepromAddress + 0x3F); 00254 00255 /****************/ 00256 00257 /* Wait on busy */ 00258 00259 /****************/ 00260 00261 v_EepromWaitBusy(w_PCIBoardEepromAddress); 00262 00263 /*************************/ 00264 00265 /* Load the high address */ 00266 00267 /*************************/ 00268 00269 outb(b_SelectedAddressHigh, 00270 w_PCIBoardEepromAddress + 0x3E); 00271 00272 /****************/ 00273 00274 /* Wait on busy */ 00275 00276 /****************/ 00277 00278 v_EepromWaitBusy(w_PCIBoardEepromAddress); 00279 00280 /************************/ 00281 00282 /* Select the READ mode */ 00283 00284 /************************/ 00285 00286 outb(NVCMD_BEGIN_READ, w_PCIBoardEepromAddress + 0x3F); 00287 00288 /****************/ 00289 00290 /* Wait on busy */ 00291 00292 /****************/ 00293 00294 v_EepromWaitBusy(w_PCIBoardEepromAddress); 00295 00296 /*****************************/ 00297 00298 /* Read data into the EEPROM */ 00299 00300 /*****************************/ 00301 00302 b_ReadByte = inb(w_PCIBoardEepromAddress + 0x3E); 00303 00304 /****************/ 00305 00306 /* Wait on busy */ 00307 00308 /****************/ 00309 00310 v_EepromWaitBusy(w_PCIBoardEepromAddress); 00311 00312 /*********************************/ 00313 00314 /* Select the upper address part */ 00315 00316 /*********************************/ 00317 00318 if (b_Counter == 0) 00319 { 00320 00321 b_ReadLowByte = b_ReadByte; 00322 00323 } // if(b_Counter==0) 00324 00325 else 00326 { 00327 00328 b_ReadHighByte = b_ReadByte; 00329 00330 } // if(b_Counter==0) 00331 00332 } // for (b_Counter=0; b_Counter<2; b_Counter++) 00333 00334 w_ReadWord = (b_ReadLowByte | (((WORD) b_ReadHighByte) * 256)); 00335 00336 } // end of if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) 00337 00338 if (!strcmp(pc_PCIChipInformation, "93C76")) 00339 { 00340 00341 /*************************************/ 00342 00343 /* Read 16 bit from the EEPROM 93C76 */ 00344 00345 /*************************************/ 00346 00347 v_EepromCs76Read(w_PCIBoardEepromAddress, w_EepromStartAddress, 00348 &w_ReadWord); 00349 00350 } 00351 00352 return (w_ReadWord); 00353 00354 } 00355 00356 /* 00357 00358 +----------------------------------------------------------------------------+ 00359 00360 | Function Name : VOID v_EepromWaitBusy | 00361 00362 | (WORD w_PCIBoardEepromAddress) | 00363 00364 +----------------------------------------------------------------------------+ 00365 00366 | Task : Wait the busy flag from PCI controller | 00367 00368 +----------------------------------------------------------------------------+ 00369 00370 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom base address | 00371 00372 +----------------------------------------------------------------------------+ 00373 00374 | Output Parameters : - | 00375 00376 +----------------------------------------------------------------------------+ 00377 00378 | Return Value : - | 00379 00380 +----------------------------------------------------------------------------+ 00381 00382 */ 00383 00384 VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress) 00385 { 00386 00387 BYTE b_EepromBusy = 0; 00388 00389 do 00390 { 00391 00392 /*************/ 00393 00394 /* IMPORTANT */ 00395 00396 /*************/ 00397 00398 /************************************************************************/ 00399 00400 /* An error has been written in the AMCC 5933 book at the page B-13 */ 00401 00402 /* Ex: if you read a byte and look for the busy statusEEPROM=0x80 and */ 00403 00404 /* the operator register is AMCC_OP_REG_MCSR+3 */ 00405 00406 /* WORD read EEPROM=0x8000 andAMCC_OP_REG_MCSR+2 */ 00407 00408 /* DWORD read EEPROM=0x80000000 and AMCC_OP_REG_MCSR */ 00409 00410 /************************************************************************/ 00411 00412 b_EepromBusy = inb(w_PCIBoardEepromAddress + 0x3F); 00413 b_EepromBusy = b_EepromBusy & 0x80; 00414 00415 } 00416 while (b_EepromBusy == 0x80); 00417 00418 } 00419 00420 /* 00421 00422 +---------------------------------------------------------------------------------+ 00423 00424 | Function Name : VOID v_EepromClock76(DWORD dw_Address, | 00425 00426 | DWORD dw_RegisterValue) | 00427 00428 +---------------------------------------------------------------------------------+ 00429 00430 | Task : This function sends the clocking sequence to the EEPROM. | 00431 00432 +---------------------------------------------------------------------------------+ 00433 00434 | Input Parameters : DWORD dw_Address : PCI eeprom base address | 00435 00436 | DWORD dw_RegisterValue : PCI eeprom register value to write.| 00437 00438 +---------------------------------------------------------------------------------+ 00439 00440 | Output Parameters : - | 00441 00442 +---------------------------------------------------------------------------------+ 00443 00444 | Return Value : - | 00445 00446 +---------------------------------------------------------------------------------+ 00447 00448 */ 00449 00450 VOID v_EepromClock76(DWORD dw_Address, DWORD dw_RegisterValue) 00451 { 00452 00453 /************************/ 00454 00455 /* Set EEPROM clock Low */ 00456 00457 /************************/ 00458 00459 outl(dw_RegisterValue & 0x6, dw_Address); 00460 00461 /***************/ 00462 00463 /* Wait 0.1 ms */ 00464 00465 /***************/ 00466 00467 udelay(100); 00468 00469 /*************************/ 00470 00471 /* Set EEPROM clock High */ 00472 00473 /*************************/ 00474 00475 outl(dw_RegisterValue | 0x1, dw_Address); 00476 00477 /***************/ 00478 00479 /* Wait 0.1 ms */ 00480 00481 /***************/ 00482 00483 udelay(100); 00484 00485 } 00486 00487 /* 00488 00489 +---------------------------------------------------------------------------------+ 00490 00491 | Function Name : VOID v_EepromSendCommand76(DWORD dw_Address, | 00492 00493 | DWORD dw_EepromCommand, | 00494 00495 | BYTE b_DataLengthInBits) | 00496 00497 +---------------------------------------------------------------------------------+ 00498 00499 | Task : This function sends a Command to the EEPROM 93C76. | 00500 00501 +---------------------------------------------------------------------------------+ 00502 00503 | Input Parameters : DWORD dw_Address : PCI eeprom base address | 00504 00505 | DWORD dw_EepromCommand : PCI eeprom command to write. | 00506 00507 | BYTE b_DataLengthInBits : PCI eeprom command data length. | 00508 00509 +---------------------------------------------------------------------------------+ 00510 00511 | Output Parameters : - | 00512 00513 +---------------------------------------------------------------------------------+ 00514 00515 | Return Value : - | 00516 00517 +---------------------------------------------------------------------------------+ 00518 00519 */ 00520 00521 VOID v_EepromSendCommand76(DWORD dw_Address, DWORD dw_EepromCommand, 00522 BYTE b_DataLengthInBits) 00523 { 00524 00525 CHAR c_BitPos = 0; 00526 00527 DWORD dw_RegisterValue = 0; 00528 00529 /*****************************/ 00530 00531 /* Enable EEPROM Chip Select */ 00532 00533 /*****************************/ 00534 00535 dw_RegisterValue = 0x2; 00536 00537 /********************************************************************/ 00538 00539 /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ 00540 00541 /********************************************************************/ 00542 00543 outl(dw_RegisterValue, dw_Address); 00544 00545 /***************/ 00546 00547 /* Wait 0.1 ms */ 00548 00549 /***************/ 00550 00551 udelay(100); 00552 00553 /*******************************************/ 00554 00555 /* Send EEPROM command - one bit at a time */ 00556 00557 /*******************************************/ 00558 00559 for (c_BitPos = (b_DataLengthInBits - 1); c_BitPos >= 0; c_BitPos--) 00560 { 00561 00562 /**********************************/ 00563 00564 /* Check if current bit is 0 or 1 */ 00565 00566 /**********************************/ 00567 00568 if (dw_EepromCommand & (1 << c_BitPos)) 00569 { 00570 00571 /***********/ 00572 00573 /* Write 1 */ 00574 00575 /***********/ 00576 00577 dw_RegisterValue = dw_RegisterValue | 0x4; 00578 00579 } 00580 00581 else 00582 { 00583 00584 /***********/ 00585 00586 /* Write 0 */ 00587 00588 /***********/ 00589 00590 dw_RegisterValue = dw_RegisterValue & 0x3; 00591 00592 } 00593 00594 /*********************/ 00595 00596 /* Write the command */ 00597 00598 /*********************/ 00599 00600 outl(dw_RegisterValue, dw_Address); 00601 00602 /***************/ 00603 00604 /* Wait 0.1 ms */ 00605 00606 /***************/ 00607 00608 udelay(100); 00609 00610 /****************************/ 00611 00612 /* Trigger the EEPROM clock */ 00613 00614 /****************************/ 00615 00616 v_EepromClock76(dw_Address, dw_RegisterValue); 00617 00618 } 00619 00620 } 00621 00622 /* 00623 00624 +---------------------------------------------------------------------------------+ 00625 00626 | Function Name : VOID v_EepromCs76Read(DWORD dw_Address, | 00627 00628 | WORD w_offset, | 00629 00630 | PWORD pw_Value) | 00631 00632 +---------------------------------------------------------------------------------+ 00633 00634 | Task : This function read a value from the EEPROM 93C76. | 00635 00636 +---------------------------------------------------------------------------------+ 00637 00638 | Input Parameters : DWORD dw_Address : PCI eeprom base address | 00639 00640 | WORD w_offset : Offset of the adress to read | 00641 00642 | PWORD pw_Value : PCI eeprom 16 bit read value. | 00643 00644 +---------------------------------------------------------------------------------+ 00645 00646 | Output Parameters : - | 00647 00648 +---------------------------------------------------------------------------------+ 00649 00650 | Return Value : - | 00651 00652 +---------------------------------------------------------------------------------+ 00653 00654 */ 00655 00656 VOID v_EepromCs76Read(DWORD dw_Address, WORD w_offset, PWORD pw_Value) 00657 { 00658 00659 CHAR c_BitPos = 0; 00660 00661 DWORD dw_RegisterValue = 0; 00662 00663 DWORD dw_RegisterValueRead = 0; 00664 00665 /*************************************************/ 00666 00667 /* Send EEPROM read command and offset to EEPROM */ 00668 00669 /*************************************************/ 00670 00671 v_EepromSendCommand76(dw_Address, (EE_READ << 4) | (w_offset / 2), 00672 EE76_CMD_LEN); 00673 00674 /*******************************/ 00675 00676 /* Get the last register value */ 00677 00678 /*******************************/ 00679 00680 dw_RegisterValue = (((w_offset / 2) & 0x1) << 2) | 0x2; 00681 00682 /*****************************/ 00683 00684 /* Set the 16-bit value of 0 */ 00685 00686 /*****************************/ 00687 00688 *pw_Value = 0; 00689 00690 /************************/ 00691 00692 /* Get the 16-bit value */ 00693 00694 /************************/ 00695 00696 for (c_BitPos = 0; c_BitPos < 16; c_BitPos++) 00697 { 00698 00699 /****************************/ 00700 00701 /* Trigger the EEPROM clock */ 00702 00703 /****************************/ 00704 00705 v_EepromClock76(dw_Address, dw_RegisterValue); 00706 00707 /**********************/ 00708 00709 /* Get the result bit */ 00710 00711 /**********************/ 00712 00713 dw_RegisterValueRead = inl(dw_Address); 00714 00715 /***************/ 00716 00717 /* Wait 0.1 ms */ 00718 00719 /***************/ 00720 00721 udelay(100); 00722 00723 /***************************************/ 00724 00725 /* Get bit value and shift into result */ 00726 00727 /***************************************/ 00728 00729 if (dw_RegisterValueRead & 0x8) 00730 { 00731 00732 /**********/ 00733 00734 /* Read 1 */ 00735 00736 /**********/ 00737 00738 *pw_Value = (*pw_Value << 1) | 0x1; 00739 00740 } 00741 00742 else 00743 { 00744 00745 /**********/ 00746 00747 /* Read 0 */ 00748 00749 /**********/ 00750 00751 *pw_Value = (*pw_Value << 1); 00752 00753 } 00754 00755 } 00756 00757 /*************************/ 00758 00759 /* Clear all EEPROM bits */ 00760 00761 /*************************/ 00762 00763 dw_RegisterValue = 0x0; 00764 00765 /********************************************************************/ 00766 00767 /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */ 00768 00769 /********************************************************************/ 00770 00771 outl(dw_RegisterValue, dw_Address); 00772 00773 /***************/ 00774 00775 /* Wait 0.1 ms */ 00776 00777 /***************/ 00778 00779 udelay(100); 00780 00781 } 00782 00783 /******************************************/ 00784 /* EEPROM HEADER READ FUNCTIONS */ 00785 /******************************************/ 00786 00787 /* 00788 +----------------------------------------------------------------------------+ 00789 | Function Name : INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress, | 00790 | PCHAR pc_PCIChipInformation,comedi_device *dev) | 00791 +----------------------------------------------------------------------------+ 00792 | Task : Read from eeprom Main Header | 00793 +----------------------------------------------------------------------------+ 00794 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 00795 | | 00796 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 00797 | | 00798 | comedi_device *dev : comedi device structure | 00799 | pointer | 00800 +----------------------------------------------------------------------------+ 00801 | Output Parameters : - | 00802 +----------------------------------------------------------------------------+ 00803 | Return Value : 0 | 00804 +----------------------------------------------------------------------------+ 00805 */ 00806 00807 INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress, 00808 PCHAR pc_PCIChipInformation, comedi_device * dev) 00809 { 00810 WORD w_Temp, i, w_Count = 0; 00811 UINT ui_Temp; 00812 str_MainHeader s_MainHeader; 00813 str_DigitalInputHeader s_DigitalInputHeader; 00814 str_DigitalOutputHeader s_DigitalOutputHeader; 00815 //str_TimerMainHeader s_TimerMainHeader,s_WatchdogMainHeader; 00816 str_AnalogOutputHeader s_AnalogOutputHeader; 00817 str_AnalogInputHeader s_AnalogInputHeader; 00818 00819 // Read size 00820 s_MainHeader.w_HeaderSize = 00821 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 00822 0x100 + 8); 00823 00824 // Read nbr of functionality 00825 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 00826 pc_PCIChipInformation, 0x100 + 10); 00827 s_MainHeader.b_Nfunctions = (BYTE) w_Temp & 0x00FF; 00828 00829 // Read functionality details 00830 for (i = 0; i < s_MainHeader.b_Nfunctions; i++) { 00831 // Read Type 00832 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 00833 pc_PCIChipInformation, 0x100 + 12 + w_Count); 00834 s_MainHeader.s_Functions[i].b_Type = (BYTE) w_Temp & 0x3F; 00835 w_Count = w_Count + 2; 00836 //Read Address 00837 s_MainHeader.s_Functions[i].w_Address = 00838 w_EepromReadWord(w_PCIBoardEepromAddress, 00839 pc_PCIChipInformation, 0x100 + 12 + w_Count); 00840 w_Count = w_Count + 2; 00841 } 00842 00843 // Display main header info 00844 for (i = 0; i < s_MainHeader.b_Nfunctions; i++) { 00845 00846 switch (s_MainHeader.s_Functions[i].b_Type) { 00847 case EEPROM_DIGITALINPUT: 00848 i_EepromReadDigitalInputHeader(w_PCIBoardEepromAddress, 00849 pc_PCIChipInformation, 00850 s_MainHeader.s_Functions[i].w_Address, 00851 &s_DigitalInputHeader); 00852 this_board->i_NbrDiChannel = 00853 s_DigitalInputHeader.w_Nchannel; 00854 break; 00855 00856 case EEPROM_DIGITALOUTPUT: 00857 i_EepromReadDigitalOutputHeader(w_PCIBoardEepromAddress, 00858 pc_PCIChipInformation, 00859 s_MainHeader.s_Functions[i].w_Address, 00860 &s_DigitalOutputHeader); 00861 this_board->i_NbrDoChannel = 00862 s_DigitalOutputHeader.w_Nchannel; 00863 ui_Temp = 0xffffffff; 00864 this_board->i_DoMaxdata = 00865 ui_Temp >> (32 - this_board->i_NbrDoChannel); 00866 break; 00867 00868 case EEPROM_ANALOGINPUT: 00869 i_EepromReadAnlogInputHeader(w_PCIBoardEepromAddress, 00870 pc_PCIChipInformation, 00871 s_MainHeader.s_Functions[i].w_Address, 00872 &s_AnalogInputHeader); 00873 if (!(strcmp(this_board->pc_DriverName, "apci3200"))) 00874 this_board->i_NbrAiChannel = 00875 s_AnalogInputHeader.w_Nchannel * 4; 00876 else 00877 this_board->i_NbrAiChannel = 00878 s_AnalogInputHeader.w_Nchannel; 00879 this_board->i_Dma = s_AnalogInputHeader.b_HasDma; 00880 this_board->ui_MinAcquisitiontimeNs = 00881 (UINT) s_AnalogInputHeader.w_MinConvertTiming * 00882 1000; 00883 this_board->ui_MinDelaytimeNs = 00884 (UINT) s_AnalogInputHeader.w_MinDelayTiming * 00885 1000; 00886 ui_Temp = 0xffff; 00887 this_board->i_AiMaxdata = 00888 ui_Temp >> (16 - 00889 s_AnalogInputHeader.b_Resolution); 00890 break; 00891 00892 case EEPROM_ANALOGOUTPUT: 00893 i_EepromReadAnlogOutputHeader(w_PCIBoardEepromAddress, 00894 pc_PCIChipInformation, 00895 s_MainHeader.s_Functions[i].w_Address, 00896 &s_AnalogOutputHeader); 00897 this_board->i_NbrAoChannel = 00898 s_AnalogOutputHeader.w_Nchannel; 00899 ui_Temp = 0xffff; 00900 this_board->i_AoMaxdata = 00901 ui_Temp >> (16 - 00902 s_AnalogOutputHeader.b_Resolution); 00903 break; 00904 00905 case EEPROM_TIMER: 00906 this_board->i_Timer = 1; //Timer subdevice present 00907 break; 00908 00909 case EEPROM_WATCHDOG: 00910 this_board->i_Timer = 1; //Timer subdevice present 00911 break; 00912 00913 case EEPROM_TIMER_WATCHDOG_COUNTER: 00914 this_board->i_Timer = 1; //Timer subdevice present 00915 } 00916 } 00917 00918 return 0; 00919 } 00920 00921 /* 00922 +----------------------------------------------------------------------------+ 00923 | Function Name : INT i_EepromReadDigitalInputHeader(WORD | 00924 | w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation, | 00925 | WORD w_Address,str_DigitalInputHeader *s_Header) | 00926 | | 00927 +----------------------------------------------------------------------------+ 00928 | Task : Read Digital Input Header | 00929 +----------------------------------------------------------------------------+ 00930 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 00931 | | 00932 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 00933 | | 00934 | str_DigitalInputHeader *s_Header: Digita Input Header | 00935 | Pointer | 00936 +----------------------------------------------------------------------------+ 00937 | Output Parameters : - | 00938 +----------------------------------------------------------------------------+ 00939 | Return Value : 0 | 00940 +----------------------------------------------------------------------------+ 00941 */ 00942 INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress, 00943 PCHAR pc_PCIChipInformation, WORD w_Address, 00944 str_DigitalInputHeader * s_Header) 00945 { 00946 WORD w_Temp; 00947 00948 // read nbr of channels 00949 s_Header->w_Nchannel = 00950 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 00951 0x100 + w_Address + 6); 00952 00953 // interruptible or not 00954 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 00955 pc_PCIChipInformation, 0x100 + w_Address + 8); 00956 s_Header->b_Interruptible = (BYTE) (w_Temp >> 7) & 0x01; 00957 00958 // How many interruptible logic 00959 s_Header->w_NinterruptLogic = 00960 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 00961 0x100 + w_Address + 10); 00962 00963 return 0; 00964 } 00965 00966 /* 00967 +----------------------------------------------------------------------------+ 00968 | Function Name : INT i_EepromReadDigitalOutputHeader(WORD | 00969 | w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation, | 00970 | WORD w_Address,str_DigitalOutputHeader *s_Header) | 00971 | | 00972 +----------------------------------------------------------------------------+ 00973 | Task : Read Digital Output Header | 00974 +----------------------------------------------------------------------------+ 00975 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 00976 | | 00977 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 00978 | | 00979 | str_DigitalOutputHeader *s_Header: Digital Output Header| 00980 | Pointer | 00981 +----------------------------------------------------------------------------+ 00982 | Output Parameters : - | 00983 +----------------------------------------------------------------------------+ 00984 | Return Value : 0 | 00985 +----------------------------------------------------------------------------+ 00986 */ 00987 INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress, 00988 PCHAR pc_PCIChipInformation, WORD w_Address, 00989 str_DigitalOutputHeader * s_Header) 00990 { 00991 // Read Nbr channels 00992 s_Header->w_Nchannel = 00993 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 00994 0x100 + w_Address + 6); 00995 return 0; 00996 } 00997 00998 /* 00999 +----------------------------------------------------------------------------+ 01000 | Function Name : INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, | 01001 | PCHAR pc_PCIChipInformation,WORD w_Address, | 01002 | str_TimerMainHeader *s_Header) | 01003 +----------------------------------------------------------------------------+ 01004 | Task : Read Timer or Watchdog Header | 01005 +----------------------------------------------------------------------------+ 01006 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 01007 | | 01008 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 01009 | | 01010 | str_TimerMainHeader *s_Header: Timer Header | 01011 | Pointer | 01012 +----------------------------------------------------------------------------+ 01013 | Output Parameters : - | 01014 +----------------------------------------------------------------------------+ 01015 | Return Value : 0 | 01016 +----------------------------------------------------------------------------+ 01017 */ 01018 INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress, 01019 PCHAR pc_PCIChipInformation, WORD w_Address, 01020 str_TimerMainHeader * s_Header) 01021 { 01022 01023 WORD i, w_Size = 0, w_Temp; 01024 01025 //Read No of Timer 01026 s_Header->w_Ntimer = 01027 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 01028 0x100 + w_Address + 6); 01029 //Read header size 01030 01031 for (i = 0; i < s_Header->w_Ntimer; i++) { 01032 s_Header->s_TimerDetails[i].w_HeaderSize = 01033 w_EepromReadWord(w_PCIBoardEepromAddress, 01034 pc_PCIChipInformation, 01035 0x100 + w_Address + 8 + w_Size + 0); 01036 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01037 pc_PCIChipInformation, 01038 0x100 + w_Address + 8 + w_Size + 2); 01039 01040 //Read Resolution 01041 s_Header->s_TimerDetails[i].b_Resolution = 01042 (BYTE) (w_Temp >> 10) & 0x3F; 01043 01044 //Read Mode 01045 s_Header->s_TimerDetails[i].b_Mode = 01046 (BYTE) (w_Temp >> 4) & 0x3F; 01047 01048 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01049 pc_PCIChipInformation, 01050 0x100 + w_Address + 8 + w_Size + 4); 01051 01052 //Read MinTiming 01053 s_Header->s_TimerDetails[i].w_MinTiming = (w_Temp >> 6) & 0x3FF; 01054 01055 //Read Timebase 01056 s_Header->s_TimerDetails[i].b_TimeBase = (BYTE) (w_Temp) & 0x3F; 01057 w_Size += s_Header->s_TimerDetails[i].w_HeaderSize; 01058 } 01059 01060 return 0; 01061 } 01062 01063 /* 01064 +----------------------------------------------------------------------------+ 01065 | Function Name : INT i_EepromReadAnlogOutputHeader(WORD | 01066 | w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation, | 01067 | WORD w_Address,str_AnalogOutputHeader *s_Header) | 01068 +----------------------------------------------------------------------------+ 01069 | Task : Read Nalog Output Header | 01070 +----------------------------------------------------------------------------+ 01071 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 01072 | | 01073 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 01074 | | 01075 | str_AnalogOutputHeader *s_Header:Anlog Output Header | 01076 | Pointer | 01077 +----------------------------------------------------------------------------+ 01078 | Output Parameters : - | 01079 +----------------------------------------------------------------------------+ 01080 | Return Value : 0 | 01081 +----------------------------------------------------------------------------+ 01082 */ 01083 01084 INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress, 01085 PCHAR pc_PCIChipInformation, WORD w_Address, 01086 str_AnalogOutputHeader * s_Header) 01087 { 01088 WORD w_Temp; 01089 // No of channels for 1st hard component 01090 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01091 pc_PCIChipInformation, 0x100 + w_Address + 10); 01092 s_Header->w_Nchannel = (w_Temp >> 4) & 0x03FF; 01093 // Resolution for 1st hard component 01094 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01095 pc_PCIChipInformation, 0x100 + w_Address + 16); 01096 s_Header->b_Resolution = (BYTE) (w_Temp >> 8) & 0xFF; 01097 return 0; 01098 } 01099 01100 /* 01101 +----------------------------------------------------------------------------+ 01102 | Function Name : INT i_EepromReadAnlogInputHeader(WORD | 01103 | w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation, | 01104 | WORD w_Address,str_AnalogInputHeader *s_Header) | 01105 +----------------------------------------------------------------------------+ 01106 | Task : Read Nalog Output Header | 01107 +----------------------------------------------------------------------------+ 01108 | Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address | 01109 | | 01110 | PCHAR pc_PCIChipInformation : PCI Chip Type. | 01111 | | 01112 | str_AnalogInputHeader *s_Header:Anlog Input Header | 01113 | Pointer | 01114 +----------------------------------------------------------------------------+ 01115 | Output Parameters : - | 01116 +----------------------------------------------------------------------------+ 01117 | Return Value : 0 | 01118 +----------------------------------------------------------------------------+ 01119 */ 01120 01121 // Reads only for ONE hardware component 01122 INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress, 01123 PCHAR pc_PCIChipInformation, WORD w_Address, 01124 str_AnalogInputHeader * s_Header) 01125 { 01126 WORD w_Temp, w_Offset; 01127 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01128 pc_PCIChipInformation, 0x100 + w_Address + 10); 01129 s_Header->w_Nchannel = (w_Temp >> 4) & 0x03FF; 01130 s_Header->w_MinConvertTiming = 01131 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 01132 0x100 + w_Address + 16); 01133 s_Header->w_MinDelayTiming = 01134 w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 01135 0x100 + w_Address + 30); 01136 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01137 pc_PCIChipInformation, 0x100 + w_Address + 20); 01138 s_Header->b_HasDma = (w_Temp >> 13) & 0x01; // whether dma present or not 01139 01140 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, pc_PCIChipInformation, 0x100 + w_Address + 72); // reading Y 01141 w_Temp = w_Temp & 0x00FF; 01142 if (w_Temp) //Y>0 01143 { 01144 w_Offset = 74 + (2 * w_Temp) + (10 * (1 + (w_Temp / 16))); // offset of first analog input single header 01145 w_Offset = w_Offset + 2; // resolution 01146 } else //Y=0 01147 { 01148 w_Offset = 74; 01149 w_Offset = w_Offset + 2; // resolution 01150 } 01151 01152 // read Resolution 01153 w_Temp = w_EepromReadWord(w_PCIBoardEepromAddress, 01154 pc_PCIChipInformation, 0x100 + w_Address + w_Offset); 01155 s_Header->b_Resolution = w_Temp & 0x001F; // last 5 bits 01156 01157 return 0; 01158 }