快乐虾
http://blog.csdn.net/lights_joy/
lights@hb165.com
本文适用于
ADI bf561 DSP
uclinux-2008r1.5-rc3 ( 移植到 vdsp5)
Visual DSP++ 5.0(update 5)
欢迎转载,但请保留作者信息
/* Enable Cycle Counter and Nesting Of Interrupts */
#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
R0 = SYSCFG_SNEN;
#else
R0 = SYSCFG_SNEN | SYSCFG_CCEN;
#endif
SYSCFG = R0;
这几行代码用于设置 SYSCFG 的值,关于 SYSCFG 这个寄存器, vdsp 文件这样说:
The System Configuration Register (SYSCFG) shown in Figure 4-3 controls the configuration of the processor
对于 BF561 而言,只有 CCEN 和 SSSTEP 两位有效,在这里将 CCEN 位设置为 1 ,表示要启用 64 位的 cycle counter 。而对 SNEN 的置位将被忽略。
在启用了 CCEN 之后, CYCLES 和 CYCLES2 两个寄存器将开始统计 CCLK 的个数。
下面是 vdsp 文档中对 CYCLES 和 CYCLES2 这两个寄存器的一个说明:
The cycle counter counts CCLK cycles while the program is executing. All cycles, including execution, wait state, interrupts, and events, are counted while the processor is in User or Supervisor mode, but the cycle counter stops counting in Emulator mode.
The cycle counter is 64 bits wide and increments every cycle. The count value is stored in two 32-bit registers, CYCLES and CYCLES2 . The least significant 32 bits (LSBs) are stored in CYCLES. The most significant 32 bits (MSBs) are stored in CYCLES2 .
Note: To ensure read coherency, first read CYCLES , then CYCLES2 , and then CYCLES again, to detect if an overflow has occurred in the LSBs during the read operations.
In User mode, these two registers may be read, but not written. In Supervisor and Emulator modes, they are read/write registers.
To enable the cycle counters, set the CCEN bit in the SYSCFG register. The following example shows how to use the cycle counter:
/* Insert code to be benchmarked here. */
通常这两个寄存器可以用于性能统计。但是由于这两个寄存器在几种模式下均是可写的,因此也可以将它们当成通用寄存器使用。在 uclinux 内核中,提供了一个叫 CONFIG_BFIN_SCRATCH_REG_CYCLES 的选项来控制 CYCLES 的用途:
config BFIN_SCRATCH_REG_CYCLES
bool "CYCLES"
help
Use the CYCLES register in the Blackfin exception handler
as a stack scratch register . This means you cannot
safely use the CYCLES performance registers on a Blackfin
board at anytime, but you can debug the system with a JTAG
ICE and use the NMI.
当设置了 CONFIG_BFIN_SCRATCH_REG_CYCLES 后,在 linux-2.6.x\arch\blackfin\mach-common\entry.S 文件中将 CYCLES 做为普通寄存器使用:
#if defined (CONFIG_BFIN_SCRATCH_REG_RETN)
# define EX_SCRATCH_REG RETN
#elif defined (CONFIG_BFIN_SCRATCH_REG_RETE)
# define EX_SCRATCH_REG RETE
#else
# define EX_SCRATCH_REG CYCLES
#endif
自然,在此时 CYCLES 是不应该自动计数的,因此 SYSCFG_CCEN 应该保持为 0 。
在 uclinux 内核代码中搜索 CYCLES ,可以发现有以下几个文件使用了它:
linux-2.6.x\drivers\char\bfin_timer_latency.c
linux-2.6.x\drivers\media\video\blackfin\blackfin_cam.c
linux-2.6.x\drivers\zaptel\bfsi-spi-framework.c
linux-2.6.x\drivers\zaptel\bfsi.c
当要使用这几个驱动时,就一定需要使 SYSCFG_CCEN=1 。
1 参考资料
head.s 分析 (1) :保存 u-boot 传递过来的指针 (2009-1-19)