- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何从 Runnable 内部确定 c 中 PIM(每实例内存)的大小(无需在生成的 RTE 中查找并添加固定值)?
情况:Runnable Foo 可以访问两个 PIM Pim1 和 Pim2。在示例中,Pim1 中的数据应复制到 Pim2。
不仅仅是因为安全性和安全性,我需要检查两个 PIM 的大小,以免覆盖非法数据区域。我知道PIM的大小是在SW-C描述(SWCD)中配置的。但由于 SWCD 在代码实现后可能会发生更改,并且为了使 Runnable 的代码更加通用,因此大小检查不应基于固定值。
我还考虑了数组的sizeof问题: How to find the 'sizeof'(a pointer pointing to an array)?
对于 PIM,RTE 生成器生成以下代码:
在Rte_Type.h中
typedef uint8 Rte_DT_DtImplRec1_0;
typedef uint16 Rte_DT_DtImplRec1_1;
typedef struct
{
Rte_DT_DtImplRec1_0 var1;
Rte_DT_DtImplRec1_1 var2;
Rte_DT_DtImplRec1_2 var3;
} DtImplRec1;
typedef uint8 Rte_DT_DtImplAry1_0;
typedef Rte_DT_DtImplAry1_0 DtImplAry1[5];
在 Rte.c
VAR(DtImplRec1, RTE_VAR_DEFAULT_RTE_PIM_GROUP) Rte_FOO_Pim1;
VAR(DtImplAry1, RTE_VAR_DEFAULT_RTE_PIM_GROUP) Rte_FOO_Pim2;
在 Rte_FOO.h 中
#define Rte_Pim_Pim1() (&Rte_FOO_Pim1)
#ifdef RTE_PTR2ARRAYBASETYPE_PASSING
# define Rte_Pim_Pim2() (&((*RtePim_Pim2())[0]))
#else
# define Rte_Pim_Pim2() RtePim_Pim2()
#endif
#define RtePim_Pim2() (&Rte_FOO_Pim2)
请注意,阵列 PIM 的定义也可能会发生变化,具体取决于 RTE_PTR2ARRAYBASETYPE_PASSING“开关”。
为 FOO 模板生成以下“访问权限”:
DtImplRec1 *Rte_Pim_Pim1(void);
Rte_DT_DtImplAry1_0 *Rte_Pim_Pim2(void)
Foo-Runnable 的代码可能如下所示:
FUNC(void, FOO_CODE) Foo(void)
{
DtImplRec1 *pim1 = Rte_Pim_Pim1();
Rte_DT_DtImplAry1_0 *pim2 = Rte_Pim_Pim2();
uint8 sizeOfPim1a = sizeof(Rte_Pim_Pim1()); /* always returns 4 as the size of the pointer */
uint8 sizeOfPim1b = sizeof(*Rte_Pim_Pim1()); /* evaluates to 6 */
uint8 sizeOfPim1c = sizeof(DtImplRec1); /* evaluates to 6 */
uint8 sizeOfPim1d = sizeof(Rte_FOO_Pim1); /* evaluates to 6 */
uint8 sizeOfPim2a = sizeof(Rte_Pim_Pim2()); /* always returns 4 as the size of the pointer */
uint8 sizeOfPim2b = sizeof(*Rte_Pim_Pim2()); /* evaluates to 1 */
uint8 sizeOfPim2c = sizeof(Rte_DT_DtImplAry1_0); /* evaluates to 1: sizeof(uint8) */
uint8 finalSize = MIN(sizeOfPim1b, sizeOfPim2b);
memcpy( pim2, pim1, finalSize ); /* (use of) memcpy is not the topic here */
}
为了让我的问题更加“明显”,这里是一个通过诊断编写 DID 的 Callback-Runnable 示例:
FUNC(Std_ReturnType, FOO_CODE)
DataServices_Data_FFFF_WriteData(P2CONST(uint8, AUTOMATIC, RTE_APPL_DATA) Data, Dcm_OpStatusType OpStatus, P2VAR(Dcm_NegativeResponseCodeType, AUTOMATIC, RTE_APPL_DATA) ErrorCode)
{
Std_ReturnType ret = E_NOT_OK;
#define sizeOfPim1 (5) /* how to determine the PIM size here if we do not know anything about it here? (PIM structure can change without modifying the code here) */
#define sizeOfDidFFFF (5) /* This is even another problem: How to determine the size of a DID. I will create another discussion thread for this question. */
/* Instead of this if-condition, an assert during compile-time would also be appropriate */
if( sizeOfPim1 == sizeOfDidFFFF )
{
/* We have to make sure that we do not copy more bytes as of the size of Pim1 */
memcpy( Rte_Pim_Pim1(), Data, sizeOfPim1 ); /* (use of) memcpy is not the topic here */
ret = E_OK;
}
return ret;
}
最佳答案
我这里没有任何 AUTOSAR 环境来测试这个,所以,如果您尝试其中任何一个,请告诉我它是否有效。此外,我不是专家,而且我已经很长时间没有编写 AUTOSAR 代码了,所以我可能会遗漏一些东西。我也不想公开任何供应商的任何 RTE 生成器,因此我只会引用标准。
sizeof(DtImplAry1)
您定义该类型并将其作为 RTE 生成器的输入,因此您知道该名称。如果您的 SWC 没有显式使用该类型,则 RTE 生成器无法将其包含在您的 .h
中,但您可以手动将其添加到 SWC arxml 中。我认为所有工具都允许执行此操作,而无需手动编辑 arxml,只需寻找在工具中包含其他 SWC 类型的选项即可。
如果您启用 API(在您的工具中查找它),该标准指定一个 Rte_CDS_FOO
类型的变量来保存指向 SWC 的 PIM(以及其他内容)的所有指针。此外,您应该可以使用变量Rte_Inst_FOO
,并在 header 中将其声明为extern
。您可以执行sizeof(*Rte_Inst_FOO->Pim_Pim2)
。
编辑:回复您的一些评论
我猜您找不到 CDS 的原因是这样的(来自 RTE 规范,4.2.2,5.4 RTE 数据结构):
The [CDS and Instance handler] definitions only apply to RTE generators operating in compatibility mode – in this mode the instance handle and the component data structure have to be defined even for those (object-code) software components for which multiple instantiation is forbidden to ensure compatibility.
另外,
[SWS_Rte_03793] If a software component does not support multiple instantiation,the name of the component data instance shall be Rte_Inst_cts, where cts is the component type symbol of the AtomicSwComponentType. (SRS_Rte_00011)
因此,当 RTE 生成器遵循此兼容模式时,这些变量必须存在。如果您使用的是特定于供应商的解决方案,那么,请尝试也使用该供应商名称来标记问题,希望有人可以回答。
我不会问你为什么要这样做,但恕我直言,我认为这听起来不对,接收缓冲区小于要复制的数据是否有意义?如果缓冲区小于您的struct
,也许最好在编译时断言。或者,您可以将数组定义为结构体,并在需要时对其进行强制转换(如果您遵循 MISRA 规则,也许您会遇到问题,只需检查一下)。仅供引用,compile time assertions can use sizeof
.
关于c - 如何确定 AUTOSAR Runnable 中 PIM 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39661464/
好吧,我的问题听起来很困惑,但实际上很简单。我有一个 Runnable 启动另一个 Runnable 实例。所以基本上: 可运行 1 -> 可运行 2 runnable1 是在 runnable2 还
我正在尝试使用我的单例的 Handler.post() 方法从另一个 runnable 运行一个 runnable,但是直到原始 runnable 完成后才运行第二个 runnable。在下面的示例代
为什么下面的第一个例子不起作用? run(R::new); 方法 R.run 未被调用。 run(new R()); 方法 R.run 被调用。 这两个示例都是可编译的。 public class C
为什么下面的代码不起作用?基本上,这是一个更困难的程序的简化版本,在该程序中,我试图创建一个可运行的初始屏幕,其中包含一些选择,然后有链接到不同可运行项的按钮,但这并没有按照我的预期运行。 impor
我有一个带有主选项卡 Activity 的 Android 应用,以及各个选项卡中的多个 Activity 。在我的主要 Activity 的 onCreate() 中,我有一个创建列表的可运行文件,
我正在使用 Mockito 进行测试。我有一个回调接口(interface): interface Callback { void onMessageRetrieved(String mess
这个问题在这里已经有了答案: Does postDelayed cause the message to jump to the front of the queue? (1 个回答) 关闭 7 年
我想将 runnable 发布到 runnable 内的 View 对象,目前我被困在这里。 var runnable = Runnable { if(numLinesToDraw
假设我有一个 ExecutorService,我用它来运行 Job 对象,这是一个扩展 Runnable 的类。我希望我的 Job 对象并行运行,除了让 2 个 Job 对象具有相同的 job.get
下面是该类的源代码。 我想验证如何 shutdownNow()适用于未提交的任务。我在下面的代码中遇到的问题是 shutdownNow()返回 List而不是 List我已经提交了 List包含提交的
我正在尝试找出如何从多线程应用程序中获得最大性能。 我有一个这样创建的线程池: ExecutorService executor = Executors.newFixedThreadPool(8);
这有什么区别?请引用选项1和选项2。因为我遇到了麻烦,因为它们好像是一样的。它们运行正确 Thread ThreadPoolExecutor executor = (ThreadPoolExecuto
当任何命令在任何 ScheduledExecutorService 上以固定速率调度时,它返回 ScheduledFuture 也可以取消。但是“cancel”并不能保证命令在 cancel 返回后仍
因此,我希望在尝试保持轻资源负载的同时同时完成几件事。例如,同时播放声音和更新 GUI。让多个处理程序具有单个可运行对象或单个处理程序具有多个并行运行的可运行对象更好吗? 我知道下面的实现实际上不会同
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Java: “implements Runnable” vs. “extends Thread” 我只是想知道创建自
为什么 Java 的 scheduleWithFixedDelay 使用 Runnable 而不是包装 runnable 的 FutureTask? 这可以很容易地用两个不同的代码示例来展示: Sch
这个问题在这里已经有了答案: What's the difference between Activity.runOnUiThread(runnable action) and Handler.pos
我有如下三个类: 1.线程实例 public class ThreadInstance extends Thread { public ThreadInstance() { }
春天给了我下面的错误,却想不出为什么!。注意:在XML文件中没有对此的Bean定义。。我也提出了这一点,但没有为我的案件找到任何解决方案
一 Runnable 的职责 Runnable 接口非常简单,只定义了一个无参无返回值的 run 方法,源码如下。 @FunctionalInterface public interface Runn
我是一名优秀的程序员,十分优秀!