TMS320C62xHPI引导过程的实现
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
…
};
3.2 主机对HPI接口的操作
TMS320C62x提供了三个16位寄存器:HPIC、HPIA、HPID和16位数据线与主处理器通信。主处理器通过HPIC、HPIA、HPID和16位数据线来与TMS320C62x进行数据交换,数据交换的过程如下:
1)首先初始化HPIC;
2)然后把地址写到HPIA;
3)最后通过HPID读或写数据。
假设主机CPU也是TMS320C62x,那么主机与目标机之间的连接如图1所示:
javascript:window.open(this.src);" style="cursor:pointer;"/>
如图1所示,假如Target 6201的/HCS连接到主机6201的CE1上。Target 6201的HPI寄存器映射到Host 6201DSP内存中,HCNTRL[1:0]和HHWIL连接到主机CPU的地址线上,那么HPIC、HPIA、HPID寄存器的地址分配如表2所示。,那么在C语言中,可以通过指针访问HPIC、HPIA、HPID,例如:
#define C6201_HPI 0x01400000 /* Host address on which C6x HPI is mapped */
int *hpi_ptr; /* define and initialize pointer*/
hpi_ptr = (int *)C6201_HPI;
/* Write dest_address to HPIA, with HOB=1 */
ptr_hpi[2] = (int)(dest_address & 0x0ffff);
ptr_hpi[3] = (int)((dest_address>>16)&0x0ffff);
表2 HPIC、HPIA、HPID各寄存器的地址分配
映射到主机的地址 | HPI控制线 | HPI寄存器访问 | |
HCNTL[1:0] | HHWIL | ||
HPI Base address + 0x00 | 00 | 0 | HPIC 1st halfword |
HPI Base address + 0x04 | 00 | 1 | HPIC 2st halfword |
HPI Base address + 0x08 | 01 | 0 | HPIA 1st halfword |
HPI Base address + 0x0C | 01 | 1 | HPIA 2st halfword |
HPI Base address + 0x10 | 10 | 0 | HPID 1st halfword HPIA 自增 |
HPI Base address + 0x14 | 10 | 1 | HPID 2st halfword HPIA自增 |
HPI Base address + 0x18 | 11 | 0 | HPID 1st halfword HPIA不自增 |
HPI Base address + 0x1C | 11 | 1 | HPID 2st halfword HPIA不自增 |
3.3 主机通过HPI下载代码和数据段到目标DSP
一个程序由初始化区和非初始化区两部分组成,主机处理器必须根据.cmd命令文件把这两个区装载到DSP正确的地址。下面这段代码就是将代码段和数据段两部分分别下载到指定地址(即程序RAM和数据RAM)。它主要是从*source中读出32位长的数据,然后通过HPI将此数据写到DSP的dest_add地址(即程序RAM和数据RAM)中。*source中的数据就是DSP的启动代码段和数据段中的数据。
void C6x_write_section(int *ptr_hpi, short *source, int dest_add, int length)
{
int i;
/* Write HPIC with HWOB=1,1st halfword transferred is least significant */
/* HCNTRL1 HCNTRL0 HHWIL */
ptr_hpi[0] = 0x0001; /* 1st halfword 0 0 0 */
ptr_hpi[1] = 0x0001; /* 2nd halfword 0 0 1 */
/* Write destination address to HPIA, 1st halfword is least significant */
/* HCNTRL1 HCNTRL0 HHWIL */
ptr_hpi[2] = (int)(dest_add & 0x0ffff); /* 0 1 0 */
ptr_hpi[3] = (int)((dest_add>>16)&0x0ffff);/* 0 1 1 */
for(i=0 ; i < length ; i++)
{
/* Write source_word to HPID with address post-increment */
/* 1st half-word transferred is least significant */
/* HCNTRL1 HCNTRL0 HHWIL */
ptr_hpi[4] = (int) *source++; /* 1 0 0 */
ptr_hpi[5] = (int) *source++; /* 1 0 1 */
}
}
3.4 目标DSP开始执行所下载的代码
主机通过HPI下载代码段和数据段到目标DSP以后,那么目标DSP就需要执行所下载的代码了。通过写HPIC寄存器的DSPINT位为1让DSP退出复位状态后,DSP就开始从地址0执行所下载的代码了。具体实现代码为:
/* Write HPIC with DSPINT=1 */
/* HCNTRL1 HCNTRL0 HHWIL */
/* 1st halfword 0 0 0 */
/* 2nd halfword 0 0 1 */
ptr_hpi[0] = 0x0002; /* 1st halfword */
ptr_hpi[1] = 0x0002; /* 2nd halfword */
4 总结
根据前面所述,TMS320C62x HPI启动过程如图2所示。
javascript:window.open(this.src);" style="cursor:pointer;"/>