例11、TMS320X280x PCLKCR0位区定义<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
// 外设时钟控制寄存器0 (PCLKCR0):
struct PCLKCR0_BITS { // 位描述
Uint16 rsvd1:2; // 1:0 保留
Uint16 TBCLKSYNC:1; // 2 eWPM 模块 TBCLK 使能/同步
Uint16 ADCENCLK:1; // 3 使能ADC的高速时钟
Uint16 I2CAENCLK:1; // 4 使能SYSCLKOUT为I<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />2C-A提供时钟
Uint16 rsvd2:1; // 5 保留
Uint16 SPICENCLK:1; // 6 使能SPI-C的低速时钟
Uint16 SPIDENCLK:1; // 7 使能SPI-D的低速时钟
Uint16 SPIAENCLK:1; // 8 使能SPI-A的低速时钟
Uint16 SPIBENCLK:1; // 9 使能SPI-B的低速时钟
Uint16 SCIAENCLK:1; // 10使能SCI-A的低速时钟
Uint16 SCIBENCLK:1; // 11使能SCI-B的低速时钟
Uint16 rsvd3:2; // 13:12 保留
Uint16 ECANAENCLK:1; // 14使能SYSCLKOUT为I eCAN-A提供时钟
Uint16 ECANBENCLK:1; // 15使能SYSCLKOUT为I eCAN-A提供时钟
};
例12、产生的位区访问汇编代码
C源代码 产生的汇编代码
存储空间 汇编指令
// 使能2801的外设时钟
EALLOW; 3F82A7 EALLOW
SysCtrlRegs.PCLKCR0.bit.rsvd1 = 0; 3F82A8 MOVW DP,#0×01C0
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; 3F82AA AND @28,#0xFFFC
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; 3F82AC AND @28,#0xFFFB
SysCtrlRegs.PCLKCR0.bit.I2CAENCLK = 1; 3F82AE OR @28,#0×0008
SysCtrlRegs.PCLKCR0.bit.rsvd2 = 0; 3F82B0 OR @28,#0×0010
SysCtrlRegs.PCLKCR0.bit.SPICENCLK = 1; 3F82B2 AND @28,#0xFFDF
SysCtrlRegs.PCLKCR0.bit.SPIDENCLK = 1; 3F82B4 OR @28,#0×0040
SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1; 3F82B6 OR @28,#0×0080
SysCtrlRegs.PCLKCR0.bit.SPIBENCLK = 1; 3F82B8 OR @28,#0×0100
SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1; 3F82BA OR @28,#0×0200
SysCtrlRegs.PCLKCR0.bit.SCIBENCLK = 0; 3F82BC OR @28,#0×0400
SysCtrlRegs.PCLKCR0.bit.rsvd3 = 0; 3F82BE AND @28,#0xF7FF
SysCtrlRegs.PCLKCR0.bit.ECANAENCLK= 1; 3F82C0 AND @28,#0xCFFF
SysCtrlRegs.PCLKCR0.bit.ECANBENCLK= 0; 3F82C2 OR @28,#0×4000
EDIS; 3F82C4 AND @28,#0×7FFF
3F82C6 EDIS
例13、使用.all共同体成员优化代码
C源代码 产生的汇编代码
存储空间 汇编指令
EALLOW; 3F82A7 EALLOW
SysCtrlRegs.PCLKCR0.all = 0×47D8; 3F82A8 MOVW DP,#0×01C0
EDIS; 3F82AA MOV @28,#0×47D8
3F82AC EDIS
例14、使用Shadow寄存器优化代码
C源代码 产生的汇编代码
存储空间 汇编指令
// 使能2801的外设时钟
union PCLKCR0_REG shadowPCLKCR0;
EALLOW; 3F82A7 EALLOW
shadowPCLKCR0.bit.rsvd1 = 0; 3F82A8 MOV @AL,#0×47D8
shadowPCLKCR0.bit.TBCLKSYNC = 0; 3F82AA MOVW DP,#0×01C0
shadowPCLKCR0.bit.ADCENCLK = 1; // ADC 3F82AC MOV @28,AL
shadowPCLKCR0.bit.I2CAENCLK = 1; // I2C3F82AD EDIS
shadowPCLKCR0.bit.rsvd2 = 0;
shadowPCLKCR0.bit.SPICENCLK = 1; // SPI-C
shadowPCLKCR0.bit.SPIDENCLK = 1; // SPI-D
shadowPCLKCR0.bit.SPIAENCLK = 1; // SPI-A
shadowPCLKCR0.bit.SPIBENCLK = 1; // SPI-B
shadowPCLKCR0.bit.SCIAENCLK = 1; // SCI-A
shadowPCLKCR0.bit.SCIBENCLK = 0; // SCI-B
shadowPCLKCR0.bit.rsvd3 = 0;
shadowPCLKCR0.bit.ECANAENCLK= 1; // eCAN-A
shadowPCLKCR0.bit.ECANBENCLK= 0; // eCAN-B
SysCtrlRegs.PCLKCR0.all = shadowPCLKCR0.all;
EDIS;
例15、IQ Math应用举例(详细参考\IQmath目录)
/* cmd链接文件实例
/******************************************************************/
MEMORY
{
PAGE 0 : RAMH0 (RW) : origin = 0×3f8000, length = 0×002000
BOOTROM (RW) : origin = 0×3ff000, length = 0×000fc0
VECTORS (RW) : origin = 0×3fffc2, length = 0×00003e
RESET (RW) : origin = 0×3fffc0, length = 0×000002
PAGE 1 : RAMM0M1 (RW) : origin = 0×000000, length = 0×000800
RAML0L1 (RW) : origin = 0×008000, length = 0×002000
}
SECTIONS
{
.reset : load = RESET, type = DSECT, PAGE = 0
/*为使H0正确boot引导并能够正常工作,需要将.text分配在RAMH0*/
.text : load = RAMH0, PAGE = 0
.cinit : load = RAMH0, PAGE = 0
.econst : load = RAMH0, PAGE = 0
.bss : load = RAML0L1, PAGE = 1
.ebss : load = RAML0L1, PAGE = 1
.data : load = RAML0L1, PAGE = 1
.const : load = RAML0L1, PAGE = 1
.stack : load = RAMM0M1, PAGE = 1
.sysmem : load = RAML0L1, PAGE = 1
/******************************************************************/
/* Iqmath函数查表定位 functions: */
/******************************************************************/
/* 对于boot ROM中没有数据表 */
IQmathTables : load = BOOTROM, PAGE = 0
/* 对于带有数据表的目标系统,如F2810/12使用下面 */
/*
IQmathTables : load = BOOTROM, type = NOLOAD, PAGE = 0
*/
IQmath : load = RAMH0, PAGE = 0
}
采用Iqmath函数产生正弦数据波形,分别计算波形的幅值和相位,具体代码如下:
/******************************************************************/
// 文件名称: IQsample.c
// IQ Math Sample Program In C (for V1.4+ of library)
// 目标设备:simulator 或F2812
// 对于simulator或F2812选用不同的.cmd分配方式
/******************************************************************/
// 选择将要使用的全局Q值:
#define GLOBAL_Q 24
long GlobalQ = GLOBAL_Q; // GEL & Graph 调试使用
// 需要的头文件:
#include <stdio.h>
#include <stdlib.h>
#include “IQmathLib.h”
// 定义数据记录长度
#define DATA_LOG_SIZE 256
// 定义使用的常数
#define PI2 1.570796327
#define PI 3.141592654
#define STEP_X_SIZE 0.314159265
#define STEP_Y_SIZE 0.314159265
// 分配数据缓冲
struct DATA_LOG_C {
_iq Xwaveform[DATA_LOG_SIZE];
_iq Ywaveform[DATA_LOG_SIZE];
long Phase[DATA_LOG_SIZE];
_iq Mag[DATA_LOG_SIZE];
} Dlog;
// 定义波形全局变量
struct STEP {
_iq Xsize;
_iq Ysize;
_iq Yoffset;
_iq X;
_iq Y;
_iq GainX;
_iq GainY;
_iq FreqX;
_iq FreqY;
} Step;
/******************************************************************/
// main函数
/******************************************************************/
int main(void)
{
unsigned int i;
float gain="5".5;
_iq w = 5.5;
_iq tempX, tempY, tempP, tempM, tempMmax;
char buffer[20];
int *WatchdogWDCR = (void *) 0×7029;
// 关闭看门狗
asm(” EALLOW “);
*WatchdogWDCR = 0×0068;
asm(” EDIS “);
Step.Xsize = _IQ(STEP_X_SIZE);
Step.Ysize = _IQ(STEP_Y_SIZE);
Step.Yoffset = 0;
Step.X = 0;
Step.Y = Step.Yoffset;
for(i=0; i < DATA_LOG_SIZE; i++)
{
Dlog.Xwaveform = 0;
Dlog.Ywaveform = 0;
Dlog.Phase = 0;
Dlog.Mag = 0;
}
// 用户输入X和Y波形的增益:
printf(”\nEnter waveform X gain (default = 1.0)= “);
gets(buffer);
Step.GainX = _atoIQ(buffer);
if( Step.GainX == 0 )
Step.GainX = _IQ(1.0);
printf(”\nEnter waveform X freq (default = 1.0)= “);
gets(buffer);
Step.FreqX = _atoIQ(buffer);
if( Step.FreqX == 0 )
Step.FreqX = _IQ(1.0);
printf(”\nEnter waveform Y gain (default = 1.0)= “);
gets(buffer);
Step.GainY = _atoIQ(buffer);
if( Step.GainY == 0 )
Step.GainY = _IQ(1.0);
printf(”\nEnter waveform Y freq (default = 1.0)= “);
gets(buffer);
Step.FreqY = _atoIQ(buffer);
if( Step.FreqY == 0 )
Step.FreqY = _IQ(1.0);
// 计算最大幅值
tempMmax = _IQmag(Step.GainX, Step.GainY);
for(;;)
{
Step.GainX = _IQ(gain); //设置断点,改变gain观察波形变化情况
tempMmax = _IQmag(Step.GainX, Step.GainY);
for(i=0; i < DATA_LOG_SIZE; i++)
{
// 计算波形
Step.X = Step.X + _IQmpy(Step.Xsize, Step.FreqX);
if( Step.X > _IQ(2*PI) )
Step.X -= _IQ(2*PI);
Step.Y = Step.Y + _IQmpy(Step.Ysize, Step.FreqY);
if( Step.Y > _IQ(2*PI) )
Step.Y -= _IQ(2*PI);
Dlog.Xwaveform = tempX = _IQmpy(_IQsin(Step.X), Step.GainX);
Dlog.Ywaveform = tempY = _IQmpy(_IQabs(_IQsin(Step.Y)), Step.GainY);
// 计算规格化的幅值:
// Mag = sqrt(X^2 + Y^2)/sqrt(GainX^2 + GainY^2);
tempM = _IQmag(tempX, tempY);
Dlog.Mag = _IQdiv(tempM, tempMmax);
// 计算规格化的相位:
// Phase = (long) (atan2PU(X,Y) * 360);
tempP = _IQatan2PU(tempY,tempX);
Dlog.Phase = _IQmpyI32int(tempP, 360);
}
}
}
文章评论(0条评论)
登录后参与讨论