]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/cli-basics.S
backporting uart_i and cli
[avr-crypto-lib.git] / test_src / cli-basics.S
1 /* cli-basics.S */
2 /*
3     This file is part of the AVR-Huffman.
4     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "avr-asm-macros.S"
21
22 .extern cli_tx
23 .extern cli_rx
24 .extern cli_echo
25
26 /******************************************************************************/
27 .global cli_putc
28 cli_putc:
29         lds r30, cli_tx
30         lds r31, cli_tx+1
31         adiw r30, 0
32         breq 2f
33         ijmp
34
35 /******************************************************************************/
36 .global cli_getc
37 cli_getc:
38         lds r30, cli_rx
39         lds r31, cli_rx+1
40         adiw r30, 0
41         breq 1f
42         ijmp
43 1:
44         ser r24
45         ser r25
46 2:
47         ret
48
49 /******************************************************************************/
50 .global cli_getc_cecho
51 cli_getc_cecho:
52         lds r30, cli_rx
53         lds r31, cli_rx+1
54         adiw r30, 0
55         brne 1f
56         ser r25
57         ser r24
58         ret
59 1:      
60         icall
61         lds r20, cli_echo
62         tst r20
63         brne 2f
64         ret
65 2:      
66         push r2
67         mov r2, r24
68         rcall cli_putc
69         mov r24, r2
70         clr r25
71         pop r2
72         ret
73         
74 /******************************************************************************/
75 .global cli_putstr
76 cli_putstr:
77         push r28
78         push r29
79         movw r28, r24
80 1:
81         ld r24, Y+
82         clr r25
83         tst r24
84         breq 2f
85         rcall cli_putc
86         rjmp 1b
87 2:      
88         pop r29
89         pop r28
90         ret
91
92 /******************************************************************************/
93 .global cli_putstr_P
94 cli_putstr_P:
95         push r28
96         push r29
97         movw r28, r24
98 1:
99         movw r30, r28
100         lpm r24, Z
101         clr r25
102         tst r24
103         breq 2f
104         rcall cli_putc
105         adiw r28, 1
106         rjmp 1b
107 2:      
108         pop r29
109         pop r28
110         ret
111
112 /******************************************************************************/
113 /*
114  * param s: r24:r25
115  * param n: r22:r23
116  */     
117 .global cli_getsn
118 cli_getsn:
119         push r28
120         push r29
121         push r16
122         push r17
123         movw r28, r24
124         ldi r20, 2
125         movw r24, r22
126         adiw r24, 0
127         breq 9f
128 1:
129         movw r16, r22
130 2:      clr r20
131         rcall cli_getc
132         cpi r24, '\r'
133         breq 9f
134         ldi r20, 1
135         tst r24
136         breq 9f
137         st Y+, r24
138         movw r26, r16
139         sbiw r26, 1
140         movw r16, r24
141         brne 2b
142 9:      
143         clr r25
144         mov r24, r20
145         st Y, r1
146         pop r17
147         pop r16
148         pop r28
149         pop r29
150         ret