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

📄 csl_pwmhwsetup.c

📁 TI达芬奇dm644x各硬件模块测试代码
💻 C
字号:
/*  ============================================================================
 *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005                 
 *                                                                              
 *   Use of this software is controlled by the terms and conditions found in the
 *   license agreement under which this software has been supplied.             
 *   ===========================================================================
 */ 

/** @file csl_pwmHwSetup.c
 *  
 *  @brief    File for functional layer of CSL API @a CSL_pwmHwSetup()
 *
 *  Path: \\(CSLPATH)\\ipmodules\\pwm\\src
 *
 *  Description
 *   - The @a CSL_pwmHwSetup() function definition & it's associated functions
 *
 *  @date 30 April, 2004
 *  @author Pratheesh Gangadhar
 */
/* =============================================================================
 *  Revision History
 *  ===============
 *  03-Aug-2004 brn Updated for the new CSL architecture.
 *  11-Oct_2004 brn File updated with the review comments
 * =============================================================================
 */
 
#include <csl_pwm.h>

/** ============================================================================
 *   @n@b   CSL_pwmHwSetup
 *
 *   @b Description
 *  @n This function initializes the device registers with the appropriate values
 *  provided through the HwSetup Data structure. This function needs to be 
 *  called only if the HwSetup Structure was not previously passed through the 
 *  Open call. After the Setup is completed, the serial device is ready for 
 *  data transfer. For information passed through the HwSetup Data structure 
 *  refer @a CSL_PwmHwSetup.
 *
 *   @b Arguments
 *
 *   @verbatim
            hPwm           Handle to the PWMS instance

            setup           Pointer to hardware setup structure
     @endverbatim
 *
 *   <b> Return Value </b>  CSL_Status
 *   @li                    CSL_SOK             - Hardware setup successful
 *   @li                    CSL_ESYS_BADHANDLE  - Invalid handle
 *   @li                    CSL_ESYS_INVPARAMS  - Hardware structure is not
 *                                                properly initialized
 *
 *   <b> Pre Condition </b>
 *   @n  None
 *
 *   <b> Post Condition </b>
 *   @n  The specified instance will be setup according to value passed
 *
 *   @b Modifies
 *   @n Hardware registers for the specified instance
 *
 *  <b> Usage Constraints: </b>
 *  Both @a CSL_emifInit() and @a CSL_emifOpen() must be called
 *  successfully in that order before this function can be called. The user
 *  has to allocate space for & fill in the main setup structure appropriately
 *  before calling this function
 *
 * @b Example:
 * @verbatim
     CSL_PwmHandle hPwm;
     CSL_PwmHwSetup hwSetup = CSL_PWM_HWSETUP_DEFAULTS;
     CSL_emifHwSetup(hPwm, &hwSetup);
  @endverbatim
 *
 * @return Returns the status of the setup operation
 * ============================================================================
 */
#pragma CODE_SECTION (CSL_pwmHwSetup, ".text:csl_section:pwm");
CSL_Status CSL_pwmHwSetup ( 
    CSL_PwmHandle hPwm,
    CSL_PwmHwSetup *setup 
)
{
    CSL_PwmRegsOvly pwmRegs = hPwm->regs;   
    CSL_PwmConfigOneShot configOneShot;    
    CSL_PwmConfigContinuous configContinuous; 
    CSL_Status status = CSL_SOK;                             
    
    if (setup == NULL) {
        return CSL_ESYS_INVPARAMS;
    }
    
    if (hPwm == NULL) {
        return CSL_ESYS_BADHANDLE;
    }    
    
    switch (setup->modeSelect) {
        case CSL_PWM_ONESHOT: 
            configOneShot = setup->mode.oneShot;
            pwmRegs->CFG = CSL_FMK (PWM_CFG_MODE, CSL_PWM_CFG_MODE_OSHOT)
                          |CSL_FMK (PWM_CFG_EVTRIG, configOneShot.evtTrig)
                          |CSL_FMK (PWM_CFG_INTEN, configOneShot.intEn)
                          |CSL_FMK (PWM_CFG_INACTOUT, configOneShot.inactOut)
                          |CSL_FMK (PWM_CFG_P1OUT, configOneShot.p1Out);  
            CSL_FINS (pwmRegs->RPT, PWM_RPT_RPT, configOneShot.rpt);
            break;   
              
        case CSL_PWM_CONTINUOUS: 
            configContinuous = setup->mode.continuous; 
            pwmRegs->CFG = CSL_FMK (PWM_CFG_MODE, CSL_PWM_CFG_MODE_CONT)
                          |CSL_FMK (PWM_CFG_INTEN, configContinuous.intEn)
                          |CSL_FMK (PWM_CFG_INACTOUT, configContinuous.inactOut)
                          |CSL_FMK (PWM_CFG_P1OUT, configContinuous.p1Out);  
                            
            break;     
        
        default:
            status = CSL_EPWM_INVMODE ; 
            break;  
    }
    
    CSL_FINS (pwmRegs->PCR, PWM_PCR_FREE, setup->emuConfig);
    CSL_FINS (pwmRegs->PER, PWM_PER_PER, setup->outPeriod); 
    CSL_FINS (pwmRegs->PH1D, PWM_PH1D_PH1D, setup->phase1Duation);
    
    return status;
}

⌨️ 快捷键说明

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