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

📄 utopia_util.c

📁 dsp tms320c6486的csl例程
💻 C
字号:
/*  ============================================================================
 *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2006
 *
 *   Use of this software is controlled by the terms and conditions found in the
 *   license agreement under which this software has been supplied.
 *   ===========================================================================
 */
/** ============================================================================
 *   @file  utopia_util.c
 *
 *   @path  $(CSLPATH)\example\c6486\utopia2\src
 *
 *   @desc  This file contains the utility function for utopia2 example
 *
 * =============================================================================
 */  
#include <utopia_util.h>
#include <csl_psc.h>
#include <cslr_psc.h>
#include <csl_gpio.h>
#include <stdio.h>
#include <string.h>

CSL_GpioHandle hGpio;
CSL_PscHandle  hPsc;
CSL_PscObj     pscObj;
CSL_Status     psc_status;

/*
 * =============================================================================
 *   @func   Init_Mem
 *
 *   @arg Uint32
       Addr           - Address 
       NoofArrays     - Number of array
       Count          - count
       IncrData       - data value to increment
 *
 *   @desc
 *     This function initialize the buffer
 *
 *   @return
 *      NONE
 *
 * =============================================================================
 */
void Init_Mem (
    Uint8  *Addr, 
    Uint32 NoofArrays, 
    Uint32 Count, 
    Uint8  IncrData
)
{
    Uint32 i;
    Uint32 Data = 0x1;
    for (i=0; i < Count * NoofArrays; i++) {
        *(Uint8*)(Addr + i) = Data;
        Data += IncrData;
    }
}

/*
 * =============================================================================
 *   @func   dataTrans_verify
 *
 *   @arg Uint32
         src_addr       - Source buffer
         dst_addr       - Destination buffer
         Cell_Num       - cell number
         Pad_Cell_Size  - pad cell size
         ATM_Cell_Size  - atm cell size
         Udc            - user defined cell 
         UtopiaBitMode  - utopia2 bit mode ie., 8 bit/16 bit
 *
 *   @desc
 *     This function is to verify the data transfer from UTOPIA and received
 *     data from the UTOPIA master (test bench acts as master.) by comparing
 *     source buffer and destination buffer i.e., src_addr, dst_addr.
 *
 *   @return
 *      NONE
 *
 * =============================================================================
 */
Uint32 Verify_Result ( 
    Uint32 src_addr,
    Uint32 dst_addr,
    Uint32 Cell_Num,
    Uint32 Pad_Cell_Size,
    Uint32 ATM_Cell_Size,
    Uint32 Udc,
    Uint32 UtopiaBitMode
)
{
	Uint8* srcArrayPtr = (Uint8*)src_addr;
	Uint8* dstArrayPtr = (Uint8*)dst_addr;
        Uint32 i, j;
	Uint32 dummy_bytes;

 	dummy_bytes = (Pad_Cell_Size -(Udc +(UtopiaBitMode?54:53)));
	
    for (i = 0; i < Cell_Num; i++) {	
  	    for (j=	dummy_bytes ; j < Pad_Cell_Size; j++) {
            if (srcArrayPtr[(i*Pad_Cell_Size) + j] != dstArrayPtr[(i*Pad_Cell_Size) + j]) {
				return (FAIL);
			}	
        }
	}
	return(PASS);
}

/*
 * =============================================================================
 *   @func   setup_PSC
 *
 *   @arg 
 *      NONE
 *
 *   @desc
 *     This function opens the PSC handle.
 *
 *   @return
 *      NONE
 *
 * =============================================================================
 */
void setup_PSC(void){
    hPsc = CSL_pscOpen(&pscObj, CSL_PSC, NULL,
                       &psc_status);
}
    
/*
 * =============================================================================
 *   @func   Close_PSC_handle
 *
 *   @arg 
 *      NONE
 *
 *   @desc
 *     This function closes the PSC handle.
 *
 *   @return
 *      NONE
 *
 * =============================================================================
 */
void Close_PSC_handle(void) {
    CSL_pscClose(hPsc);
}

/*
 * =============================================================================
 *   @func   UTOPIA_Domain_Enable
 *
 *   @arg 
 *      NONE
 *
 *   @desc
 *     This function enables the utopia2 domain.
 *
 *   @return
 *      NONE
 *
 * =============================================================================
 */
void UTOPIA_Domain_Enable (
)
{
    CSL_PscPeripherals  module;
    CSL_PscPowerDomain  pwrDmn;
    
    setup_PSC();
    
    /* Enabling UTOPIA Clock */
    module = CSL_PSC_MODULE_UTOPIA;
    CSL_pscHwControl (hPsc, CSL_PSC_CMD_ENABLE_MODULE, &module);
    
    /* set Go for Power domain transition*/
    pwrDmn = CSL_PSC_PWRDMN_ALWAYSON;
    CSL_pscHwControl (hPsc, CSL_PSC_CMD_PWRDMN_TRNS, &pwrDmn);
    
    Close_PSC_handle();
}

/*
 * =============================================================================
 *   @func   set_design_done
 *
 *   @arg 
 *      NONE
 *
 *   @desc
 *     This function is for utopia2 test bench sychronization .
 *
 *   @return
 *      NONE
 *
 * =============================================================================
 */
void set_design_done (
    CSL_GpioPinNum gpio_in_pin_num,
    CSL_GpioPinNum gpio_out_pin_num
) 
{

    CSL_GpioPinConfig           config;
    CSL_Status                  status;
    CSL_GpioObj                 gpioObj;
    Uint32                      iCount = 0;
    
    hGpio = CSL_gpioOpen(&gpioObj, CSL_GPIO, NULL, &status);

    config.pinNum = (CSL_GpioPinNum)gpio_out_pin_num;
    config.trigger = CSL_GPIO_TRIG_RISING_EDGE;
    config.direction = CSL_GPIO_DIR_OUTPUT;
    
    status = CSL_gpioHwControl(hGpio, CSL_GPIO_CMD_CONFIG_BIT, &config);

    status = CSL_gpioHwControl (hGpio, CSL_GPIO_CMD_SET_BIT, &gpio_out_pin_num);

    while (((hGpio->regs->IN_DATA & (1 << gpio_in_pin_num)) == 0) && 
           (iCount <= 500)) {
        iCount++;
    }
    iCount = 0;

    status = CSL_gpioHwControl(hGpio, CSL_GPIO_CMD_CLEAR_BIT, &gpio_out_pin_num);

    while(((hGpio->regs->IN_DATA & (1 << gpio_in_pin_num)) != 0) && 
          (iCount <= 500)) {
        iCount++;
    }

  CSL_gpioClose(hGpio);
  return;
}

/* End of utopia_util.c */

⌨️ 快捷键说明

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