📄 dsp281x_ini.c
字号:
//###########################################################################
//
// FILE: DSP281x_Ini.c
//
// TITLE: DSP281x CPU Initialization & Support Functions.
//
// NOTES: All DSP281x CPU initialization is list in the file.
// CpuTimer1 and CpuTimer2 are reserved for use with DSP BIOS and
// other realtime operating systems.
//
// Do not use these two timers in your application if you ever plan
// on integrating DSP-BIOS or another realtime OS.
//
// For this reason, the code to manipulate these two timers is
// commented out and not used in these examples.
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|=======|==============================================
// 1.00| 17 Mar 2004 | Y.Z.Y | First Version V1.0
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|=======|===============================================
// 1.00| 30 June 2004 | Y.Z.Y | Second Version V2.0
//###########################################################################
#include "F2812reg.h"
#include "Main.h"
#include "DSP281x_ECan.h"
// volatile C28X_TIMER * Timer0 = (C28X_TIMER *)0xc00;
//===========================================================================
// InitSysCtrl:
// This function initializes the System Control registers to a known state.
// - Disables the watchdog
// - Set the PLLCR for proper SYSCLKOUT frequency
// - Set the pre-scaler for the high and low frequency peripheral clocks
// - Enable the clocks to the peripherals
//===========================================================================
void InitSysCtrl(void)
{
EALLOW; /* Enable accesses to protected registers */
PLLCR = PLLSCALE;
/* Enable ADC,EVA,EVB High Speed Mode; SCIA, SCIB, SPI, MCBSP Low Speed Mode;
Ecan (System clock) */
PCLKCR = 0x4d0b;
HISPCP = 0x0000; /* CLKIN/1 */
LOSPCP = 0x0002; /* CLKIN/4 */
EDIS; /* Disable accesses to protected registers */
}
//===========================================================================
// KickDog:
// This function resets the watchdog timer.
// Enable this function for using KickDog in the application
//===========================================================================
void KickDog(void)
{
EALLOW;
WDKEY = 0x0055;
WDKEY = 0x00AA;
EDIS;
}
//===========================================================================
// DisableDog:
// This function disables the watchdog timer.
//===========================================================================
void DisableDog(void)
{
EALLOW;
WDCR = 0x0068;
EDIS;
}
//===========================================================================
// EnableDog:
// This function enables the watchdog timer.
//===========================================================================
void EnableDog(void)
{
EALLOW;
WDCR = 0x002F; //Prescale as 64,means OSCCLK / 512 / 64
EDIS;
}
//===========================================================================
// ConfigCPUTimers:
// This function initializes CPU timer0 to a known state.
//===========================================================================
void ConfigCpuTimers( void )
{
/* Setting Timer 1ms*/
EALLOW;
Timer0.Timer = T0PERIOD; //Used for Request Data
Timer0.Period = T0PERIOD; //period equal 250ms
Timer0.Prescale = 0;
Timer0.Control = 0x4030; /* Enable interrupt;Not Free run;reload */
Timer1.Timer = T1PERIOD; //Used for lightning LED
Timer1.Period = T1PERIOD; //period equal 500ms
Timer1.Prescale = 0;
Timer1.Control = 0x4030; /* Enable interrupt;Not Free run;reload */
Timer2.Timer = T2PERIOD; //
Timer2.Period = T2PERIOD; //period equal 40ms
Timer2.Prescale = 0;
Timer2.Control = 0x4030; /* enable interrupt;Not Free run;reload */
EDIS;
}
void Timers0Start( void)
{
Timer0.Control &= 0xffef;
}
void Timers0Stop( void)
{
Timer0.Control |= 0x0010;
}
void Timers1Start( void)
{
Timer1.Control &= 0xFFEF;
}
void Timers1Stop( void)
{
Timer1.Control |= 0x0010;
}
void Timers2Start( void)
{
Timer2.Control &= 0xFFEF;
}
void Timers2Stop( void)
{
Timer2.Control |= 0x0010;
}
//===========================================================================
// GpioInit:
// This function initializes the Gpio to a known state.
//===========================================================================
void GpioInit( void )
{
EALLOW;
GPAMUX = 0x1000; /* Enable Cap1, Cap2 */
GPBMUX = 0x03FF; /* Enable Cap4, Cap5 */
GPEMUX = 0x0003; /* Enable XINT1, XINT2 */
GPFMUX = 0x00FF; /* Enable SCIA, Ecan, SPI */
GPGMUX = 0x0030; /* Enable SCIB */
GPADIR = 0x0001; /*configure the gpio a as input*/
GPBDIR = 0x0000;
GPEDIR = 0x0000;
GPFDIR = 0x4050; /* SCIA TX RX; Ecan Tx Rx; Config the XF as GPIO(output) 2004/9/14*/
GPGDIR = 0x0010; /* SCIB TX RX*/
EDIS;
}
//===========================================================================
// EvInit:
// This function initializes the EV to a known state.
//===========================================================================
void EvInit( void )
{
//Initialize the EVA
T1CNT = 0x0000;
T1CON = 0x1010; // EVT1CLK = TCLKIN/1, T1CON.6(TENABLE) = 0(Disable time1), use external clock
T1PR = 0x03E8;
T2CNT = 0x0000;
T2CON = 0x1100; // EVT2CLK = HSPCLK/2, T2CON.6(TENABLE) = 0(disnable time2), use timer1's enable bit
T2PR = 0x03E8;
EVAIFRA = 0x0080;
EVAIFRB = 0x0001; // Clear the interrupt flags;
EVAIMRA = 0x0080;
EVAIMRB = 0x0001; // Enable Timer1 and Timer2's interrupt function
/* GPTCONA = 0x0049; // Use the timer2 to start the ADC ( underflow )
T1CNT = 0x0000;
T1CON = 0x1042; // EVT1CLK = HSPCLK/1, T1CON.6(TENABLE) = 1(Enable time1)
T1PR = 0xFFFF;
T1CMPR = 0x3C00;
T2CNT = 0x0000;
T2CON = 0x1042; // EVT2CLK = HSPCLK/8, T2CON.6(TENABLE) = 0(disnable time2)
T2PR = 0x0FFF;
T1CMPR = 0x03C0;
CMPR1 = 0x0C00;
CMPR2 = 0x3C00;
CMPR3 = 0xFC00;
ACTRA = 0x0666;
DBTCONA = 0x0000;
COMCONA = 0xA600;
// Default value
// Cap 1,2,3
//CAPFIFOA = 0x0000; // Each two generates interrupt
//CAPCONA = 0x0000; // Reset cap1,2,3
//NOP;
//CAPCONA = 0xB6FF; // Using GP Timer 1 and both edge detection for cap1,2,3
// Interrupts mask
EVAIMRA = 0x0000; // Disnable T1PINT
EVAIMRB = 0x0001; // Enable T2PINT
EVAIMRC = 0x0003; // Enable cap1 and cap2 interrupts
//Initialize the EVB
//GPTCONB = 0x0000;
//T3CNT = 0x0000;
//T3CON = 0x1040; // EVT3CLK = HSPCLK/1, T3CON.6(TENABLE) = 1(Enable time3)
//T3PR = EVT3PERIOD;
//T4CNT = 0x0000;
//T4CON = 0x1700; // EVT4CLK = HSPCLK/128, T4CON.6(TENABLE) = 0(Disnable time4)
//T4PR = EVT4PERIOD;
//Cap 4,5,6
//CAPFIFOB = 0x0000; // Each two generates interrupt
//CAPCONB = 0x0000; // Reset cap3,4,5
//NOP;
//CAPCONB = 0xB6FF; // Using GP Timer 3 and both edge detection for cap4,5,6
// Interrupts mask
//EVBIMRA = 0x0000; // Disable T3PINT
//EVBIMRB = 0x0001; // Enable T4PINT
//EVBIMRC = 0x0003; // Enable cap4 and cap5 interrupts*/
}
//===========================================================================
// SciInit:
// This function initializes the SCIs to a known state.
//===========================================================================
void SciInit( void )
{
//setup SCIA
SCIFFTXA = 0x0000; // reset transmit chanel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -