本系列的其它几篇文章:
《英飞凌 AURIX 系列单片机的HSM详解(1)——何为HSM》
《英飞凌 AURIX 系列单片机的HSM详解(2)——与HSM相关的UCB和寄存器》
《英飞凌 AURIX 系列单片机的HSM详解(3)——开发方法》
《英飞凌 AURIX 系列单片机的HSM详解(4)——Tricore核与HSM核之间的通信方法》
《英飞凌 AURIX 系列单片机的HSM详解(5)——HSM硬件加速模块的使用》
因为HSM有单独的一个ARM核,实际使用过程中HSM核与主CPU Tricore核之间需要进行通信,本文就来介绍一下二者之间的通信方法。
1. 中断
HSM核可以向主核发送中断,支持两个中断,主Tricore核中断控制寄存器地址分别为:0xF0038870u 、0xF0038874u,在iLLD中的定义如下:
/** \brief 870, HSM Service Request */
#define SRC_HSM_HSM0_HSM0 /*lint --e(923)*/ (*(volatile Ifx_SRC_SRCR*)0xF0038870u)
/** Alias (User Manual Name) for SRC_HSM_HSM0_HSM0.
* To use register names with standard convension, please use SRC_HSM_HSM0_HSM0.
*/
#define SRC_HSM0 (SRC_HSM_HSM0_HSM0)
/** \brief 874, HSM Service Request */
#define SRC_HSM_HSM0_HSM1 /*lint --e(923)*/ (*(volatile Ifx_SRC_SRCR*)0xF0038874u)
/** Alias (User Manual Name) for SRC_HSM_HSM0_HSM1.
* To use register names with standard convension, please use SRC_HSM_HSM0_HSM1.
*/
#define SRC_HSM1 (SRC_HSM_HSM0_HSM1)
初始化中断后,HSM核可以软件触发该中断,使主Tricore核进入中断执行程序。
主核初始化中断示例代码:
void init_interrupts(void)
{
SRC_HSM0.U = (0 << 11) | (1 << 10) | 1; /* 0<11 => ON CPU0, 1<<10 => Enable*/
interruptHandlerInstall(1, (uint32) &Bridge2Host_IRQHandler);
}
sint32 Bridge2Host_IRQHandler(void)
{
/***中断处理函数***/
}
2. 共享内存
TC3XX系列MCU有一块RAM空间被预留了出来,用于在主核和HSM核之间互相传递数据,被称为主核与HSM核之间的“桥梁”(Bridge):
其定义如下:
/*------------- BRIDGE Module ----------------------------------------------*/
typedef struct
{
uint32_t RESERVED0[2] ;
__IO uint32_t HSM_ID ; // Module Identifier Register
uint32_t RESERVED1[5] ;
__IO uint32_t HT2HSMF ; // Host to HSM Flag Register
__IO uint32_t HT2HSMIE ; // Host to HSM Interrupt Enable
__IO uint32_t HSM2HTF ; // HSM to Host Flag Register
__IO uint32_t HSM2HTIE ; // HSM to Host Interrupt Enable
__IO uint32_t HSM2HTIS ; // HSM to Host Interrupt Select
__IO uint32_t HSM2HTS ; // HSM to Host Status
__IO uint32_t HT2HSMS ; // Host to HSM Status
uint32_t RESERVED2 ;
__IO uint32_t CLKCTRL ; // Clock Control Register
uint32_t RESERVED3[7] ;
__IO uint32_t DBGCTRL ; // Debug Control Register
__IO uint32_t PINCTRL ; // Pin Control Register
uint32_t RESERVED4[6] ;
__IO uint32_t ERRCTRL ; // Error Control Register
__IO uint32_t ERRIE ; // Error Interrupt Enable Register
__IO uint32_t ERRADDR ; // Error Address Register
uint32_t RESERVED5[5] ;
__IO uint32_t EXTIF ; // External Interrupt Flag Register
__IO uint32_t EXTIE ; // External Interrupt Enable
uint32_t RESERVED6[6] ;
__IO uint32_t SAHBASE ; // Single Access to Host Base Address Register
uint32_t RESERVED7[7] ;
__IO uint32_t RSTCTRL ; // Reset Control Register
__IO uint32_t RSTPWD ; // Reset Password Register
uint32_t RESERVED8[2] ;
__IO uint32_t SENSIF ; // Sensor Interrupt Flag Register
__IO uint32_t SENSIE ; // Sensor Interrupt Enable Register
__IO uint32_t SENSAPPRST ; // Sensor Application Reset Enable Register
__IO uint32_t SENSSYSRST ; // Sensor System Reset Enable Register
uint32_t RESERVED9[16320] ;
__IO uint32_t SAHMEM[16384] ; // Single Access to Host Memory Window
} HSM_BRIDGE_TypeDef;
我们可以看到0xF0040000-0xF004FFFF这段地址空间内的一些地址被定义成了寄存器,可用于HSM核与主核之间相互控制、触发中断、获取状态等,详细的定义见HSM用户手册。
0xF0050000-0xF005FFFF这段地址空间没有具体的定义,但也是HSM核和主核都可以访问的区域。在使用的时候,我们可以在这个空间内定义一些大的数据块,比如用来存放待加解密的数据的buffer和加解密之后的数据的buffer,定义好之后可以将buffer的入口地址通过上面的寄存器(HSM2HTS & HT2HSMS)在HSM核与主核之间进行传递,就可以实现大块数据的传输,且传输过程中不需要进行数据的copy。