how can I resolve the compiling issue ? Adding a custom block to the Lego EV3 Simulink package

30 views (last 30 days)
Shdn on 11 Dec 2015
Commented: john schlitz on 26 May 2017
I am trying to produce s-function of following code to run it on ev3(legomindstorm)platform but I had trouble compiling the code using MinGw compiler from gcc in matlabR15-windows7.The error I get is that sys/mman.h does not exist. What do you suggest to solve it?
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "lms2012.h"
#include "driver_ev3.h"
#include "driver_ev3_camera_sensor.h"
//Runtime constants
const int MAX_SAMPLES = 100;
const char XGL_PORT = 0x0; //EV3 label minus 1
const int XGL_PACKET_SIZE = 10; //2(gyyro angle) + 2(gyro rate) + 2(acc x) + 2(acc y) + 2(acc z)
float functionCdriver(void)
//int main()
int xgl_device_file;
IIC *pXgl;
int i;
float angle;
float rate;
float acc_x;
float acc_y;
float acc_z;
//Open the device xgl_device_file
if((xgl_device_file = open(IIC_DEVICE_NAME, O_RDWR | O_SYNC)) == -1)
printf("Failed to open device\n");
return -1;
pXgl =(IIC*)mmap(0, sizeof(IIC), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, xgl_device_file, 0);
if (pXgl == MAP_FAILED)
printf("Map failed\n");
return -1;
//Setup IIC to read 2 packets
IicDat.Port = XGL_PORT;
IicDat.Time = 0;
IicDat.Repeat = 0;
IicDat.WrLng = 2;
// Set the device I2C address
IicDat.WrData[0] = 0x02;
// Specify the register that will be read (0x42 = angle)
IicDat.WrData[1] = 0x42;
// Setup I2C comunication
printf("Device is ready\n");
for(i = 0;i<MAX_SAMPLES;i++)
//Compute angle, angular rate and accelerations
//acc_z = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][0]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][1])/100.0;
//acc_y = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][2]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][3])/100.0;
//acc_x = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][4]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][5])/100.0;
//rate = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][6]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][7])/100.0;
//angle = (pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][8]*256+pXgl->Raw[XGL_PORT][pXgl->Actual[XGL_PORT]][9])/100.0;
angle = (unsigned char)pIic->Raw[IIC_PORT][pIic->Actual[IIC_PORT]][0];
//printf("Angle = %0.2f [deg], Rate = %0.2f [deg/s]\n", angle,rate);
//printf("AccX = %0.2f, AccY = %0.2f,AccZ = %0.2f [m/s^2g]\n\n", acc_x, acc_y, acc_z);
printf("Clossing device\n");
// return 0;
  1 Comment
john schlitz
john schlitz on 26 May 2017
Hi, Anybody has a solution?
I have the same problem. sys/mman.h is missing when I compile with 64 bit gcc compiler.

Sign in to comment.

Answers (1)

Shruti Sapre
Shruti Sapre on 17 Dec 2015
I understand that you are using the MinGw on Windows7. The sys/mman.h is a Unix header file not available on Windows. You may have to use a Windows equivalent:
Hope this helps!
  1 Comment
Shdn on 18 Dec 2015
Thanks for the reply. I tried to use also, but it leads to another errors of undeclared flags. As an example: 'O_SYNC' undeclared

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by