首先,让我恭维您对纯 Simulink 的追求!这是很有可能的,但是,Mathworks 代码生成器不处理这个用例。它非常草率,并创建了整个队列的缓冲副本。这是一个例子:
然后,看一些代码。哎呀!
/* Model output function */
static void queue_output(int_T tid)
{
{
real_T rtb_MathFunction;
/* DataStoreRead: '<S1>/Data Store Read' */
memcpy((void *)(&queue_B.DataStoreRead[0]), (void *)(&queue_DWork.A[0]),
100000U * sizeof(uint16_T));
/* Outport: '<Root>/Out1' incorporates:
* DataStoreRead: '<S1>/Data Store Read1'
* Selector: '<S1>/Selector'
*/
queue_Y.Out1 = queue_B.DataStoreRead[(int32_T)queue_DWork.idx];
/* If: '<Root>/If' incorporates:
* ActionPort: '<S2>/Action Port'
* Constant: '<Root>/Constant'
* SubSystem: '<Root>/WriteToQueue'
*/
if (queue_P.Constant_Value > 0.0) {
/* DataStoreRead: '<S2>/Data Store Read3' */
memcpy((void *)(&queue_B.Assignment[0]), (void *)(&queue_DWork.A[0]),
100000U * sizeof(uint16_T));
/* Math: '<S2>/Math Function' incorporates:
* Constant: '<S2>/Constant1'
* Constant: '<S3>/FixPt Constant'
* DataStoreRead: '<S2>/Data Store Read2'
* Sum: '<S3>/FixPt Sum1'
*/
rtb_MathFunction = rt_mod_snf(queue_DWork.idx +
queue_P.FixPtConstant_Value, queue_P.Constant1_Value);
/* Assignment: '<S2>/Assignment' incorporates:
* Constant: '<S2>/Constant'
*/
queue_B.Assignment[(int32_T)rtb_MathFunction] = queue_P.Constant_Value_h;
/* DataStoreWrite: '<S2>/Data Store Write' */
memcpy((void *)(&queue_DWork.A[0]), (void *)(&queue_B.Assignment[0]),
100000U * sizeof(uint16_T));
/* DataStoreWrite: '<S2>/Data Store Write1' */
queue_DWork.idx = rtb_MathFunction;
}
}
Memcpy 10000 uint16 的每个循环!在 Mathworks 以稳健的方式解决这个问题之前,这是一个需要硬编码索引的初始尝试,S-Function 是唯一的方法。