![](/img/trans.png)
[英]Mixing the usage of static, extern and inline keywords between definition and declaration
[英]Strange register definition ,declaration and usage
我正在使用GTM模塊,很難理解MCAL代碼,這是代碼示例:
/* Here the definition of the register */
/** \brief CMU Global Clock Control Numerator Register */
typedef struct _Ifx_GTM_CMU_GCLK_NUM_Bits
{
Ifx_Strict_32Bit GCLK_NUM:24; /**< \brief [23:0] Numerator for global clock divider (rw) */
Ifx_Strict_32Bit reserved_24:8; /**< \brief \internal Reserved */
} Ifx_GTM_CMU_GCLK_NUM_Bits;
/**
\brief CMU Global Clock Control Numerator Register */
typedef union
{
unsigned int U; /**< \brief Unsigned access */
signed int I; /**< \brief Signed access */
Ifx_GTM_CMU_GCLK_NUM_Bits B; /**< \brief Bitfield access */
} Ifx_GTM_CMU_GCLK_NUM;
/*CMU Global Clock Control Numerator Register */
#define GTM_CMU_GCLK_NUM /*lint --e(923)*/ (*(volatile fx_GTM_CMU_GCLK_NUM*)0xF0100304u)
/* Here we are using the register */
/* The content of Numerator and Denominator are temporarily taken in local
variables and used in the if statement below for Misra reasons. */
RegTemp3 = GTM_CMU_GCLK_NUM.U;
那么,為什么在聯合中存在U和I字段,為什么在位字段Ifx_GTM_CMU_GCLK_NUM_Bits B中使用U,
我在執行此代碼時遇到問題,因為在執行時有算術溢出異常:
RegTemp3 = GTM_CMU_GCLK_NUM.U;
GTM_CMU_GCLK_NUM
是特定於目標系統的硬編碼硬件寄存器。
必須將RegTemp3
作為無符號值讀入RegTemp3
,以確保以32位的形式對硬件進行單次訪問。
您是否在目標系統上執行此代碼?
您確定支持arithmetic overflow exception
嗎?
如果您在主機系統上運行代碼,則很可能會導致分段錯誤。
該代碼正在target system
上運行。 是的,支持overflow arithmetic exception
為了讀取寄存器值,為什么代碼未使用:
RegTemp3 = GTM_CMU_GCLK_NUM.B;
代替
RegTemp3 = GTM_CMU_GCLK_NUM.U;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.