You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.0 KiB
132 lines
4.0 KiB
16 years ago
|
/*
|
||
|
LUFA Library
|
||
|
Copyright (C) Dean Camera, 2009.
|
||
|
|
||
|
dean [at] fourwalledcubicle [dot] com
|
||
|
www.fourwalledcubicle.com
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||
|
|
||
|
Permission to use, copy, modify, and distribute this software
|
||
|
and its documentation for any purpose and without fee is hereby
|
||
|
granted, provided that the above copyright notice appear in all
|
||
|
copies and that both that the copyright notice and this
|
||
|
permission notice and warranty disclaimer appear in supporting
|
||
|
documentation, and that the name of the author not be used in
|
||
|
advertising or publicity pertaining to distribution of the
|
||
|
software without specific, written prior permission.
|
||
|
|
||
|
The author disclaim all warranties with regard to this
|
||
|
software, including all implied warranties of merchantability
|
||
|
and fitness. In no event shall the author be liable for any
|
||
|
special, indirect or consequential damages or any damages
|
||
|
whatsoever resulting from loss of use, data or profits, whether
|
||
|
in an action of contract, negligence or other tortious action,
|
||
|
arising out of or in connection with the use or performance of
|
||
|
this software.
|
||
|
*/
|
||
|
|
||
16 years ago
|
/** \file
|
||
|
*
|
||
|
* Main source file for the MassStorage demo. This file contains the main tasks of
|
||
|
* the demo and is responsible for the initial application hardware configuration.
|
||
|
*/
|
||
|
|
||
16 years ago
|
#include "MassStorage.h"
|
||
|
|
||
16 years ago
|
/** LUFA Mass Storage Class driver interface configuration and state information. This structure is
|
||
|
* passed to all Mass Storage Class driver functions, so that multiple instances of the same class
|
||
|
* within a device can be differentiated from one another.
|
||
|
*/
|
||
16 years ago
|
USB_ClassInfo_MS_t Disk_MS_Interface =
|
||
|
{
|
||
|
.InterfaceNumber = 0,
|
||
16 years ago
|
|
||
16 years ago
|
.DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
|
||
|
.DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||
16 years ago
|
|
||
16 years ago
|
.DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
|
||
|
.DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
|
||
16 years ago
|
|
||
16 years ago
|
.TotalLUNs = TOTAL_LUNS,
|
||
|
};
|
||
16 years ago
|
|
||
16 years ago
|
/** Main program entry point. This routine contains the overall program flow, including initial
|
||
|
* setup of all components and the main program loop.
|
||
|
*/
|
||
16 years ago
|
int main(void)
|
||
16 years ago
|
{
|
||
|
SetupHardware();
|
||
|
|
||
|
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||
|
|
||
|
for (;;)
|
||
|
{
|
||
|
USB_MS_USBTask(&Disk_MS_Interface);
|
||
|
USB_USBTask();
|
||
|
}
|
||
|
}
|
||
|
|
||
16 years ago
|
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||
16 years ago
|
void SetupHardware(void)
|
||
16 years ago
|
{
|
||
|
/* Disable watchdog if enabled by bootloader/fuses */
|
||
|
MCUSR &= ~(1 << WDRF);
|
||
|
wdt_disable();
|
||
|
|
||
16 years ago
|
/* Disable clock division */
|
||
|
clock_prescale_set(clock_div_1);
|
||
16 years ago
|
|
||
|
/* Hardware Initialization */
|
||
|
LEDs_Init();
|
||
|
Dataflash_Init(SPI_SPEED_FCPU_DIV_2);
|
||
16 years ago
|
USB_Init();
|
||
16 years ago
|
|
||
|
/* Clear Dataflash sector protections, if enabled */
|
||
|
DataflashManager_ResetDataflashProtections();
|
||
|
}
|
||
|
|
||
16 years ago
|
/** Event handler for the library USB Connection event. */
|
||
16 years ago
|
void EVENT_USB_Connect(void)
|
||
16 years ago
|
{
|
||
16 years ago
|
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
|
||
16 years ago
|
}
|
||
|
|
||
16 years ago
|
/** Event handler for the library USB Disconnection event. */
|
||
16 years ago
|
void EVENT_USB_Disconnect(void)
|
||
16 years ago
|
{
|
||
16 years ago
|
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
|
||
16 years ago
|
}
|
||
|
|
||
16 years ago
|
/** Event handler for the library USB Configuration Changed event. */
|
||
16 years ago
|
void EVENT_USB_ConfigurationChanged(void)
|
||
16 years ago
|
{
|
||
16 years ago
|
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||
16 years ago
|
|
||
16 years ago
|
if (!(USB_MS_ConfigureEndpoints(&Disk_MS_Interface)))
|
||
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
||
16 years ago
|
}
|
||
|
|
||
16 years ago
|
/** Event handler for the library USB Unhandled Control Packet event. */
|
||
16 years ago
|
void EVENT_USB_UnhandledControlPacket(void)
|
||
16 years ago
|
{
|
||
16 years ago
|
USB_MS_ProcessControlPacket(&Disk_MS_Interface);
|
||
16 years ago
|
}
|
||
|
|
||
16 years ago
|
/** Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.
|
||
|
*
|
||
|
* \param MSInterfaceInfo Pointer to the Mass Storage class interface configuration structure being referenced
|
||
|
*/
|
||
16 years ago
|
bool CALLBACK_USB_MS_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo)
|
||
16 years ago
|
{
|
||
16 years ago
|
bool CommandSuccess;
|
||
16 years ago
|
|
||
16 years ago
|
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
|
||
|
CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
|
||
|
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||
16 years ago
|
|
||
16 years ago
|
return CommandSuccess;
|
||
16 years ago
|
}
|