在 core_cm4.h 上为什么会出现像 ((uint32_t)(int32_t)IRQn) 这样的转换? [英] On core_cm4.h why is there casting like ((uint32_t)(int32_t)IRQn)?

查看:75
本文介绍了在 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-Core 源,从 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天全站免登陆