对ARM紧致内存TCM的理解

作者在 2009-08-04 11:21:53 发布以下内容

ARM紧致内存TCM的理解

紧致内存是指片上快速存储区,与片上缓存具有同等的性能,但因为程序可完全控制紧致内存,因而比统计复用的缓存有更好的可预测性。这是ARM5TE引入的特性,目的是通过这一快速的存储区,一方面提高某些关键代码(如中断处理函数)的性能,另方面使存储访问延迟保持一致,这是实时性应用所要求的。ARM6对TCM操作做了进一步的规范。

TCM的应用领域:可预测的实时处理(中断处理)、避免缓存分析(加密算法)、或单纯的性能提高(处理器侧编解码)等。

如同缓存的哈佛结构,指令TCM和数据TCM是分开的。TCM有两种使用方式:作为快缓存使用,和作为本地内存使用。

本地内存
这时,TCM被用作更快速的内存,如同一般的RAM。因为指令段有时也是数据访问的对象,指令TCM实际上是指令数据一体化TCM。对TCM写操作后和后续对此写操作的依赖指令之间必须跟一个阻塞操作。

快缓存(smartcache)
TCM可以配置成当作外部RAM的缓存使用,对应的外部RAM也要设置可缓存标志。如果被缓存的外部RAM可以由多处理器共享,那么TCM是否与共享数据保持一致并没有规定,而由具体实现厂家决定。

TCM与缓存的内容不会自动保持一致,这意味着TCM映射到的内存区域必须是不缓存的区域。如果一个地址同时落在缓存和TCM内,那么访问这一地址的结果是不能预测的。另一个限制是各个TCM必须要配置成不相交的。

TCM的配置
通过CP15的0、1、9号寄存器进行:
0号寄存器
读CP15的0号寄存器,opcode2为2:
MRC p15, 0, Rd, C0, C0, 2
返回TCM状态寄存器的内容,其中,16-18位代表数据TCM个数,0-3代表指令TCM个数。

1号寄存器
ARM6之前,1号寄存器的16位和18位用于使能数据TCM和指令TCM(ARM946,ARM966),ARM6因为可以使用9号寄存器控制每一块TCM的使能状态,所以1号寄存器的这两个位就过时了,应该置1。

9号寄存器
每个TCM都有一个TCM区域寄存器,设置这个寄存器就可以设置TCM的基址和大小。在设置TCM区域寄存器前,需要设置TCM选择寄存器。
下面是访问这些相关寄存器的指令:

ARM Instruction                             TCM Region Register
MRC/MCR P15, 0, Rd, C9, C1, 0 Data TCM Region Register
MRC/MCR P15, 0, Rd, C9, C1, 1 Instruction/Unified TCM Region Register
MRC/MCR P15, 0, Rd, C9, C2, 0 TCM Selection Register

TCM区域寄存器的结构:
Base Address (Physical Address)[31-12] SBZ/UNP[11-7] Size[6-2] SC[1] En[0]

其中:
En位是使能位,置1时使能此TCM
SC位置位表示此TCM被用作快缓存(smartcache),清零表示本地内存;
Size字段是只读的,含义如下:
Size         Memory     Size             Memory
filed size field size
0b00000 0K 0b01101 4M
0b00011 4K 0b01110 8M
0b00100 8K 0b01111 16M
0b00101 16K 0b10000 32M
0b00110 32K 0b10001 64M
0b00111 64K 0b10010 128M
0b01000 128K 0b10011 256M
0b01001 256K 0b10100 512M
0b01010 512K 0b10101 1G
0b01011 1M 0b10110 2G
0b01100 2M 0b10111 4G
注意TCM区域寄存器配置出来的各个TCM块不能相交,否则后果不可预测(会损坏硬件?)。
技术 | 阅读 7634 次
文章评论,共1条
vfdff(作者)
2009-08-04 11:37
1
2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Memory initialization requirements<br />
The ARM Cortex-M1 processor loads the exception vector table from memory address 0x00000000 at reset.&nbsp;&nbsp;The vector table must be initialized with pointers to the exception handlers in your software before the processor comes out of reset.<br />
<br />
When it is enabled, the Instruction Tightly Coupled Memory (ITCM) starts at 0x00000000 in the processor’s memory map.&nbsp;&nbsp;The vector table will therefore reside in the ITCM when the ITCM is present.<br />
<br />
2.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Instruction memory and the vector table<br />
You should initialize the ITCM so that it contains at least an initialized vector table.&nbsp;&nbsp;You may also decide to initialize the ITCM with your entire software image because the ARM Cortex-M1 processor can achieve better performance when it is executing code from the TCMs.&nbsp;&nbsp;If you only initialize the vector table, then you must ensure that other memory in your system is initialized to contain startup code.<br />
<br />
If you configured the processor to have no ITCM then you must ensure that some external memory is available at address 0x00000000 and that this is initialized to contain a vector table.<br />
<br />
The following sections summarize some of the instruction memory initialization techniques that you can use with your software.<br />
<br />
2.1.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Initializing the ITCM with the entire software image<br />
If your code fits inside the ITCM then you can initialize the ITCM with the vector table and the entire software image.&nbsp;&nbsp;When the processor is reset the ITCM will already be initialized and the processor will start to execute the software immediately.&nbsp;&nbsp;This method has several advantages:<br />
<br />
·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;no boot loaders are required;<br />
<br />
·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;highest performance is achieved when executing from TCMs.<br />
<br />
However, you would need to re-synthesize the system to change the contents of the ITCM.<br />
<br />
Note<br />
On-chip memories, such as those used for the ARM Cortex-M1 TCMs, are initialized during the FPGA’s configuration phase.&nbsp;&nbsp;This is typically when the device is powered on or when a new image is programmed using a download cable.&nbsp;&nbsp;Resetting the processor does not reset the on-chip memories, so you must ensure that software running on the processor does not accidentally overwrite the instruction code or else the software might not work correctly when the processor is reset.&nbsp;&nbsp;You can configure the processor to have a read-only ITCM to protect against this.<br />
<br />
2.1.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Initializing the ITCM with vectors and using boot code<br />
You can initialize the ITCM with initial vectors pointing to code in external memory that copies the software image into the ITCM before executing it.&nbsp;&nbsp;Once the software image has been copied to the ITCM, the bootloader can either branch to the ITCM code or, after updating the vectors, request a reset.<br />
<br />
The biggest advantage of this technique is that the software can be changed without re-synthesizing the processor.<br />
<br />
If you use the boot loader method, you should ensure that:<br />
<br />
·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the processor has been configured to have a read/write ITCM so that the boot loader can modify the contents of the ITCM;<br />
<br />
·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;your boot code includes appropriate handlers for exceptions that may occur while executing the boot code, for example Non-Maskable Interrupt, HardFault and any exceptions that your boot code enables;<br />
<br />
·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;your boot code updates the ITCM vectors to their application run-time values;<br />
<br />
·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;your external memory has been initialized with the software image and boot code.<br />
<br />
2.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Data memory<br />
You can also initialize the Data Tightly Coupled Memory (DTCM) if your startup code requires initialized data.
游客请输入验证码
浏览1940620次