7. Smart ETK

VAB-600 is designed with enhanced features including Watch Dog, RTC Power On, Programmable GPIO, and Serial Ports.

7.1. Develop Environment

Eclipse is Android application integrated development environment (IDE) by official recommendation. It requires to import the specific reference Java Archive file to develop VAB-600 enhance features.

Open Eclipse IDE and create an Android project. In project properties, import the smartetk.jar by clicking “Add External JARs...” into your project.

7.2. SDK Class Definitions

All functions and values are placed in class named com.via.vepd.SmartETK. Import this package into Java code to use them.

7.2.1. GPIO PIN definitions

ID 0 1 2 3 4 5 6 7
GPIO 20 21 22 23 24 25 26 27

7.3. Function Return Values

Other than the Boolean TRUE and FALSE return values, there are eight other types of return values found throughout the Smart ETK SDK API.

Error code Constant
S_OK 0
E_FAIL -1000
E_BOARD_NOT_SUPPORT -1001
E_ALREADY_INITIALIZED -1002
E_INVALID_ARG -1003
E_OUT_OF_MEMORY -1004
E_FUNC_NOT_SUPPORT -1005
E_HARDWARE_ERROR -1006

7.3.1. SmartETK.S_OK

The S_OK return value has the constant value 0. When a function returns the S_OK value, it indicates that the function has successfully completed.

7.3.2. SmartETK.E_FAIL

The E_FAIL return value has the constant value -1000. When a function returns the E_FAIL value, it indicates that the function has failed to complete.

7.3.3. SmartETK.E_BOARD_NOT_SUPPORT

The E_BOARD_NOT_SUPPORT return value has the constant value -1001. When a function returns the E_BOARD_NOT_SUPPORT value, it indicates that the mainboard is not supported.

7.3.4. SmartETK.E_ALREADY_INITIALIZED

The E_ALREADY_INITIALIZED return value has the constant value -1002. When a function returns the E_ALREADY_INITIALIZED value, it indicates that libbssjni.so has already been loaded.

7.3.5. SmartETK.E_INVALID_ARG

The E_INVALID_ARG return value has the constant value -1003. When a function returns the E_INVALID_ARG value, it indicates that the arguments are invalid.

7.3.6. SmartETK.E_OUT_OF_MEMORY

The E_OUT_OF_MEMORY return value has the constant value -1004. When a function returns the E_OUT_OF_MEMORY value, it indicates that there is insufficient memory.

7.3.7. SmartETK.E_FUNC_NOT_SUPPORT

The E_FUNC_NOT_SUPPORT return value has the constant value -1005. When a function returns the E_FUNC_NOT_SUPPORT value, it indicates that the function is not supported on this board.

7.3.8. SmartETK.E_HARDWARE_ERROR

The E_HARDWARE_ERROR return value has the constant value -1006. When a function returns the E_HARDWARE_ERROR value, it indicates that there is a hardware error.

7.4. API List

7.4.1. SmartETK.Init

static int SmartETK.Init()
Description:This function initializes the Smart ETK and loads the JNI.
Returns:
  • S_OK if the function succeeds
  • E_FAIL if the function fails
static int SmartETK.SupportGpio()
Description:Check if current platform supports GPIO.
Returns:
  • S_OK if support GPIO.
  • E_FUNC_NOT_SUPPORT if not support GPIO.
static int SmartETK.SupportWdt()
Description:Check if current platform supports watch dog timer
Returns:
  • S_OK if support watch dog timer
  • E_FUNC_NOT_SUPPORT if not support watch dog timer
static int SmartETK.SupportRtcWake()
Description:Check if current platform supports RTC wake-up
Returns:
  • S_OK if support RTC wake-up
  • E_FUNC_NOT_SUPPORT if not support RTC wake-up
GpioInfo SmartETK.Gpio_GetInfo()
Description:Gets the information of GPIO
Returns:An array representing GPIO
Return type:SmartETK.GpioInfo
static int SmartETK.Gpio_Enable(int pinId, boolean enable)
Description:

Enable specific GPIO pin.

Parameters:
  • pinId (int) – ID of GPIO pin. Refer to the GPIO PIN definitions section for pin definition
  • enable (boolean) – true for enable, false for disable
Returns:

  • S_OK if the function succeeds
  • E_FAIL if the function fails

public static int SmartETK.Gpio_Set(int pinId, int inOut, int upDown)
Description:

Setup I/O configuration for specific GPIO pin

Parameters:
  • pinId (int) – ID of GPIO pin. Refer to the GPIO PIN definitions section for pin definition
  • inOut (int) –
    • SmartETK.GM_GPI for input
    • SmartETK.GM_GPO for output
  • upDown (int) –
    • SmartETK.GM_NO_PULL for disable internal pull
    • SmartETK.GM_PULL_UP for pull up,
    • SmartETK.GM_PULL_DOWN for pull down.
Returns:

  • S_OK if the function succeeds
  • E_FAIL if the function fails

static int SmartETK.Gpio_Write(int pinId, int pinVal)
Description:

Set GPIO output signal

Parameters:
  • pinId (int) – ID of GPIO pin. Refer to the GPIO PIN definitions section for pin definition
  • pinVal (int) – GPIO signal, 0 for logic low, 1 for logic high
Returns:

  • S_OK if the function succeeds
  • E_FAIL if the function fails

static int SmartETK.Gpio_Read(int pinId, int pinVal[])
Description:

Get GPIO input signal.

Parameters:
  • pinId (int) – ID of GPIO pin. Refer to the GPIO PIN definitions section for pin definition
  • pinVal (int[]) – A single-element array returns GPIO signal. 0 for logic low, 1 for logic high. Caller should allocate array space manually
Returns:

  • S_OK if the function succeeds
  • E_FAIL if the function fails

static int SmartETK.Wdt_SetTimer(int sec)
Description:

Set watch dog timer to specific time in second. The time should not exceed the number defined by a constant SmartETK.WDT_MAX_SEC

Parameters:
  • sec (int) – time in second to reset
Returns:

  • S_OK if the function succeeds
  • E_FAIL if the function fails

static int SmartETK.Wdt_Refresh()
Escription:Refresh the timer to the time set in Wdt_SetTimer
Returns:
  • S_OK if the function succeeds
  • E_FAIL if the function fails
static int SmartETK.Wdt_Start()
Description:Start watch dog timer. If application does not call Wdt_Refresh in time set in Wdt_SetTimer, system will be reset
Returns:
  • S_OK if the function succeeds
  • E_FAIL if the function fails
static int SmartETK.Wdt_Stop()
Description:Stop watch dog timer
Returns:
  • S_OK if the function succeeds
  • E_FAIL if the function fails
static int SmartETK.Rtc_WakeupEnable()
Description:Enable RTC wake-up
Returns:
  • S_OK if the function succeeds
  • E_FAIL if the function fails
static int SmartETK.Rtc_WakeupDisable()
Description:Disable RTC wake-up
Returns:
  • S_OK if the function succeeds
  • E_FAIL if the function fails
static int SmartETK.Rtc_SetWakeupTime(int mode, int yr, int mm, int dd, int hr, int min, int sec)
Description:

Set time to wake up by RTC

Parameters:
  • mode (int) –
    • SmartETK.RWM_HHMM: wake up when hour and minute match
    • SmartETK.RWM_MONTH: wake up when month day, hour and minute match
    • SmartETK.RWM_WEEK: wake up when week day, hour and minute match
  • yr (int) – Year to wake up
  • mm (int) – Month to wake up
  • dd (int) – Day to wake up
  • hr (int) – Hour to wake up
  • min (int) – Minute to wake up
  • sec (int) – Second to wake up
Returns:

  • S_OK if the function succeeds
  • E_FAIL if the function fails

native public static UartConfig Uart_GetConfig(FileDescriptor fd)
Description:

Return terminal configuration of specific FileDescriptor

Parameters:
  • fd (FileDescriptor) – the opened file, must be a device file (under /dev)
Returns:

  • UartConfig if the function succeeds, see the UART Parameters section for detail
  • null if the function fails

native public static int Uart_SetConfig(FileDescriptor fd, UartConfig cfg)
Description:

Set terminal configuration of specific FileDescriptor

Parameters:
  • fd (FileDescriptor) – the opened file, must be a device file (under /dev)
  • cfg (UartConfig) – Terminal configuration, see the UART Parameters section for detail
Returns:

  • 0 if the function succeeds
  • 1 if the function fails

7.5. UART Parameters

SmartETK defines UART (Universal Asynchronous Receiver/Transmitter) related values into another class`` com.via.UartConfig`` for configuration. Instead of one-time setup for other devices, UART is transferring data continually. Developers may blocked read, selected read, or buffered read from UART. In order to provide developers all types of transmissions, the APIs should be based on Java class java.io.FileDescriptor.

To get FileDescriptor, the developers have to open the device file manually (e.g. /dev/ttyS1 or /dev/ttyUSB0) with Java class java.io.File. Then select a suitable Java transmission helper class (e.g. java.io.FileOutputStream). To setup UART parameters with FileDescriptor and class UartConfig which are provided by VIA. Please check SDK sample code for details.

Parameters in UartConfig are the same as the values in Linux Kernel. Developers who are familiar with terminal programming in C may apply the same macro to port existing applications to Java with UartConfig. See Linux Programmer’s Manual for details. To read the manual, enter man tcsetattr in Ubuntu terminal.

Currently, four connection options (in struct termios) and two speed options for Linux are available.

The four connection options are: c_cflag, c_iflag, c_oflag, c_lflag

The two speed options are: ispeed, ospeed

Four options will be applied with tcsetattr in Linux C library. c_cc[VMIN] is set to 1 and c_cc[VTIME] is set to 0. ispeed and ospeed in UartConfig will be applied to struct termios with cfsetispeed and cfsetospeed in Linux C library.

All options have to be set before applying them. It is recommended to get current configurations of FileDescriptor into UartConfig via SmartETK.Uart_GetConfig instead of allocating one manually.

All types of file transmissions in Java are available since we shared existing FileDescriptor class. After FileDescriptor is configured, developers can access UART as a normal file.