1

I am writing a C S-function in Simulink/Matlab, which fills an output buffer of size 500 kB for a later application. I have done this in mdlInitializeSizes:

ssSetOutputPortWidth(S, 0, 500000);
ssSetOutputPortDataType(S, 0, SS_UINT8);    

Later, in mdlOutputs, I am writing into the buffer as:

uint8_T  *payload     =  (uint8_T*) ssGetOutputPortSignal(S,0);
for (uint32_T i = 0; i < 500000; ++i)
{
    payload[i] = ...;
}

My questions are:

  • Are those 500000 bytes safely allocated with the code I posted?
  • Are those 500000 bytes contiguous? I know I can do ssSetInputPortRequiredContiguous for inputs, but I didn't find that option for outputs...
  • Is it safe/legit to fill in the output array like this? Is there a better way of doing this?

I am asking this because right now the code crashes when I try to write at positions larger than ~128k. This is a rough estimate I got through lots of trials, since this code runs on an embedded system that doesn't really provide error traces.

Thanks in advance!

user1011113
  • 1,114
  • 8
  • 27
  • I remember something about `ssSetInputPortRequiredContiguous`, but I'm not a Matlab expert – LPs Feb 23 '16 at 11:02
  • Yes, that works for inputs, but I can't find the equivalent for outputs... Maybe it works if this output is connected to other block whose input is set to be contiguous? – user1011113 Feb 23 '16 at 11:09
  • 1
    The syntax you have above is correct. (Without knowing the specifics of your hardware) my first suspicion is that it's something to do with what the maximum size of an int is defined on your hardware, so that you cannot actually get 500000 elements, but rather you are getting it truncated down to ~128k. – Phil Goddard Feb 23 '16 at 17:59

0 Answers0