Skip to content

Commit

Permalink
Merge branch 'feature-invert-reset'
Browse files Browse the repository at this point in the history
  • Loading branch information
msalau committed Mar 15, 2017
2 parents 8c4b1e6 + fa387c6 commit 692bcf9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 26 deletions.
13 changes: 11 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*********************************************************************************************************************
* The MIT License (MIT) *
* Copyright (c) 2012-2014 Maksim Salau *
* Copyright (c) 2012-2016 Maksim Salau *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated *
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation *
Expand Down Expand Up @@ -46,6 +46,7 @@ const char *usage =
"\t\t\tn=3 Single-wire UART, Reset by RTS\n"
"\t\t\tn=4 Two-wire UART, Reset by RTS\n"
"\t\t\tdefault: n=1\n"
"\t-n\tInvert reset\n"
"\t-p v\tSpecify power supply voltage\n"
"\t\t\tdefault: 3.3\n"
"\t-t baud\tStart terminal with specified baudrate\n"
Expand All @@ -60,14 +61,15 @@ int main(int argc, char *argv[])
char wait = 0;
char display_info = 0;
char mode = 0;
char invert_reset = 0;
int baud = 115200;
float voltage = 3.3f;
char terminal = 0;
int terminal_baud = 0;

char *endp;
int opt;
while ((opt = getopt(argc, argv, "ab:cvwrdeim:p:t:h?")) != -1)
while ((opt = getopt(argc, argv, "ab:cvwrdeim:np:t:h?")) != -1)
{
switch (opt)
{
Expand Down Expand Up @@ -139,13 +141,20 @@ int main(int argc, char *argv[])
case 'i':
display_info = 1;
break;
case 'n':
invert_reset = 1;
break;
case 'h':
case '?':
default:
printf("%s", usage);
return 0;
}
}
if (invert_reset)
{
mode |= MODE_INVERT_RESET;
}
char *portname = NULL;
char *filename = NULL;
switch (argc - optind)
Expand Down
11 changes: 10 additions & 1 deletion src/main_g10.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const char *usage =
"\t\t\tn=1 Single-wire UART, Reset by DTR\n"
"\t\t\tn=2 Single-wire UART, Reset by RTS\n"
"\t\t\tdefault: n=1\n"
"\t-n\tInvert reset\n"
"\t-t baud\tStart terminal with specified baudrate\n"
"\t-v\tVerbose mode\n"
"\t-h\tDisplay help\n";
Expand All @@ -50,12 +51,13 @@ int main(int argc, char *argv[])
char reset_after = 0;
char wait = 0;
char mode = 0;
char invert_reset = 0;
char terminal = 0;
int terminal_baud = 0;

char *endp;
int opt;
while ((opt = getopt(argc, argv, "acvwrdm:t:h?")) != -1)
while ((opt = getopt(argc, argv, "acvwrdm:nt:h?")) != -1)
{
switch (opt)
{
Expand Down Expand Up @@ -97,13 +99,20 @@ int main(int argc, char *argv[])
case 'd':
wait = 1;
break;
case 'n':
invert_reset = 1;
break;
case 'h':
case '?':
default:
printf("%s", usage);
return 0;
}
}
if (invert_reset)
{
mode |= MODE_INVERT_RESET;
}
char *portname = NULL;
char *filename = NULL;
char *codesizestr = NULL;
Expand Down
12 changes: 8 additions & 4 deletions src/rl78.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*********************************************************************************************************************
* The MIT License (MIT) *
* Copyright (c) 2012-2015 Maksim Salau *
* Copyright (c) 2012-2016 Maksim Salau *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated *
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation *
Expand Down Expand Up @@ -29,13 +29,15 @@ static unsigned char communication_mode;

static void rl78_set_reset(port_handle_t fd, int mode, int value)
{
int level = (mode & MODE_INVERT_RESET) ? !value : value;

if (MODE_RESET_RTS == (mode & MODE_RESET))
{
serial_set_rts(fd, value);
serial_set_rts(fd, level);
}
else
{
serial_set_dtr(fd, value);
serial_set_dtr(fd, level);
}
}

Expand All @@ -54,7 +56,9 @@ int rl78_reset_init(port_handle_t fd, int wait, int baud, int mode, float voltag
}
if (4 <= verbose_level)
{
printf("Using communication mode %u\n", mode + 1);
printf("Using communication mode %u%s\n",
(mode & (MODE_UART | MODE_RESET)) + 1,
(mode & MODE_INVERT_RESET) ? " with RESET inversion" : "");
}
rl78_set_reset(fd, mode, 0); /* RESET -> 0 */
serial_set_txd(fd, 0); /* TOOL0 -> 0 */
Expand Down
19 changes: 10 additions & 9 deletions src/rl78.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*********************************************************************************************************************
* The MIT License (MIT) *
* Copyright (c) 2012-2014 Maksim Salau *
* Copyright (c) 2012-2016 Maksim Salau *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated *
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation *
Expand Down Expand Up @@ -70,14 +70,15 @@
#define RL78_MIN_VOLTAGE 1.8f
#define RL78_MAX_VOLTAGE 5.5f

#define MODE_UART 1
#define MODE_UART_1 0
#define MODE_UART_2 MODE_UART
#define MODE_RESET 2
#define MODE_RESET_DTR 0
#define MODE_RESET_RTS MODE_RESET
#define MODE_MAX_VALUE (MODE_UART | MODE_RESET)
#define MODE_MIN_VALUE 0
#define MODE_UART 1
#define MODE_UART_1 0
#define MODE_UART_2 MODE_UART
#define MODE_RESET 2
#define MODE_RESET_DTR 0
#define MODE_RESET_RTS MODE_RESET
#define MODE_MAX_VALUE (MODE_UART | MODE_RESET)
#define MODE_MIN_VALUE 0
#define MODE_INVERT_RESET 0x80

#include "serial.h"

Expand Down
9 changes: 5 additions & 4 deletions src/rl78g10.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*********************************************************************************************************************
* The MIT License (MIT) *
* Copyright (c) 2014 Maksim Salau *
* Copyright (c) 2014,2016 Maksim Salau *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated *
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation *
Expand Down Expand Up @@ -47,13 +47,14 @@ static int get_size_from_code (unsigned int code)

static void rl78g10_set_reset(port_handle_t fd, int mode, int value)
{
if (MODE_RESET_RTS == mode)
int level = (mode & MODE_INVERT_RESET) ? !value : value;
if (MODE_RESET_RTS == (mode & MODE_RESET))
{
serial_set_rts(fd, value);
serial_set_rts(fd, level);
}
else
{
serial_set_dtr(fd, value);
serial_set_dtr(fd, level);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/rl78g10.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*********************************************************************************************************************
* The MIT License (MIT) *
* Copyright (c) 2014 Maksim Salau *
* Copyright (c) 2014,2016 Maksim Salau *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated *
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation *
Expand Down Expand Up @@ -42,9 +42,11 @@
#define RESPONSE_FORMAT_ERROR (-2)
#define RESPONSE_EXPECTED_LENGTH_ERROR (-3)

#define MODE_RESET_DTR 0
#define MODE_RESET_RTS 1
#define MODE_MAX_VALUE MODE_RESET_RTS
#define MODE_RESET 1
#define MODE_RESET_DTR 0
#define MODE_RESET_RTS MODE_RESET
#define MODE_MAX_VALUE MODE_RESET
#define MODE_INVERT_RESET 0x80

#include "serial.h"

Expand Down
10 changes: 8 additions & 2 deletions src/serial_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <stdio.h>

extern int verbose_level;
static int last_dtr_setting;
static int last_rts_setting;

port_handle_t serial_open(const char *port)
{
Expand Down Expand Up @@ -62,8 +64,8 @@ port_handle_t serial_open(const char *port)
dcbSerialParams.ByteSize = 8;
dcbSerialParams.StopBits = TWOSTOPBITS;
dcbSerialParams.Parity = NOPARITY;
dcbSerialParams.fDtrControl = DTR_CONTROL_DISABLE;
dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE;
last_dtr_setting = (DTR_CONTROL_ENABLE == dcbSerialParams.fDtrControl) ? SETDTR : CLRDTR;
last_rts_setting = (RTS_CONTROL_ENABLE == dcbSerialParams.fRtsControl) ? SETRTS : CLRRTS;
dcbSerialParams.fInX = FALSE;
dcbSerialParams.fOutX = FALSE;
SetCommState(fd, &dcbSerialParams);
Expand All @@ -85,6 +87,8 @@ int serial_set_baud(port_handle_t fd, int baud)
DCB dcbSerialParams;
GetCommState(fd, &dcbSerialParams);
dcbSerialParams.BaudRate = baud;
dcbSerialParams.fDtrControl = (SETDTR == last_dtr_setting) ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE;
dcbSerialParams.fRtsControl = (SETRTS == last_rts_setting) ? RTS_CONTROL_ENABLE : RTS_CONTROL_DISABLE;
return SetCommState(fd, &dcbSerialParams) != 0 ? 0 : -1;
}

Expand Down Expand Up @@ -118,6 +122,7 @@ int serial_set_dtr(port_handle_t fd, int level)
{
command = SETDTR;
}
last_dtr_setting = command;
return EscapeCommFunction(fd, command) != 0 ? 0 : -1;
}

Expand All @@ -132,6 +137,7 @@ int serial_set_rts(port_handle_t fd, int level)
{
command = SETRTS;
}
last_rts_setting = command;
return EscapeCommFunction(fd, command) != 0 ? 0 : -1;
}

Expand Down

0 comments on commit 692bcf9

Please sign in to comment.