📄 main.c
字号:
//=============================================================================
// Filename: main.c
//
// Description: A sample driver application for the bootloader.
//
// Copyright (C) 2000 - 2002 Texas Instruments Incorporated
//
//============================================================================
#include "arm_boot.h"
#include "api_mem.h"
#include "dsp_proj_code.h"
#include "dsp_proj_data.h"
#include <stdio.h>
// ---------------------- Clock Setup --------------------------------
#define DSPCLK_ENABLE 0x00004000
#define MCLK_ENABLE 0x00008000
#define KBDIO_IO ((unsigned long *)0xFFFF2900)
#define KBDIO_CIO ((unsigned long *)0xFFFF2904)
#define KBDIO_EN ((unsigned long *)0xFFFF2914)
#define KBDIO_IO1 0x00000002
static unsigned long nandgpio( unsigned long *addr, unsigned long Data )
{
unsigned long readback;
readback = *addr;
readback &= ~(Data);
*addr = readback;
return( readback );
}
static void EnableDSPCLK(void)
{
nandgpio(KBDIO_EN, DSPCLK_ENABLE);
}
static void EnableMCLK(void)
{
nandgpio(KBDIO_EN, MCLK_ENABLE);
}
// ---------------------- Main Driver --------------------------------
// Trigger a DSPINT interrupt on the DSP side
static void interrupt_dsp()
{
volatile unsigned short *apic = (unsigned short *)0xffe40000;
*apic |= 0x4; // set bit 2 [DSPINT] of the API Control Register
}
// set up a structure to represent the DSP program and data to be loaded
#define PMST_VAL 0xFF88
static dsp_app_struct test_dsp_app =
{dsp_proj_program, dsp_proj_data, PMST_VAL};
main()
{
volatile unsigned short *dsp_running = (unsigned short *)DSP_RUNNING;
volatile unsigned long *dsp_input = (unsigned long *)DSP_INPUT;
unsigned long num = 9; // input to the DSP
// disable all interrupts
resetinterrupts();
setupstacks();
pll_init(44, 100); // setup arm and dsp PLLs
EnableMCLK(); // enable external arm clock
EnableDSPCLK(); // enable dsp clkout
// enable DSP_XF output on KBGPIO1
nandgpio(KBDIO_CIO, KBDIO_IO1);
nandgpio(KBDIO_EN, KBDIO_IO1);
// The DSP is not yet running its main app
Write_Short_API(dsp_running, 0);
// load the DSP with the program and data
if (dsp_load(&test_dsp_app) != LOAD_OK) {
while (1) {
}
}
setup_api_interrupt();
// start the DSP
dsp_start() ;
// Make sure DSP is done bootloading: synchronize via an API flag
while (*dsp_running == 0) {
}
Write_Long_API(dsp_input, num);
// Trigger an API interrupt on the DSP
interrupt_dsp();
while(1) {
if (factorial != 0xFFFFFFFF) {
printf("Factorial of %d computed by the DSP is %d\n",
num, factorial);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -