MATLAB Answers

Simulink 2016a compatibility with WiringPi

8 views (last 30 days)
mprice
mprice on 17 Mar 2017
Commented: svenb on 11 Feb 2018
I'm using S-functions in Simulink to call the WiringPi library installed on a Raspberry Pi Ver. 2 Model B. I have successfully implemented this in Matlab 2015b, but when trying to run a simple model which performs an SPI transmission in 2016a, I get the following error:
Error executing command "touch -c /home/pi/pi_test_ert_rtw/*.*;make -f pi_test.mk all -C /home/pi/pi_test_ert_rtw". Details:
STDERR: ert_main.c:8:29: fatal error: linuxinitialize.h: No such file or directory
compilation terminated.
make: *** [ert_main.c.o] Error 1
I have not manually included the linuxinitialize.h file in any of my s-Function code, nor is it included in the wiringPi library as far as I've been able to find, so I'm assuming it is included in some auto-generated code when the model is built. I have located a "linuxinitialize.h" file as well as a "linuxinitialize.c" in C:\Program Files\MATLAB\R2016a\toolbox\target\codertarget\rtos, in the inc and src folders, respectively. Moving the .h file into the active Matlab folder which contains my Simulink model and then building that produces the following error:
Error executing command "touch -c /home/pi/pi_test_ert_rtw/*.*;make -f pi_test.mk all -C /home/pi/pi_test_ert_rtw". Details:
STDERR: make: *** No rule to make target 'rt_main.c', needed by 'rt_main.c.o'. Stop.
I'm not sure what has changed that causes the build to fail between 2015b and 2016a, but the make process seems to be different. I don't know what rt_main.c refers to in the makefile (also not a script I've written) and so I'm running out of ideas on how to fix it. My s-function code is attached along with a picture of the model I am trying to run.
SPI.c:
/*
* File: SPI.c
*
*
* --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 3.0 ---
*
* This file is an S-function produced by the S-Function
* Builder which only recognizes certain fields. Changes made
* outside these fields will be lost the next time the block is
* used to load, edit, and resave this file. This file will be overwritten
* by the S-function Builder block. If you want to edit this file by hand,
* you must change it only in the area defined as:
*
* %%%-SFUNWIZ_defines_Changes_BEGIN
* #define NAME 'replacement text'
* %%%SFUNWIZ_defines_Changes_END
*
* DO NOT change NAME--Change the 'replacement text' only.
*
* For better compatibility with the Simulink Coder, the
* "wrapper" S-function technique is used. This is discussed
* in the Simulink Coder's Manual in the Chapter titled,
* "Wrapper S-functions".
*
* -------------------------------------------------------------------------
* | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
* -------------------------------------------------------------------------
* Created: Fri Mar 17 17:13:02 2017
*/
#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME SPI
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
#define NUM_INPUTS 1
/* Input Port 0 */
#define IN_PORT_0_NAME write
#define INPUT_0_WIDTH 1
#define INPUT_DIMS_0_COL 1
#define INPUT_0_DTYPE uint8_T
#define INPUT_0_COMPLEX COMPLEX_NO
#define IN_0_FRAME_BASED FRAME_NO
#define IN_0_BUS_BASED 0
#define IN_0_BUS_NAME
#define IN_0_DIMS 1-D
#define INPUT_0_FEEDTHROUGH 1
#define IN_0_ISSIGNED 0
#define IN_0_WORDLENGTH 8
#define IN_0_FIXPOINTSCALING 1
#define IN_0_FRACTIONLENGTH 9
#define IN_0_BIAS 0
#define IN_0_SLOPE 0.125
#define NUM_OUTPUTS 2
/* Output Port 0 */
#define OUT_PORT_0_NAME read
#define OUTPUT_0_WIDTH 1
#define OUTPUT_DIMS_0_COL 1
#define OUTPUT_0_DTYPE uint8_T
#define OUTPUT_0_COMPLEX COMPLEX_NO
#define OUT_0_FRAME_BASED FRAME_NO
#define OUT_0_BUS_BASED 0
#define OUT_0_BUS_NAME
#define OUT_0_DIMS 1-D
#define OUT_0_ISSIGNED 1
#define OUT_0_WORDLENGTH 8
#define OUT_0_FIXPOINTSCALING 1
#define OUT_0_FRACTIONLENGTH 3
#define OUT_0_BIAS 0
#define OUT_0_SLOPE 0.125
/* Output Port 1 */
#define OUT_PORT_1_NAME spi_test
#define OUTPUT_1_WIDTH 1
#define OUTPUT_DIMS_1_COL 1
#define OUTPUT_1_DTYPE real_T
#define OUTPUT_1_COMPLEX COMPLEX_NO
#define OUT_1_FRAME_BASED FRAME_NO
#define OUT_1_BUS_BASED 0
#define OUT_1_BUS_NAME
#define OUT_1_DIMS 1-D
#define OUT_1_ISSIGNED 1
#define OUT_1_WORDLENGTH 8
#define OUT_1_FIXPOINTSCALING 1
#define OUT_1_FRACTIONLENGTH 3
#define OUT_1_BIAS 0
#define OUT_1_SLOPE 0.125
#define NPARAMS 0
#define SAMPLE_TIME_0 INHERITED_SAMPLE_TIME
#define NUM_DISC_STATES 1
#define DISC_STATES_IC [0]
#define NUM_CONT_STATES 0
#define CONT_STATES_IC [0]
#define SFUNWIZ_GENERATE_TLC 1
#define SOURCEFILES "__SFB__"
#define PANELINDEX 6
#define USE_SIMSTRUCT 0
#define SHOW_COMPILE_STEPS 0
#define CREATE_DEBUG_MEXFILE 0
#define SAVE_CODE_ONLY 0
#define SFUNWIZ_REVISION 3.0
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h"
extern void SPI_Outputs_wrapper(const uint8_T *write,
uint8_T *read,
real_T *spi_test,
const real_T *xD);
extern void SPI_Update_wrapper(const uint8_T *write,
uint8_T *read,
real_T *spi_test,
real_T *xD);
/*====================*
* S-function methods *
*====================*/
/* Function: mdlInitializeSizes ===============================================
* Abstract:
* Setup sizes of the various vectors.
*/
static void mdlInitializeSizes(SimStruct *S)
{
DECL_AND_INIT_DIMSINFO(inputDimsInfo);
DECL_AND_INIT_DIMSINFO(outputDimsInfo);
ssSetNumSFcnParams(S, NPARAMS);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
return; /* Parameter mismatch will be reported by Simulink */
}
ssSetNumContStates(S, NUM_CONT_STATES);
ssSetNumDiscStates(S, NUM_DISC_STATES);
if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
ssSetInputPortWidth(S, 0, INPUT_0_WIDTH);
ssSetInputPortDataType(S, 0, SS_UINT8);
ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX);
ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
/* Output Port 0 */
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
ssSetOutputPortDataType(S, 0, SS_UINT8);
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
/* Output Port 1 */
ssSetOutputPortWidth(S, 1, OUTPUT_1_WIDTH);
ssSetOutputPortDataType(S, 1, SS_DOUBLE);
ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetSimulinkVersionGeneratedIn(S, "8.7");
/* Take care when specifying exception free code - see sfuntmpl_doc.c */
ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
SS_OPTION_USE_TLC_WITH_ACCELERATOR |
SS_OPTION_WORKS_WITH_CODE_REUSE));
}
# define MDL_SET_INPUT_PORT_FRAME_DATA
static void mdlSetInputPortFrameData(SimStruct *S,
int_T port,
Frame_T frameData)
{
ssSetInputPortFrameData(S, port, frameData);
}
/* Function: mdlInitializeSampleTimes =========================================
* Abstract:
* Specifiy the sample time.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, SAMPLE_TIME_0);
ssSetModelReferenceSampleTimeDefaultInheritance(S);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS
/* Function: mdlInitializeConditions ========================================
* Abstract:
* Initialize the states
*/
static void mdlInitializeConditions(SimStruct *S)
{
real_T *xD = ssGetRealDiscStates(S);
xD[0] = 0;
}
#define MDL_SET_INPUT_PORT_DATA_TYPE
static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dType)
{
ssSetInputPortDataType( S, 0, dType);
}
#define MDL_SET_OUTPUT_PORT_DATA_TYPE
static void mdlSetOutputPortDataType(SimStruct *S, int port, DTypeId dType)
{
ssSetOutputPortDataType(S, 0, dType);
}
#define MDL_SET_DEFAULT_PORT_DATA_TYPES
static void mdlSetDefaultPortDataTypes(SimStruct *S)
{
ssSetInputPortDataType( S, 0, SS_DOUBLE);
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
}
/* Function: mdlOutputs =======================================================
*
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
const uint8_T *write = (const uint8_T*) ssGetInputPortSignal(S,0);
uint8_T *read = (uint8_T *)ssGetOutputPortRealSignal(S,0);
real_T *spi_test = (real_T *)ssGetOutputPortRealSignal(S,1);
const real_T *xD = ssGetDiscStates(S);
SPI_Outputs_wrapper(write, read, spi_test, xD);
}
#define MDL_UPDATE /* Change to #undef to remove function */
/* Function: mdlUpdate ======================================================
* Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S, int_T tid)
{
real_T *xD = ssGetDiscStates(S);
const uint8_T *write = (const uint8_T*) ssGetInputPortSignal(S,0);
uint8_T *read = (uint8_T *)ssGetOutputPortRealSignal(S,0);
real_T *spi_test = (real_T *)ssGetOutputPortRealSignal(S,1);
SPI_Update_wrapper(write, read, spi_test, xD);
}
/* Function: mdlTerminate =====================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in mdlStart, this is the place to free it.
*/
static void mdlTerminate(SimStruct *S)
{
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
SPI_wrapper.c
/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
# ifndef MATLAB_MEX_FILE
#include </home/pi/wiringPi/wiringPi/wiringPi.h>
#include </home/pi/wiringPi/wiringPi/wiringPiSPI.h>
#include </home/pi/wiringPi/wiringPi/wiringPi.c>
#include </home/pi/wiringPi/wiringPi/piHiPri.c>
#include </home/pi/wiringPi/wiringPi/piThread.c>
#include </home/pi/wiringPi/wiringPi/wiringPiSPI.c>
// global variables for address, high and low bits for data
int fd, inputSize;
# endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output functions
*
*/
void SPI_Outputs_wrapper(const uint8_T *write,
uint8_T *read,
real_T *spi_test,
const real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
if(xD[0] == 1)
{
#ifndef MATLAB_MEX_FILE
// Read high byte, low byte, then combine:
unsigned char spiData[1];
int n;
// inputSize = sizeof(write)/sizeof(write[0]);
// for (n = 0; n < 1; n++){
// spiData[n] = write[n];
// }
spiData[0] = write[0];
// spiData[1] = write[1];
// spiData[2] = write[2];
// spiData[3] = write[3];
// spiData[4] = write[4];
// spiData[5] = write[5];
// spiData[0] = 0x01;
// spiData[1] = 0x00;
// spiData[2] = 0x02;
// spiData[3] = 0x03;
// spiData[4] = 0x04;
// spiData[5] = 0x05;
// spiData [0] = 1 ; // Start bit
// spiData [1] = 0x80 ;
// spiData [2] = 0 ;
spi_test[0] = wiringPiSPIDataRW(0,spiData,1) ;
read[0] = spiData[0];
// read[0] = ((spiData[1] << 8) | spiData[2]) & 0x3FF;
#endif
}
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
void SPI_Update_wrapper(const uint8_T *write,
uint8_T *read,
real_T *spi_test,
real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
if(xD[0] != 1){
# ifndef MATLAB_MEX_FILE
// Check that device is connected and setup:
wiringPiSetup ();
fd = wiringPiSPISetup(0,4000000,1);
#endif
//done with initialization
xD[0] = 1;
}
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}
  2 Comments
svenb
svenb on 11 Feb 2018
same here
STDERR: ert_main.c:26:29: fatal error: linuxinitialize.h: No such file or directory
#include "linuxinitialize.h"

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!