From 9c5f940dad9b7d17b5d6a5f2711bc6ac88987121 Mon Sep 17 00:00:00 2001 From: Mihai Tudor Panu Date: Thu, 31 May 2018 21:04:20 -0700 Subject: [PATCH] aiotdevkit: add support for IEI Tank platforms Signed-off-by: Mihai Tudor Panu --- api/mraa/types.h | 1 + api/mraa/types.hpp | 1 + include/x86/iei_tank.h | 41 ++++++++++++ src/CMakeLists.txt | 3 + src/x86/iei_tank.c | 140 +++++++++++++++++++++++++++++++++++++++++ src/x86/x86.c | 4 ++ 6 files changed, 190 insertions(+) create mode 100644 include/x86/iei_tank.h create mode 100644 src/x86/iei_tank.c diff --git a/api/mraa/types.h b/api/mraa/types.h index e9cd4a5..f28ba51 100644 --- a/api/mraa/types.h +++ b/api/mraa/types.h @@ -59,6 +59,7 @@ typedef enum { MRAA_UP2 = 16, /**< The UP^2 Board */ MRAA_MTK_LINKIT = 17, /**< Mediatek MT7688 based Linkit boards */ MRAA_MTK_OMEGA2 = 18, /**< MT7688 based Onion Omega2 board */ + MRAA_IEI_TANK = 19, /**< IEI Tank System*/ // USB platform extenders start at 256 MRAA_FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */ diff --git a/api/mraa/types.hpp b/api/mraa/types.hpp index 1b7c7b4..753afba 100644 --- a/api/mraa/types.hpp +++ b/api/mraa/types.hpp @@ -55,6 +55,7 @@ typedef enum { PHYBOARD_WEGA = 14, /**< The phyBOARD-Wega */ DE_NANO_SOC = 15, /**< Terasic DE-Nano-SoC Board */ INTEL_UP2 = 16, /**< The UP^2 Board */ + IEI_TANK = 19, /**< IEI Tank System*/ FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */ diff --git a/include/x86/iei_tank.h b/include/x86/iei_tank.h new file mode 100644 index 0000000..94f0836 --- /dev/null +++ b/include/x86/iei_tank.h @@ -0,0 +1,41 @@ +/* + * Author: Mihai Tudor Panu + * Copyright (c) 2018 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mraa_internal.h" + +#define MRAA_IEI_TANK_PINCOUNT 9 +#define MRAA_IEI_TANK_UARTCOUNT 6 + +mraa_board_t* +mraa_iei_tank(); + +#ifdef __cplusplus +} +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70f2254..6dcf406 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,7 @@ set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/up.c ${PROJECT_SOURCE_DIR}/src/x86/up2.c ${PROJECT_SOURCE_DIR}/src/x86/intel_joule_expansion.c + ${PROJECT_SOURCE_DIR}/src/x86/iei_tank.c ) message (STATUS "INFO - Adding support for platform ${MRAAPLATFORMFORCE}") @@ -82,6 +83,8 @@ if (NOT ${MRAAPLATFORMFORCE} STREQUAL "ALL") set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/up2.c) elseif( ${MRAAPLATFORMFORCE} STREQUAL "MRAA_INTEL_JOULE_EXPANSION") set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/intel_joule_expansion.c) + elseif( ${MRAAPLATFORMFORCE} STREQUAL "MRAA_IEI_TANK") + set (mraa_LIB_X86_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/x86/x86.c ${PROJECT_SOURCE_DIR}/src/x86/iei_tank.c) else () message (FATAL_ERROR "Unknown x86 platform enabled!") endif () diff --git a/src/x86/iei_tank.c b/src/x86/iei_tank.c new file mode 100644 index 0000000..06325d4 --- /dev/null +++ b/src/x86/iei_tank.c @@ -0,0 +1,140 @@ +/* + * Author: Mihai Tudor Panu + * Copyright (c) 2018 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "common.h" +#include "x86/iei_tank.h" + +#define PLATFORM_NAME "IEI Tank" + +mraa_board_t* +mraa_iei_tank() +{ + mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t)); + if (b == NULL) { + return NULL; + } + + b->platform_name = PLATFORM_NAME; + b->phy_pin_count = MRAA_IEI_TANK_PINCOUNT; + b->chardev_capable = 1; + + b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t)); + if (b->adv_func == NULL) { + goto error; + } + + b->pins = (mraa_pininfo_t*) calloc(MRAA_IEI_TANK_PINCOUNT,sizeof(mraa_pininfo_t)); + if (b->pins == NULL) { + free(b->adv_func); + goto error; + } + + // Maps the DB9 DIO connector + strncpy(b->pins[0].name, "DIN0", 8); + b->pins[0].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[0].gpio.gpio_chip = 0; + b->pins[0].gpio.gpio_line = 4; + strncpy(b->pins[1].name, "DOUT0", 8); + b->pins[1].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[1].gpio.gpio_chip = 0; + b->pins[1].gpio.gpio_line = 0; + strncpy(b->pins[2].name, "DIN1", 8); + b->pins[2].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[2].gpio.gpio_chip = 1; + b->pins[2].gpio.gpio_line = 1; + strncpy(b->pins[3].name, "DOUT1", 8); + b->pins[3].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[3].gpio.gpio_chip = 0; + b->pins[3].gpio.gpio_line = 1; + strncpy(b->pins[4].name, "DIN2", 8); + b->pins[4].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[4].gpio.gpio_chip = 1; + b->pins[4].gpio.gpio_line = 2; + strncpy(b->pins[5].name, "DOUT2", 8); + b->pins[5].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[5].gpio.gpio_chip = 0; + b->pins[5].gpio.gpio_line = 2; + strncpy(b->pins[6].name, "DIN3", 8); + b->pins[6].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[6].gpio.gpio_chip = 1; + b->pins[6].gpio.gpio_line = 3; + strncpy(b->pins[7].name, "DOUT3", 8); + b->pins[7].capabilities = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[0].gpio.gpio_chip = 0; + b->pins[0].gpio.gpio_line = 3; + strncpy(b->pins[8].name, "5V", 8); + b->pins[8].capabilities = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 }; + + // Maps the 6 uart ports + b->uart_dev_count = 6; + b->def_uart_dev = 0; + //b->uart_dev[0].device_path = "/dev/ttyS0"; + //b->uart_dev[1].device_path = "/dev/ttyS1"; + //b->uart_dev[2].device_path = "/dev/ttyS2"; + //b->uart_dev[3].device_path = "/dev/ttyS3"; + //b->uart_dev[4].device_path = "/dev/ttyS4"; + //b->uart_dev[5].device_path = "/dev/ttyS5"; + if (mraa_find_uart_bus_pci("/sys/devices/pnp0/00:03/tty", + &(b->uart_dev[0].device_path)) != MRAA_SUCCESS) { + syslog(LOG_WARNING, "Unable to initialize COM1"); + b->uart_dev_count--; + } + if (mraa_find_uart_bus_pci("/sys/devices/pnp0/00:04/tty", + &(b->uart_dev[1].device_path)) != MRAA_SUCCESS) { + syslog(LOG_WARNING, "Unable to initialize COM2"); + b->uart_dev_count--; + } + if (mraa_find_uart_bus_pci("/sys/devices/pnp0/00:05/tty", + &(b->uart_dev[2].device_path)) != MRAA_SUCCESS) { + syslog(LOG_WARNING, "Unable to initialize COM3"); + b->uart_dev_count--; + } + if (mraa_find_uart_bus_pci("/sys/devices/pnp0/00:06/tty", + &(b->uart_dev[3].device_path)) != MRAA_SUCCESS) { + syslog(LOG_WARNING, "Unable to initialize COM4"); + b->uart_dev_count--; + } + if (mraa_find_uart_bus_pci("/sys/devices/pnp0/00:07/tty", + &(b->uart_dev[4].device_path)) != MRAA_SUCCESS) { + syslog(LOG_WARNING, "Unable to initialize COM5"); + b->uart_dev_count--; + } + if (mraa_find_uart_bus_pci("/sys/devices/pnp0/00:08/tty", + &(b->uart_dev[5].device_path)) != MRAA_SUCCESS) { + syslog(LOG_WARNING, "Unable to initialize COM6"); + b->uart_dev_count--; + } + + return b; +error: + syslog(LOG_CRIT, "iei-tank: Platform failed to initialize"); + free(b); + return NULL; +} diff --git a/src/x86/x86.c b/src/x86/x86.c index 8836ff9..4c7285f 100644 --- a/src/x86/x86.c +++ b/src/x86/x86.c @@ -39,6 +39,7 @@ #include "x86/up.h" #include "x86/up2.h" #include "x86/intel_joule_expansion.h" +#include "x86/iei_tank.h" mraa_platform_t mraa_x86_platform() @@ -102,6 +103,9 @@ mraa_x86_platform() } else if (strncasecmp(line, "SDS", strlen("SDS") + 1) == 0) { platform_type = MRAA_INTEL_JOULE_EXPANSION; plat = mraa_joule_expansion_board(); + } else if ((strncasecmp(line, "SAF3", strlen("SAF3") + 1) == 0) ) { + platform_type = MRAA_IEI_TANK; + plat = mraa_iei_tank(); } else { syslog(LOG_ERR, "Platform not supported, not initialising"); platform_type = MRAA_UNKNOWN_PLATFORM;