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

📄 dss_isr_evm62.c

📁 Using DSP/BIOS I/O in Multichannel Systems
💻 C
字号:
/* ***********************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, 
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR 
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE. 
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET 
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY 
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR 
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL, 
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY 
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT 
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM. 
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF 
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS 
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF 
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S 
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF 
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS 
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted 
* by Texas Instruments is distributed as "freeware".  You may, 
* only under TI's copyright in the Program, use and modify the 
* Program without any charge or restriction.  You may 
* distribute to third parties, provided that you transfer a 
* copy of this license to the third party and the third party 
* agrees to these terms by its first use of the Program. You 
* must reproduce the copyright notice and any other legend of 
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains 
* copyrighted material, trade secrets and other TI proprietary 
* information and is protected by copyright laws, 
* international copyright treaties, and trade secret laws, as 
* well as other intellectual property laws.  To protect TI's 
* rights in the Program, you agree not to decompile, reverse 
* engineer, disassemble or otherwise translate any object code 
* versions of the Program to a human-readable form.  You agree 
* that in no event will you alter, remove or destroy any 
* copyright notice included in the Program.  TI reserves all 
* rights not specifically granted under this license. Except 
* as specifically provided herein, nothing in this agreement 
* shall be construed as conferring by implication, estoppel, 
* or otherwise, upon you, any license or other right under any 
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
* ********************************************************* */

/*
 *  ======== dss_evm62.c ========
 */

#include <std.h>
#include <swi.h>
#include <trc.h>
#include <log.h>
#include <c6x.h>
#include <sts.h>
#include <clk.h>

#include "dss_isr.h"
#include "_dss_isr.h"

extern far LOG_Obj trace;

/* McBSP 0 Memory Mapped Registers */
#define DRR  (*(volatile unsigned int *)0x018c0000) /* Data Receive Reg */
#define DXR  (*(volatile unsigned int *)0x018c0004) /* Data Transmit Reg */
#define SPCR (*(volatile unsigned int *)0x018c0008) /* Serial Port Cont Reg */
#define RCR  (*(volatile unsigned int *)0x018c000c) /* Receive Control Reg */
#define XCR  (*(volatile unsigned int *)0x018c0010) /* Transmit Control Reg */
#define MCR  (*(volatile unsigned int *)0x018c0018) /* Multichannel Reg */
#define PCR  (*(volatile unsigned int *)0x018c0024) /* Pin Control Reg */

/* CPLD (Complex Programmable Logic Device) Memory Mapped Register */
#define CPLD (*(volatile unsigned int *)0x01780000)

/* Codec Memory Mapped Registers */
#define IAR  (*(volatile unsigned int *)0x01720000) /* Index Address Reg */
#define IDR  (*(volatile unsigned int *)0x01720004) /* Indexed Data Reg */
#define SR   (*(volatile unsigned int *)0x01720008) /* Status Reg */
#define PIO  (*(volatile unsigned int *)0x0172000c) /* PIO Data Reg */

/* Codec Indirect Mapped Registers */
#define DAC_LEFT_CNTL   0x06  /* I6  - Left DAC Output Control */
#define DAC_RIGHT_CNTL  0x07  /* I7  - Right DAC Output Control */
#define FS_PDF_CNTL     0x48  /* I8  - FS & Playback Data Control (MCE set) */
#define PIO_CNTL        0x49  /* I9  - Interface Control (MCE set) */
#define MODE_CNTL       0x0c  /* I12 - Mode and ID Control */
#define SP_CNTL         0x50  /* I16 - Alternate Feature enable 1 (MCE set) */
#define LINE_LEFT_CNTL  0x12  /* I18 - Left Line Input Control */
#define LINE_RIGHT_CNTL 0x13  /* I19 - Right Line Input Control */
#define CDF_CNTL        0x5c  /* I28 - Capture Data Format (MCE set)*/

/* Codec Commands */
#define DAC_UNMUTE    0x00  /* Unmute DAC-to-mixer */
#define MODE2_ENABLE  0x40  /* Enable MODE 2 */
#define INIT_DONE     0x80  /* Initialization bit */
#define SP_32_ENABLE  0x0a  /* Serial Port (32 bits) */
#define CDF_S_L16     0x50  /* CDF; Stereo, linear, 16-bit */
#define FS8_S_L16     0x50  /* FS: 8kHz, PDF; Stereo, linear, 16-bit */
#define FS48_S_L16    0x5c  /* FS: 48kHz, PDF; Stereo, linear, 16-bit */
#define PIO_ENABLE    0xc3  /* Enable PIO (capture and playback) */
#define MCE_RESET     0xbf  /* Reset Mode Control Bit (MCE) */

/* CPLD Commands */
#define CODEC_DISABLE  0xf8
#define CODEC_ENABLE   0x04


/* McBSP 0 commands */
#define SPCR_DISABLE   0x00        /* Disable serial port */
#define SPCR_STANDBY   0x00200020  /* Wait for frame synch, enable RX int */
#define SPCR_ENABLE    0x00010001  /* enable serial port */
#define PCR_SET        0x00        /* external RX/TX clock and frame synch */
#define CR_32_SET      0x000000a0  /* 32 bit word, 1 w/frame, single phase */
#define MCR_SET        0x00        /* enable TX and RX channels */
#define MCSP_RXINT_BIT 0x0800      /* assume serial RX interrupt on INT 11 */


/* Macros */
#define SETBITMASKCODEC(i,n) IAR=(i); IDR|=(n);
#define SETREGCODEC(i,n) IAR=(i); IDR=(n);


static void enableCodec(void);  /* Configure Codec */
static void enableMcBSP0(void); /* Configure McBSP 0 */

extern cregister volatile unsigned int IFR;
extern cregister volatile unsigned int ICR;
extern cregister volatile unsigned int IER;    

/*
 * ======== DSS_init ========
 */
void
dss_isr_init_platform(void)
{
    /* Configure codec */
    enableCodec();

    /* Configure McBSP 0 */
    enableMcBSP0();

    /* Unmute left and right DAC-to-mixer */
    SETREGCODEC(DAC_LEFT_CNTL, DAC_UNMUTE);
    SETREGCODEC(DAC_RIGHT_CNTL, DAC_UNMUTE);
}

/*
 * ======== enableCodec ========
 */
static void
enableCodec(void)
{

    /* Reset and enable codec */
    CPLD &= CODEC_DISABLE;
    CPLD |= CODEC_ENABLE;

    /* wait for codec to finish initialization */
    while(IAR & INIT_DONE);
  
    /* Enable mode 2 */
    SETBITMASKCODEC(MODE_CNTL, MODE2_ENABLE);

    /* Set codec Serial port format */
    SETREGCODEC(SP_CNTL, SP_32_ENABLE);

    /* Set capture format */
    SETREGCODEC(CDF_CNTL, CDF_S_L16);

    /* Set playback format and sampling rate */
    SETREGCODEC(FS_PDF_CNTL, FS8_S_L16);

    /* Enable bits in PIO (programmed I/O) */
    SETREGCODEC(PIO_CNTL, PIO_ENABLE);

    /* Reset Mode Control Bit (MCE) */
    IAR &= MCE_RESET;
}

/*
 * ======== enableMcBSP0 ========
 */
static void
enableMcBSP0(void)
{
    /* Disable serial port */
    SPCR = SPCR_DISABLE;

    /* Configure pin control register */
    PCR = PCR_SET;
    
    /* Configure receive control register */
    RCR = CR_32_SET;
    
    /* Configure transmit control register */
    XCR = CR_32_SET;

    /* Enable transmit and receive channels */
    MCR = MCR_SET;

    /* Put serial port in 'standby' and wait for frame synch */
    SPCR = SPCR_STANDBY;

    while(!(IFR & MCSP_RXINT_BIT));

    /* Clear the frame synch interrupt */
    ICR = MCSP_RXINT_BIT;

    /* Enable serial port */
    SPCR = SPCR_ENABLE;
}

void
dss_isr_start()
{
    /* Enable INT 11 */
    IER |= MCSP_RXINT_BIT;
}

void
dss_isr_stop()
{
    /* Disable INT 11 */
    IER &= ~MCSP_RXINT_BIT;
}

/*
 *  ======== DSS_cisr ========
 */
int dss_isr_evm62_rxDropped[2] = {0, 0};
static int dropping[2] = {0, 0};
static int postCount = 0;

void dss_isr_evm62_cisr(void)
{
    int tmp;
    
    tmp = DRR;
    if (dss_isr_rxCnt[0]) {
		dropping[0] = 0;
		*dss_isr_rxPtr[0]++ = tmp >> 16;
		dss_isr_rxCnt[0]--;
		if (dss_isr_rxCnt[0] == 0) {
#if DEBUG
	    	LOG_printf(&trace, "ISR: Receive buffer for channel 0 is full",0); 
#endif 
	    	SWI_or(dss_isr_swi[0], DSS_ISR_RX_0_FLAG | DSS_ISR_HWI_FLAG);
	    	postCount++;
		}
    } else {
		dss_isr_evm62_rxDropped[0]++;
		if (!dropping[0]) {
	    	LOG_message("Receive drop on channel 0, postCount = %d",
						postCount);
	    	LOG_printf(&trace, "ISR: Receive dropped on channel 0");
	    	dropping[0] = 1;
		} else {
	    	dropping[0]++;
	    	if (dropping[0] >= 100) {
				LOG_message("100th Receive sample dropped on channel 0",0);
	    	}
		}
    }
    if (dss_isr_rxCnt[1]) {
		dropping[1] = 0;
		*dss_isr_rxPtr[1]++ = tmp & 0xffff;
		dss_isr_rxCnt[1]--;
		if (dss_isr_rxCnt[1] == 0) {
	    	LOG_message("Receive buffer for channel 1 is full",0);
	    	SWI_or(dss_isr_swi[1], DSS_ISR_RX_1_FLAG | DSS_ISR_HWI_FLAG);
	    	postCount++;
		}
    } else {
		dss_isr_evm62_rxDropped[1]++;
		if (!dropping[1]) {
	    	LOG_message("Receive sample dropped on channel 1",0);
	    	LOG_printf(&trace, "Receive sample dropped on channel 1");
	    	dropping[1] = 1;
		} else {
	    	dropping[1]++;
	    	if (dropping[1] >= 100) {
				LOG_message("100th Receive sample dropped on channel 1",0);
	    	}
		}
    }
    tmp = 0;
    if (dss_isr_txCnt[0]) {
		tmp = *dss_isr_txPtr[0]++ << 16;
        dss_isr_txCnt[0]--;
        if (dss_isr_txCnt[0] == 0) {
#if DEBUG
	    	LOG_printf(&trace, "ISR: Transmit buffer for channel 0 is empty",0);
#endif
            SWI_or(dss_isr_swi[0], DSS_ISR_TX_0_FLAG | DSS_ISR_HWI_FLAG);
	    	postCount++;
        }
    } else {
		LOG_message("Transmit sample dropped on channel 0",0);
    }
    if (dss_isr_txCnt[1]) {
		tmp |= *dss_isr_txPtr[1]++ & 0xffff;
        dss_isr_txCnt[1]--;
        if (dss_isr_txCnt[1] == 0) {
	    	LOG_message("Transmit buffer for channel 1 is empty",0);
            SWI_or(dss_isr_swi[1], DSS_ISR_TX_1_FLAG | DSS_ISR_HWI_FLAG);
	    	postCount++;
        }
    } else {
		LOG_message("Transmit sample dropped on channel 1",0);
    }
    DXR = tmp;
}

volatile int bar;
foo()
{
    bar = 0;
}




⌨️ 快捷键说明

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