Permalink
Browse files

Add baudrate option

  • Loading branch information...
1 parent 20fca4e commit 73a007bbd041fdd93cfb801ef532abfc3426465c @msalau committed Aug 2, 2012
Showing with 37 additions and 7 deletions.
  1. +32 −4 src/main.c
  2. +4 −2 src/rl78.c
  3. +1 −1 src/rl78.h
View
36 src/main.c
@@ -41,9 +41,11 @@ int main(int argc, char *argv[])
char write = 0;
char reset_after = 0;
char display_info = 0;
+ int baud = 500000;
+ char *endp;
int opt;
- while ((opt = getopt(argc, argv, "avwcreih?")) != -1)
+ while ((opt = getopt(argc, argv, "ab:cvwreih?")) != -1)
{
switch (opt)
{
@@ -53,6 +55,14 @@ int main(int argc, char *argv[])
verify = 1;
reset_after = 1;
break;
+ case 'b':
+ baud = strtoul(optarg, &endp, 10);
+ if (optarg == endp)
+ {
+ printf("%s", usage);
+ return 0;
+ }
+ break;
case 'v':
++verbose_level;
break;
@@ -126,9 +136,27 @@ int main(int argc, char *argv[])
|| 1 == verify
|| 1 == display_info)
{
- rl78_reset_init(fd);
- rl78_cmd_reset(fd);
- rl78_cmd_silicon_signature(fd, device_name, &code_size, &data_size);
+ rc = rl78_reset_init(fd, baud);
+ if (0 > rc)
+ {
+ fprintf(stderr, "Initialization failed\n");
+ serial_close(fd);
+ return rc;
+ }
+ rc = rl78_cmd_reset(fd);
+ if (0 > rc)
+ {
+ fprintf(stderr, "Synchronization failed\n");
+ serial_close(fd);
+ return rc;
+ }
+ rc = rl78_cmd_silicon_signature(fd, device_name, &code_size, &data_size);
+ if (0 > rc)
+ {
+ fprintf(stderr, "Silicon signature read failed\n");
+ serial_close(fd);
+ return rc;
+ }
}
if (1 == display_info)
{
View
6 src/rl78.c
@@ -26,7 +26,7 @@
extern int verbose_level;
-int rl78_reset_init(int fd)
+int rl78_reset_init(int fd, int baud)
{
serial_set_dtr(fd, 0);
serial_set_rts(fd, 0);
@@ -45,7 +45,7 @@ int rl78_reset_init(int fd)
rc = serial_read(fd, &r, 1);
serial_sync(fd);
usleep(1000);
- return rl78_cmd_baud_rate_set(fd, 115200, 3300);
+ return rl78_cmd_baud_rate_set(fd, baud, 3300);
}
int rl78_reset(int fd)
@@ -188,6 +188,7 @@ int rl78_cmd_baud_rate_set(int fd, int baud, int voltage)
default:
buf[0] = BAUD_115200;
new_baud = B115200;
+ baud = 115200;
break;
/* case 250000:
* buf[0] = BAUD_250000;
@@ -227,6 +228,7 @@ int rl78_cmd_baud_rate_set(int fd, int baud, int voltage)
printf("\tFrequency: %u MHz\n", data[1]);
printf("\tMode: %s\n", 0 == data[2] ? "full-speed mode" : "wide-voltage mode");
}
+ serial_set_baud(fd, new_baud);
return 0;
}
View
2 src/rl78.h
@@ -64,7 +64,7 @@
#define RESPONSE_FORMAT_ERROR (-2)
#define RESPONSE_EXPECTED_LENGTH_ERROR (-3)
-int rl78_reset_init(int fd);
+int rl78_reset_init(int fd, int baud);
int rl78_reset(int fd);
int rl78_send_cmd(int fd, int cmd, const void *data, int len);
int rl78_send_data(int fd, const void *data, int len, int last);

0 comments on commit 73a007b

Please sign in to comment.