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

📄 blink with external memory.asm

📁 ADI 公司的DSP ADSP21369 EZ-KIT LITE开发板的全部源代码
💻 ASM
字号:
///////////////////////////////////////////////////////////////////////////////////////
//NAME:     Blink with External Memory.asm
//DATE:     10/23/06
//PURPOSE:  Program to test each memory type for the ADSP-21375 Ez-kit
//
//USAGE:    Contains variable declarations for all possible types of memory that can be
//          used on the ADSP-21375 EZ-kit. It then reads in the external memory buffers
//          that were initialized for verification. Finally it blinks the flags to
//          indicate that the memory reads have completed.
////////////////////////////////////////////////////////////////////////////////////////
#include <def21369.h>

// The following definition allows the SRU macro to check for errors. Once the routings have
// been verified, this definition can be removed to save some program memory space.
// The preprocessor will issue a warning stating this when using the SRU macro without this
// definition
#define SRUDEBUG  // Check SRU Routings for errors.
#include <sru.h>

#define BUFLEN 100

.extern _initPLL;
.extern _initSDRAM;

// ******************************************************************
//  DM
.section/dm seg_dm64;
    .var dmsixtyfour[] = 0x01234567, 0x12341234, 0xabcdabcd, 0x11112222, 0x643333aa, 0x643333bb ;
        .var dmsixtyfourzeros[] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;

.section/DATA64 seg_6464;
    .var dm6464z[] = 0,0,0,0,0;
    .var dm6464[] = 0xAAAABBBBCCCCDDDD, 0x1111222233334444, 0x6464333364643333;


.section/dm seg_dm40;
    .var dmfourtyzeros[] = 0,0,0,0,0;
    .var dmfourty[] = 0xd401111111, 0xd402222222, 0xd403333333;

.section/dm seg_dm32;
    .var dmthirty[] = 0xD3211111, 0xD3222222, 0xd3233333, 0xd3244444, 0xd3255555;
    .var dmthirtyzeros[] = 0,0,0,0,0;
    .var sdram0holder[5];
    .var sdram1holder[5];
    .var sdram0zerosholder[BUFLEN-5];
    .var sdram1zerosholder[BUFLEN-5];
    
// Variables used in IVT
    .global EP0I_Serviced;
    .global EP1I_Serviced;

    .var EP0I_Serviced=0;
    .var EP1I_Serviced=0;

.section/dm seg_dm16;
    .var dmsixteenzeros[] = 0,0,0,0,0;
    .var dmsixteen[] = 0xd161, 0xd162, 0xd163, 0xd164, 0xd165;

// ******************************************************************
//  External

.section/dm seg_sdram;
    .var sdram0zeros[BUFLEN-5] ;
    .var sdram0[5] = 0xE0811111, 0xE0822222, 0xE0833333, 0xE0844444, 0xE0855555;


    .var sdram1zeros[BUFLEN-5];
    .var sdram1[5] = 0xE3211111, 0xE3222222, 0xE3233333, 0xE3244444, 0xE3255555;


// ******************************************************************
//  PM

.section/pm seg_pm64;
    .var pmsixtyfour[] = 0xC0DE6464, 0xC0DE6464, 0xC0DE6464, 0xC0DE6464, 0x6464333a, 0x6464333b;
    .var pmsixtyfourzeros[] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;

.section/pm seg_pm40;
    .var pmfourtyzeros[] = 0,0,0,0,0;
    .var pmfourty[] = 0xC0DE40111100, 0xC0DE40222200, 0xC0DE40333300;

.section/pm seg_pm32;
    .var pmthirtyzeros[] = 0,0,0,0,0;
    .var pmthirty[] = 0xC0DE1111, 0xC0DE2222, 0xC0DE3333, 0xC0DE4444, 0xC0DE5555;

.section/pm seg_pm16;
    .var pmsixteenzeros[] = 0,0,0,0,0;
    .var pmsixteen[] = 0x1234, 0xabcd, 0x1111, 0xcafe, 0xc0de;

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

.global _main;

//Main code section
.section/pm seg_pmco;
_main:

//Enable the External Port interrupt.
    bit set mode1 IRPTEN;
    bit set lirptl EP0IMSK|EP1IMSK;     //Enable EP0 and EP1 interrupts

    call _initPLL;          // Initialize the PLL to run at ~393 MHz with an SDCLK of ~157 MHz
    call _initSDRAM;        // Set up the SDRAM and AMI control registers for the 3 external memories.
                            // SDRAM is on MS2, SRAM is on MS0, Flash is on MS1

// -----------------------------------------------------------------------------------------
// Set up the SRU for the DPI and DAI

//Setting up the SRU to route Flag signals to DPI pin buffers.
//Use Flags 4 to 15 only. Flags 0 to 3 are not available on the DPI.

    SRU(FLAG4_O,DPI_PB06_I);    //Drive DPI Pin 6 with Flag 4 (LED 1)
    SRU(FLAG5_O,DPI_PB07_I);    //Drive DPI Pin 7 with Flag 5 (LED 2)
    SRU(FLAG6_O,DPI_PB08_I);    //Drive DPI Pin 8 with Flag 6 (LED 3)
    SRU(FLAG7_O,DPI_PB13_I);    //Drive DPI Pin 13 with Flag 7 (LED 4)
    SRU(FLAG8_O,DPI_PB14_I);    //Drive DPI Pin 14 with Flag 8 (LED 5)

//LED's 6 & 7 are on DAI pins. No Flag signals are available on the DAI.
//To use the DAI pins as a flag pin, we can manipulate the logic level of the DAI pin buffer
//directly. We set the value of these pins to LOW at startup.
    SRU(LOW,DAI_PB15_I);        //DAI => We can't use flags. Value has to be set low or high.
    SRU(LOW,DAI_PB16_I);        //DAI => We can't use flags. Value has to be set low or high.

//Enabling the Buffer direction for DAI and DPI pins using the following sequence:
//High -> Output, Low -> Input
    SRU(HIGH,DPI_PBEN06_I);
    SRU(HIGH,DPI_PBEN07_I);
    SRU(HIGH,DPI_PBEN08_I);
    SRU(HIGH,DPI_PBEN13_I);
    SRU(HIGH,DPI_PBEN14_I);
    SRU(HIGH,PBEN15_I);
    SRU(HIGH,PBEN16_I);
// -----------------------------------------------------------------------------------------

/* Using External Port
   The memory sections above declare two variables for  SDRAM. The
   following demonstrates accessing SDRAM using DMA and core writes. */


//Writing values to first buffer in sdram using the core, both immediate and indirect addressing are allowed.
i0 = sdram0;
m0 = 1;
r0 = 0x11111111;
dm(i0,m0) = r0;
r0 = 0x22222222;
dm(i0,m0) = r0;
r0 = 0x33333333;
dm(i0,m0) = r0;
r0 = 0x44444444;
dm(i0,m0) = r0;
r0 = 0x55555555;
dm(i0,m0) = r0;

//Writing values to sdram using the core, both immediate and indirect addressing are allowed.
r0 = 0x10101010;
dm(sdram0) =  r0;
r0 = 0x20202020;
dm(sdram0+1) = r0;
r0 = 0x30303030;
dm(sdram0+2) = r0;
r0 = 0x40404040;
dm(sdram0+3) = r0;
r0 = 0x50505050;
dm(sdram0+4) = r0;

// Both External DMA Channels can be used simultaneously
// Reading sram using External Port DMA channel 0.
r4=0x0;
dm(DMAC0)=r4;
r0=sdram0holder;
dm(IIEP0)=r0;   // Internal Memory Destination
r0=sdram1;
dm(EIEP0)=r0;   // External Memory Source
r0=1;
dm(IMEP0)=r0;   // Set up external and internal modify
dm(EMEP0)=r0;
r0=@sdram0holder;
dm(ICEP0)=r0;
dm(ECEP0)=r0;   // Internal and External count should always match

ustat1= DEN|DFLSH;  //Enable DMA after flushing the FIFO
dm(DMAC0)=ustat1;

// Reading sdram using DMA Channel 1
r0=0;
dm(DMAC1)=r0;
r0=sdram1holder;
dm(IIEP1)=r0;   // Internal Memory Destination
r0=sdram1;
dm(EIEP1)=r0;   // External Memory Source
r0=1;
dm(IMEP1)=r0;
dm(EMEP1)=r0;   // Set up external and internal modify
r0=@sdram1holder;
dm(ICEP1)=r0;
dm(ECEP1)=r0;   // Internal and External count should always match

ustat1= DEN|DFLSH;  //Enable DMA after flushing the FIFO
dm(DMAC1)=ustat1;

call wait_for_DMAs;

// Reading sdramzeros using DMA Channel 0.
r4=0x0;
dm(DMAC0)=r4;
r0=sdram0zerosholder;
dm(IIEP0)=r0;   // Internal Memory Destination
r0=sdram0zeros;
dm(EIEP0)=r0;   // External Memory Source
r0=1;
dm(IMEP0)=r0;   // Set up external and internal modify
dm(EMEP0)=r0;
r0=@sdram0zerosholder;
dm(ICEP0)=r0;
dm(ECEP0)=r0;   // Internal and External count should always match

ustat1= DEN|DFLSH;  //Enable DMA after flushing the FIFO
dm(DMAC0)=ustat1; nop;

// Reading sramzeros using DMA Channel 1
r0=0;
dm(DMAC1)=r0;
r0=sdram1zerosholder;
dm(IIEP1)=r0;   // Internal Memory Destination
r0=sdram1zeros;
dm(EIEP1)=r0;   // External Memory Source
r0=1;
dm(IMEP1)=r0;
dm(EMEP1)=r0;   // Set up external and internal modify
r0=@sdram1zerosholder;
dm(ICEP1)=r0;
dm(ECEP1)=r0;   // Internal and External count should always match

ustat1= DEN|DFLSH;  //Enable DMA after flushing the FIFO
dm(DMAC1)=ustat1;

call wait_for_DMAs;


//Setting flag pins
    bit set flags FLG3O|FLG4O|FLG5O|FLG6O|FLG7O|FLG8O;

//Clearing flag pins
    bit clr flags FLG3|FLG4|FLG5|FLG6|FLG7|FLG8;

//Disabling MS2&3 so that we can use Flag 3 to drive LED 8
//With this bit clear, we cannot access SDRAM
    ustat3 = dm(SYSCTL);
    bit clr ustat3 MSEN;
    dm(SYSCTL) = ustat3;

//Disable External Port DMAs
    r0=0;
    dm(DMAC0)=r0;
    dm(DMAC1)=r0;

//Set up initial values for blink algorithm
r7=1;
r4=2;
r0=1;

//Start the blink routine that will loop forever
top:
r1=1;
r8=0;

//Delay for ~10 ms at 400 MHz
lcntr=40000000;
    do (pc,_delay_loop_end) until lce;
_delay_loop_end:
    nop;

//Use  r2 to create an LED pattern
r2=r4;

btst r2 by 7;
if not sz r2=bclr r2 by 7;

btst r2 by 0;
if not sz r2=bclr r2 by 0;

r7=pass r7;
if gt jump left;

right:
r2=rot r2 by -1;
jump(pc,2);

left:
r2=rot r2 by 1;

ustat3=r2;
bit tst ustat3 0x2;
if tf r2=bset r2 by 0;
if tf r7=r1;

bit tst ustat3 0x40;
if tf r2=bset r2 by 7;
if tf r7=r8;

//Save value of the last pattern to r4 for next pass through the loop
r4=r2;

//Write the value of the pattern to the LEDs
call write_to_LEDs;

jump top;

_main.end:
jump(pc,0);


// This subroutine shows the value of the first 8 bits of r2 on the 8 LEDs
write_to_LEDs:

bit clr flags FLG6|FLG7|FLG4|FLG5|FLG8|FLG3; //clear flags
r6= flags; //r6 will be used for shifter functions, copy value of flags into r6

r3= 0x048;  //Start at FLG4 -> LED1, R3 holds the 12 bit operand for the field deposit
            //instruction. Deposit 1 bit, starting at the 8th bit of the destination.

// Loop 5 times for LEDs 1-5.
lcntr = 5; do led1to5_loop until lce;

// Transfer the lowest bit of r2 to the correct location in R6 corresponding to the
// flag being used in this iteration of the loop.
r6= r6 OR FDEP r2 by r3;

r2= LSHIFT r2 by -1;        //Shift r2 by 1 to the right for next iteration

r9= 0x2;
led1to5_loop: r3=r3 + r9; //increment r3 by 2 to ignore the FLGnO values (Flag Output)

// FLG3 -> LED8
r3= 0x046;

//Shift to the right by 2 to get to FLG3 (because of PB15 and PB16).
r2= LSHIFT r2 by -2;

//Transfer 1 bit to the starting # of bits in the destination register and OR the result with register r6.
r6= r6 OR FDEP r2 by r3;


FLAGS= r6;  //Put the result of r6 in the FLAGS register.

//Test if LED6 should be lit
LED6:   btst r4 by 5;
        if not SZ jump Flag06_Set;  //Set when result =0

    Flag06_Clear:
        SRU(LOW,DAI_PB15_I);    //Turn off LED6
        jump LED7;

    Flag06_Set:
        SRU(HIGH,DAI_PB15_I);   //Light up LED6


//Test if LED7 should be lit
LED7:   btst r4 by 6;
        if not SZ jump Flag07_Set;


    Flag07_Clear:
        SRU(LOW,DAI_PB16_I);    //Turn off LED7
        rts;

    Flag07_Set:
        SRU(HIGH,DAI_PB16_I);   //Light up LED7

write_to_LEDs.end:
rts;

//Wait for EP DMA channels to both finish
wait_for_DMAs:
//Wait for EP0 to finish
r0=dm(EP0I_Serviced);
r0=r0-1;
if lt jump(pc,-2);
dm(EP0I_Serviced)=r0;

//Wait for EP1 to finish
r0=dm(EP1I_Serviced);
r0=r0-1;
if lt jump(pc,-2);
dm(EP1I_Serviced)=r0;


wait_for_DMAs.end:
rts;


⌨️ 快捷键说明

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