Browse Source

Merge pull request #1165 from jean-m-cyr/master

px4io_uploader cleanup and minor optimization
sbg
Lorenz Meier 11 years ago
parent
commit
1dd4282099
  1. 51
      src/drivers/px4io/px4io_uploader.cpp
  2. 1
      src/drivers/px4io/uploader.h

51
src/drivers/px4io/px4io_uploader.cpp

@ -204,12 +204,8 @@ PX4IO_Uploader::upload(const char *filenames[])
if (bl_rev <= 2) { if (bl_rev <= 2) {
ret = verify_rev2(fw_size); ret = verify_rev2(fw_size);
} else if(bl_rev == 3) {
ret = verify_rev3(fw_size);
} else { } else {
/* verify rev 4 and higher still uses the same approach and /* verify rev 3 and higher. Every version *needs* to be verified. */
* every version *needs* to be verified.
*/
ret = verify_rev3(fw_size); ret = verify_rev3(fw_size);
} }
@ -276,14 +272,14 @@ PX4IO_Uploader::recv(uint8_t &c, unsigned timeout)
int int
PX4IO_Uploader::recv(uint8_t *p, unsigned count) PX4IO_Uploader::recv(uint8_t *p, unsigned count)
{ {
int ret;
while (count--) { while (count--) {
int ret = recv(*p++, 5000); ret = recv(*p++, 5000);
if (ret != OK) if (ret != OK)
return ret; break;
} }
return ret;
return OK;
} }
void void
@ -314,21 +310,19 @@ PX4IO_Uploader::send(uint8_t c)
#endif #endif
if (write(_io_fd, &c, 1) != 1) if (write(_io_fd, &c, 1) != 1)
return -errno; return -errno;
return OK; return OK;
} }
int int
PX4IO_Uploader::send(uint8_t *p, unsigned count) PX4IO_Uploader::send(uint8_t *p, unsigned count)
{ {
int ret;
while (count--) { while (count--) {
int ret = send(*p++); ret = send(*p++);
if (ret != OK) if (ret != OK)
return ret; break;
} }
return ret;
return OK;
} }
int int
@ -419,12 +413,15 @@ PX4IO_Uploader::program(size_t fw_size)
int ret; int ret;
size_t sent = 0; size_t sent = 0;
file_buf = (uint8_t *)malloc(PROG_MULTI_MAX); file_buf = new uint8_t[PROG_MULTI_MAX];
if (!file_buf) { if (!file_buf) {
log("Can't allocate program buffer"); log("Can't allocate program buffer");
return -ENOMEM; return -ENOMEM;
} }
ASSERT((fw_size & 3) == 0);
ASSERT((PROG_MULTI_MAX & 3) == 0);
log("programming %u bytes...", (unsigned)fw_size); log("programming %u bytes...", (unsigned)fw_size);
ret = lseek(_fw_fd, 0, SEEK_SET); ret = lseek(_fw_fd, 0, SEEK_SET);
@ -443,34 +440,26 @@ PX4IO_Uploader::program(size_t fw_size)
(unsigned)sent, (unsigned)sent,
(int)count, (int)count,
(int)errno); (int)errno);
} ret = -errno;
break;
if (count == 0) {
free(file_buf);
return OK;
} }
sent += count; sent += count;
if (count < 0)
return -errno;
ASSERT((count % 4) == 0);
send(PROTO_PROG_MULTI); send(PROTO_PROG_MULTI);
send(count); send(count);
send(&file_buf[0], count); send(file_buf, count);
send(PROTO_EOC); send(PROTO_EOC);
ret = get_sync(1000); ret = get_sync(1000);
if (ret != OK) { if (ret != OK) {
free(file_buf); break;
return ret;
} }
} }
free(file_buf);
return OK; delete [] file_buf;
return ret;
} }
int int

1
src/drivers/px4io/uploader.h

@ -75,7 +75,6 @@ private:
INFO_FLASH_SIZE = 4, /**< max firmware size in bytes */ INFO_FLASH_SIZE = 4, /**< max firmware size in bytes */
PROG_MULTI_MAX = 60, /**< protocol max is 255, must be multiple of 4 */ PROG_MULTI_MAX = 60, /**< protocol max is 255, must be multiple of 4 */
READ_MULTI_MAX = 60, /**< protocol max is 255, something overflows with >= 64 */
}; };

Loading…
Cancel
Save