使用sprc097的DSP281x_usDelay.asm
在ti sprc097的example中,提供了一個us延時函數,其使用很簡單,它的聲明放在了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);的參數相對應。
使用時候,調用即可,單位為us(microseconds)。但是為了確保延時準確,還要注意兩個事情:
1、在 0 waitstate ram中執行此函數,我們知道讀flash會有一個waitstate的延時,這個會影響此函數計時的準確性,F2812各個存儲區的waitstate如下:
from:TMS320F281x Data Sheet (Rev. L).pdf
所以,如上表,我們可以放在M0,M1,L0&L1,H0來運行此函數。
2、為確保準確性,在運行此函數之前關中斷。如果不能關中斷,那么這個延時可能比預想的要長。
?
? 實際使用中,如何將此函數放在0 waitstate ram中運行呢?
情景一、Ram調試(即程序段(page0)和數據段(page1)都在ram中),那么不用過多的管,因為本來就載入(Load)在ram中,運行肯定也是。
情景二、寫入到Flash,在Flash中運行。注意到在DSP281x_usDelay.asm中是將此函數定義到了段“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 ... ... }
可以看到,這個段加載在FLASHD,運行在RAML0,完全ok,這樣,只要再運行DSP28x_usDelay之前,手動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);運行一下這個MemCopy函數即可,RamfuncsLoadStart, RamfuncsLoadEnd, 和RamfuncsRunStart是在上面的cmd文件中定義的,連接器在分配空間之后,把段ramfuncs 的幾個地址幅值到這幾個變量中了。LOAD_START等幾個的定義可見
spru513b :TMS320C28x Assembly Language Tools User’s Guide
?
而當你決定在Flash中運行,其實上面MemCopy的工作本來就是必須做的,因為在Flash中運行的話,InitFlash(); 本來就必須在Ram中運行,而InitFlash()也剛好定義在ramfuncs里面,在運行InitFlash()之前就必須運行一次MemCopy了,所以,對于使用DSP28x_usDelay,相當于不用任何附加的操作,添加其源文件直接使用即可(當然,要自己考慮中斷的影響)。
?
轉載于:https://www.cnblogs.com/TrueElement/archive/2012/11/27/2791302.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的使用sprc097的DSP281x_usDelay.asm的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 九度OJ-1088剩下的树
- 下一篇: gateway sentinel 熔断