Title: ? ?:?C321?
1DSP?????I
????? ? ??C321? Phone13819195905 EmailChenp
eng_at_zjut.edu.cn
2????????
1?DSP????--2?
A. DSP (Digital Signal Processing)???????(??),??
????????????,?????????????????????????????????,???
????????????
B. DSP (Digital Signal Processor)????????????????
???????,?????????????????????????????
3????????(?)
2?DSP??????--?????????????
3?DSP???????? --?????????( ??1)????2)?????3)???
?)
4?DSP????? -- TI?DSP( C2000,C5000,C6000,OMAP,
DaVinci)
4????????(?)
5???DSP????????--?????????????????????????
6?DSP???????? --
????????????????????DSP?????\FPGA???????????
5????????(?)
7?TMS320F281?TMS320C281???
?C281X????,F281X???DSP???Flash????
F281X??,??????????,???????????????
8?F2810?F2811?F2812?????
F2812?F2810?F2811?????????? F2812?F2811?Flash?128K
,F2810?Flash??64K? F2812??????176,
?F2810?F2811??????128?
6????
- ???????
- ???????
- CPU???
- ??I/O
- ????????(PIE)
- ???????
71 ???????
TMS320F281?????PLL?????,??????????????
???(OSCCLK)???????
a)??????X1/XCLKIN?X2???????? b)??????????????X1
/XCLKIN??,X2??,???????????
81 ???????(?)
????(CLKIN)??? 1)?????,??XPLLDIS0?,CPU??????????
???????????? 2)?????,??XPLLDIS1?,??????PLL(Phase
Locked Loop)???????CPU?????
(1)
???????????
(2)
(3)
8
91. ???????(?)
?? ???? SYSCLKOUT
??PLL ???????/XPLLDIS????,???PLL?????????X1/XCLKIN?????????CPU??? XCLKIN
??PLL ??????????PLL?????,?PLL????????,????X1/XCLKIN?????????2?????CPU??? XCLKIN/2
??PLL ???PLLCCR??????????n????PLL?/2???PLL?????????CPU??? (XCLKINn)/2
30MHz
15MHz
15-150MHz
????????(PLLCR--0x00007021)
101 ???????(?)
????????(PLLCR--0x00007021)
????????PLL??,OSCCLK30MHz,??5???
111. ???????(?)
// This function initializes the PLLCR
register. void InitPll(unsigned int val)
volatile unsigned int i EALLOW
SysCtrlRegs.PLLCR.bit.DIV val EDIS
DisableDog() // Wait PLL lock
cycles. for(i 0 ilt ( (131072/2)/12 )
i)
???PLLCR?????
Val 010
????????????
????PLL??????
?????????????0???????RAM?????????FLASH???????????
,????????????
121 ???????(?)
volatile unsigned int i
??????????????,???????????/???????C?????????/???,?
??????volatile ??????,???????????????,????DSP?
???????,???????C???????????volatile
???????????????,???????????????
131 ???????(?)
?????volatile ??????????,?????????????????,??????
??????????????????????????
volatile int i10 int a i ...
//????,?????????,?i????? int b i
??volatile,????????i??????????????i?????,????????
?????b????????i????????,??i???????????????????????
,???volatile???????????????
141 ???????(?)
sum
1.8V
3.3V
?????
??DSP??????????,?????????
151 ???????(?)
????????? (PCLKCR)????????????(?CAN??)
- ????????? (HISPCP)
- ????(??)EVA,EVB,ADC
- HSPCLKSYSCLK/(114)
- ????????SYSCLK/2
75MHz
- ????????? (LOSPCP)
- ????(??)SCIA,SCIB,SPI,McBSp
- LSPCLKSYSCLK/(114)
- ????????SYSCLK/4
37.5MHz
16????????P19 ?2.4?2.5?2.6
void InitPeripheralClocks(void) EALLOW //
HISPCP/LOSPCP will be set to default values
SysCtrlRegs.HISPCP.all 0x0001 //
HSPCLKSYSCLK/2 SysCtrlRegs.LOSPCP.all
0x0002 // LSPCLKSYSCLK/4 // Peripheral
clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK1
SysCtrlRegs.PCLKCR.bit.EVBENCLK1
SysCtrlRegs.PCLKCR.bit.SCIAENCLK1
SysCtrlRegs.PCLKCR.bit.SCIBENCLK1
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK1
SysCtrlRegs.PCLKCR.bit.SPIENCLK1
SysCtrlRegs.PCLKCR.bit.ECANENCLK1
SysCtrlRegs.PCLKCR.bit.ADCENCLK1 EDIS
// This function initializes the clocks to the
peripheral modules.
1???????,????????????? 2??????????,??????????????
172 ???????
?????
182 ???????(?)
????? 30MHz/512/64/2563.58Hz,?????????279ms
????????WDCR
- ??????????WDFLAG
- ?1--?????(WDRST)0--????
- ?1--?WDFLAG??0--WDFLAG????
- ?1?WDDIS,????????0????????
- WDCHK(53)???101,??????DSP???
- WDPS(20)?????????(2???)
- WDCLKOSCCLK/512/(164)?
192 ???????(?)
// This function disables the watchdog
timer. void DisableDog(void) EALLOW
SysCtrlRegs.WDCR 0x0068 //WDDIS1, WDCHK101,
EDIS //
WDPS000 (WDCLKOSCCLK/512)
// This function enables the watchdog
timer. void EnableDog(void) EALLOW
SysCtrlRegs.WDCR 0x0028 //WDDIS0, WDCHK101,
EDIS //
WDPS000 (WDCLKOSCCLK/512)
202 ???????(?)
??????????SCSR
- WDINTS????????,??WDINT????
- WDENINT
- 1--???????(WDRST)???, ?????????(WDINT)
- 0--???????(WDRST)???, ?????????(WDINT)
- WDOVERRIDE
- 1--????WDCR????????WDDIS0--????WDDIS
- ???????????????????,??????????
212 ???????(?)
????????WDKEY
- ???0x550xAA?WDKEY??WDCNTR??
- ??????????????
- ????????WDCR??????
222 ???????(?)
// This function resets the watchdog timer. void
KickDog(void) EALLOW SysCtrlRegs.WDKEY
0x0055 SysCtrlRegs.WDKEY 0x00AA
EDIS
???????????,????????????KickDog??,????????????????
????
232 ???????(?)
????????WDCNTR
- WDCNTR??????????????(0-0xFF)
- ???????,??????????DSP
- ???WDKEY??????( 0x550xAA ),????????
242 ???????(?)
???????
// -This function initializes the System Control
registers to a known state. void
InitSysCtrl(void) // Disable the watchdog
DisableDog() // Initialize the
PLLCR to 0xA InitPll(0xA) // Initialize
the peripheral clocks InitPeripheralClocks()
1???????? 2???PLLCR???,??SYSCLKOUT???
3?????/???????????? 4?????????
??????????????,??????????????? PLLCR????10,?CPU???
???30MHz5?
253 CPU???
- F281????3?32?CPU???(TIMER0/1/2)
- TIMER0??????????,TIMER1/2???DSP BIOS??(????DSP
BIOS,????????)? - ??????4????
- 1)?????(TIMHTIM)32?
- 2)?????(PRDHPRD)32?
- 3)??????(TPR) 32?(??????PSC?????TDDR)
- 4)?????(TCR)16?
25
263 CPU???(?)
TIMERx?????(TCR)
- TIF-Timer Interrupt Flag
- TIE-Timer Interrupt Enable
- TRB-Timer Reload Bit
- TSS-Timer Stop/Start Bit
???P27 ?2.17
273 CPU???(?)
???????? 1)?32??????(TIMHTIM)???????(PRDHP
RD)?????? 2)???????SYSCLKOUT??????(16?32?)
3)????????0?,??????????????????,?????????(TI
NT0)?
CPU???????
283 CPU???(?)
???????????????DSP????Freq(MHz)??????Period(µs)
?????????????????????
void ConfigCpuTimer(struct CPUTIMER_VARS Timer,
float Freq, float Period) unsigned long
temp Timer-gtCPUFreqInMHz Freq //
Initialize timer period Timer-gtPeriodInUSec
Period temp (long) (Freq Period)
// 150MHz100us15000 Timer-gtRegsAddr-gtPRD.all
temp Timer-gtRegsAddr-gtTPR.all 0 // Set
pre-scale counter to divide by 1
Timer-gtRegsAddr-gtTPRH.all 0 // Initialize
timer control register Timer-gtRegsAddr-gtTCR.bit.
TSS 1 // 1 Stop timer, 0 Start Timer
Timer-gtRegsAddr-gtTCR.bit.TRB 1 // 1
reload timer Timer-gtRegsAddr-gtTCR.bit.SOFT
1 Timer-gtRegsAddr-gtTCR.bit.FREE 1 //
Timer Free Run Timer-gtRegsAddr-gtTCR.bit.TIE 1
// 1 Enable Timer Interrupt
294 ??I/O
- F281????56????????,
- ??GPxMUX??????????????I/O??
- ???????I/O??,?????????(GPxDIR)?????????????????
(GPxQUAL)????????(QUAL PRD),?????????????
304 ??I/O(?)
- GPxMUX???
- GPxMUX.bit0- ???I/O??1-???????
- GPxDIR???
- GPxDIR.bit0- ???????1-???????
- GPxDAT???
- GPxDAT.bit?????????,????????
- GPxSET???
- GPxSET.bit 1- ???????????
- GPxCLEAR???
- GPxCLEAR.bit 1-???????????
- GPxTOGGLE???
- GPxTOGGLE.bit1-????????????
31void InitGpio(void) // This function
initializes the Gpio to a known state.
EALLOW // ?? GPIO A??,
AL(70)???-AH(158)??? GpioMuxRegs.GPAMUX.al
l0x0000 // sets GPIO Muxs as I/Os
GpioMuxRegs.GPADIR.all0xFF00 // upper byte as
output/low byte as input GpioMuxRegs.GPAQUAL.
all0x0000 // Input qualifier disabled
GpioDataRegs.GPADAT.all0xAA00 // Toggle I/Os
using DATA registers GpioDataRegs.GPASET.all
0xAA00 // Toggle I/Os using SET/CLEAR registers
GpioDataRegs.GPACLEAR.all0x5500
GpioDataRegs.GPATOGGLE.all0xFF00 // Toggle I/Os
using TOGGLE registers // Set GPIO B port
pins, configured as EVB signals
GpioMuxRegs.GPBMUX.all0xFFFF // Configure
peripherals signals on the pins
GpioMuxRegs.GPBQUAL.all0x0000 // Input
qualifier0 (disabled) EDIS
325 PIE????
- F281???17?CPU???,??1???????NMI?16??????(INT1INT
14,RTOSINT?DLOGINT)
- ????????(PIE)????????1??????PIE????96????,??8????
???,????????,???12?????(INT1INT12) - PIE ?????????????INT1-INT12,??8??????????????INTx
.1-INTx.8 - ?????????????????RAM?,????????????????????????
- ??????25616??SRAM??,??????????2?16??????(??P39
?2.23)?
33- DSP281X???
- 45?PIE??
- 16?CPU??
- ??NMI??
- 3??????
34PIEIFRx.y
IERx
INTM
PIEIERx.y
PIEACKx
ISR
355 PIE????
PIE???????(PIECTRL)
PIEVECT(151)???????????????
ENPIE1?????????PIE????? ENPIE0???CPU???
??P42 ?2.25
365 PIE????
PIE???????(PIEACK)
INT12
INT1
- PIEACK(110)
- ????????????,?PIEACK?????1???PIE???????????CPU???
?? - ?PIEACK?????????????????
375 PIE????(?)
PIE???????(PIEIFRx)
- ??????,????1?DSP??????,?????????
- ?????????????????
385 PIE????(?)
PIE???????(PIEIERx)
?1??????????0??????
395 PIE????(?)
CPU???????(IFR)
- 0--?????
- 1--?????????
- ???????????????
405 PIE????(?)
CPU???????(IER)
- 0--????
- 1--????
- ???IER?????
- ????OR IER ???????AND IER??????
416 ???????
- ?? CPU???0??????
- ????LED???????(0/1)
??????? 1)???????????? 2)?????????????--InitPieCt
rl() 3)CPU???????????--main() 4)?????????????--ma
in() 5)??????--ISRTimer0()
41
426 ???????(?)
??1????????
const struct PIE_VECT_TABLE PieVectTableInit
PDPINTA_ISR, // EV-A
PDPINTB_ISR, // EV-B rsvd_ISR,
XINT1_ISR, XINT2_ISR,
ADCINT_ISR, // ADC TINT0_ISR,
// Timer 0 WAKEINT_ISR, // WD
??2?????????????,?CPU???0?
volatile unsigned long TINT0(volatile unsigned
long )0x000D4C
43define EINT asm(" clrc INTM") define DINT
asm(" setc INTM")
void InitPieCtrl(void) DINT
// Disable Interrupts
at the CPU level PieCtrlRegs.PIECRTL.bit.ENPIE
0 // Disable the PIE PieCtrlRegs.PIEIER1.
all 0 // Clear all PIEIER registers
PieCtrlRegs.PIEIER2.all 0
PieCtrlRegs.PIEIER12.all 0
PieCtrlRegs.PIEIFR1.all 0 // Clear
all PIEIFR registers. PieCtrlRegs.PIEIFR2.all
0 PieCtrlRegs.PIEIFR12.all 0
PieCtrlRegs.PIECRTL.bit.ENPIE 1 // Enable the
PIE PieCtrlRegs.PIEACK.all 0xFFFF //
Enables PIE to drive a pulse into the CPU
446 ???????(?)
void InitPieVectTable(void) // Initializes the
PIE vector table to a known state. int16 i Ui
nt32 Source (void ) PieVectTableInit Uint32
Dest (void ) 0x000D00 EALLOW for(i0 i
lt 128 i) Dest Source EDIS PieCtrl
Regs.PIECRTL.bit.ENPIE 1 // Enable the PIE
Vector Table
45void main(void) InitSysCtrl()
//??????? DINT //??? IER
0x0000 IFR 0x0000 InitPieCtrl()
//???PIE InitPieVectTable()
//???PIE?????,?????1 InitPeripherals()
//?????,???????? EALLOW PieVectTable.TINT0
ISRTimer0 //??1 TINT0 (unsigned
long)ISRTimer0 //??2 EDIS ConfigCpuTimer(C
puTimer0, 150, 1000000) //??CPU???0 CpuTimer0Reg
s.TCR.bit.TSS 0 //??CPU???0
PieCtrl.PIEIER1.all 0x40
//??CPU???0?? IER 0x0001 EINT
// Enable Global
interrupt INTM for()
466 ???????(?)
define LED1_ON GpioDataRegs.GPFDAT.bit.GPIOF110
define LED1_OFF GpioDataRegs.GPFDAT.bit.GPIOF11
1 // PIE Group 1 - MUXed into CPU INT1 interrupt
void ISRTimer0(void) PieCtrl.PIEACK.all
0x0001 if(Led_Flag 1)
LED1_ON Led_Flag 0 else
LED1_OFF Led_Flag 1
47?????????3? ????????
??2-2,2-3
?????!