annotate target-utils/libcommon/cmdentry.c @ 116:22c8199e08af

started integrating TI's serial code
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 28 Oct 2013 06:49:44 +0000
parents 165040ce4929
children 17c1e2a38418
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements ASCII command entry via the serial port,
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * with normal echo and minimal editing (rubout and kill).
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 *
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * The command string buffer is bss-allocated here as well. It is
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 * sized to allow a maximum-size S-record to be sent as a command,
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 * as that is how we expect flash loading and XRAM chain-loading
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 * to be done.
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 */
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #define MAXCMD 527
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 char command[MAXCMD+1];
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 /*
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 * The command_entry() function takes no arguments, and begins by waiting
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 * for serial input - hence the prompt should be printed before calling it.
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 *
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 * This function returns when one of the following characters is received:
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 * CR - accepts the command
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 * ^C or ^U - cancels the command
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 *
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 * The return value is non-zero if a non-empty command was accepted with CR,
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 * or 0 if the user hit CR with no input or if the command was canceled
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 * with ^C or ^U. In any case a CRLF is sent out the serial port
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 * to close the input echo line before this function returns.
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 */
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 command_entry()
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 {
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 int inlen, ch;
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 for (inlen = 0; ; ) {
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 ch = mygetchar();
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 if (ch >= ' ' && ch <= '~') {
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 if (inlen < MAXCMD) {
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 command[inlen++] = ch;
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 putchar(ch);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 } else
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 putchar(7);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 continue;
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 }
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 switch (ch) {
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 case '\r':
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 case '\n':
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 command[inlen] = '\0';
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 putchar('\n');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 return(inlen);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 case '\b': /* BS */
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 case 0x7F: /* DEL */
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 if (inlen) {
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 putchar('\b');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 putchar(' ');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 putchar('\b');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 inlen--;
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 } else
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 putchar(7);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 continue;
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 case 0x03: /* ^C */
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 putchar('^');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 putchar('C');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 putchar('\n');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 return(0);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 case 0x15: /* ^U */
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 putchar('^');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 putchar('U');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 putchar('\n');
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 return(0);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 default:
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 putchar(7);
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 }
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
165040ce4929 terget-utils: command entry implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 }