//
// Lab11 : TMS320F2812 Teaching CD ROM
// (C) Frank Bormann
//
//###########################################################################
//
// FILE: Flash.c
//
// TITLE: DSP28 GPIO - Port B7..B0 : 8-Bit "Knight - Rider" ,
// CPU Timer0 ISR every 50 ms
// Watchdog active , served in ISR and main-loop
// FLASH - Based Version , silicon rev. C
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 2.0 | 11 Nov 2003 | F.B. | adapted to header-files Version 1.00
//###########################################################################
#include "DSP281x_Device.h"
// Global symbols defined in the linker command file
extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadEnd;
extern Uint16 RamfuncsRunStart;
Uint16 DEVICEID = 3;
// Prototype statements for functions found within this file.
void Gpio_select(void);
void InitSystem(void);
interrupt void cpu_timer0_isr(void); // Prototype for Timer 0 Interrupt Service Routine
// User Code starts here :
void main(void)
{
unsigned int i,m;
unsigned int LED[8]= {0x0001,0x0002,0x0004,0x0008,
0x0010,0x0020,0x0040,0x0080};
InitSystem(); // Initialize the DSP's core Registers
// ANSI - C standard function "memcpy" to copy FlashSpeed-init-routine out of
// Flash(RamfuncsLoadStart) into RAM(RamfuncsRunStart)
// Symbols are linked to a dedicated code section by "F2812.cmd" and "DSP281x_SysCtrl.c"
memcpy(&RamfuncsRunStart,
&RamfuncsLoadStart,
&RamfuncsLoadEnd - &RamfuncsLoadStart);
InitFlash(); // Initialize the Flash; Call original function from "DSP281x_SysCtrl.c"
Gpio_select(); // Setup the GPIO Multiplex Registers
InitPieCtrl(); // Function Call to init PIE-unit ( code : DSP281x_PieCtrl.c)
InitPieVectTable(); // Function call to init PIE vector table ( code : DSP281x_PieVect.c )
// re-map PIE - entry for Timer 0 Interrupt
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
InitCpuTimers();
// Configure CPU-Timer 0 to interrupt every 50 ms:
// 150MHz CPU Freq, 50000 祍econds interrupt period
ConfigCpuTimer(&CpuTimer0, 150, 50000);
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable CPU INT1 which is connected to CPU-Timer 0:
IER = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
CpuTimer0Regs.TCR.bit.TSS = 0;
while(1)
{
for(i=0;i {
// if(i // else GpioDataRegs.GPBDAT.all = LED[14-i];
for(m=0;m {
*(short int *)(0x8000+m) = m;
}
while(CpuTimer0.InterruptCount < 3); // wait for Timer 0
CpuTimer0.InterruptCount = 0;
EALLOW;
SysCtrlRegs.WDKEY = 0xAA; // and serve watchdog #2
EDIS;
}
}
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all = 0x0; // all GPIO port Pin's to I/O
GpioMuxRegs.GPBMUX.all = 0x0;
GpioMuxRegs.GPDMUX.all = 0x0;
GpioMuxRegs.GPFMUX.all = 0x0;
GpioMuxRegs.GPEMUX.all = 0x0;
GpioMuxRegs.GPGMUX.all = 0x0;
GpioMuxRegs.GPADIR.all = 0x0; // GPIO PORT as input
GpioMuxRegs.GPBDIR.all = 0x00FF; // GPIO Port B15-B8 input , B7-B0 output
GpioMuxRegs.GPDDIR.all = 0x0; // GPIO PORT as input
GpioMuxRegs.GPEDIR.all = 0x0; // GPIO PORT as input
GpioMuxRegs.GPFDIR.all = 0x0; // GPIO PORT as input
GpioMuxRegs.GPGDIR.all = 0x0; // GPIO PORT as input
GpioMuxRegs.GPAQUAL.all = 0x0; // Set GPIO input qualifier values to zero
GpioMuxRegs.GPBQUAL.all = 0x0;
GpioMuxRegs.GPDQUAL.all = 0x0;
GpioMuxRegs.GPEQUAL.all = 0x0;
EDIS;
}
void InitSystem(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x00AF; // Setup the watchdog
// 0x00E8 to disable the Watchdog , Prescaler = 1
// 0x00AF to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0; // Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10; // Setup the Clock PLL to multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
EDIS;
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
// Serve the watchdog every Timer 0 interrupt
EALLOW;
SysCtrlRegs.WDKEY = 0x55; // Serve watchdog #1
EDIS;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//===========================================================================
// End of SourceCode.
//===========================================================================