From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/5] loadb: Use local cdev
Date: Tue, 17 Nov 2015 12:10:47 +0100 [thread overview]
Message-ID: <1447758651-26575-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1447758651-26575-1-git-send-email-s.hauer@pengutronix.de>
We already retrieve a console_device using console_get_first_active().
Use this one also to send/receive characters instead of the combined
input/output of all console devices with putc/getc.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/loadb.c | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/commands/loadb.c b/commands/loadb.c
index aabb00a..bdf1710 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -67,13 +67,24 @@ static char his_eol; /* character he needs at end of packet */
static int his_pad_count; /* number of pad chars he needs */
static char his_pad_char; /* pad chars he needs */
static char his_quote; /* quote chars he'll use */
+static struct console_device *cdev; /* The console device we are using */
+
+static void sendchar(char c)
+{
+ cdev->putc(cdev, c);
+}
+
+static int receivechar(void)
+{
+ return cdev->getc(cdev);
+}
static void send_pad(void)
{
int count = his_pad_count;
while (count-- > 0)
- console_putc(CONSOLE_STDOUT, his_pad_char);
+ sendchar(his_pad_char);
}
/* converts escaped kermit char to binary char */
@@ -100,9 +111,8 @@ static int chk1(char *buffer)
static void s1_sendpacket(char *packet)
{
send_pad();
- while (*packet) {
- console_putc(CONSOLE_STDOUT, *packet++);
- }
+ while (*packet)
+ sendchar(*packet++);
}
static char a_b[24];
@@ -397,7 +407,7 @@ static int k_recv(void)
/* get a packet */
/* wait for the starting character or ^C */
for (;;) {
- switch (getc()) {
+ switch (receivechar()) {
case START_CHAR: /* start packet */
goto START;
case ETX_CHAR: /* ^C waiting for packet */
@@ -411,13 +421,13 @@ static int k_recv(void)
START:
/* get length of packet */
sum = 0;
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
length = untochar(new_char);
/* get sequence number */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -447,7 +457,7 @@ START:
/* END NEW CODE */
/* get packet type */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -457,19 +467,19 @@ START:
if (length == -2) {
/* (length byte was 0, decremented twice) */
/* get the two length bytes */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_hi = untochar(new_char);
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_lo = untochar(new_char);
length = len_hi * 95 + len_lo;
/* check header checksum */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char !=
@@ -488,7 +498,7 @@ START:
}
}
while (length > 1) {
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -505,13 +515,13 @@ START:
}
}
/* get and validate checksum character */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
goto packet_error;
/* get END_CHAR */
- new_char = getc();
+ new_char = receivechar();
if (new_char != END_CHAR) {
packet_error:
/* restore state machines */
@@ -566,8 +576,8 @@ static ulong load_serial_bin(void)
* box some time (100 * 1 ms)
*/
for (i = 0; i < 100; ++i) {
- if (tstc())
- (void)getc();
+ if (cdev->tstc(cdev))
+ (void)receivechar();;
udelay(1000);
}
@@ -607,7 +617,6 @@ static int do_load_serial_bin(int argc, char *argv[])
int rcode = 0, ret;
int opt;
char *output_file = NULL;
- struct console_device *cdev = NULL;
while ((opt = getopt(argc, argv, "f:b:o:c")) > 0) {
switch (opt) {
--
2.6.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-11-17 11:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 11:10 loadb console cleanups Sascha Hauer
2015-11-17 11:10 ` Sascha Hauer [this message]
2015-11-17 11:10 ` [PATCH 2/5] loadb: deactivate console before using it for loadb Sascha Hauer
2015-11-17 11:10 ` [PATCH 3/5] console: Set baudrate during registration Sascha Hauer
2015-11-17 11:10 ` [PATCH 4/5] loadb: Allow to specify device to use Sascha Hauer
2015-11-17 11:10 ` [PATCH 5/5] loads: Use putchar rather than console_putc Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447758651-26575-2-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox