3 Copyright (C) Dean Camera, 2013.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2013 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * Main source file for the Mass Storage class bootloader. This file contains the complete bootloader logic.
36 #include "BootloaderMassStorage.h"
38 /** LUFA Mass Storage Class driver interface configuration and state information. This structure is
39 * passed to all Mass Storage Class driver functions, so that multiple instances of the same class
40 * within a device can be differentiated from one another.
42 USB_ClassInfo_MS_Device_t Disk_MS_Interface
=
49 .Address
= MASS_STORAGE_IN_EPADDR
,
50 .Size
= MASS_STORAGE_IO_EPSIZE
,
55 .Address
= MASS_STORAGE_OUT_EPADDR
,
56 .Size
= MASS_STORAGE_IO_EPSIZE
,
64 /** Main program entry point. This routine contains the overall program flow, including initial
65 * setup of all components and the main program loop.
71 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
72 GlobalInterruptEnable();
76 MS_Device_USBTask(&Disk_MS_Interface
);
81 /** Configures the board hardware and chip peripherals for the demo's functionality. */
82 void SetupHardware(void)
84 /* Disable watchdog if enabled by bootloader/fuses */
85 MCUSR
&= ~(1 << WDRF
);
88 /* Disable clock division */
89 clock_prescale_set(clock_div_1
);
91 /* Relocate the interrupt vector table to the bootloader section */
95 /* Hardware Initialization */
99 /* Bootloader active LED toggle timer initialization */
100 TIMSK1
= (1 << TOIE1
);
101 TCCR1B
= ((1 << CS11
) | (1 << CS10
));
104 /** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */
105 ISR(TIMER1_OVF_vect
, ISR_BLOCK
)
107 LEDs_ToggleLEDs(LEDS_LED1
| LEDS_LED2
);
110 /** Event handler for the library USB Connection event. */
111 void EVENT_USB_Device_Connect(void)
113 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
116 /** Event handler for the library USB Disconnection event. */
117 void EVENT_USB_Device_Disconnect(void)
119 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
122 /** Event handler for the library USB Configuration Changed event. */
123 void EVENT_USB_Device_ConfigurationChanged(void)
125 bool ConfigSuccess
= true;
127 ConfigSuccess
&= MS_Device_ConfigureEndpoints(&Disk_MS_Interface
);
129 LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY
: LEDMASK_USB_ERROR
);
132 /** Event handler for the library USB Control Request reception event. */
133 void EVENT_USB_Device_ControlRequest(void)
135 MS_Device_ProcessControlRequest(&Disk_MS_Interface
);
138 /** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
140 * \param[in] MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
142 bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t
* const MSInterfaceInfo
)
146 LEDs_SetAllLEDs(LEDMASK_USB_BUSY
);
147 CommandSuccess
= SCSI_DecodeSCSICommand(MSInterfaceInfo
);
148 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
150 return CommandSuccess
;