⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xspwm.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:       XsPwm.c
**
**  PURPOSE:        Defines configuration and access functions for the PWM
**                  device driver
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
**  EAS VERSION:    2.1
******************************************************************************/

#include "systypes.h"
#include "xspwm.h"

/******************* PERVAL Register Access Functions ************************/
/*
*******************************************************************************
*
* FUNCTION:         XsPwmReadPerval
*
* DESCRIPTION:      Reads the PERVAL register.
*
* INPUT PARAMETERS: 32 bit PWM channel number
*
* RETURNS:          32 bit register data with reserved/unused bits masked to
*                   zero
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      If the requested channel number is not 1, channel 0 is
*                   assumed.
*
* CALLS:            None
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 XsPwmReadPerval(UINT32 channel);
*
*******************************************************************************
*/
UINT32 XsPwmReadPerval(UINT32 channel)
{
    volatile PwmCtrlRegsT *pwmRegs;
    UINT32 regData;
    
    if (channel == 1)
    {
        pwmRegs = (volatile PwmCtrlRegsT *)PWM1_REG_BASE;
    }
    else
    {
        pwmRegs = (volatile PwmCtrlRegsT *)PWM0_REG_BASE;
    }
     
    // Read and format the register data
    regData = pwmRegs->PERVAL;
    // Mask value for bits in register
    regData &= PWM_PERVAL_MASK;

    return (regData);
}

/*
*******************************************************************************
*
* FUNCTION:         XsPwmWritePerval
*
* DESCRIPTION:      Writes the PV fields of the PERVAL register with a value
*                   that specifies the period of the PWM signal.
*
*                   During system reset, the PWM_CTRL and PWM_DUTY registers
*                   are reset to "0" and bits 9:0 of the PWM_PERVAL register
*                   are set to "1". This places the PWM_OUT pin to a "0" state.
*
*                   Care must be taken by the programmer to ensure that the
*                   value of the PWM_PERVAL register remains larger than
*                   PWM_DUTY register. In the case where PWM_PERVAL is less
*                   than PWM_DUTY the output will maintain a "1" state.
*
* INPUT PARAMETERS: 32 bit PWM channel number
*                   32 bit value to be written - only bits 0-9 pertinent
*
* RETURNS:          32 bit register data with reserved/unused bits masked to
*                   zero
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      If the requested channel number is not 1, channel 0 is
*                   assumed.
*
* CALLS:            None
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 XsPwmWritePerval(UINT32 channel, UINT32 value);
*
*******************************************************************************
*/
UINT32 XsPwmWritePerval(UINT32 channel, UINT32 value)
{
    volatile PwmCtrlRegsT    *pwmRegP;
    
    if (channel == 1)
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM1_REG_BASE;
    }
    else
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM0_REG_BASE;
    }
    
    // Mask value for bits in register to write
    value &= PWM_PERVAL_MASK;
    // Write to register
    pwmRegP->PERVAL = value;

    return (value);
}

/******************* DUTY Register Access Functions **************************/
/*
*******************************************************************************
*
* FUNCTION:         XsPwmReadDuty
*
* DESCRIPTION:      Reads the DUTY register.
*
* INPUT PARAMETERS: 32 bit PWM channel number
*
* RETURNS:          32 bit register data with reserved/unused bits masked to
*                   zero
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      If the requested channel number is not 1, channel 0 is
*                   assumed.
*
* CALLS:            None
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 XsPwmReadDuty(UINT32 channel);
*
*******************************************************************************
*/
UINT32 XsPwmReadDuty(UINT32 channel)
{
    volatile PwmCtrlRegsT    *pwmRegP;
    UINT32          regData;
    
    if (channel == 1)
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM1_REG_BASE;
    }
    else
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM0_REG_BASE;
    }

    // Read and format the register data
    regData = pwmRegP->DUTY;
    // Mask value for bits in register
    regData &= PWM_DUTY_MASK;

    return (regData);
}

/*
*******************************************************************************
*
* FUNCTION:         XsPwmWriteDuty
*
* DESCRIPTION:      Writes the DUTY register with a control value.
*
*                   During system reset, the PWM_CTRL and PWM_DUTY registers
*                   are reset to "0" and bits 9:0 of the PWM_PERVAL register
*                   are set to "1". This places the PWM_OUT pin to a "0" state.
*
*                   Care must be taken by the programmer to ensure that the
*                   value of the PWM_PERVAL register remains larger than
*                   PWM_DUTY register. In the case where PWM_PERVAL is less
*                   than PWM_DUTY the output will maintain a "1" state.
*
* INPUT PARAMETERS: 32 bit PWM channel number
*                   32 bit value to be written - only bits 0-10 pertinent
*
* RETURNS:          32 bit register data with reserved/unused bits masked to
*                   zero
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      If the requested channel number is not 1, channel 0 is
*                   assumed.
*
* CALLS:            None
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 XsPwmWriteDuty(UINT32 channel, UINT32 value);
*
*******************************************************************************
*/
UINT32 XsPwmWriteDuty(UINT32 channel, UINT32 value)
{
    volatile PwmCtrlRegsT    *pwmRegP;
    
    if (channel == 1)
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM1_REG_BASE;
    }
    else
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM0_REG_BASE;
    }
    
    // Mask value for bits in register to write
    value &= PWM_DUTY_MASK;
    // Write to register
    pwmRegP->DUTY = value;

    return (pwmRegP->DUTY);
}

/*
*******************************************************************************
*
* FUNCTION:         XsPwmSetDutyCycle
*
* DESCRIPTION:      Writes a duty cycle value (bits 0-9) to the DUTY register.
*                   Bit 10 is cleared.  The values in bits 11-31 of the DUTY
*                   register are maintained.
*
*                   During system reset, the PWM_CTRL and PWM_DUTY registers
*                   are reset to "0" and bits 9:0 of the PWM_PERVAL register
*                   are set to "1". This places the PWM_OUT pin to a "0" state.
*
*                   Care must be taken by the programmer to ensure that the
*                   value of the PWM_PERVAL register remains larger than
*                   PWM_DUTY register. In the case where PWM_PERVAL is less
*                   than PWM_DUTY the output will maintain a "1" state.
*
* INPUT PARAMETERS: 32 bit PWM channel number
*                   32 bit value to be written
*
* RETURNS:          32 bit register data with reserved/unused bits masked to
*                   zero
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:      If the requested channel number is not 1, channel 0 is
*                   assumed.
*
* CALLS:            XsPwmWriteDuty
*
* CALLED BY:        Anyone
*
* PROTOTYPE:        UINT32 XsPwmSetDutyCycle(UINT32 channel, UINT32 value);
*
*******************************************************************************
*/
UINT32 XsPwmSetDutyCycle(UINT32 channel, UINT32 value)
{
    volatile PwmCtrlRegsT    *pwmRegP;
    
    if (channel == 1)
    {
        pwmRegP = (volatile PwmCtrlRegsT *)PWM1_REG_BASE;
    }
    else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -