]> git.cryptolib.org Git - labortage2013badge.git/blob - firmware/special_functions.S
this should work
[labortage2013badge.git] / firmware / special_functions.S
1 /* special_functions.S */
2 /*
3     This file is part of the Labotage2011_Badge.
4     Copyright (C) 2011 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/io.h>
21 #include "usbconfig.h"
22
23 .global exec_spm
24 /* void exec_spm(uint16_t z, uint16_t r0r1, void* dest, void* src, uint8_t len); */
25 exec_spm:
26         push r28
27         push r29
28         movw r30, r24
29         movw r0, r22
30         movw r28, r20
31         movw r26, r18
32         movw r24, r16
33         in r23, _SFR_IO_ADDR(SREG)
34         cli
35         tst r24
36         breq spm_cmd
37         dec r24
38         breq last_store
39 copy_loop:
40         ld r22, X+
41         st Y+, r22
42         dec r24
43         brne copy_loop
44 last_store:
45         ld r22, X+
46         st Y+, r22
47 spm_cmd:
48         spm
49         out _SFR_IO_ADDR(SREG), r23
50         clr r1
51         pop r29
52         pop r28
53         ret
54
55 .global soft_reset
56 soft_reset:
57         cli
58         andi r24, 0x0F
59         cpi r24, 0x0F
60         breq 1f
61         bst r24, 3
62         bld r24, 5
63         ori r24, 0x08
64         ldi r25, 0x18
65         or r25, r24
66         sbi _SFR_IO_ADDR(PORTB), USB_CFG_DMINUS_BIT
67         out _SFR_IO_ADDR(WDTCR), r25
68         out _SFR_IO_ADDR(WDTCR), r24
69 1:
70         rjmp 1b