diff options
author | Andreas Fritiofson <andreas.fritiofson@gmail.com> | 2013-09-28 21:43:37 +0200 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2013-10-31 20:43:27 +0000 |
commit | ba2fbe22470915359e1905aaad4c613eacbdf6dc (patch) | |
tree | 701c642d7bd3badb2b97b971cce811c4140e778b /src/jtag/drivers/stlink_usb.c | |
parent | 704082443d03cdeba9c89a8f70d1f1017330d903 (diff) |
Remove unnecessary casts
Change-Id: Ia97283707282ccccdc707c969f59337313b4e291
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1767
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/jtag/drivers/stlink_usb.c')
-rw-r--r-- | src/jtag/drivers/stlink_usb.c | 148 |
1 files changed, 38 insertions, 110 deletions
diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index e94e6c8a..957f1d40 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -209,12 +209,10 @@ static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t siz /** */ static int stlink_usb_xfer_v1_get_status(void *handle) { - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - /* read status */ memset(h->cmdbuf, 0, STLINK_SG_SIZE); @@ -244,12 +242,10 @@ static int stlink_usb_xfer_v1_get_status(void *handle) /** */ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size) { - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (jtag_libusb_bulk_write(h->fd, STLINK_TX_EP, (char *)h->cmdbuf, cmdsize, STLINK_WRITE_TIMEOUT) != cmdsize) { return ERROR_FAIL; @@ -276,12 +272,10 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int static int stlink_usb_xfer_v1_get_sense(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 16); h->cmdbuf[h->cmdidx++] = REQUEST_SENSE; @@ -305,12 +299,10 @@ static int stlink_usb_xfer_v1_get_sense(void *handle) static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size) { int err, cmdsize = STLINK_CMD_SIZE_V2; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->version.stlink == 1) cmdsize = STLINK_SG_SIZE; @@ -337,12 +329,10 @@ static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size) /** */ static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size) { - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - assert(h->version.stlink >= 2); if (jtag_libusb_bulk_read(h->fd, STLINK_TRACE_EP, (char *)buf, @@ -357,9 +347,7 @@ static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size) /** */ static void stlink_usb_xfer_v1_create_cmd(void *handle, uint8_t direction, uint32_t size) { - struct stlink_usb_handle_s *h; - - h = (struct stlink_usb_handle_s *)handle; + struct stlink_usb_handle_s *h = handle; /* fill the send buffer */ strcpy((char *)h->cmdbuf, "USBC"); @@ -376,9 +364,7 @@ static void stlink_usb_xfer_v1_create_cmd(void *handle, uint8_t direction, uint3 /** */ static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t size) { - struct stlink_usb_handle_s *h; - - h = (struct stlink_usb_handle_s *)handle; + struct stlink_usb_handle_s *h = handle; h->direction = direction; @@ -400,12 +386,10 @@ static int stlink_usb_error_check(void *handle) { int res; const char *err_msg = 0; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - /* TODO: no error checking yet on api V1 */ if (h->jtag_api == STLINK_JTAG_API_V1) h->databuf[0] = STLINK_DEBUG_ERR_OK; @@ -432,12 +416,10 @@ static int stlink_usb_version(void *handle) { int res; uint16_t v; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 6); h->cmdbuf[h->cmdidx++] = STLINK_GET_VERSION; @@ -476,11 +458,9 @@ static int stlink_usb_version(void *handle) static int stlink_usb_check_voltage(void *handle, float *target_voltage) { - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; uint32_t adc_results[2]; - h = (struct stlink_usb_handle_s *)handle; - /* only supported by stlink/v2 and for firmware >= 13 */ if (h->version.stlink == 1 || h->version.jtag < 13) return ERROR_COMMAND_NOTFOUND; @@ -512,12 +492,10 @@ static int stlink_usb_check_voltage(void *handle, float *target_voltage) static int stlink_usb_current_mode(void *handle, uint8_t *mode) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); h->cmdbuf[h->cmdidx++] = STLINK_GET_CURRENT_MODE; @@ -537,12 +515,10 @@ static int stlink_usb_mode_enter(void *handle, enum stlink_mode type) { int res; int rx_size = 0; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - /* on api V2 we are able the read the latest command * status * TODO: we need the test on api V1 too @@ -593,12 +569,10 @@ static int stlink_usb_mode_enter(void *handle, enum stlink_mode type) static int stlink_usb_mode_leave(void *handle, enum stlink_mode type) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_NULL_EP, 0); switch (type) { @@ -636,12 +610,10 @@ static int stlink_usb_init_mode(void *handle, bool connect_under_reset) int res; uint8_t mode; enum stlink_mode emode; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - res = stlink_usb_current_mode(handle, &mode); if (res != ERROR_OK) @@ -750,12 +722,10 @@ static int stlink_usb_init_mode(void *handle, bool connect_under_reset) static int stlink_usb_idcode(void *handle, uint32_t *idcode) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 4); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -775,13 +745,11 @@ static int stlink_usb_idcode(void *handle, uint32_t *idcode) static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *val) { - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; int res; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 8); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -802,12 +770,10 @@ static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *v static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -831,12 +797,10 @@ static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) /** */ static void stlink_usb_trace_read(void *handle) { - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->trace.enabled && h->version.jtag >= STLINK_TRACE_MIN_VERSION) { int res; @@ -889,12 +853,10 @@ static enum target_state stlink_usb_v2_get_status(void *handle) static enum target_state stlink_usb_state(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->jtag_api == STLINK_JTAG_API_V2) return stlink_usb_v2_get_status(handle); @@ -920,12 +882,10 @@ static enum target_state stlink_usb_state(void *handle) static int stlink_usb_reset(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -952,12 +912,10 @@ static int stlink_usb_reset(void *handle) static int stlink_usb_assert_srst(void *handle, int srst) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->jtag_api == STLINK_JTAG_API_V1) return ERROR_COMMAND_NOTFOUND; @@ -980,12 +938,10 @@ static int stlink_configure_target_trace_port(void *handle) { int res; uint32_t reg; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - /* configure the TPI */ /* enable the trace subsystem */ @@ -1037,12 +993,10 @@ out: static void stlink_usb_trace_disable(void *handle) { int res = ERROR_OK; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - assert(h->version.jtag >= STLINK_TRACE_MIN_VERSION); LOG_DEBUG("Tracing: disable\n"); @@ -1061,12 +1015,10 @@ static void stlink_usb_trace_disable(void *handle) static int stlink_usb_trace_enable(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->version.jtag >= STLINK_TRACE_MIN_VERSION) { uint32_t trace_hz; @@ -1105,12 +1057,10 @@ static int stlink_usb_trace_enable(void *handle) static int stlink_usb_run(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->jtag_api == STLINK_JTAG_API_V2) { res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN); @@ -1142,12 +1092,10 @@ static int stlink_usb_run(void *handle) static int stlink_usb_halt(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->jtag_api == STLINK_JTAG_API_V2) { res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN); @@ -1174,12 +1122,10 @@ static int stlink_usb_halt(void *handle) static int stlink_usb_step(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->jtag_api == STLINK_JTAG_API_V2) { /* TODO: this emulates the v1 api, it should really use a similar auto mask isr * that the cortex-m3 currently does. */ @@ -1205,12 +1151,10 @@ static int stlink_usb_step(void *handle) static int stlink_usb_read_regs(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 84); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1231,12 +1175,10 @@ static int stlink_usb_read_regs(void *handle) static int stlink_usb_read_reg(void *handle, int num, uint32_t *val) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, h->jtag_api == STLINK_JTAG_API_V1 ? 4 : 8); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1265,12 +1207,10 @@ static int stlink_usb_read_reg(void *handle, int num, uint32_t *val) static int stlink_usb_write_reg(void *handle, int num, uint32_t val) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1293,12 +1233,10 @@ static int stlink_usb_write_reg(void *handle, int num, uint32_t val) static int stlink_usb_get_rw_status(void *handle) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); - h = (struct stlink_usb_handle_s *)handle; - if (h->jtag_api == STLINK_JTAG_API_V1) return ERROR_OK; @@ -1321,7 +1259,7 @@ static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, { int res; uint16_t read_len = len; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); @@ -1331,8 +1269,6 @@ static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, return ERROR_FAIL; } - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, read_len); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1361,7 +1297,7 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); @@ -1371,8 +1307,6 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len, return ERROR_FAIL; } - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_TX_EP, len); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1395,7 +1329,7 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, uint8_t *buffer) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); @@ -1405,8 +1339,6 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len, return ERROR_TARGET_UNALIGNED_ACCESS; } - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_RX_EP, len); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1431,7 +1363,7 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, const uint8_t *buffer) { int res; - struct stlink_usb_handle_s *h; + struct stlink_usb_handle_s *h = handle; assert(handle != NULL); @@ -1441,8 +1373,6 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len, return ERROR_TARGET_UNALIGNED_ACCESS; } - h = (struct stlink_usb_handle_s *)handle; - stlink_usb_init_buffer(handle, STLINK_TX_EP, len); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; @@ -1473,7 +1403,7 @@ static int stlink_usb_read_mem(void *handle, uint32_t addr, uint32_t size, { int retval = ERROR_OK; uint32_t bytes_remaining; - struct stlink_usb_handle_s *h = (struct stlink_usb_handle_s *)handle; + struct stlink_usb_handle_s *h = handle; /* calculate byte count */ count *= size; @@ -1534,7 +1464,7 @@ static int stlink_usb_write_mem(void *handle, uint32_t addr, uint32_t size, { int retval = ERROR_OK; uint32_t bytes_remaining; - struct stlink_usb_handle_s *h = (struct stlink_usb_handle_s *)handle; + struct stlink_usb_handle_s *h = handle; /* calculate byte count */ count *= size; @@ -1593,9 +1523,7 @@ static int stlink_usb_write_mem(void *handle, uint32_t addr, uint32_t size, /** */ static int stlink_usb_close(void *fd) { - struct stlink_usb_handle_s *h; - - h = (struct stlink_usb_handle_s *)fd; + struct stlink_usb_handle_s *h = fd; if (h->fd) jtag_libusb_close(h->fd); |