annotate cons.c @ 3:15d89caaf516

Add support for single UART devices, although untested apart from a compile. Doesn't break dual UART ones :) Also checks for PRR before setting it.
author darius@Inchoate
date Wed, 11 Mar 2009 17:28:39 +1030
parents 3879f487b661
children 095216e8453d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
1 /*
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
2 * Console code for AVR board
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
3 *
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
4 * Copyright (c) 2008
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
6 *
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
9 * are met:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
15 *
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
26 * SUCH DAMAGE.
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
27 */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
28
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
29 #include <ctype.h>
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
30 #include <stdio.h>
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
31 #include <stdint.h>
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
32 #include <stdlib.h>
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
33 #include <avr/interrupt.h>
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
34 #include <avr/pgmspace.h>
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
35 #include "cons.h"
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
36
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
37 #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
38
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
39 #ifdef UBRR0
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
40 #define DUALUART
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
41 #endif
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
42
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
43 /* Receive buffer storage */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
44 consbuf_t cmd;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
45
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
46 /*
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
47 * Stub to use with fdevopen
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
48 *
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
49 * We ignore f and always succeed
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
50 */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
51 static int _putc(char c, FILE *f) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
52 cons_putc(c);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
53 return(0);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
54 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
55
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
56 /*
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
57 * Stub to use with fdevopen
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
58 *
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
59 * We ignore f and always succeed
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
60 */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
61 static int _getc(FILE *f) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
62 return(cons_getc());
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
63 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
64
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
65 void
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
66 cons_init(void) {
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
67 #ifdef DUALUART
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
68 UBRR0 = UART_BAUD_SELECT(38400, F_CPU);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
69
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
70 /* Enable receiver and transmitter. Turn on rx interrupts */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
71 UCSR0A = 0;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
72 UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
73 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
74 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
75 UBRRH = UART_BAUD_SELECT(38400, F_CPU) >> 8;
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
76 UBRRL = (uint8_t)UART_BAUD_SELECT(38400, F_CPU);
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
77
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
78 /* Enable receiver and transmitter. Turn on rx interrupts */
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
79 UCSRA = 0;
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
80 UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE);
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
81 UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
82 #endif
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
83
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
84 fdevopen(_putc, NULL); /* Open stdout */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
85 fdevopen(NULL, _getc); /* Open stdin */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
86 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
87
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
88 int
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
89 cons_putc(char c) {
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
90 #ifdef DUALUART
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
91 loop_until_bit_is_set(UCSR0A, UDRE0);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
92 UDR0 = c;
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
93 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
94 loop_until_bit_is_set(UCSRA, UDRE);
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
95 UDR = c;
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
96 #endif
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
97
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
98 return(0);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
99 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
100
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
101 void
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
102 cons_putsP(const char *addr) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
103 char c;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
104
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
105 while ((c = pgm_read_byte_near(addr++)))
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
106 cons_putc(c);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
107 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
108
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
109 void
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
110 cons_puts(const char *addr) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
111 while (*addr)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
112 cons_putc(*addr++);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
113 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
114
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
115 void
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
116 cons_puts_dec(uint8_t a, uint8_t l) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
117 char s[4];
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
118
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
119 if (l && a < 10)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
120 cons_putsP(PSTR("0"));
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
121 cons_puts(utoa(a, s, 10));
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
122 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
123
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
124 void
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
125 cons_puts_hex(uint8_t a) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
126 char s[3];
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
127
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
128 if (a < 0x10)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
129 cons_putc('0');
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
130
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
131 cons_puts(utoa(a, s, 16));
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
132 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
133
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
134 char
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
135 cons_getc(void) {
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
136 #ifdef DUALUART
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
137 while (!(UCSR0A & _BV(RXC0)))
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
138 ;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
139 return (UDR0);
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
140 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
141 while (!(UCSRA & _BV(RXC)))
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
142 ;
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
143 return (UDR);
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
144 #endif
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
145 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
146
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
147 /* Rx complete */
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
148 #ifdef DUALUART
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
149 ISR(USART0_RX_vect) {
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
150 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
151 ISR(USART_RXC_vect) {
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
152 #endif
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
153 char c;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
154
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
155 #ifdef DUALUART
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
156 while (UCSR0A & _BV(RXC0)) {
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
157 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
158 while (UCSRA & _BV(RXC)) {
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
159 #endif
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
160
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
161 #ifdef DUALUART
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
162 c = UDR0;
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
163 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
164 c = UDR;
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
165 #endif
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
166 /* 255 means we're waiting for main to process the command,
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
167 * just throw stuff away
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
168 */
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
169 if (cmd.state == 255)
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
170 continue;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
171
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
172 /* End of line? */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
173 if (c == '\n' || c == '\r') {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
174 cmd.buf[cmd.state] = '\0';
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
175 printf_P(PSTR("\r\n"));
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
176 cmd.len = cmd.state;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
177 cmd.state = 255;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
178 continue;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
179 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
180
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
181 /* Backspace/delete */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
182 if (c == 0x08 || c == 0x7f) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
183 if (cmd.state > 0) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
184 cmd.state--;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
185 printf_P(PSTR("\010\040\010"));
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
186 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
187 continue;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
188 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
189
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
190 /* Anything unprintable just ignore it */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
191 if (!isprint(c))
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
192 continue;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
193
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
194 cmd.buf[cmd.state] = tolower(c);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
195
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
196 /* Echo back to the user */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
197 cons_putc(cmd.buf[cmd.state]);
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
198
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
199 cmd.state++;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
200 /* Over flow? */
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
201 if (cmd.state == ((sizeof(cmd.buf) / sizeof(cmd.buf[0])) - 1)) {
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
202 printf_P(PSTR("\r\nLine too long"));
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
203 cmd.state = 0;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
204 continue;
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
205 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
206 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
207 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
208
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
209 /* Tx complete */
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
210 #ifdef DUALUART
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
211 ISR(USART0_TX_vect) {
3
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
212 #else
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
213 ISR(USART_TXC_vect) {
15d89caaf516 Add support for single UART devices, although untested apart from a compile.
darius@Inchoate
parents: 0
diff changeset
214 #endif
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
215 }
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
216