changeset 64:a6e7bcf2492e

8066898: Small type mismatch at native files Summary: Fixed return value for a number of functions Reviewed-by: snazarki Contributed-by: alexey.mironov@oracle.com
author snazarki
date Thu, 11 Dec 2014 13:53:07 +0400
parents 57d30652361c
children 4f321d3dab0c
files src/share/linux/native/com/oracle/dio/gpio/gpio.c src/share/linux/native/com/oracle/dio/mmio/mmio.c src/share/linux/native/com/oracle/dio/spibus/spi.c src/share/linux/native/com/oracle/dio/uart/uart.c
diffstat 4 files changed, 56 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/linux/native/com/oracle/dio/gpio/gpio.c	Thu Dec 11 13:48:52 2014 +0400
+++ b/src/share/linux/native/com/oracle/dio/gpio/gpio.c	Thu Dec 11 13:53:07 2014 +0400
@@ -97,7 +97,7 @@
 
 void get_platform_direction_string(javacall_gpio_dir direction, javacall_bool initialValue, /*OUT*/ javacall_ascii_string* outString);
 void get_platform_edge_string(javacall_gpio_trigger_mode edgeMode, javacall_ascii_string* string);
-javacall_bool is_pin_pull_up(int pinNumber);
+javacall_dio_result is_pin_pull_up(int pinNumber);
 javacall_dio_result enable_gpio_pin(int pinNumber);
 javacall_dio_result disable_gpio_pin(int pinNumber);
 javacall_dio_result write_direction_to_file(int dirFD, javacall_gpio_dir direction, javacall_bool initialValue);
@@ -243,7 +243,7 @@
 
     if(JAVACALL_DIO_OK != write_value_to_pin(pinHandle, val)) {
         JAVACALL_REPORT_ERROR1(JC_DIO, "Can not write value to GPIO pin %d", pinHandle->number);
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     }
 
     JAVACALL_REPORT_INFO1(JC_DIO, "Pin %d write value done", pinHandle->number);
@@ -263,7 +263,7 @@
     int iterator = 0;
     javautil_list_reset_iterator(portHandle->pinList);
 
-    while(JAVACALL_DIO_FAIL != (listOperationsResult = javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin))) {
+    while(JAVACALL_FAIL != (listOperationsResult = javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin))) {
         if(JAVACALL_DIO_INVALID_CONFIG == listOperationsResult) {
             JAVACALL_REPORT_ERROR(JC_DIO, "Invalid handle of GPIO port was passed to read function. Operation aborted");
             return JAVACALL_DIO_INVALID_CONFIG;
@@ -297,7 +297,7 @@
 
     JAVACALL_REPORT_INFO1(JC_DIO, "Write value %d to port start", val);
 
-    while(JAVACALL_DIO_FAIL != (listOperationsResult = javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin))) {
+    while(JAVACALL_FAIL != (listOperationsResult = javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin))) {
         if(JAVACALL_DIO_INVALID_CONFIG == listOperationsResult) {
             JAVACALL_REPORT_ERROR(JC_DIO, "Invalid handle of GPIO port was passed to write function. Operation aborted");
             return JAVACALL_DIO_INVALID_CONFIG;
@@ -413,7 +413,7 @@
 
     if(JAVACALL_DIO_OK != write_direction_to_file(pinHandle->directionFD, direction, JAVACALL_FALSE)) {
         JAVACALL_REPORT_ERROR1(JC_DIO, "There is unexpected error, when configure direction of GPIO pin %d", pinHandle->number);
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     };
     pinHandle->direction = direction;
     return JAVACALL_DIO_OK;
@@ -441,7 +441,7 @@
     javautil_list_reset_iterator(portHandle->pinList);
     JAVACALL_REPORT_INFO1(JC_DIO, "Set direction %d to port", direction);
 
-    while(JAVACALL_DIO_FAIL != (listOperationsResult = javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin))) {
+    while(JAVACALL_FAIL != (listOperationsResult = javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin))) {
         if(JAVACALL_DIO_INVALID_CONFIG == listOperationsResult) {
             JAVACALL_REPORT_ERROR(JC_DIO, "Invalid handle of GPIO port was passed to set direction function. Operation aborted");
             return JAVACALL_DIO_FAIL;
@@ -491,7 +491,7 @@
 
     javacall_int8 bufForDirectionFilename[DIRECTION_FILENAME_MAX_LENGTH];
     GPIOHandle* handle;
-    javacall_dio_result pinCondition;
+    javacall_dio_result res;
     int directionFD;
 
     JAVACALL_REPORT_INFO3(JC_DIO, "Try to open pin %d on port %d with direction %d", pin, port, direction);
@@ -517,16 +517,18 @@
         return JAVACALL_DIO_BUSY;
     }
 
-    pinCondition = check_trigger(trigger);
-    if (JAVACALL_DIO_OK != pinCondition) {
+    res = check_trigger(trigger);
+    if (JAVACALL_DIO_OK != res) {
         unlock_pin_list();
         // error is printed at check_trigger
-        return pinCondition;
+        return res;
     }
 
-    if(JAVACALL_DIO_OK != enable_gpio_pin(pin)) {
+    res = enable_gpio_pin(pin);
+    if (JAVACALL_DIO_OK != res) {
         unlock_pin_list();
-        return JAVACALL_DIO_FAIL;
+        // error is printed at enable_gpio_pin
+        return res;
     }
 
     snprintf(bufForDirectionFilename, DIRECTION_FILENAME_MAX_LENGTH, GPIO_DIRECTION_FILENAME_TEMPLATE, pin);
@@ -595,7 +597,7 @@
         /*OUT*/ javacall_handle* pHandle) {
 
     int i = 0;
-    javacall_result pinState, result;
+    javacall_dio_result pinState, result;
     javacall_int32 pin, mode;
     javacall_gpio_trigger_mode trigger;
     javacall_handle listHandle;
@@ -716,9 +718,9 @@
 
     snprintf(pinNameBuffer, 4, PIN_NAME_TEMPLATE, pinNumber);
     if(-1 == write(expordFD, pinNameBuffer, 4)) {
-        JAVACALL_REPORT_ERROR1(JC_DIO, "There is unexpected error, when open GPIO pin %d", pinNumber);
+        JAVACALL_REPORT_ERROR1(JC_DIO, "Can't export GPIO pin %d", pinNumber);
         close(expordFD);
-        return JAVACALL_DIO_FAIL;
+        return JAVACALL_DIO_NOT_FOUND;
     };
 
     close(expordFD);
@@ -745,7 +747,7 @@
         return JAVACALL_DIO_FAIL;
     }
 
-    return JAVACALL_OK;
+    return JAVACALL_DIO_OK;
 }
 
 javacall_dio_result write_direction_to_file(int dirFD, javacall_gpio_dir direction, javacall_bool initialValue) {
@@ -918,7 +920,7 @@
     JAVACALL_REPORT_INFO1(JC_DIO, "Remove value file of pin %d from polling", pinHandle->number);
     if(-1 == epoll_ctl(epoll_descriptor, EPOLL_CTL_DEL, pinHandle->valueFD, NULL)) {
         JAVACALL_REPORT_ERROR1(JC_DIO, "Del value file of pin %d to polling failed", pinHandle->number);
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     };
     pinCountForPolling--;
     javacall_free(pinHandle->pollEvent->data.ptr);
@@ -1004,7 +1006,7 @@
     if(JAVACALL_TRUE != success) {
         javautil_list_reset_iterator(portHandle->pinList);
         while(JAVACALL_OK == javautil_list_get_next(portHandle->pinList, (javacall_handle*) &pin)) {
-            if(JAVACALL_OK != del_pin_from_polling(pin)) {
+            if(JAVACALL_DIO_OK != del_pin_from_polling(pin)) {
                 JAVACALL_REPORT_WARN1(JC_DIO, "Can not remove pin %d from polling", pin->number);
             }
         }
@@ -1045,7 +1047,7 @@
 
     if(-1 == edgeFD) {
         JAVACALL_REPORT_ERROR1(JC_DIO, "Can open edge file for pin %d", pin->number);
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     }
     get_platform_edge_string(pin->edgeMode, &platformValue);
     if(-1 == write(edgeFD, platformValue, strlen(platformValue) + 1)) {
@@ -1057,7 +1059,7 @@
     return JAVACALL_DIO_OK;
 }
 
-javacall_bool is_pin_pull_up(int pinNumber) {
+javacall_dio_result is_pin_pull_up(int pinNumber) {
     if(2 == pinNumber || 3 == pinNumber) {
         return JAVACALL_TRUE;
     }
--- a/src/share/linux/native/com/oracle/dio/mmio/mmio.c	Thu Dec 11 13:48:52 2014 +0400
+++ b/src/share/linux/native/com/oracle/dio/mmio/mmio.c	Thu Dec 11 13:53:07 2014 +0400
@@ -45,19 +45,19 @@
 static int open_count = 0;
 
 
-javacall_result check_addr_len(const int addr, const int len) {
+javacall_dio_result check_addr_len(const int addr, const int len) {
     if (addr > BASE_ADDR + BLOCK_LEN || addr + len > BASE_ADDR + BLOCK_LEN ||
         addr < BASE_ADDR || addr + len < BASE_ADDR) {
         JAVACALL_REPORT_ERROR1(JC_DIO, "Invalid MMIO address %d\n", addr);
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     }
 
-    return JAVACALL_OK;
+    return JAVACALL_DIO_OK;
 }
 
 
 /* see javacall_mmio.h for description */
-javacall_result javacall_mmio_open(const javacall_uint8* addr, const javacall_int32 size,
+javacall_dio_result javacall_mmio_open(const javacall_uint8* addr, const javacall_int32 size,
                                    /*out*/javacall_handle* const handle,
                                    /*out*/javacall_uint8** const mappedAddr) {
     void* result;
@@ -65,8 +65,8 @@
     void* aligned_addr;
     size_t aligned_size;
 
-    if (JAVACALL_OK != check_addr_len((int)addr, size)) {
-        return JAVACALL_INVALID_ARGUMENT;
+    if (JAVACALL_DIO_OK != check_addr_len((int)addr, size)) {
+        return JAVACALL_DIO_INVALID_CONFIG;
     }
 
     if (0 == mem_fd) {
@@ -74,12 +74,11 @@
         mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
         drop_privileges();
     }
-
     /* open /dev/mem */
     if (mem_fd < 0) {
         mem_fd = 0;
         JAVACALL_REPORT_ERROR(JC_DIO, "cannot open /dev/mem \n");
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     }
 
     aligned_addr = (void*)(((long int)addr / page_size) * page_size);
@@ -98,7 +97,7 @@
     if (result == (void*)-1) {
         JAVACALL_REPORT_ERROR1(JC_DIO, "cannot remap: \n", errno);
         close(mem_fd);
-        return JAVACALL_FAIL;
+        return JAVACALL_DIO_FAIL;
     }
 
     open_count++;
@@ -111,17 +110,17 @@
       tmp[1] = (javacall_int32)aligned_size;
       *handle = (javacall_handle)tmp;
     }
-    return JAVACALL_OK;
+    return JAVACALL_DIO_OK;
 }
 
 
 /* see javacall_mmio.h for description */
-javacall_result javacall_mmio_close(const javacall_handle handle) {
-    javacall_result result = JAVACALL_OK;
+javacall_dio_result javacall_mmio_close(const javacall_handle handle) {
+    javacall_dio_result result = JAVACALL_DIO_OK;
     javacall_int32* tmp = (javacall_int32*)handle;
     if (0 != munmap((void*)tmp[0], (size_t)tmp[1])) {
         JAVACALL_REPORT_ERROR(JC_DIO, "cannot release maped memory");
-        result = JAVACALL_FAIL;
+        result = JAVACALL_DIO_FAIL;
     }
 
     javacall_free((void*)handle);
@@ -138,7 +137,7 @@
 }
 
 /* see javacall_mmio.h for description */
-javacall_result javacall_mmio_start_listening_with_buffer(
+javacall_dio_result javacall_mmio_start_listening_with_buffer(
         const javacall_handle handle,
         const javacall_uint32 offset,
         const javacall_uint32 event_id,
@@ -149,13 +148,13 @@
     (void)event_id;
     (void)buffer;
     (void)bufferLength;
-    return JAVACALL_FAIL;
+    return JAVACALL_DIO_FAIL;
 }
 
 /* see javacall_mmio.h for description */
-javacall_result javacall_mmio_stop_listening(const javacall_handle handle, const javacall_uint32 event_id){
+javacall_dio_result javacall_mmio_stop_listening(const javacall_handle handle, const javacall_uint32 event_id){
     (void)handle;
     (void)event_id;
-    return JAVACALL_OK;
+    return JAVACALL_DIO_OK;
 }
 
--- a/src/share/linux/native/com/oracle/dio/spibus/spi.c	Thu Dec 11 13:48:52 2014 +0400
+++ b/src/share/linux/native/com/oracle/dio/spibus/spi.c	Thu Dec 11 13:53:07 2014 +0400
@@ -58,9 +58,8 @@
     char* rxBuf;
 };
 
-typedef struct _spi_slave_config spi_slave_config;
 
-struct _spi_slave_config{
+typedef struct {
     int                busId;        /* bus ID */
     int                address;      /* chip enable:                */
                                      /*    =  0 - NO_CS             */
@@ -80,9 +79,9 @@
     int                devFd;
     javacall_spi_cs_active csActive;
     javacall_bool          busOwner;
-    spi_slave_config* next;
+    struct spi_slave_config* next;
     spi_context* xfer_list;
-};
+} spi_slave_config;
 
 #define SSC(arg) ((spi_slave_config*)arg)
 
@@ -99,7 +98,7 @@
     spi_slave_config* next = _spi_dev_list;
 
     if(0 != pthread_mutex_lock(&_list_mutex)){
-        JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] get_opened_device: cannot lock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] get_opened_device: cannot lock mutex errno=%d\n", errno);
         return NULL;
     }
 
@@ -111,7 +110,7 @@
     }
 
     if(0 != pthread_mutex_unlock(&_list_mutex)){
-        JAVACALL_REPORT_WARN1(JC_DAAPI, "[SPI] get_opened_device: cannot unlock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_WARN1(JC_DIO, "[SPI] get_opened_device: cannot unlock mutex errno=%d\n", errno);
     }
     return next;
 }
@@ -120,7 +119,7 @@
     spi_slave_config* next = _spi_dev_list;
 
     if(0 != pthread_mutex_lock(&_list_mutex)){
-        JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] get_bus_owner: cannot lock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] get_bus_owner: cannot lock mutex errno=%d\n", errno);
         return NULL;
     }
 
@@ -132,7 +131,7 @@
     }
 
     if(0 != pthread_mutex_unlock(&_list_mutex)){
-        JAVACALL_REPORT_WARN1(JC_DAAPI, "[SPI] get_bus_owner: cannot unlock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_WARN1(JC_DIO, "[SPI] get_bus_owner: cannot unlock mutex errno=%d\n", errno);
     }
     return next;
 }
@@ -149,7 +148,7 @@
 static javacall_dio_result add_dev_to_list(spi_slave_config* spi_dev) {
 
     if(0 != pthread_mutex_lock(&_list_mutex)){
-        JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] add_dev_to_list: cannot lock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] add_dev_to_list: cannot lock mutex errno=%d\n", errno);
         return JAVACALL_DIO_FAIL;
     }
 
@@ -157,7 +156,7 @@
     _spi_dev_list = spi_dev;
 
     if(0 != pthread_mutex_unlock(&_list_mutex)){
-        JAVACALL_REPORT_WARN1(JC_DAAPI, "[SPI] add_dev_to_list: cannot unlock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_WARN1(JC_DIO, "[SPI] add_dev_to_list: cannot unlock mutex errno=%d\n", errno);
     }
 
     return JAVACALL_DIO_OK;
@@ -176,7 +175,7 @@
     spi_slave_config* next;
 
     if(0 != pthread_mutex_lock(&_list_mutex)){
-        JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] remove_dev_from_list: cannot lock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] remove_dev_from_list: cannot lock mutex errno=%d\n", errno);
         return JAVACALL_DIO_FAIL;
     }
 
@@ -195,7 +194,7 @@
         }
     }
     if(0 != pthread_mutex_unlock(&_list_mutex)){
-        JAVACALL_REPORT_WARN1(JC_DAAPI, "[SPI] remove_dev_from_list: cannot unlock mutex errno=%d\n", errno);
+        JAVACALL_REPORT_WARN1(JC_DIO, "[SPI] remove_dev_from_list: cannot unlock mutex errno=%d\n", errno);
     }
     return JAVACALL_DIO_OK;
 }
@@ -410,7 +409,6 @@
     restore_privileges();
     cfg->devFd = open(device, O_RDWR | O_EXCL);
     drop_privileges();
-
     if (0 <= cfg->devFd) {
         lock.l_type   = F_WRLCK;  /* exclusive lock*/
         lock.l_whence = SEEK_SET;
@@ -424,7 +422,7 @@
                 cfg->devFd = -1;
                 return JAVACALL_DIO_BUSY;
             }else{
-                JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] Can't lock device. errno %d", errno);
+                JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] Can't lock device. errno %d", errno);
                 close(cfg->devFd);
                 cfg->devFd = -1;
                 return JAVACALL_DIO_FAIL;
@@ -437,7 +435,7 @@
         return JAVACALL_DIO_OK;
     }else{
         if(errno == EACCES){
-            JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] Can't open %s. Permission denied", device);
+            JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] Can't open %s. Permission denied", device);
         }
     }
 
@@ -456,7 +454,7 @@
     lock.l_pid    = getpid();
 
     if(-1 == fcntl(cfg->devFd , F_SETLK, &lock)){
-        JAVACALL_REPORT_ERROR1(JC_DAAPI, "[SPI] Can't unclock device. errno %d", errno);
+        JAVACALL_REPORT_ERROR1(JC_DIO, "[SPI] Can't unclock device. errno %d", errno);
     }
 
     close( cfg->devFd );
--- a/src/share/linux/native/com/oracle/dio/uart/uart.c	Thu Dec 11 13:48:52 2014 +0400
+++ b/src/share/linux/native/com/oracle/dio/uart/uart.c	Thu Dec 11 13:53:07 2014 +0400
@@ -461,22 +461,22 @@
     //setting daapi parameters
     if (JAVACALL_OK != javacall_serial_set_baudRate((javacall_handle)p, baudRate) ){
         javacall_uart_close_start(p, NULL);
-        return JAVACALL_DIO_UNSUPPORTED_OPERATION;
+        return JAVACALL_DIO_INVALID_CONFIG;
     }
 
     if (JAVACALL_DIO_OK != javacall_uart_set_bits_per_char((javacall_handle)p, bitsPerchar)){
         javacall_uart_close_start(p, NULL);
-        return JAVACALL_DIO_UNSUPPORTED_OPERATION;
+        return JAVACALL_DIO_INVALID_CONFIG;
     }
 
     if (JAVACALL_DIO_OK != javacall_uart_set_stop_bits((javacall_handle)p, stopBits)){
         javacall_uart_close_start(p, NULL);
-        return JAVACALL_DIO_UNSUPPORTED_OPERATION;
+        return JAVACALL_DIO_INVALID_CONFIG;
     }
 
     if (JAVACALL_DIO_OK != javacall_uart_set_parity((javacall_handle)p, parity)){
         javacall_uart_close_start(p, NULL);
-        return JAVACALL_DIO_UNSUPPORTED_OPERATION;
+        return JAVACALL_DIO_INVALID_CONFIG;
     }
 
     if(JAVACALL_DIO_OK != jc_serial_init_buffers_threads(p)){
@@ -580,5 +580,3 @@
     *grp = -1;
     return JAVACALL_DIO_UNSUPPORTED_OPERATION;
 }
-
-