这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » 将DSP的C++程序写的和ARM/MCU一样简单明了

共1条 1/1 1 跳转至

将DSP的C++程序写的和ARM/MCU一样简单明了

工程师
2015-01-09 14:47:42     打赏
//哈哈,真不喜欢DSP的常规写法~~~

/*-----------------------------------------
  DSP菜鸟的第1个定时器实战演示程序
HotPower@126.com

2005.6.12        于西安大雁塔村队部

http://hotpower.21ic.org
-----------------------------------------*/
#include <cstdio> //C语言可以用stdio.h
#include <cstring>//C语言可以用string.h
#include "C5402DEF.h"//

volatile bool IOXF;
volatile unsigned int SystemRamTest;

extern "C" interrupt void Timer0Isr();
extern "C" interrupt void Timer1Isr();

class SystemObj {//系统类
public:
  SystemObj(void);
public:
  inline void SystemInit(void);
  inline void PllInit(void);
private:
  unsigned int SystemRamTest;
};

SystemObj::SystemObj(void)
{
  Disable();//关中断
  SREG->IMR = 0x0000;
  SREG->IFR = 0xffff;
//设置0x0080为中断向量表首址,在第2个128页内。
  SREG->PMST = (0x01 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY);
//  SREG->PMST |= (1 << PMST_DROM);//数据可const. 
/*---------------------------------------------------------------------------
若:设置0x0100为中断向量表首址,在第3个128页内。
则:*.cmd文件应该改为:
     PAGE 0: VECS: origin=0x0100,  length=0x66
则:
  SREG->PMST = (0x02 << PMST_IPTR) | (1 << PMST_MP_MC) | (1 << PMST_OVLY);
----------------------------------------------------------------------------*/
  SystemInit();//系统初始化
}

void SystemObj::SystemInit(void)
{
  PllInit();//PLL初始化
  if (::SystemRamTest != 0x55aa) {
    ::SystemRamTest = 0x55aa;
  }
  if (SystemRamTest != 0x55aa) {
    SystemRamTest = 0x55aa;
  }
  IOXF = 0;
}

void SystemObj::PllInit(void)
{
volatile unsigned int start;
  do {
    SREG->CLKMD = 0;
    __nop(); 
  }
  while(SREG->CLKMD & (1 << CLKMD_PLLSTATUS));
  SREG->CLKMD = (9 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//100M
//  SREG->CLKMD = (14 << CLKMD_PLLMUL) | (30 << CLKMD_PLLCOUNT) | (1 << CLKMD_PLLONOFF) | (1 << CLKMD_PLLNDIV) | (1 << CLKMD_PLLSTATUS);//150M
  for (start = 0; start < 10000; start ++);//等待外设上电复位正常结束
}

SystemObj Sys;

int main(void)
{
  DMA->DMSDI = 0;
  DMA->DMPREC = 0;
  TI_BASE_McBSP0->DXR10 = 0x00;
  TI_BASE_McBSP0->SPSA0 = SPCR1;
  TI_BASE_McBSP0->SPSD0 = 0x00;//SPCR1 = 0x00
  McBSP0->DXR10 = 0x00;
  McBSP0->SPSA0 = SPCR1;
  McBSP0->SPSD0 = 0x00;//SPCR1 = 0x00
  SREG->ST1 |= (1 << ST1_INTM);//应该用Disable();//关中断!!!否则无效!
  __nop();
  __nop();
  SREG->ST1 &= ~(1 << ST1_INTM);//应该用Enable();//开中断!!!否则无效!
  __nop();
  __nop();
  TIMER0->TCR |= (1 << TCR_TSS);//关闭启动定时器0
  SREG->IMR = 0x0000;
  SREG->IFR = 0xffff;
  TIMER0->PRD = 50000;//设置定时周期
  TIMER0->TCR &= ~(1 << TCR_TSS);//启动定时器0
  SREG->IMR |= (1 << IMR_TINT0);//允许TINT0中断
  TIMER1->TCR &= ~(1 << TCR_TSS);//启动定时器1
  SREG->IMR |= (1 << IMR_TINT1);//允许TINT1中断
  Enable();//开中断
  while(1)
  {
    __nop();
//   SREG->ST1 ^= (1 << ST1_XF);
    __nop();

    if (::IOXF) {
      SREG->ST1 |= (1 << ST1_XF);
    }
    else {
      SREG->ST1 &= ~(1 << ST1_XF);
    }
    idle1();
  }
}

interrupt void Timer0Isr() {
static int count = 0;
  count ++;
  if (count >= 4 * 250) {
    count = 0;
    ::IOXF = !::IOXF;//郁闷~~~中断中ST1被保护~~~
  }
//  SREG->ST1 ^= (1 << ST1_XF);//本想在此翻转,无奈被迫移入主程序中
/*
    if (::IOXF) {
      SREG->ST1 |= (1 << ST1_XF);
    }
    else {
      SREG->ST1 &= ~(1 << ST1_XF);
    }
*/
//  TIMER0->TCR |= (1 << TCR_TSS);//关闭启动定时器0
}

interrupt void Timer1Isr() {//只运行1次
  TIMER1->TCR |= (1 << TCR_TSS);//关闭启动定时器1(自毁)
}

 


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]