使用sprc097的DSP281x_usDelay.asm
在ti sprc097的example中,提供了一個(gè)us延時(shí)函數(shù),其使用很簡單,它的聲明放在了DSP281x_Examples.h里面:
#define CPU_RATE??? 6.667L?? // for a 150MHz CPU clock speed (SYSCLKOUT)// DO NOT MODIFY THIS LINE. #define DELAY_US(A) DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)
ps:上面的CPU_RATE的值要與DSP281x_SysCtrl.c里面的InitPll(0xA);的參數(shù)相對應(yīng)。
使用時(shí)候,調(diào)用即可,單位為us(microseconds)。但是為了確保延時(shí)準(zhǔn)確,還要注意兩個(gè)事情:
1、在 0 waitstate ram中執(zhí)行此函數(shù),我們知道讀flash會(huì)有一個(gè)waitstate的延時(shí),這個(gè)會(huì)影響此函數(shù)計(jì)時(shí)的準(zhǔn)確性,F2812各個(gè)存儲(chǔ)區(qū)的waitstate如下:
from:TMS320F281x Data Sheet (Rev. L).pdf
所以,如上表,我們可以放在M0,M1,L0&L1,H0來運(yùn)行此函數(shù)。
2、為確保準(zhǔn)確性,在運(yùn)行此函數(shù)之前關(guān)中斷。如果不能關(guān)中斷,那么這個(gè)延時(shí)可能比預(yù)想的要長。
?
? 實(shí)際使用中,如何將此函數(shù)放在0 waitstate ram中運(yùn)行呢?
情景一、Ram調(diào)試(即程序段(page0)和數(shù)據(jù)段(page1)都在ram中),那么不用過多的管,因?yàn)楸緛砭洼d入(Load)在ram中,運(yùn)行肯定也是。
情景二、寫入到Flash,在Flash中運(yùn)行。注意到在DSP281x_usDelay.asm中是將此函數(shù)定義到了段“ramfuncs”中:
.def _DSP28x_usDelay.sect "ramfuncs"而“ramfuncs”在cmd中是這么定義的:
MEMORY { PAGE 0: /* Program Memory *//* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */... ...?? RAML0?????? : origin = 0x008000, length = 0x001000???? /* on-chip RAM block L0 */FLASHD : origin = 0x3EC000, length = 0x004000 /* on-chip FLASH */ ... ...PAGE 1 : /* Data Memory *//* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation *//* Registers remain on PAGE1 */... ...RAML1 : origin = 0x009000, length = 0x001000 /* on-chip RAM block L1 */ ... ...}/* Allocate sections to memory blocks.Note:codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code execution when booting to flashramfuncs user defined section to store functions that will be copied from Flash into RAM */ SECTIONS { ... ...ramfuncs : LOAD = FLASHD, RUN = RAML0, LOAD_START(_RamfuncsLoadStart),LOAD_END(_RamfuncsLoadEnd),RUN_START(_RamfuncsRunStart),PAGE = 0 ... ... }
可以看到,這個(gè)段加載在FLASHD,運(yùn)行在RAML0,完全ok,這樣,只要再運(yùn)行DSP28x_usDelay之前,手動(dòng)copy一下就行了:
// Copy time critical code and Flash setup code to RAM // This includes the following ISR functions: EvaTimer1(), EvaTimer2() // EvbTimer3 and and InitFlash(); // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart // symbols are created by the linker. Refer to the F2812.cmd file. MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);運(yùn)行一下這個(gè)MemCopy函數(shù)即可,RamfuncsLoadStart, RamfuncsLoadEnd, 和RamfuncsRunStart是在上面的cmd文件中定義的,連接器在分配空間之后,把段ramfuncs 的幾個(gè)地址幅值到這幾個(gè)變量中了。LOAD_START等幾個(gè)的定義可見
spru513b :TMS320C28x Assembly Language Tools User’s Guide
?
而當(dāng)你決定在Flash中運(yùn)行,其實(shí)上面MemCopy的工作本來就是必須做的,因?yàn)樵贔lash中運(yùn)行的話,InitFlash(); 本來就必須在Ram中運(yùn)行,而InitFlash()也剛好定義在ramfuncs里面,在運(yùn)行InitFlash()之前就必須運(yùn)行一次MemCopy了,所以,對于使用DSP28x_usDelay,相當(dāng)于不用任何附加的操作,添加其源文件直接使用即可(當(dāng)然,要自己考慮中斷的影響)。
?
轉(zhuǎn)載于:https://www.cnblogs.com/TrueElement/archive/2012/11/27/2791302.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的使用sprc097的DSP281x_usDelay.asm的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 九度OJ-1088剩下的树
- 下一篇: gateway sentinel 熔断