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

📄 volume_hst.c

📁 TI 公司的5000系列DSP的BIOS C语言程序,希望对大家有帮助
💻 C
字号:
/*
 *  Copyright 1999 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  U.S. Patent Nos. 5,283,900  5,392,448
 */
/* "@(#) BIOS-C54x 3.01b 09-07-99 (bios54x-b15)" */
/***************************************************************************/
/*                                                                         */
/*     V O L U M E . C                                                     */
/*                                                                         */
/*     Audio gain processing using CLK ISR as data source, and a software  */
/*     interrupt for processing routine.                                   */
/*                                                                         */
/***************************************************************************/

#include <std.h>
#include <log.h>   
#include <swi.h>  
#include <clk.h>
#include <trc.h>
#include <sts.h>  
#include <rtdx.h> 
#include <hst.h>
#include <pip.h>


#include "volume.h"

/* Global declarations */
Int inp_buffer[BUFSIZE];       /* processing data buffers */
Int out_buffer[BUFSIZE];

Int gain = MINGAIN;             /* volume control variable */
Uns processingLoad = BASELOAD;  /* processing routine load value */
RTDX_CreateInputChannel(control_channel);

int i=0;

/* Objects created by the Configuration Tool */
extern LOG_Obj trace;       
extern SWI_Obj processing_SWI;
   

/* Functions */
extern Void load(Uns loadValue);

Int processing(Int *input, Int *output);
Void dataIO(Void);   
static Void error(Void);

/*
 *  ======== A2DscaleD2A ========
 *
 * FUNCTION: Called from A2DscaleD2A_SWI to obtaine digitized data from
 *           a host file through an HST input channel, scale the data by the
 *           volume factor, and send output data back to the host through an
 *           HST output channel.
 *
 * PARAMETERS: address of input and output HST channels.
 *
 * RETURN VALUE: None.
 */
Void A2DscaleD2A(HST_Obj *inpChannel, HST_Obj *outChannel)
{
    PIP_Obj *inp_PIP;
    PIP_Obj *out_PIP;
    int *input;
    int *output;
    Uns size;

    inp_PIP = HST_getpipe(inpChannel);
    out_PIP = HST_getpipe(outChannel);

    if ((PIP_getReaderNumFrames(inp_PIP) <= 0) || (PIP_getWriterNumFrames(out_PIP) <= 0)) {
            /* Software interrupt should not have been triggered!  */
            error();
    }

    /*
     *  A2D: get digitized input (get signal from the host through HST).
     *  Obtain input frame and allocate output frame from the host pipes.
     */
    
    PIP_get(inp_PIP);
    PIP_alloc(out_PIP);
    
    input = PIP_getReaderAddr(inp_PIP);
    output = PIP_getWriterAddr(out_PIP);

    size = PIP_getReaderSize(inp_PIP);
    PIP_setWriterSize(out_PIP, size);
    
    /*
     *  Vector Scale: Scale the input signal by the volume factor to
     *  produce the output signal.
     */
    while(size--){
            *output++ = *input++ * gain;
    }
    
    /*
     *  D2A: produce analog output (send signal to the host through HST).
     *  Send output data to the host pipe and free the frame from the input
     *  pipe.
     */
    PIP_put(out_PIP);
    PIP_free(inp_PIP);
}

/*
 *  ======== error ========
 *
 * FUNCTION: Traps processor in loop forever if error condition occurs.
 *
 * PARAMETERS: None.
 *
 * RETURN VALUE: None.
 */
static Void error(Void)
{
    LOG_printf(&trace,"Error condition!");
    
}



Void mytest()
{ int j;
  static int control=1;
  
/*  LOG_printf(&trace,"i=%d\n",i++);  */
  
/*    if(TRC_query(TRC_USER0) == 0) 
       STS_set(&mytestSTS,CLK_gethtime());
       
   for(j=0;j<32;j++);   

   
   if(TRC_query(TRC_USER0) == 0) 
       STS_delta(&mytestSTS,CLK_gethtime()); 
*/       
       
   if(!RTDX_channelBusy(&control_channel))
    {   
        RTDX_readNB(&control_channel,&control,sizeof(control));
        gain=control;
        LOG_printf(&trace,"Load new value=%d\n",control);
    }    
}  

/*
 * ======== main ========
 */
Void main()   
{
    LOG_printf(&trace,"volume example started\n");
                
    RTDX_enableInput(&control_channel);   
                  
       /* fall into DSP/BIOS idle loop */
    return;
}

/*
 *  ======== processing ========
 *
 * FUNCTION: Called from processing_SWI to apply signal processing
 *           transform to input signal.
 *
 * PARAMETERS: address of input and output buffers.
 *
 * RETURN VALUE: TRUE.
 */
Int processing(Int *input, Int *output)
{
    Int size = BUFSIZE;

/*    while(size--){
        *output++ = *input++ * gain;
    }    */
     
    
    /* additional processing load */
    load(processingLoad);
                             
    return(TRUE);
}

/*
 *  ======== dataIO ========
 *
 * FUNCTION: Called from timer ISR to fake a periodic hardware interrupt that
 *           reads in the input signal and outputs the processed signal.
 *
 * PARAMETERS: none.
 *
 * RETURN VALUE: none.
 */
Void dataIO()
{
    /* do data I/O */     
   SWI_dec(&processing_SWI); 
    
       /* post processing_SWI software interrupt */   
}

⌨️ 快捷键说明

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