|
@@ -61,6 +61,7 @@ struct lpc_device *lpc_setup(struct serial_device *port) {
|
|
dev = malloc(sizeof(struct lpc_device));
|
|
dev = malloc(sizeof(struct lpc_device));
|
|
dev->port = port;
|
|
dev->port = port;
|
|
dev->part = NULL;
|
|
dev->part = NULL;
|
|
|
|
+ dev->reply_time = 500;
|
|
lpc_reset(dev, 1);
|
|
lpc_reset(dev, 1);
|
|
return dev;
|
|
return dev;
|
|
}
|
|
}
|
|
@@ -94,6 +95,7 @@ void lpc_write(struct lpc_device *dev, const struct sprog_data *d) {
|
|
static const int chunk_sizes[] = {256, 512, 1024, 4096, 0};
|
|
static const int chunk_sizes[] = {256, 512, 1024, 4096, 0};
|
|
struct sprog_data chunk;
|
|
struct sprog_data chunk;
|
|
int i;
|
|
int i;
|
|
|
|
+ int j;
|
|
int offset;
|
|
int offset;
|
|
int chunk_size;
|
|
int chunk_size;
|
|
int data_size;
|
|
int data_size;
|
|
@@ -107,12 +109,18 @@ void lpc_write(struct lpc_device *dev, const struct sprog_data *d) {
|
|
lpc_command(dev, "P 0 %d\r\n", i);
|
|
lpc_command(dev, "P 0 %d\r\n", i);
|
|
|
|
|
|
sprog_info("Erasing Flash memory... ");
|
|
sprog_info("Erasing Flash memory... ");
|
|
|
|
+ j = dev->reply_time;
|
|
|
|
+ dev->reply_time = 5000;
|
|
if(lpc_command(dev, "E 0 %d\r\n", i))
|
|
if(lpc_command(dev, "E 0 %d\r\n", i))
|
|
sprog_info("Error\n");
|
|
sprog_info("Error\n");
|
|
else
|
|
else
|
|
sprog_info("OK\n");
|
|
sprog_info("OK\n");
|
|
|
|
+ dev->reply_time = j;
|
|
|
|
|
|
i = d->size/4096 - 1;
|
|
i = d->size/4096 - 1;
|
|
|
|
+ if(d->size % 4096)
|
|
|
|
+ i++;
|
|
|
|
+
|
|
lpc_command(dev, "P 0 %d\r\n", i); /* prepare sectors for write */
|
|
lpc_command(dev, "P 0 %d\r\n", i); /* prepare sectors for write */
|
|
|
|
|
|
while(d->size-offset>0) {
|
|
while(d->size-offset>0) {
|
|
@@ -127,7 +135,8 @@ void lpc_write(struct lpc_device *dev, const struct sprog_data *d) {
|
|
}
|
|
}
|
|
|
|
|
|
chunk_size = chunk_sizes[i];
|
|
chunk_size = chunk_sizes[i];
|
|
- if(chunk_size==0) chunk_size = chunk_sizes[i-1];
|
|
|
|
|
|
+ if(chunk_size==0)
|
|
|
|
+ chunk_size = chunk_sizes[i-1];
|
|
sprog_alloc_data(&chunk, chunk_size);
|
|
sprog_alloc_data(&chunk, chunk_size);
|
|
|
|
|
|
data_size = chunk_size;
|
|
data_size = chunk_size;
|
|
@@ -173,10 +182,12 @@ void lpc_write_ram(struct lpc_device *dev, const struct sprog_data *d, unsigned
|
|
int i;
|
|
int i;
|
|
int j;
|
|
int j;
|
|
|
|
|
|
- if(d->size & 3)
|
|
|
|
- sprog_error("Invalid data size - should be aligned to 4\n");
|
|
|
|
|
|
+ /* align data size to 4 */
|
|
|
|
+ i = d->size;
|
|
|
|
+ if(i & 3)
|
|
|
|
+ i = (i & ~3) + 4;
|
|
|
|
|
|
- lpc_command(dev, "W %u %u\r\n", addr, d->size);
|
|
|
|
|
|
+ lpc_command(dev, "W %u %u\r\n", addr, i);
|
|
sprog_info("Writing %d bytes\n", d->size);
|
|
sprog_info("Writing %d bytes\n", d->size);
|
|
|
|
|
|
last_i = 0;
|
|
last_i = 0;
|
|
@@ -235,7 +246,7 @@ int lpc_await_reply(struct lpc_device *dev, ...) {
|
|
|
|
|
|
|
|
|
|
int lpc_getline(struct lpc_device *dev, char *buf) {
|
|
int lpc_getline(struct lpc_device *dev, char *buf) {
|
|
- if(sprog_waitdata(dev->port, 5000)==0)
|
|
|
|
|
|
+ if(sprog_waitdata(dev->port, dev->reply_time)==0)
|
|
return 0;
|
|
return 0;
|
|
fgets(buf, 4096, dev->port->f);
|
|
fgets(buf, 4096, dev->port->f);
|
|
return 1;
|
|
return 1;
|