?? btc_cdemo.cpp
字號:
/////////////////////////////////////////////////////////////////////////////
//
// Example C program using Background Telemetry Channel (BTC)
// Analog Devices 2004
//
// This program defines several BTCs to allow transfer of data over the BTC
// interface while the DSP is running. Use the BTC Memory window in the
// debugger to view each channels data. The defined channels are described
// below:
//
// Timer Interrupt Counter: This channel is defined to be 1-word (4-bytes)
// in length and simply counts the number of timer
// interrupts that have occured.
//
// Constant Data Value: This channel is defined to be 1-word (4-bytes) in length and
// simply displays a constant value that is not changed by the
// the running program.
//
// Constant Data Buffer: This channel is defined to be 8-words (32-bytes) in length and
// simply displays an array of constant values that are not changed by the
// the running program.
//
// Data Array (8kw): This channel is defined to be 8-kwords in length. The first word of the
// channel is used to count the number of timer interrupts that have occured.
//
// NOTE: In order for the LEDs to function properly SW8.6 (LED_CS_SW) should be set in the OFF position.
/////////////////////////////////////////////////////////////////////////////
#include "btc.h"
#include "signal.h"
#if defined (__ADSP21262__)
#include "def21262.h"
asm("#include <def21262.h>");
#elif defined (__ADSP21364__)
#include "def21364.h"
asm("#include <def21364.h>");
#elif defined (__ADSP21369__)
#include "def21369.h"
asm("#include <def21369.h>");
#endif
#define DATA_BUF_SIZE 8
#define ARRAY_SIZE 0x2000
////////////////////////////
// Variable Definitions
////////////////////////////
int timerCounter = 0;
int dataVal = 0x11223344;
int dataBuf[DATA_BUF_SIZE] = {0x11223344,0x55667788,0x99aabbcc,0xddeeff00,
0x55555555,0x66666666,0x77777777,0x88888888};
int array1[ARRAY_SIZE];
////////////////////////
// Function Prototypes
////////////////////////
void initLEDs(void);
void initInterrupts(void);
void initTimer(void);
void GPTimer0_isr(int signal);
////////////////////
// BTC Definitions
////////////////////
BTC_MAP_BEGIN
// Channel Name, Starting Address, Length
BTC_MAP_ENTRY("Timer Interrupt Counter", (long)&timerCounter, sizeof(timerCounter))
BTC_MAP_ENTRY("Constant Data Value", (long)&dataVal, sizeof(dataVal))
BTC_MAP_ENTRY("Constant Data Buffer", (long)dataBuf, sizeof(dataBuf))
BTC_MAP_ENTRY("Data Array (8kw)", (long)array1, sizeof(array1))
BTC_MAP_END
///////////////////
// Main Program
///////////////////
int main()
{
// an example of getting the starting address and length of
// a defined channel using macros defined in btc.h
int addr, len;
addr = BTC_CHANNEL_ADDR(0);
len = BTC_CHANNEL_LEN(0);
for(int i = 0; i < ARRAY_SIZE; ++i)
{
array1[i] = i;
}
// initialize the different components of the program
btc_init();
initLEDs();
initInterrupts();
initTimer();
while(1);
}
void initLEDs()
{
// disable the parallel port and use AD pins as Flags
unsigned int *pSysctl = (unsigned int *)SYSCTL;
#if defined (__ADSP21262__) || (__ADSP21364__)
*pSysctl |= PPFLGS;
#elif defined (__ADSP21369__)
*pSysctl |= MSEN;
#endif
// set flags 8-15 as outputs and turn them off
asm("bit set flags FLG15O|FLG14O|FLG13O|FLG12O|FLG11O|FLG10O|FLG9O|FLG8O;");
asm("bit clr flags FLG15|FLG14|FLG13|FLG12|FLG11|FLG10|FLG9|FLG8;");
}
void initInterrupts()
{
// enable the gptimer0 and low-priority emulator interrupt
#if defined (__ADSP21262__)
interrupt(SIG_GPTMR0, GPTimer0_isr);
#else // ADSP-21364
interrupt(SIG_P2, GPTimer0_isr);
#endif
interrupt(SIG_EMUL, btc_isr);
}
void initTimer()
{
unsigned int *pTim0Ctl = (unsigned int *)TM0CTL;
unsigned int *pTim0Prd = (unsigned int *)TM0PRD;
unsigned int *pTim0Wid = (unsigned int *)TM0W;
unsigned int *pTimStat = (unsigned int *)TMSTAT;
*pTim0Ctl = TIMODEPWM | PRDCNT | IRQEN; // configure the timer
*pTim0Prd = 0x00800000; // timer period
*pTim0Wid = 1; // timer width
*pTimStat = BIT_8; // enable the timer
}
void GPTimer0_isr(int signal)
{
// clear timer interrupt status
unsigned int *pTim0Stat = (unsigned int *)TMSTAT;
*pTim0Stat = TIM0IRQ;
++timerCounter; // count number of timer interrupts
array1[0] = timerCounter; // reflect count in first location of array1
// toggle LED1 on the EZ-Kit
asm("bit tgl flags FLG8;");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -