📄 btc_cdemo.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.
//
// PF0 Counter: This channel is defined to be 1-word (4-bytes) in length and
// simply counts the number of times the PF0 pushbutton is pressed
// on the BF533 Ez-Kit. (Must have SW5.1 set to ON for PF0 pushbutton to work)
//
// PF1 Counter: This channel is defined to be 1-word (4-bytes) in length and
// simply counts the number of times the PF1 pushbutton is pressed
// on the BF533 Ez-Kit. (Must have SW5.2 set to ON for PF1 pushbutton to work)
//
// 256 word channel (PF0): This channel is defined to be 256-words (1024-bytes) in length and
// simply counts the number of times the PF0 pushbutton is pressed
// on the BF533 Ez-Kit. Each word in the channel is updated with the count.
//
// 256 word channel (PF1): This channel is defined to be 256-words (1024-bytes) in length and
// simply counts the number of times the PF1 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 <defBF538.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 PF0Counter; // counts the number of times the PF0 pushbutton on the ez-kit was pressed
int PF1Counter; // counts the number of times the PF1 pushbutton on the ez-kit was pressed
int PF0Array[0x100]; // a 256-word array
int PF1Array[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("PF0 Counter", (long)&PF0Counter, sizeof(PF0Counter))
BTC_MAP_ENTRY("PF1 Counter", (long)&PF1Counter, sizeof(PF1Counter))
BTC_MAP_ENTRY("256 word channel (PF0)", (long)&PF0Array, sizeof(PF0Array))
BTC_MAP_ENTRY("256 word channel (PF1)", (long)&PF1Array, sizeof(PF1Array))
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*)PORTCIO_FER; // PC Config register
*smmrPtr = 0x03F0;
smmrPtr = (unsigned short*)PORTCIO_DIR; // PC Config register
*smmrPtr = 0x03F0; // PC4-PC9 as outputs, everything else as inputs
smmrPtr = (unsigned short*)PORTCIO_SET; // PC Set register
*smmrPtr = 0x03F0; // turn all LEDs on
smmrPtr = (unsigned short*)PORTCIO_CLEAR; // PC Clear register
*smmrPtr = 0x03F0; // turn all LEDs off
smmrPtr = (unsigned short*)PORTFIO_INEN; // PF Input enable
*smmrPtr = 0xF; // Enable Push-buttons(PF0-PF1) as input
smmrPtr = (unsigned short*)PORTFIO_DIR;
*smmrPtr = ~0xF;
smmrPtr = (unsigned short*)PORTFIO_MASKA_SET; // PF Interrupt A Mask Set register
*smmrPtr = 0xF; // unmask PF0-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 = 0xF; // make PF0-PF21 edge triggered ints
mmrPtr = (unsigned int*)SIC_IMASK; // System Interrupt Control Mask register
*mmrPtr = *mmrPtr | 0x00080000; // 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*)PORTCIO_TOGGLE;
*smmrPtr = (*smmrPtr & 0x10) | ( (timerCounter & 0x00000001) << 4); // 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 PF0-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 PF0 is set
if (temp & PF0)
{
++PF0Counter;
PF0Array[0] = PF0Counter;
bFlag = true;
ucShift = 0x9;
}
// check if PF1 is set
if (temp & PF1)
{
++PF1Counter;
PF1Array[0] = PF1Counter;
bFlag = true;
ucShift = 0x8;
}
// if any of PF0 or PF1 were set then update the LEDs
if (bFlag)
{
smmrPtr = (unsigned short*)PORTFIO_CLEAR; // PF Clear register
*smmrPtr = temp; // clear the input pins (PF0-PF1)
++pbCounter; // inc the global pushbutton counter
// toggle the PB LED
smmrPtr = (unsigned short*)PORTCIO_TOGGLE;
*smmrPtr = (*smmrPtr & 0x300) | ((pbCounter & 0x00000001) << ucShift);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -