?? btc_cdemo.cpp
字號(hào):
/////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////
#include "btc.h"
#include "signal.h"
#ifdef __ADSP21375__
asm("#include <def21375.h>");
#elif __ADSP21369__
asm("#include <def21369.h>");
#endif
#include <SRU.h>
#define DATA_BUF_SIZE 8
#ifdef __ADSP21375__
#define ARRAY_SIZE 0xF00
#define DATA_ARRAY_STRING "Data Array (3.8kw)"
#elif __ADSP21369__
#define ARRAY_SIZE 0x2000
#define DATA_ARRAY_STRING "Data Array (8kw)"
#endif
////////////////////////////
// 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_STRING, (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;
*pSysctl |= MSEN;
SRU(FLAG6_O,DPI_PB08_I); // Connect Flag6 output to DPI_PB08 input (LED3)
SRU(FLAG7_O,DPI_PB13_I); // Connect Flag7 output to DPI_PB13 input (LED4)
SRU(FLAG4_O,DPI_PB06_I); // Connect Flag4 output to DPI_PB06 input (LED1)
SRU(FLAG5_O,DPI_PB07_I); // Connect Flag5 output to DPI_PB07 input (LED2)
SRU(FLAG8_O,DPI_PB14_I); // Connect Flag8 output to DPI_PB14 input (LED5)
SRU(LOW,DAI_PB15_I); // Connect Input LOW to LED6
SRU(LOW,DAI_PB16_I); // Connect Input LOW to LED7
//Enabling the Buffer using the following sequence: High -> Output, Low -> Input
SRU(HIGH,DPI_PBEN08_I);
SRU(HIGH,DPI_PBEN13_I);
SRU(HIGH,DPI_PBEN06_I);
SRU(HIGH,DPI_PBEN07_I);
SRU(HIGH,DPI_PBEN14_I);
SRU(HIGH,DPI_PBEN01_I);
SRU(HIGH,PBEN15_I);
SRU(HIGH,PBEN16_I);
//Setting flag pins
asm("bit set flags FLG3O|FLG4O|FLG5O|FLG6O|FLG7O|FLG8O;");
//Clearing flag pins
asm("bit clr flags FLG3|FLG4|FLG5|FLG6|FLG7|FLG8;");
}
void initInterrupts()
{
interrupt(SIG_P2, GPTimer0_isr);
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 FLG4;"); //light LED 1
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -