changeset 35:28468c289784

8056080: GPIO DIR_BOTH_INIT_INPUT and DIR_BOTH_INIT_OUTPUT are not supported Reviewed-by: jld Contributed-by: alexey.mironov@oracle.com
author alkonsta
date Tue, 26 Aug 2014 19:36:41 +0400
parents 93cb5cb04f26
children 44692fd6565d
files src/share/linux/native/com/oracle/dio/gpio/gpio.c src/share/native/com/oracle/dio/javacall_gpio.h
diffstat 2 files changed, 23 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/linux/native/com/oracle/dio/gpio/gpio.c	Tue Aug 26 19:32:35 2014 +0400
+++ b/src/share/linux/native/com/oracle/dio/gpio/gpio.c	Tue Aug 26 19:36:41 2014 +0400
@@ -222,7 +222,6 @@
     GPIOHandle* pinHandle = (GPIOHandle*) handle;
 
     JAVACALL_REPORT_INFO1(JC_DAAPI, "Read value from pin %d", pinHandle->number);
-    //: Is there necessary to check direction?
 
     if(JAVACALL_DIO_FAIL == read_value_from_pin(pinHandle, pVal)) {
         JAVACALL_REPORT_ERROR1(JC_DAAPI, "Can not read value from pin %d", pinHandle->number);
@@ -238,7 +237,7 @@
 javacall_dio_result javacall_gpio_pin_write(const javacall_handle handle,
         const javacall_bool val){
     GPIOHandle* pinHandle = (GPIOHandle*) handle;
-    //: Is there necessary to check direction?
+
     JAVACALL_REPORT_INFO2(JC_DAAPI, "Pin %d write value %d", pinHandle->number, val);
 
     if(JAVACALL_DIO_OK != write_value_to_pin(pinHandle, val)) {
@@ -483,7 +482,7 @@
 * See javacall_gpio.h for definition
 */
 javacall_dio_result javacall_gpio_pin_open(javacall_int32 port,
-        javacall_int32 pin, const javacall_gpio_dir initDirection,
+        javacall_int32 pin, const javacall_gpio_dir direction,
         const javacall_gpio_mode mode, const javacall_gpio_trigger_mode trigger,
         const javacall_bool initValue,
         const javacall_bool exclusive,
@@ -494,7 +493,7 @@
     javacall_dio_result pinCondition;
     int directionFD;
 
-    JAVACALL_REPORT_INFO3(JC_DAAPI, "Try to open pin %d on port %d with direction %d", pin, port, initDirection);
+    JAVACALL_REPORT_INFO3(JC_DAAPI, "Try to open pin %d on port %d with direction %d", pin, port, direction);
 
     if (JAVACALL_FALSE == exclusive) {
         // exclusive mode only
@@ -524,33 +523,6 @@
         return pinCondition;
     }
 
-    //: There is no safely way to configure pin mode using sysfs interface, so all pins can be opened only
-    //by default setting as system set to them:
-    //For INPUT GPIO pins: for pin 2, 3 it can be PULL UP or 0(default on system. On raspberry it will be high impedance);
-    //For OUTPUT pin: 0(default on system, On Raspberry it will be Push-pull mode)
-    //So if user want open pin in unsupported mode there will be error.
-    switch(initDirection) {
-        case JAVACALL_GPIO_INPUT_MODE:
-            if(PERIPHERAL_CONFIG_DEFAULT != mode && ((2 == pin || 3 == pin) && JAVACALL_MODE_INPUT_PULL_UP != mode)) {
-                JAVACALL_REPORT_ERROR2(JC_DAAPI, "Unsupported mode %d was passed for GPIO pin %d. Open failed", mode, pin);
-                unlock_pin_list();
-                return JAVACALL_DIO_INVALID_CONFIG;
-            }
-            break;
-        case JAVACALL_GPIO_OUTPUT_MODE:
-            if(PERIPHERAL_CONFIG_DEFAULT != mode && JAVACALL_MODE_OUTPUT_PUSH_PULL != mode) {
-                JAVACALL_REPORT_ERROR1(JC_DAAPI, "Unsupported mode was passed for GPIO pin %d number. Open failed", pin);
-                unlock_pin_list();
-                return JAVACALL_DIO_INVALID_CONFIG;
-            }
-            break;
-        default:
-            JAVACALL_REPORT_ERROR1(JC_DAAPI, "Unsupported direction was passed for GPIO pin %d number. Open failed", pin);
-            unlock_pin_list();
-            return JAVACALL_DIO_INVALID_CONFIG;
-    }
-
-
     if(JAVACALL_DIO_OK != enable_gpio_pin(pin)) {
         unlock_pin_list();
         return JAVACALL_DIO_FAIL;
@@ -568,7 +540,7 @@
             return JAVACALL_DIO_FAIL;
     }
 
-    if(JAVACALL_DIO_OK != write_direction_to_file(directionFD, initDirection, initValue)) {
+    if(JAVACALL_DIO_OK != write_direction_to_file(directionFD, direction, initValue)) {
         JAVACALL_REPORT_ERROR1(JC_DAAPI, "Can not set direction while open GPIO pin %d Open failed", pin);
         close(directionFD);
         unlock_pin_list();
@@ -584,7 +556,7 @@
         return JAVACALL_DIO_FAIL;
     }
 
-    handle->direction = initDirection;
+    handle->direction = direction;
     handle->number = pin;
     handle->notificationsEnabled = JAVACALL_FALSE;
     handle->inPort = JAVACALL_FALSE;
@@ -614,7 +586,7 @@
 javacall_dio_result javacall_gpio_port_open_with_pins(
         const javacall_int32 portsAndPins[][4],
         const javacall_int32 pinCount,
-        const javacall_gpio_dir initDirection,
+        const javacall_gpio_dir direction,
         const javacall_int32 initValue,  const javacall_bool exclusive,
         /*OUT*/ javacall_handle* pHandle) {
 
@@ -649,7 +621,7 @@
         pin = portsAndPins[i][1];
         mode = portsAndPins[i][2];
         trigger = portsAndPins[i][3];
-        pinState = javacall_gpio_pin_open(0, pin, initDirection, mode, trigger, JAVACALL_FALSE, JAVACALL_TRUE, (javacall_handle*) &pinHandle);
+        pinState = javacall_gpio_pin_open(0, pin, direction, mode, trigger, JAVACALL_FALSE, JAVACALL_TRUE, (javacall_handle*) &pinHandle);
         if(JAVACALL_DIO_OK != pinState) {
             JAVACALL_REPORT_ERROR1(JC_DAAPI, "Can not open pin %d, so port open operation aborted", pin);
             close_pins_in_list(listHandle);
@@ -675,11 +647,11 @@
     }
 
     handle->pinList = listHandle;
-    handle->direction = initDirection;
+    handle->direction = direction;
     handle->maxValue = (1 << pinCount) - 1;
     *pHandle = handle;
 
-    if(JAVACALL_GPIO_OUTPUT_MODE == initDirection) {
+    if(JAVACALL_GPIO_OUTPUT_MODE == direction) {
         if(JAVACALL_DIO_OK != javacall_gpio_port_write(handle, initValue)) {
             javacall_gpio_port_close(handle);
             return JAVACALL_DIO_FAIL;
@@ -705,9 +677,11 @@
 void get_platform_direction_string(javacall_gpio_dir direction, javacall_bool initialValue, /*OUT*/ javacall_ascii_string* outString) {
 
     switch(direction) {
+        case JAVACALL_GPIO_BOTH_MODE_INIT_INPUT:
         case JAVACALL_GPIO_INPUT_MODE:
             *outString = PLATFORM_IN_GPIO_DIRECTION;
             break;
+        case JAVACALL_GPIO_BOTH_MODE_INIT_OUTPUT:
         case JAVACALL_GPIO_OUTPUT_MODE:
             if(JAVACALL_TRUE == initialValue) {
                 *outString = PLATFORM_HIGH_GPIO_DIRECTION;
@@ -784,7 +758,6 @@
 
 javacall_dio_result write_value_to_pin(GPIOHandle* handle, javacall_bool value) {
     javacall_ascii_string outValue;
-    //: Is there necessary to check direction?
 
     outValue = JAVACALL_TRUE == value ? "1" : "0";
 
--- a/src/share/native/com/oracle/dio/javacall_gpio.h	Tue Aug 26 19:32:35 2014 +0400
+++ b/src/share/native/com/oracle/dio/javacall_gpio.h	Tue Aug 26 19:36:41 2014 +0400
@@ -304,10 +304,11 @@
  *
  * @param port hardware GPIO Port's number
  * @param pin hardware GPIO Pin's number in the port
- * @param initDirection initial direction for pin JAVACALL_GPIO_INPUT_MODE or JAVACALL_GPIO_OUTPUT_MODE
+ * @param direction direction for pin JAVACALL_GPIO_INPUT_MODE, JAVACALL_GPIO_OUTPUT_MODE,
+ *        JAVACALL_GPIO_BOTH_MODE_INIT_INPUT or JAVACALL_GPIO_BOTH_MODE_INIT_OUTPUT
  * @param mode the drive mode of the pin, a bitwise OR of drive mode possible values
  * @param trigger the interrupt trigger events, one of javacall_gpio_trigger_mode
- * @param initValue the initial value of the pin when initDirection set for output
+ * @param initValue the initial value of the pin when direction set for output
  * @param exclusive      exclusive mode flag: JAVACALL_TRUE
  *                       means EXCLUSIVE mode, SHARED for the
  *                       rest
@@ -320,12 +321,13 @@
  *         in exclusive mode or pin was locked by {@link
  *         #javacall_gpio_pin_lock(const javacall_handle,
  *         javacall_handle* const)}
- * @retval JAVACALL_DIO_INVALID_CONFIG if one or more of parameters are wrong or unsupported by target platform
  * @retval JAVACALL_DIO_UNSUPPORTED_ACCESS_MODE    if EXCLUSIVE or SHARED
  *         mode is not supported
+ *
+ * Note: call parameters must conform specifications
  */
 javacall_dio_result javacall_gpio_pin_open(const javacall_int32 port,
-        const javacall_int32 pin, const javacall_gpio_dir initDirection,
+        const javacall_int32 pin, const javacall_gpio_dir direction,
         const javacall_gpio_mode mode, const javacall_gpio_trigger_mode trigger,
         const javacall_bool initValue,
         const javacall_bool exclusive,
@@ -341,9 +343,10 @@
  * The pins are arrange in the exact same order they compose the
  * virtual port
  * @param pinCount number of port and pin pairs in the first parameter
- * @param initDirection initial direction for pin JAVACALL_GPIO_INPUT_MODE or JAVACALL_GPIO_OUTPUT_MODE
+ * @param direction direction for pin JAVACALL_GPIO_INPUT_MODE, JAVACALL_GPIO_OUTPUT_MODE,
+ *        JAVACALL_GPIO_BOTH_MODE_INIT_INPUT or JAVACALL_GPIO_BOTH_MODE_INIT_OUTPUT
  * @param trigger the interrupt trigger events, one of javacall_gpio_trigger_mode
- * @param initValue the initial value of the port when initDirection set for output
+ * @param initValue the initial value of the port when direction set for output
  * @param exclusive      exclusive mode flag: JAVACALL_TRUE
  *                       means EXCLUSIVE mode, SHARED for the
  *                       rest
@@ -354,11 +357,13 @@
  * @retval JAVACALL_DIO_BUSY  Peripheral is in busy state. so it's not available.
  * @retval JAVACALL_DIO_UNSUPPORTED_ACCESS_MODE    if EXCLUSIVE or SHARED
  *         mode is not supported
+ *
+ * Note: call parameters must conform specifications
  */
 javacall_dio_result javacall_gpio_port_open_with_pins(
         const javacall_int32 portsAndPins[][4],
         const javacall_int32 pinCount,
-        const javacall_gpio_dir initDirection,
+        const javacall_gpio_dir direction,
         const javacall_int32 initValue, const javacall_bool exclusive,
         /*OUT*/ javacall_handle* pHandle);