• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  *         Brendan Le Foll <brendan.le.foll@intel.com>
4  * Copyright (c) 2014-2016 Intel Corporation.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "mraa_internal.h"
30 
31 #include "x86/intel_galileo_rev_d.h"
32 #include "x86/intel_galileo_rev_g.h"
33 #include "x86/intel_edison_fab_c.h"
34 #include "x86/intel_de3815.h"
35 #include "x86/intel_nuc5.h"
36 #include "x86/intel_minnow_byt_compatible.h"
37 #include "x86/intel_sofia_3gr.h"
38 
39 mraa_platform_t
mraa_x86_platform()40 mraa_x86_platform()
41 {
42 #ifndef MRAA_PLATFORM_FORCE
43     mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
44 
45     char* line = NULL;
46     // let getline allocate memory for *line
47     size_t len = 0;
48     FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
49     if (fh != NULL) {
50         if (getline(&line, &len, fh) != -1) {
51             if (strncmp(line, "GalileoGen2", 11) == 0) {
52                 platform_type = MRAA_INTEL_GALILEO_GEN2;
53                 plat = mraa_intel_galileo_gen2();
54             } else if (strncmp(line, "BODEGA BAY", 10) == 0) {
55                 platform_type = MRAA_INTEL_EDISON_FAB_C;
56                 plat = mraa_intel_edison_fab_c();
57             } else if (strncmp(line, "SALT BAY", 8) == 0) {
58                 platform_type = MRAA_INTEL_EDISON_FAB_C;
59                 plat = mraa_intel_edison_fab_c();
60             } else if (strncmp(line, "DE3815", 6) == 0) {
61                 platform_type = MRAA_INTEL_DE3815;
62                 plat = mraa_intel_de3815();
63             } else if (strncmp(line, "NUC5i5MYBE", 10) == 0 || strncmp(line, "NUC5i3MYBE", 10) == 0) {
64                 platform_type = MRAA_INTEL_NUC5;
65                 plat = mraa_intel_nuc5();
66             } else if (strncmp(line, "NOTEBOOK", 8) == 0) {
67                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
68                 plat = mraa_intel_minnowboard_byt_compatible(0);
69             } else if (strncasecmp(line, "MinnowBoard MAX", 15) == 0) {
70                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
71                 plat = mraa_intel_minnowboard_byt_compatible(0);
72             } else if (strncasecmp(line, "Galileo", 7) == 0) {
73                 platform_type = MRAA_INTEL_GALILEO_GEN1;
74                 plat = mraa_intel_galileo_rev_d();
75             } else if (strncasecmp(line, "MinnowBoard Compatible", 22) == 0) {
76                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
77                 plat = mraa_intel_minnowboard_byt_compatible(1);
78             } else if (strncasecmp(line, "MinnowBoard Turbot", 18) == 0) {
79                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
80                 plat = mraa_intel_minnowboard_byt_compatible(1);
81             } else {
82                 syslog(LOG_ERR, "Platform not supported, not initialising");
83                 platform_type = MRAA_UNKNOWN_PLATFORM;
84             }
85             free(line);
86         }
87         fclose(fh);
88     } else {
89         fh = fopen("/proc/cmdline", "r");
90         if (fh != NULL) {
91             if (getline(&line, &len, fh) != -1) {
92                 if (strstr(line, "sf3gr_mrd_version=P2.0")) {
93                     platform_type = MRAA_INTEL_SOFIA_3GR;
94                     plat = mraa_intel_sofia_3gr();
95                 }
96                 free(line);
97             }
98             fclose(fh);
99         }
100     }
101     return platform_type;
102 #else
103     #if defined(xMRAA_INTEL_GALILEO_GEN2)
104     plat = mraa_intel_galileo_gen2();
105     #elif defined(xMRAA_INTEL_EDISON_FAB_C)
106     plat = mraa_intel_edison_fab_c();
107     #elif defined(xMRAA_INTEL_DE3815)
108     plat = mraa_intel_de3815();
109     #elif defined(xMRAA_INTEL_MINNOWBOARD_MAX)
110     plat = mraa_intel_minnowboard_byt_compatible();
111     #elif defined(xMRAA_INTEL_GALILEO_GEN1)
112     plat = mraa_intel_galileo_rev_d();
113     #elif defined(xMRAA_INTEL_NUC5)
114     plat = mraa_intel_nuc5();
115     #elif defined(xMRAA_INTEL_SOFIA_3GR)
116     plat = mraa_intel_sofia_3gr();
117     #else
118         #error "Not using a valid platform value from mraa_platform_t - cannot compile"
119     #endif
120     return MRAA_PLATFORM_FORCE;
121 #endif
122 }
123