clang-format: run clang-format on C/C++ code
[contrib/mraa.git] / src / x86 / x86.c
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "mraa_internal.h"
29 #include "x86/intel_galileo_rev_d.h"
30 #include "x86/intel_galileo_rev_g.h"
31 #include "x86/intel_edison_fab_c.h"
32 #include "x86/intel_de3815.h"
33 #include "x86/intel_minnow_max.h"
34
35 mraa_platform_t
36 mraa_x86_platform()
37 {
38     mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
39     char* line = NULL;
40     // let getline allocate memory for *line
41     size_t len = 0;
42     FILE* fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
43     if (fh != NULL) {
44         if (getline(&line, &len, fh) != -1) {
45             if (strncmp(line, "GalileoGen2", 11) == 0) {
46                 platform_type = MRAA_INTEL_GALILEO_GEN2;
47                 plat = mraa_intel_galileo_gen2();
48             } else if (strncmp(line, "BODEGA BAY", 10) == 0) {
49                 platform_type = MRAA_INTEL_EDISON_FAB_C;
50                 plat = mraa_intel_edison_fab_c();
51             } else if (strncmp(line, "SALT BAY", 8) == 0) {
52                 platform_type = MRAA_INTEL_EDISON_FAB_C;
53                 plat = mraa_intel_edison_fab_c();
54             } else if (strncmp(line, "DE3815", 6) == 0) {
55                 platform_type = MRAA_INTEL_DE3815;
56                 plat = mraa_intel_de3815();
57             } else if (strncmp(line, "NOTEBOOK", 8) == 0) {
58                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
59                 plat = mraa_intel_minnow_max();
60             } else if (strncasecmp(line, "MinnowBoard MAX", 15) == 0) {
61                 platform_type = MRAA_INTEL_MINNOWBOARD_MAX;
62                 plat = mraa_intel_minnow_max();
63             } else if (strncasecmp(line, "Galileo", 7) == 0) {
64                 platform_type = MRAA_INTEL_GALILEO_GEN1;
65                 plat = mraa_intel_galileo_rev_d();
66             } else {
67                 syslog(LOG_ERR, "Platform not supported, not initialising");
68                 platform_type = MRAA_UNKNOWN_PLATFORM;
69             }
70             free(line);
71         }
72         fclose(fh);
73     }
74
75     return platform_type;
76 }