4.2 OsExcSaveIntStatus中断寄存器信息转储
OsExcSaveIntStatus()函数用于转储中断寄存器的数据,⑴、⑵和⑶和其他转储函数类似,分别是获取存储区域的结束地址,设置类型和大小信息,并后移g_excContent指针。⑷处的OS_NVIC_SETENA_BASE定义在kernel\arch\arm\cortex-m7\gcc\los_arch_interrupt.h,是Interrupt enable register中断使能寄存器的地址,它的大小由OS_NVIC_INT_ENABLE_SIZE定义。后续的代码分别转储其他中断寄存器,比如Interrupt Set-Pending Registers中断设置请求寄存器的地址OS_NVIC_SETPEND_BASE、Interrupt Active Bit Register中断活跃寄存器的地址OS_NVIC_INT_ACT_BASE、Interrupt Priority Register中断优先级寄存器的地址OS_NVIC_PRI_BASE,这些中断寄存器可以查看官网了解更多,或者查看下图。
⑸处的代码是System Handler Priority Register系统处理优先级寄存器的地址OS_NVIC_EXCPRI_BASE,⑹处是System Handler Control and State Register系统处理控制和状态寄存器的地址OS_NVIC_SHCSR、⑺处是Interrupt Control and State Register中断控制和状态寄存器的地址OS_NVIC_INT_CTRL,有关这些寄存器的信息可以访问官网https://developer.arm.com/documentation/ddi0489/f/system-control/register-summary。
STATIC UINT32 OsExcSaveIntStatus(UINT32 type, VOID *arg)
{
UINT32 ret;
⑴ UINTPTR excContentEnd = (UINTPTR)MAX_INT_INFO_SIZE + (UINTPTR)g_excContent;
(VOID)arg;
⑵ *((UINT32 *)g_excContent) = type;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
⑶ *((UINT32 *)g_excContent) = EXC_INT_STATUS_LEN;
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
/* save IRQ ENABLE reg group */
⑷ ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_SETENA_BASE, OS_NVIC_INT_ENABLE_SIZE);
if (ret != EOK) {
return LOS_NOK;
}
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ENABLE_SIZE;
/* save IRQ PEND reg group */
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_SETPEND_BASE, OS_NVIC_INT_PEND_SIZE);
if (ret != EOK) {
return LOS_NOK;
}
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PEND_SIZE;
/* save IRQ ACTIVE reg group */
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_INT_ACT_BASE, OS_NVIC_INT_ACT_SIZE);
if (ret != EOK) {
return LOS_NOK;
}
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ACT_SIZE;
/* save IRQ Priority reg group */
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_PRI_BASE, OS_NVIC_INT_PRI_SIZE);
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PRI_SIZE;
/* save Exception Priority reg group */
⑸ ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_EXCPRI_BASE, OS_NVIC_EXCPRI_SIZE);
if (ret != EOK) {
return LOS_NOK;
}
g_excContent = (UINT8 *)g_excContent + OS_NVIC_EXCPRI_SIZE;
/* save IRQ Handler & SHCSR */
⑹ ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_SHCSR, OS_NVIC_SHCSR_SIZE);
if (ret != EOK) {
return LOS_NOK;
}
g_excContent = (UINT8 *)g_excContent + OS_NVIC_SHCSR_SIZE;
/* save IRQ Control & ICSR */
⑺ ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
(const VOID *)OS_NVIC_INT_CTRL, OS_NVIC_INT_CTRL_SIZE);
if (ret != EOK) {
return LOS_NOK;
}
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_CTRL_SIZE;
return LOS_OK;
}