📄 addi_eeprom.c
字号:
/**@verbatimCopyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module. ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier Tel: +19(0)7223/9493-0 Fax: +49(0)7223/9493-92 http://www.addi-data-com info@addi-data.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAYou shoud also find the complete GPL in the COPYING file accompanying this source code.@endverbatim*//* +-----------------------------------------------------------------------+ | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier | +-----------------------------------------------------------------------+ | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | +-----------------------------------------------------------------------+ | Project : ADDI DATA | Compiler : GCC | | Modulname : addi_eeprom.c | Version : 2.96 | +-------------------------------+---------------------------------------+ | Project manager: Eric Stolz | Date : 02/12/2002 | +-----------------------------------------------------------------------+ | Description : ADDI EEPROM Module | +-----------------------------------------------------------------------+ | UPDATE'S | +-----------------------------------------------------------------------+ | Date | Author | Description of updates | +----------+-----------+------------------------------------------------+ | | | | | | | | +----------+-----------+------------------------------------------------+*/#define NVCMD_BEGIN_READ (0x7 << 5 ) // nvRam begin read command#define NVCMD_LOAD_LOW (0x4 << 5 ) // nvRam load low command#define NVCMD_LOAD_HIGH (0x5 << 5 ) // nvRam load high command#define EE76_CMD_LEN 13 // bits in instructions #define EE_READ 0x0180 // 01 1000 0000 read instruction#define WORD unsigned short#define PWORD unsigned short *#define PDWORD unsigned int *#ifndef DWORD#define DWORD unsigned int#endif#define EEPROM_DIGITALINPUT 0#define EEPROM_DIGITALOUTPUT 1#define EEPROM_ANALOGINPUT 2#define EEPROM_ANALOGOUTPUT 3#define EEPROM_TIMER 4#define EEPROM_WATCHDOG 5 #define EEPROM_TIMER_WATCHDOG_COUNTER 10struct str_Functionality{ BYTE b_Type; WORD w_Address;};typedef struct { WORD w_HeaderSize; BYTE b_Nfunctions; struct str_Functionality s_Functions[7];}str_MainHeader;typedef struct{ WORD w_Nchannel; BYTE b_Interruptible; WORD w_NinterruptLogic;}str_DigitalInputHeader;typedef struct{ WORD w_Nchannel;}str_DigitalOutputHeader;// used for timer as well as watchdogtypedef struct{ WORD w_HeaderSize; BYTE b_Resolution; BYTE b_Mode; // in case of Watchdog it is functionality WORD w_MinTiming; BYTE b_TimeBase;}str_TimerDetails;typedef struct{ WORD w_Ntimer; str_TimerDetails s_TimerDetails[4]; // supports 4 timers}str_TimerMainHeader; typedef struct{ WORD w_Nchannel; BYTE b_Resolution; }str_AnalogOutputHeader ;typedef struct{ WORD w_Nchannel; WORD w_MinConvertTiming; WORD w_MinDelayTiming; BYTE b_HasDma; BYTE b_Resolution;} str_AnalogInputHeader; /*****************************************/ /* Read Header Functions */ /*****************************************/INT i_EepromReadMainHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,comedi_device *dev);INT i_EepromReadDigitalInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalInputHeader *s_Header);INT i_EepromReadDigitalOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_DigitalOutputHeader *s_Header);INT i_EepromReadTimerHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_TimerMainHeader *s_Header);INT i_EepromReadAnlogOutputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogOutputHeader *s_Header);INT i_EepromReadAnlogInputHeader(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_Address,str_AnalogInputHeader *s_Header); /******************************************/ /* Eeprom Specific Functions */ /******************************************/WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_EepromStartAddress);VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress);VOID v_EepromClock76(DWORD dw_Address,DWORD dw_RegisterValue);VOID v_EepromWaitBusy(WORD w_PCIBoardEepromAddress);VOID v_EepromSendCommand76(DWORD dw_Address,DWORD dw_EepromCommand,BYTE b_DataLengthInBits);VOID v_EepromCs76Read(DWORD dw_Address,WORD w_offset,PWORD pw_Value);/*+----------------------------------------------------------------------------+| Function Name : WORD w_EepromReadWord || (WORD w_PCIBoardEepromAddress, || PCHAR pc_PCIChipInformation, || WORD w_EepromStartAddress) |+----------------------------------------------------------------------------+| Task : Read from eepromn a word |+----------------------------------------------------------------------------+| Input Parameters : WORD w_PCIBoardEepromAddress : PCI eeprom address || || PCHAR pc_PCIChipInformation : PCI Chip Type. || || WORD w_EepromStartAddress : Selected eeprom address |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value : Read word value from eeprom |+----------------------------------------------------------------------------+*/WORD w_EepromReadWord(WORD w_PCIBoardEepromAddress,PCHAR pc_PCIChipInformation,WORD w_EepromStartAddress){ BYTE b_Counter = 0; BYTE b_ReadByte = 0; BYTE b_ReadLowByte = 0; BYTE b_ReadHighByte = 0; BYTE b_SelectedAddressLow = 0; BYTE b_SelectedAddressHigh = 0; WORD w_ReadWord = 0; /**************************/ /* Test the PCI chip type */ /**************************/ if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) { for (b_Counter=0; b_Counter<2; b_Counter++) { b_SelectedAddressLow = (w_EepromStartAddress + b_Counter) % 256; //Read the low 8 bit part b_SelectedAddressHigh = (w_EepromStartAddress + b_Counter) / 256; //Read the high 8 bit part /************************************/ /* Select the load low address mode */ /************************************/ outb(NVCMD_LOAD_LOW,w_PCIBoardEepromAddress + 0x3F); /****************/ /* Wait on busy */ /****************/ v_EepromWaitBusy (w_PCIBoardEepromAddress); /************************/ /* Load the low address */ /************************/ outb(b_SelectedAddressLow,w_PCIBoardEepromAddress + 0x3E); /****************/ /* Wait on busy */ /****************/ v_EepromWaitBusy (w_PCIBoardEepromAddress); /*************************************/ /* Select the load high address mode */ /*************************************/ outb(NVCMD_LOAD_HIGH,w_PCIBoardEepromAddress + 0x3F); /****************/ /* Wait on busy */ /****************/ v_EepromWaitBusy (w_PCIBoardEepromAddress); /*************************/ /* Load the high address */ /*************************/ outb(b_SelectedAddressHigh,w_PCIBoardEepromAddress +0x3E); /****************/ /* Wait on busy */ /****************/ v_EepromWaitBusy (w_PCIBoardEepromAddress); /************************/ /* Select the READ mode */ /************************/ outb(NVCMD_BEGIN_READ,w_PCIBoardEepromAddress + 0x3F); /****************/ /* Wait on busy */ /****************/ v_EepromWaitBusy (w_PCIBoardEepromAddress); /*****************************/ /* Read data into the EEPROM */ /*****************************/ b_ReadByte = inb(w_PCIBoardEepromAddress + 0x3E); /****************/ /* Wait on busy */ /****************/ v_EepromWaitBusy (w_PCIBoardEepromAddress); /*********************************/ /* Select the upper address part */ /*********************************/ if(b_Counter==0) { b_ReadLowByte=b_ReadByte; } // if(b_Counter==0) else { b_ReadHighByte=b_ReadByte; } // if(b_Counter==0) } // for (b_Counter=0; b_Counter<2; b_Counter++) w_ReadWord=(b_ReadLowByte | (((WORD) b_ReadHighByte) * 256)); } // end of if ((!strcmp(pc_PCIChipInformation, "S5920")) || (!strcmp(pc_PCIChipInformation, "S5933"))) if (!strcmp(pc_PCIChipInformation, "93C76")) { /*************************************/ /* Read 16 bit from the EEPROM 93C76 */ /*************************************/ v_EepromCs76Read(w_PCIBoardEepromAddress, w_EepromStartAddress, &w_ReadWord); } return (w_ReadWord); }/*+----------------------------------------------------------------------------+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -