annotate target-utils/libcommon/cmdentry.c @ 445:9eeeef3ff7db

os_sem_fl.c: os_QuerySemaphore() done
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 23 Jun 2014 01:19:50 +0000
parents 17c1e2a38418
children
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
125
17c1e2a38418 target-utils command input: don't emit BEL on error conditions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 12
diff changeset
39 /* putchar(7) */;
12
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
125
17c1e2a38418 target-utils command input: don't emit BEL on error conditions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 12
diff changeset
56 /* putchar(7) */;
12
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:
125
17c1e2a38418 target-utils command input: don't emit BEL on error conditions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 12
diff changeset
69 /* putchar(7) */;
12
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 }