FORUM TOPIC · READ ONLY

Passing a Vector to the C-Function Call block

Passing a Vector to the C-Function Call block

Forum : bug reports

6 message(s) · archive en lecture seule

malife
Hello Lubin,

I am trying to pass a vector to the C-Function Call block but apparently it is only getting the first element in that vector: You can see in the image shown below I assemble a vector using a Mux, and then pass it to the C function call, but the call to the function call is this:


* S-Function "dsPIC_Digital_OutputWrite" Block: <Root>/Digital Output Write3 */
  LATBbits.LATB2 = FALSE;

  /* S-Function "dsPIC_C_function_Call" Block: <Root>/C Function Call */
  myPutSPI(8U);

  /* S-Function "dsPIC_Digital_OutputWrite" Block: <Root>/Digital Output Write2 */
  LATBbits.LATB2 = TRUE;


which is of course wrong since the function myPutSPI is expecting a vector and not a constant. Any ideas what I am doing wrong? Is this a bug? I have attached the code so you can verify it for yourself.



Thanks!

Pièce jointe : spi.JPG

Pièce jointe : spi.zip

LubinKerhuel

Re: Passing a Vector to the C-Function Call block

Hi Mariano,





I confirm the bug.

Will fix that shortly !



I propose the following solution (while I am working on that bug !)



- add an output to the C function call block (like char or whatever)

- uncheck the "inline parameters" in Simulation ==> Configuration Parameters ==> Optimization



This solution is working on my blockset version. Note that I already made some change on the C function call block that are not yet published (blockset still in developments).

If you encounter a problem with the "dirty" solution proposed here, let me know.



Anyway, I will correct that bug soon. Thanks for reporting it !
malife

Re: Passing a Vector to the C-Function Call block

Thanks for a very quick response. I will try what you suggest and report back.



If it does not work I will wait for the next version.



DMA SPI si comming along, hope to give positive reports soon :-)



Thanks!
malife

Re: Passing a Vector to the C-Function Call block

Yes, that took care of it. I confirm the work around solves the problem.



Thanks for excellent support!



Mariano
LubinKerhuel

Re: Passing a Vector to the C-Function Call block

Hi, I corrected the bug : if you have only one input vector, you do not need to add an (unused) output to the function.

This will be available in the next version (i.e. 0.97b)



Remark about the inline parameters :

When the C call function use input vectors with more than 2 elements (an array in C language), the adress of the first element (pointer) is passed to the C function .

In your exemple, when inline parameters is checked in simulink options, the first element of the array is a constant. This constant may not be stored next to the remaining vector variables values.



When inline parameters, the vectors intern variable usually follows each other in memory. (from experiment, I did not read anything about it)

Thus, I suggest to use an intermediate variable :

I wish you good luck with SPI using DMA !



Right now, I have done a new SPI block that use interrupt (but no DMA) However, It works only in master mode. It is usefull if you read data from external component (ADC, gyro or others) and have stringent real-time constraints. I will try to extend to slave mode.

Pièce jointe : C_funCall_WithInterVariable.png

Pièce jointe : SPI_CFunctionCall.zip

bmairs

Re: Passing a Vector to the C-Function Call block

This bug still exists. I'd like to keep inline parameters checked as an optimization, is there anyway to fix this on your end, Lubin, or is this something that we're just going to have to deal with?



Mariano did find that replicating a Mux block with an embedded Matlab block fixed the bug. I'm not certain if that helps to fix this.