1 /*******************************************************************
2 Copyright (C) 2008 FreakLabs
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 Please post support questions to the FreakLabs forum.
19 *******************************************************************/
21 \defgroup hw_at90usb Hardware - AT90USB
25 /*******************************************************************/
27 #include <avr/interrupt.h>
29 #include <avr/pgmspace.h>
33 /**************************************************************************/
35 Initialize the hardware.
36 1) Turn off the watchdog timer (in AVR MCUs)
38 3) Enable the USB and relevant peripherals
39 4) Enable the global interrupt.
41 /**************************************************************************/
44 MCUSR
&= ~(1 << WDRF
);
50 // config PLL and turn it on
51 PLLCSR
= (1 << PLLP1
) | (1 << PLLP0
);
52 PLLCSR
|= (1 << PLLE
);
55 // enable the USB block
56 USBCON
|= ((1 << USBE
) | (1 << OTGPADE
));
59 USBCON
&= ~(1 << FRZCLK
);
64 // set the interrupts: vbus, suspend, and end of reset
65 USBCON
|= (1 << VBUSTE
);
66 UDIEN
|= (1 << SUSPE
) | (1 << EORSTE
);
68 // set the interrupts: vbus, suspend, and end of reset
69 UDIEN
|= (_BV(SUSPE
) | _BV(EORSTE
));
71 // enable vbus sense pin
72 VBUS_SENSE_DDR
&= ~_BV(VBUS_SENSE_IO
);
73 VBUS_SENSE_PORT
&= ~_BV(VBUS_SENSE_IO
);
75 // enable the vbus sense interrupt
78 // disable the usb interface
81 // enable the usb interface
85 // turn on the global interrupts
89 /**************************************************************************/
91 Returns a byte stored in the flash. Some MCUs can't access the flash
92 memory from a standard pointer so they need a special function to handle it.
94 /**************************************************************************/
95 U8
hw_flash_get_byte(U8
*addr
)
97 return pgm_read_byte(addr
);
100 /**************************************************************************/
102 Disable global interrupts
104 /**************************************************************************/
105 void hw_intp_disable()
110 /**************************************************************************/
112 Enable global interrupts
114 /**************************************************************************/
115 void hw_intp_enable()