📄 apci1710_pwm.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 Dieselstraße 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 : API APCI1710 | Compiler : gcc | | Module name : PWM.C | Version : 2.96 | +-------------------------------+---------------------------------------+ | Project manager: Eric Stolz | Date : 02/12/2002 | +-----------------------------------------------------------------------+ | Description : APCI-1710 Wulse wide modulation module | | | | | +-----------------------------------------------------------------------+ | UPDATES | +-----------------------------------------------------------------------+ | Date | Author | Description of updates | +-----------------------------------------------------------------------+ | 08/05/00 | Guinot C | - 0400/0228 All Function in RING 0 | | | | available | +-----------------------------------------------------------------------+*//*+----------------------------------------------------------------------------+| Included files |+----------------------------------------------------------------------------+*/#include "APCI1710_Pwm.h"/*+----------------------------------------------------------------------------+| Function Name :INT i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) |+----------------------------------------------------------------------------+| Task : Pwm Init and Get Pwm Initialisation |+----------------------------------------------------------------------------+| Input Parameters : +----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value : +----------------------------------------------------------------------------+*/INT i_APCI1710_InsnConfigPWM(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ BYTE b_ConfigType; INT i_ReturnValue=0; b_ConfigType=CR_CHAN(insn->chanspec); switch(b_ConfigType) { case APCI1710_PWM_INIT : i_ReturnValue=i_APCI1710_InitPWM (dev, (BYTE)CR_AREF(insn->chanspec), // b_ModulNbr (BYTE) data[0], //b_PWM (BYTE) data[1], // b_ClockSelection (BYTE) data[2], // b_TimingUnit (ULONG)data[3], //ul_LowTiming (ULONG)data[4], //ul_HighTiming (PULONG)&data[0], //pul_RealLowTiming (PULONG)&data[1] //pul_RealHighTiming ); break; case APCI1710_PWM_GETINITDATA : i_ReturnValue=i_APCI1710_GetPWMInitialisation (dev, (BYTE)CR_AREF(insn->chanspec), // b_ModulNbr (BYTE) data[0], //b_PWM (PBYTE)&data[0], //pb_TimingUnit (PULONG)&data[1], //pul_LowTiming (PULONG)&data[2], //pul_HighTiming (PBYTE) &data[3], // pb_StartLevel (PBYTE) &data[4], // pb_StopMode (PBYTE) &data[5], // pb_StopLevel (PBYTE) &data[6], // pb_ExternGate (PBYTE) &data[7], // pb_InterruptEnable (PBYTE) &data[8] // pb_Enable ); break; default: printk(" Config Parameter Wrong\n"); } if(i_ReturnValue>=0) i_ReturnValue =insn->n; return (i_ReturnValue);}/*+----------------------------------------------------------------------------+| Function Name : _INT_ i_APCI1710_InitPWM || (BYTE_ b_BoardHandle, || BYTE_ b_ModulNbr, || BYTE_ b_PWM, || BYTE_ b_ClockSelection, || BYTE_ b_TimingUnit, || ULONG_ ul_LowTiming, || ULONG_ ul_HighTiming, || PULONG_ pul_RealLowTiming, || PULONG_ pul_RealHighTiming) |+----------------------------------------------------------------------------+| Task : Configure the selected PWM (b_PWM) from selected module|| (b_ModulNbr). The ul_LowTiming, ul_HighTiming and || ul_TimingUnit determine the low/high timing base for || the period. pul_RealLowTiming, pul_RealHighTiming || return the real timing value. || You must calling this function be for you call any || other function witch access of the PWM. |+----------------------------------------------------------------------------+| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 || BYTE_ b_ModulNbr : Module number to configure|| (0 to 3) || BYTE_ b_PWM : Selected PWM (0 or 1). || BYTE_ b_ClockSelection : Selection from PCI bus || clock || - APCI1710_30MHZ : || The PC have a 30 MHz || PCI bus clock || - APCI1710_33MHZ : || The PC have a 33 MHz || PCI bus clock || - APCI1710_40MHZ || The APCI-1710 have a || integrated 40Mhz || quartz. || BYTE_ b_TimingUnit : Base timing Unit (0 to 4) || 0 : ns || 1 : æs || 2 : ms || 3 : s || 4 : mn || ULONG_ ul_LowTiming : Low base timing value. || ULONG_ ul_HighTiming : High base timing value. |+----------------------------------------------------------------------------+| Output Parameters : PULONG_ pul_RealLowTiming : Real low base timing || value. || PULONG_ pul_RealHighTiming : Real high base timing || value. |+----------------------------------------------------------------------------+| Return Value : 0: No error || -1: The handle parameter of the board is wrong || -2: Module selection wrong || -3: The module is not a PWM module || -4: PWM selection is wrong || -5: The selected input clock is wrong || -6: Timing Unit selection is wrong || -7: Low base timing selection is wrong || -8: High base timing selection is wrong || -9: You can not used the 40MHz clock selection with || this board |+----------------------------------------------------------------------------+*/INT i_APCI1710_InitPWM (comedi_device *dev, BYTE b_ModulNbr, BYTE b_PWM, BYTE b_ClockSelection, BYTE b_TimingUnit, ULONG ul_LowTiming, ULONG ul_HighTiming, PULONG pul_RealLowTiming, PULONG pul_RealHighTiming) { INT i_ReturnValue = 0; ULONG ul_LowTimerValue = 0; ULONG ul_HighTimerValue = 0; DWORD dw_Command; double d_RealLowTiming = 0; double d_RealHighTiming = 0; /**************************/ /* Test the module number */ /**************************/ if (b_ModulNbr < 4) { /***************/ /* Test if PWM */ /***************/ if ((devpriv-> s_BoardInfos. dw_MolduleConfiguration [b_ModulNbr] & 0xFFFF0000UL) == APCI1710_PWM) { /**************************/ /* Test the PWM selection */ /**************************/ if (b_PWM <= 1) { /******************/ /* Test the clock */ /******************/ if ((b_ClockSelection == APCI1710_30MHZ) || (b_ClockSelection == APCI1710_33MHZ) || (b_ClockSelection == APCI1710_40MHZ)) { /************************/ /* Test the timing unit */ /************************/ if (b_TimingUnit <= 4) { /*********************************/ /* Test the low timing selection */ /*********************************/ if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 266) && (ul_LowTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571230650UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571230UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 571UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 9UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 242) && (ul_LowTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 519691043UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 519691UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 520UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 8UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_LowTiming >= 200) && (ul_LowTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429496729UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429496UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_LowTiming >= 1) && (ul_LowTiming <= 429UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_LowTiming >= 1) && (ul_LowTiming <= 7UL))) { /**********************************/ /* Test the High timing selection */ /**********************************/ if (((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 266) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230650UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571230UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 571UL)) || ((b_ClockSelection == APCI1710_30MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 9UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 242) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691043UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 519691UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 520UL)) || ((b_ClockSelection == APCI1710_33MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 8UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 0) && (ul_HighTiming >= 200) && (ul_HighTiming <= 0xFFFFFFFFUL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 1) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496729UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 2) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429496UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 3) && (ul_HighTiming >= 1) && (ul_HighTiming <= 429UL)) || ((b_ClockSelection == APCI1710_40MHZ) && (b_TimingUnit == 4) && (ul_HighTiming >= 1) && (ul_HighTiming <= 7UL))) { /**************************/ /* Test the board version */ /**************************/ if (((b_ClockSelection == APCI1710_40MHZ) && (devpriv-> s_BoardInfos. b_BoardVersion > 0)) || (b_ClockSelection != APCI1710_40MHZ)) { /************************************/ /* Calculate the low division fator */ /************************************/ fpu_begin (); switch (b_TimingUnit) { /******/ /* ns */ /******/ case 0: /******************/ /* Timer 0 factor */ /******************/ ul_LowTimerValue = (ULONG) (ul_LowTiming * (0.00025 * b_ClockSelection)); /*******************/ /* Round the value */ /*******************/ if ((double) ((double) ul_LowTiming * (0.00025 * (double) b_ClockSelection)) >= ((double) ((double) ul_LowTimerValue + 0.5))) { ul_LowTimerValue = ul_LowTimerValue + 1; } /*****************************/ /* Calculate the real timing */ /*****************************/ *pul_RealLowTiming = (ULONG) (ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)); d_RealLowTiming = (double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection); if ((double) ((double) ul_LowTimerValue / (0.00025 * (double) b_ClockSelection)) >= (double) ((double) *pul_RealLowTiming + 0.5)) { *pul_RealLowTiming = *pul_RealLowTiming + 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -