flash/nor/tcl: Distinguish between sectors and blocks in status messages
[openocd.git] / src / jtag / drivers / versaloon / versaloon.c
index e33a260f006a02803d2d319e3b72d09c0ba09ff3..146383961399b9240353dcc2c5368fb948dd0857 100644 (file)
@@ -12,9 +12,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -23,6 +21,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <libusb.h>
 
 #include "versaloon_include.h"
 #include "versaloon.h"
@@ -36,7 +35,7 @@ uint16_t versaloon_buf_size;
 struct versaloon_pending_t versaloon_pending[VERSALOON_MAX_PENDING_NUMBER];
 uint16_t versaloon_pending_idx;
 
-usb_dev_handle *versaloon_usb_device_handle;
+libusb_device_handle *versaloon_usb_device_handle;
 static uint32_t versaloon_usb_to = VERSALOON_TIMEOUT;
 
 RESULT versaloon_init(void);
@@ -139,7 +138,7 @@ RESULT versaloon_add_want_pos(uint16_t offset, uint16_t size, uint8_t *buff)
 {
        struct versaloon_want_pos_t *new_pos = NULL;
 
-       new_pos = (struct versaloon_want_pos_t *)malloc(sizeof(*new_pos));
+       new_pos = malloc(sizeof(*new_pos));
        if (NULL == new_pos) {
                LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
                return ERRCODE_NOT_ENOUGH_MEMORY;
@@ -196,6 +195,7 @@ RESULT versaloon_add_pending(uint8_t type, uint8_t cmd, uint16_t actual_szie,
 RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
 {
        int ret;
+       int transferred;
 
 #if PARAM_CHECK
        if (NULL == versaloon_buf) {
@@ -208,25 +208,24 @@ RESULT versaloon_send_command(uint16_t out_len, uint16_t *inlen)
        }
 #endif
 
-       ret = usb_bulk_write(versaloon_usb_device_handle,
-                       versaloon_interface.usb_setting.ep_out, (char *)versaloon_buf,
-                       out_len, versaloon_usb_to);
-       if (ret != out_len) {
-               LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "send usb data",
-                       usb_strerror());
+       ret = libusb_bulk_transfer(versaloon_usb_device_handle,
+                       versaloon_interface.usb_setting.ep_out,
+                       versaloon_buf, out_len, &transferred, versaloon_usb_to);
+       if (0 != ret || transferred != out_len) {
+               LOG_ERROR(ERRMSG_FAILURE_OPERATION, "send usb data");
                return ERRCODE_FAILURE_OPERATION;
        }
 
        if (inlen != NULL) {
-               ret = usb_bulk_read(versaloon_usb_device_handle,
-                               versaloon_interface.usb_setting.ep_in, (char *)versaloon_buf,
-                               versaloon_interface.usb_setting.buf_size, versaloon_usb_to);
-               if (ret > 0) {
-                       *inlen = (uint16_t)ret;
+               ret = libusb_bulk_transfer(versaloon_usb_device_handle,
+                       versaloon_interface.usb_setting.ep_in,
+                       versaloon_buf, versaloon_interface.usb_setting.buf_size,
+                       &transferred, versaloon_usb_to);
+               if (0 == ret) {
+                       *inlen = (uint16_t)transferred;
                        return ERROR_OK;
                } else {
-                       LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRSTRING, "receive usb data",
-                               usb_strerror());
+                       LOG_ERROR(ERRMSG_FAILURE_OPERATION, "receive usb data");
                        return ERROR_FAIL;
                }
        } else
@@ -241,8 +240,7 @@ RESULT versaloon_init(void)
        uint32_t timeout_tmp;
 
        /* malloc temporary buffer */
-       versaloon_buf =
-               (uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
+       versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
        if (NULL == versaloon_buf) {
                LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
                return ERRCODE_NOT_ENOUGH_MEMORY;
@@ -274,15 +272,13 @@ RESULT versaloon_init(void)
        free(versaloon_buf);
        versaloon_buf = NULL;
 
-       versaloon_buf =
-               (uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
+       versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
        if (NULL == versaloon_buf) {
                versaloon_fini();
                LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
                return ERRCODE_NOT_ENOUGH_MEMORY;
        }
-       versaloon_cmd_buf =
-               (uint8_t *)malloc(versaloon_interface.usb_setting.buf_size - 3);
+       versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3);
        if (NULL == versaloon_cmd_buf) {
                versaloon_fini();
                LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)