Using Simulink to read arbitrarily sized arrays from embedded FLASH

2 次查看(过去 30 天)
Hi,
I am attempting to write a block for a library that will allow me to read an arbitrary number of bytes from an embedded processor's FLASH memory and have the block output a byte array of the size of the requested number of bytes to be read. I'm having trouble getting the block I have created using the S-Function builder to output anything other than the first element in that array. Here is how I've set the S-Function up:
I'm using a discrete time system with an inherited sample mode. The block has two inputs, both with a data type of uint32, and there's one output of data type uint8. The inputs both have dimensions of 1, where the output has dimensions of -1, which is supposed to inherit the dimensions of the output from the code (if I'm not mistaken). The code entered in the Output tab of the S-Function builder is as follows, where the inputs are AddressStart and NumBytes, and the output is supposed to be the DataOut array:
int i;
for(i = 0; i < NumBytes[0]; i++){
DataOut[i] = *((volatile uint8_T*) (&AddressStart + 8*i));
}
There is another issue with this code that I may need to visit another forum to address. I can view the memory sections that are being written to in the IDE I use to debug the code, and the first three bytes are copied incorrectly, but from then on out what is returned to the DataOut array is correct. Unfortunately, the output from the block is only the first byte as the code generated by the builder looks like this:
void sfun_Flash_Read_Outputs_wrapper(const uint32_T *AddressStart,
const uint32_T *NumBytes,
uint8_T *DataOut,
const real_T *xD,
const int_T y_width, const int_T u_width)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* This sample sets the output equal to the input
y0[0] = u0[0];
For complex signals use: y0[0].re = u0[0].re;
y0[0].im = u0[0].im;
y1[0].re = u1[0].re;
y1[0].im = u1[0].im;
*/
int i;
for(i = 0; i < NumBytes[0]; i++){
DataOut[i] = *((volatile uint8_T*) (&AddressStart + 8*i));
}
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
The test block looks like this in the test model:
Am I going about this all wrong? Any suggestions on how to return an arbitrarily sized array from this block? I will be extremely grateful for any and all help you can provide.
Thanks in advance for your time.
-Chris

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by