为什么要在core_cm4.h上进行类似((uint32_t)(int32_t)IRQn)的转换? [英] On core_cm4.h why is there casting like ((uint32_t)(int32_t)IRQn)?

查看:211
本文介绍了为什么要在core_cm4.h上进行类似((uint32_t)(int32_t)IRQn)的转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下来自core_cm4.h的代码中,为什么要进行两次强制转换((uint32_t)(int32_t)IRQn)?

In the following code from core_cm4.h why is there a double cast ((uint32_t)(int32_t)IRQn)?

例如以下功能:

__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
  NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
}

这是什么目的?

推荐答案

由于CM4软件为内核实现了负中断源,因此您必须先将值转换为32位有符号整数,然后再转换为无符号32位,以使用填充零进行正确的右移在数字的左侧.

Since CM4 software implements negative interrupt sources for core, you have to cast value first to 32bit signed integer and later to unsigned 32bit to make proper right shift with padding zeros on the left side of number.

CM4使用-15到-1作为CM4核心源,使用0到下一个作为供应商特定源.

CM4 uses -15 to -1 as CM4-Core sources and from 0 to next as vendor specific sources.

这篇关于为什么要在core_cm4.h上进行类似((uint32_t)(int32_t)IRQn)的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆