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

📄 txinit.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
📖 第 1 页 / 共 2 页
字号:

 ****************************************************************************/

void initIrq(void)
{
    /* Enable EDMA interrupts to the CPU */
    IRQ_clear(IRQ_EVT_EDMAINT);    // Clear any pending EDMA interrupts
    IRQ_enable(IRQ_EVT_EDMAINT);   // Enable EDMA interrupt
}


/****************************************************************************
  Function    : initEdma()
 ****************************************************************************

  Description : Initialize the DMA controller.  Use linked transfers to
				automatically transition from ping to pong and visa-versa.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-18 Adrian Schumacher / source by Texas Instruments

 ****************************************************************************/

void initEdma(void)
{
    /* Configure transmit channel */
    hEdmaXmt = EDMA_open(EDMA_CHA_XEVT1, EDMA_OPEN_RESET);  // get hEdmaXmt handle and reset channel
    hEdmaReloadXmtPing = EDMA_allocTable(-1);               // get hEdmaReloadXmtPing handle
    hEdmaReloadXmtPong = EDMA_allocTable(-1);               // get hEdmaReloadXmtPong handle
    
    gEdmaConfigXmt.dst = MCBSP_getXmtAddr(hMcbsp1);         // set the desination address to McBSP1 DXR
        
    gXmtChan = EDMA_intAlloc(-1);                           // get an open TCC
    gEdmaConfigXmt.opt |= EDMA_FMK(OPT,TCC,gXmtChan);       // set TCC to gXmtChan
        
    EDMA_config(hEdmaXmt, &gEdmaConfigXmt);                 // then configure the registers
    EDMA_config(hEdmaReloadXmtPing, &gEdmaConfigXmt);       // and the reload for Ping
    
    gEdmaConfigXmt.src = EDMA_SRC_OF(gBufferXmtPong);       // change the structure to have a source of Pong
    EDMA_config(hEdmaReloadXmtPong, &gEdmaConfigXmt);       // and configure the reload for Pong        
    
    EDMA_link(hEdmaXmt,hEdmaReloadXmtPong);                 // link the regs to Pong
    EDMA_link(hEdmaReloadXmtPong,hEdmaReloadXmtPing);       // link Pong to Ping
    EDMA_link(hEdmaReloadXmtPing,hEdmaReloadXmtPong);       // and link Ping to Pong    

    /* Configure receive channel */
    hEdmaRcv = EDMA_open(EDMA_CHA_REVT1, EDMA_OPEN_RESET);  // get hEdmaRcv handle and reset channel
    hEdmaReloadRcvPing = EDMA_allocTable(-1);               // get hEdmaReloadRcvPing handle
    hEdmaReloadRcvPong = EDMA_allocTable(-1);               // get hEdmaReloadRcvPong handle
    
    gEdmaConfigRcv.src = MCBSP_getRcvAddr(hMcbsp1);         // and the desination address to McBSP1 DXR
        
    gRcvChan = EDMA_intAlloc(-1);                           // get an open TCC
    gEdmaConfigRcv.opt |= EDMA_FMK(OPT,TCC,gRcvChan);       // set TCC to gRcvChan

    EDMA_config(hEdmaRcv, &gEdmaConfigRcv);                 // then configure the registers
    EDMA_config(hEdmaReloadRcvPing, &gEdmaConfigRcv);       // and the reload for Ping
    
    gEdmaConfigRcv.dst = EDMA_DST_OF(gBufferRcvPong);       // change the structure to have a destination of Pong
    EDMA_config(hEdmaReloadRcvPong, &gEdmaConfigRcv);       // and configure the reload for Pong
    
    EDMA_link(hEdmaRcv,hEdmaReloadRcvPong);                 // link the regs to Pong
    EDMA_link(hEdmaReloadRcvPong,hEdmaReloadRcvPing);       // link Pong to Ping
    EDMA_link(hEdmaReloadRcvPing,hEdmaReloadRcvPong);       // and link Ping to Pong
        
    /* Enable interrupts in the EDMA controller */
    EDMA_intClear(gXmtChan);    
    EDMA_intClear(gRcvChan);                                // clear any possible spurious interrupts

    EDMA_intEnable(gXmtChan);                               // enable EDMA interrupts (CIER)
    EDMA_intEnable(gRcvChan);                               // enable EDMA interrupts (CIER)

    EDMA_enableChannel(hEdmaXmt);                           // enable EDMA channel
    EDMA_enableChannel(hEdmaRcv);                           // enable EDMA channel
    
    /* Do a dummy write to generate the first McBSP transmit event */
    MCBSP_write(hMcbsp1, 0);
}

/****************************************************************************
  Function    : disableEdma()
 ****************************************************************************

  Description : Disables the DMA transfers by disabling the interrupts.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-24 Adrian Schumacher / source by KTH
  						   (edma_mcbsp_aic23_setup.c from DSK6713_rxtx.pjt)

 ****************************************************************************/

void disableEdma(void)
{	
	IRQ_disable(IRQ_EVT_EDMAINT);   	// Turn DMA interupts off wait for next host call.				
	EDMA_intDisable(gXmtChan);          // disable EDMA interrupts (CIER)    
	EDMA_intDisable(gRcvChan);          // disable EDMA interrupts (CIER)
}


/****************************************************************************
  Function    : startEdma()
 ****************************************************************************

  Description : Initialize and set up the ping pong DMA transfer.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-26 Adrian Schumacher

 ****************************************************************************/

void startEdma(void)
{
	if (firstCall == TRUE)
	{
		IRQ_globalDisable();       // Disable global interrupts during setup             
		setup_ping_pong();
		IRQ_globalEnable();        // Re-enable global interrupts
	    firstCall = FALSE;
		#ifdef _DEBUGLOG
			LOG_printf(&trace,"EDMA initialized");
		#endif
	}
	else
	{
		IRQ_globalDisable();       // Disable global interrupts during setup             
		restart_ping_pong();
		IRQ_globalEnable();        // Re-enable global interrupts
		#ifdef _DEBUGLOG
			LOG_printf(&trace,"EDMA restarted");
		#endif
	}
}


/****************************************************************************
  Function    : setup_ping_pong()
 ****************************************************************************

  Description : Initialize and set up the ping pong DMA transfer.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-24 Adrian Schumacher / source by KTH
  						   (edma_mcbsp_aic23_setup.c from DSK6713_rxtx.pjt)

 ****************************************************************************/

void setup_ping_pong(void)
{
    AIC23_setParams(&AIC23config);  // Configure the codec
    initMcbsp();               // Initialize McBSP1 for audio transfers
    initEdma();                // Initialize the EDMA controller
    initIrq();                 // Initialize interrupts
}


/****************************************************************************
  Function    : restart_ping_pong()
 ****************************************************************************

  Description : Initialize and start the ping pong DMA transfer.

  Inputs      : none

  Outputs     : none

  By          : 2005-04-24 Adrian Schumacher / source by KTH
  						   (edma_mcbsp_aic23_setup.c from DSK6713_rxtx.pjt)

 ****************************************************************************/

void restart_ping_pong(void)
{
    //static Uint32 pingOrPong = PING;  // Ping-pong state variable
    //static Int16 xmtdone = 0, rcvdone = 0;

	EDMA_Config temp;

	// Change state of EDMAs so they properly set to start with a PING buffer.
	EDMA_getConfig(hEdmaReloadXmtPing, &temp);
    EDMA_config(hEdmaXmt, &temp);
    
	EDMA_getConfig(hEdmaReloadRcvPing, &temp);
    EDMA_config(hEdmaRcv, &temp);

	pingOrPong = PING;  // Ping-pong state variable
	xmtdone = 0; 		// Reset what is done
	rcvdone = 0; 		// Reset what is done

    //AIC23_setParams(&AIC23config);  // Configure the codec
    //initMcbsp();
    /* Do a dummy write to generate the first McBSP transmit event */
    //MCBSP_write(hMcbsp1, 0);

    EDMA_intClear(gXmtChan);    
	EDMA_intClear(gRcvChan);                                // clear any possible spurious interrupts

    EDMA_intEnable(gXmtChan);                               // enable EDMA interrupts (CIER)    
	EDMA_intEnable(gRcvChan);                               // enable EDMA interrupts (CIER)

    initIrq();                 // Initialize interrupts
}


/* --- Interrupt Service Routines ----------------------------------------- */

/****************************************************************************
  Function    : edmaHwi()
 ****************************************************************************

  Description : Interrupt service routine for the DMA transfer.  It is
                triggered when a complete DMA receive frame has been
                transferred.   The edmaHwi ISR is inserted into the interrupt
                vector table at compile time through a setting in the DSP/BIOS
                configuration under Scheduling --> HWI --> HWI_INT8.  edmaHwi
                uses the DSP/BIOS Dispatcher to save register state and make
                sure the ISR co-exists with other DSP/BIOS functions.

  Inputs      : pointer to buffer to copy from

  Outputs     : pointer to buffer to copy to

  By          : 2005-04-18 Adrian Schumacher / source by Texas Instruments

 ****************************************************************************/

void edmaHwi(void)
{
//    static Uint32 pingOrPong = PING;  // Ping-pong state variable
//    static Int16 xmtdone = 0, rcvdone = 0;
    
    /* Check CIPR to see which transfer completed */
    if (EDMA_intTest(gXmtChan))
    {
        EDMA_intClear(gXmtChan);
        xmtdone = 1;
    }
    if (EDMA_intTest(gRcvChan))
    {
        EDMA_intClear(gRcvChan);
        rcvdone = 1;
    }
        
    /* If both transfers complete, signal processBufferSwi to handle */
    if (xmtdone && rcvdone)
    {
        if (pingOrPong==PING)
        {
            SWI_or(&processBufferSwi, PING);
            pingOrPong = PONG;
        } else
        {
            SWI_or(&processBufferSwi, PONG);
            pingOrPong = PING;
        }
        rcvdone = 0;
        xmtdone = 0;
    }
}


/*=== End of global functions definition ===================================*/

/*--- AUTOMATICALLY GENERATED VERSION HISTORY --------------------------------

$Log: /MIMO/Transmitter/txinit.c $ 
 * 
 * 1     05-05-11 14:50 Adrian
 * created and added to VSS

===== END OF AUTOMATICALLY GENERATED VERSION HISTORY =======================*/

/**** End of file ***********************************************************/

⌨️ 快捷键说明

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