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

📄 main.c

📁 很多的经典的嵌入式例子 自己去看吧
💻 C
字号:

#define GLOBAL_INT_ENABLE    asm( " rsbx intm ")
#define GLOBAL_INT_DISABLE   asm( " ssbx intm ")

#define IMR ( (unsigned short *) 0x0000) 
#define IFR ( (unsigned short *) 0x0001) 
#define IMR_API 0x0200

unsigned long dummy = 0;

static unsigned long delay(volatile unsigned long ctr)
{
    while(ctr-- ) dummy++;
    return(dummy);
}

volatile unsigned long xf_flash = 0;

static void mcu_interrupt(void)
{
    unsigned short int * const bscr = (unsigned short int *)0x29;
    const unsigned short int  bscr_hint = 0x8;

    *bscr |= bscr_hint;

    delay(100);

    *bscr &= ~bscr_hint;
}

// Interrupt service routine for the API interrupt
interrupt                                    
void api_isr(void)
{
    xf_flash = 1;
}



static void xf_on()
{
    asm("      SSBX	xf");
    asm("      nop");
    asm("      nop");
}

static void xf_off()
{
    asm("      RSBX	xf");
    asm("      nop");
    asm("      nop");
}

// compute and return the factorial of 'num'
unsigned long factorial(unsigned long num)
{
	unsigned long result = 1;
	
    while (num > 1) {
		result = result * num;
		num    = num - 1;
	}
	
    return result;
}

main() 
{
    volatile unsigned short *dsp_running = (unsigned short*)0x3805;
    volatile unsigned long  *dsp_input   = (unsigned long*) 0x3808;
    volatile unsigned long  *dsp_output  = (unsigned long*) 0x380C;
    unsigned long i, num;

    // Disable interrupts
    GLOBAL_INT_DISABLE;  

    // Clear all pending interrupts
   *IFR = 0xffff;

   // Enable the API interrupt
   *IMR = IMR_API; 
   GLOBAL_INT_ENABLE;

   // Signal to the MCU that DSP is ready to receive interrupts
   *dsp_running = 1;

   // Wait for the interrupt from the ARM to come in
   while (xf_flash == 0) ;

   num = *dsp_input;

   // toggle DSP_XF pin the number of times requested by the ARM app
   for (i = 0; i < num; i++) {
       xf_on();
       (void)delay(0x100000);
       xf_off();
       (void)delay(0x100000);
   }

   // compute the factorial of the number supplied by the ARM; write the
   // result into shared memory
   *dsp_output = factorial(num);

   // allow time for memory write to complete
   delay(0x100000);
   
   // Write the factorial result into the API and signal the ARM
   mcu_interrupt();
}

⌨️ 快捷键说明

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