⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btc_cdemo.c

📁 基于visual dsp++开发环境
💻 C
字号:
/////////////////////////////////////////////////////////////////////////////
//
// 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.
//
// PF2 Counter: This channel is defined to be 1-word (4-bytes) in length and
//			     simply counts the number of times the PF2 pushbutton is pressed
//				 on the BF533 Ez-Kit. (Must have SW5.1 set to ON for PF2 pushbutton to work)
//
// PF3 Counter: This channel is defined to be 1-word (4-bytes) in length and
//			     simply counts the number of times the PF3 pushbutton is pressed
//				 on the BF533 Ez-Kit. (Must have SW5.2 set to ON for PF3 pushbutton to work)
//
// 256 word channel (PF2): This channel is defined to be 256-words (1024-bytes) in length and
//			     			simply counts the number of times the PF2 pushbutton is pressed
//				 			on the BF533 Ez-Kit.  Each word in the channel is updated with the count.
//
// 256 word channel (PF21): This channel is defined to be 256-words (1024-bytes) in length and
//			     			simply counts the number of times the PF21 pushbutton is pressed
//				 			on the BF533 Ez-Kit.  Each word in the channel is updated with the count.
//
// 4k byte channel:   This channel is defined to be 4-kbytes in length.  The first word of the
//					  channel is used to count the number of timer interrupts that have occured.
//
/////////////////////////////////////////////////////////////////////////////
#include <defbf537.h>
#include <def_lpblackfin.h>
#include <sys/exception.h>
#include "btc.h"

////////////////////////
// function prototypes
////////////////////////
void initTimer(void);
void initGPIO(void);

/////////////////////////////////
// interrupt handler prototypes
/////////////////////////////////
EX_INTERRUPT_HANDLER(timerISR);		// timer interrupt handler
EX_INTERRUPT_HANDLER(int12ISR);		// int12 interrupt handler (pushbuttons)

/////////////////////
// global variables
/////////////////////
int timerCounter;		// counts the number of timer interrupts that have fired
int pbCounter;			// counts the number of times any pushbutton on the ez-kit was pressed
int PF2Counter;			// counts the number of times the PF2 pushbutton on the ez-kit was pressed
int PF3Counter;			// counts the number of times the PF3 pushbutton on the ez-kit was pressed

int PF2Array[0x100];		// a 256-word array
int PF3Array[0x100];		// a 256-word array

char array1[0x1000];		// a 4k-byte array

////////////////////
// BTC Definitions
////////////////////
BTC_MAP_BEGIN
//             Channel Name,             Starting Address,    Length
BTC_MAP_ENTRY("Timer Interrupt Counter", (long)&timerCounter, sizeof(timerCounter))
BTC_MAP_ENTRY("PF2 Counter",            (long)&PF2Counter,  sizeof(PF2Counter))
BTC_MAP_ENTRY("PF3 Counter",            (long)&PF3Counter,  sizeof(PF3Counter))
BTC_MAP_ENTRY("256 word channel (PF2)", (long)&PF2Array, 	  sizeof(PF2Array))
BTC_MAP_ENTRY("256 word channel (PF3)", (long)&PF3Array, 	  sizeof(PF3Array))
BTC_MAP_ENTRY("4k byte channel",         (long)&array1, 	  sizeof(array1))
BTC_MAP_END

///////////////
// main
///////////////
void 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);
	
	// install our interrupt handlers
   	register_handler(ik_ivg12, int12ISR);	
   	register_handler(ik_timer, timerISR);
      
   	// initialize the timer and the programmable flags
   	initTimer();
   	initGPIO();

	// initialize the BTC
	btc_init();
	
	// this is the polling loop for servicing all BTC transactions
	while (1)
		btc_poll();
	
}

//////////////////////
// initTimer
//////////////////////
void initTimer()
{
	unsigned int *mmrPtr;
	
	mmrPtr  = (unsigned int*)TCNTL;		// timer control register
	*mmrPtr = TMPWR | TAUTORLD;							
	
	mmrPtr  = (unsigned int*)TPERIOD;	// timer period register
	*mmrPtr = 0x00040000;
	
	mmrPtr  = (unsigned int*)TSCALE;		// timer scale register
	*mmrPtr = 0x00000080;
	
	mmrPtr  = (unsigned int*)TCOUNT;		// timer count register
	*mmrPtr = 0x00040000;
	
	mmrPtr  = (unsigned int*)TCNTL;		// timer control register
	*mmrPtr = TMPWR | TMREN | TAUTORLD;	// enable the timer
}


/////////////////////
// initGPIO
/////////////////////
void initGPIO()
{
	unsigned short *smmrPtr;
	unsigned int *mmrPtr;
	unsigned int nSiRev;
	
	smmrPtr = (unsigned short*)PORTFIO_DIR;		// PF Config register
	*smmrPtr = 0xFC0;						// PF2-PF21 as outputs, everything else as inputs
	
	smmrPtr = (unsigned short*)PORTFIO_INEN;
	*smmrPtr = 0x1C;
	
	smmrPtr = (unsigned short*)PORTFIO_SET;	// PF Set register
	*smmrPtr = 0xFC0;						// turn all LEDs on
	
	smmrPtr = (unsigned short*)PORTFIO_CLEAR;	// PF Clear register
	*smmrPtr = 0xFC0;						// turn all LEDs off
		
	smmrPtr = (unsigned short*)PORTFIO_MASKA_SET;	// PF Interrupt A Mask Set register
	*smmrPtr = 0x1C;						// unmask PF2-PF21
	
	smmrPtr = (unsigned short*)PORTFIO_POLAR;	// PF Polarity register
	*smmrPtr = 0x0000;						// all PFs are active high
	
	smmrPtr = (unsigned short*)PORTFIO_EDGE;	// PF Interrupt Sensitivity register
	*smmrPtr = 0x1C;						// make PF2-PF21 edge triggered ints
	
	mmrPtr = (unsigned int*)SIC_IMASK;		// System Interrupt Control Mask register
	*mmrPtr = *mmrPtr | 0x08000000;			// enable peripheral #17 (PF Int A), set the bit
	
}



////////////////////////////
// timer interrupt handler
////////////////////////////
EX_INTERRUPT_HANDLER(timerISR)
{
	unsigned short *smmrPtr;
	int i;
	
	++timerCounter;							// count the timer interrupts
	for (i = 0; i < 4; ++i)
	{
		// update the first location of array1 with the timerCounter
		array1[i] = ((char*)&timerCounter)[i];
	}
	
	// toggle the timer LED
	smmrPtr = (unsigned short*)PORTFIO_TOGGLE;
	*smmrPtr = (*smmrPtr & 0x40) | ( (timerCounter & 0x00000001) << 6);	// turn on the timer LED
	
}

////////////////////////
// interrupt12 handler
////////////////////////
EX_INTERRUPT_HANDLER(int12ISR)
{
	unsigned short *smmrPtr;
	unsigned long *memPtr;
	unsigned long length;
	unsigned short temp;
	bool bFlag = false;
	unsigned long i;
	unsigned char ucShift = 0;
	
	// figure out which push button was pressed and increment the appropriate
	// counter...if PF2-PF21 did not generate the interrupt then just return
	smmrPtr = (unsigned short*)PORTFIO_SET;	// PF Set register
	temp = *smmrPtr;						// get which flags are currently set
	
	// check if PF2 is set
	if (temp & 0x4)
	{
		++PF2Counter;
		PF2Array[0] = PF2Counter;
		bFlag = true;
		ucShift = 0xB;
	}
	// check if PF3 is set
	if (temp & 0x8)
	{
		++PF3Counter;
		PF3Array[0] = PF3Counter;
		bFlag = true;
		ucShift = 0xA;
	}
				
	// if any of PF2 or PF3 were set then update the LEDs
	if (bFlag)
	{
		smmrPtr = (unsigned short*)PORTFIO_CLEAR;	// PF Clear register
		*smmrPtr = temp;							// clear the input pins (PF2-PF5)
		
		++pbCounter;								// inc the global pushbutton counter
		
		// toggle the PB LED
		smmrPtr = (unsigned short*)PORTFIO_TOGGLE;
		*smmrPtr = (*smmrPtr & 0xC00) | ((pbCounter & 0x00000001) << ucShift);
		
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -