📄 apci1710_pwm.c
字号:
| - APCI1710_ENABLE : || Enable the PWM interrupt|| A interrupt occur after || each period || - APCI1710_DISABLE : || Disable the PWM || interrupt || PBYTE_ pb_Enable : Indicate if the PWM is || enabled or no || 0 : PWM not enabled || 1 : PWM enabled |+----------------------------------------------------------------------------+| 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: PWM not initialised see function || "i_APCI1710_InitPWM" |+----------------------------------------------------------------------------+*/INT i_APCI1710_GetPWMInitialisation (comedi_device *dev, BYTE b_ModulNbr, BYTE b_PWM, PBYTE pb_TimingUnit, PULONG pul_LowTiming, PULONG pul_HighTiming, PBYTE pb_StartLevel, PBYTE pb_StopMode, PBYTE pb_StopLevel, PBYTE pb_ExternGate, PBYTE pb_InterruptEnable, PBYTE pb_Enable) { INT i_ReturnValue = 0; DWORD dw_Status; DWORD dw_Command; /**************************/ /* 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 if PWM initialised */ /***************************/ dw_Status=inl(devpriv->s_BoardInfos. ui_Address + 12 + (20 * b_PWM) + (64 * b_ModulNbr)); if (dw_Status & 0x10) { /***********************/ /* Read the low timing */ /***********************/ *pul_LowTiming = inl(devpriv->s_BoardInfos. ui_Address + 0 + (20 * b_PWM) + (64 * b_ModulNbr)); /************************/ /* Read the high timing */ /************************/ *pul_HighTiming= inl(devpriv->s_BoardInfos. ui_Address + 4 + (20 * b_PWM) + (64 * b_ModulNbr)); /********************/ /* Read the command */ /********************/ dw_Command = inl(devpriv->s_BoardInfos. ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); *pb_StartLevel = (BYTE) ((dw_Command >> 5) & 1); *pb_StopMode = (BYTE) ((dw_Command >> 0) & 1); *pb_StopLevel = (BYTE) ((dw_Command >> 1) & 1); *pb_ExternGate = (BYTE) ((dw_Command >> 4) & 1); *pb_InterruptEnable = (BYTE) ((dw_Command >> 3) & 1); if (*pb_StopLevel) { *pb_StopLevel = *pb_StopLevel + (BYTE) ((dw_Command >> 2) & 1); } /********************/ /* Read the command */ /********************/ dw_Command=inl(devpriv->s_BoardInfos. ui_Address + 8 + (20 * b_PWM) + (64 * b_ModulNbr)); *pb_Enable = (BYTE) ((dw_Command >> 0) & 1); *pb_TimingUnit = devpriv-> s_ModuleInfo [b_ModulNbr]. s_PWMModuleInfo. s_PWMInfo [b_PWM]. b_TimingUnit; } // if (dw_Status & 0x10) else { /***********************/ /* PWM not initialised */ /***********************/ DPRINTK("PWM not initialised\n"); i_ReturnValue = -5; } // if (dw_Status & 0x10) } // if (b_PWM >= 0 && b_PWM <= 1) else { /******************************/ /* Tor PWM selection is wrong */ /******************************/ DPRINTK("Tor PWM selection is wrong\n"); i_ReturnValue = -4; } // if (b_PWM >= 0 && b_PWM <= 1) } else { /**********************************/ /* The module is not a PWM module */ /**********************************/ DPRINTK("The module is not a PWM module\n"); i_ReturnValue = -3; } } else { /***********************/ /* Module number error */ /***********************/ DPRINTK("Module number error\n"); i_ReturnValue = -2; } return (i_ReturnValue); }/*+----------------------------------------------------------------------------+| Function Name :INT i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) |+----------------------------------------------------------------------------+| Task : Pwm Enable Disable and Set New Timing |+----------------------------------------------------------------------------+| Input Parameters : +----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| Return Value : +----------------------------------------------------------------------------+*/INT i_APCI1710_InsnWritePWM(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){ BYTE b_WriteType; INT i_ReturnValue=0; b_WriteType=CR_CHAN(insn->chanspec); switch(b_WriteType) { case APCI1710_PWM_ENABLE : i_ReturnValue=i_APCI1710_EnablePWM (dev, (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0], (BYTE) data[1], (BYTE) data[2], (BYTE) data[3], (BYTE) data[4], (BYTE) data[5]); break; case APCI1710_PWM_DISABLE : i_ReturnValue=i_APCI1710_DisablePWM (dev, (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0]); break; case APCI1710_PWM_NEWTIMING: i_ReturnValue=i_APCI1710_SetNewPWMTiming (dev, (BYTE) CR_AREF(insn->chanspec), (BYTE) data[0], (BYTE) data[1], (ULONG) data[2], (ULONG) data[3]); break; default: printk("Write Config Parameter Wrong\n"); } if(i_ReturnValue>=0) i_ReturnValue =insn->n; return (i_ReturnValue);}/*+----------------------------------------------------------------------------+| Function Name : _INT_ i_APCI1710_EnablePWM || (BYTE_ b_BoardHandle, || BYTE_ b_ModulNbr, || BYTE_ b_PWM, || BYTE_ b_StartLevel, || BYTE_ b_StopMode, || BYTE_ b_StopLevel, || BYTE_ b_ExternGate, || BYTE_ b_InterruptEnable) |+----------------------------------------------------------------------------+| Task : Enable the selected PWM (b_PWM) from selected module || (b_ModulNbr). You must calling the "i_APCI1710_InitPWM"|| function be for you call this function. || If you enable the PWM interrupt, the PWM generate a || interrupt after each period. || See function "i_APCI1710_SetBoardIntRoutineX" and the || Interrupt mask description chapter. |+----------------------------------------------------------------------------+| Input Parameters : BYTE_ b_BoardHandle : Handle of board APCI-1710 || BYTE_ b_ModulNbr : Selected module number || (0 to 3) || BYTE_ b_PWM : Selected PWM (0 or 1) || BYTE_ b_StartLevel : Start period level selection || 0 : The period start with a || low level || 1 : The period start with a || high level || BYTE_ b_StopMode : Stop mode selection || 0 : The PWM is stopped || directly after the || "i_APCI1710_DisablePWM" || function and break the || last period || 1 : After the || "i_APCI1710_DisablePWM" || function the PWM is || stopped at the end from|| last period cycle. || BYTE_ b_StopLevel : Stop PWM level selection || 0 : The output signal keep || the level after the || "i_APCI1710_DisablePWM" || function || 1 : The output signal is set|| to low after the || "i_APCI1710_DisablePWM" || function || 2 : The output signal is set|| to high after the || "i_APCI1710_DisablePWM" || function || BYTE_ b_ExternGate : Extern gate action selection || 0 : Extern gate signal not || used. || 1 : Extern gate signal used.|| BYTE_ b_InterruptEnable : Enable or disable the PWM || interrupt. || - APCI1710_ENABLE : || Enable the PWM interrupt || A interrupt occur after || each period || - APCI1710_DISABLE : || Disable the PWM interrupt |+----------------------------------------------------------------------------+| Output Parameters : - |+----------------------------------------------------------------------------+| 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: PWM not initialised see function || "i_APCI1710_InitPWM" || -6: PWM start level selection is wrong || -7: PWM stop mode selection is wrong || -8: PWM stop level selection is wrong || -9: Extern gate signal selection is wrong || -10: Interrupt parameter is wrong || -11: Interrupt function not initialised. || See function "i_APCI1710_SetBoardIntRoutineX" |+----------------------------------------------------------------------------+*/INT i_APCI1710_EnablePWM (comedi_device *dev, BYTE b_ModulNbr, BYTE b_PWM, BYTE b_StartLevel, BYTE b_StopMode, BYTE b_StopLevel, BYTE b_ExternGate, BYTE b_InterruptEnable) { INT i_ReturnValue = 0; DWORD dw_Status; DWORD dw_Command; devpriv->tsk_Current=current; // Save the current process task structure /**************************/ /* Test the module number */ /**************************/ if (b_ModulNbr < 4) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -