diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2013-03-09 10:51:19 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2013-03-09 10:51:19 +0000 |
commit | d5d83b8e8f8238114426a0ca4476062cdc765ea1 (patch) | |
tree | 6448f033322b6f20c5175d1e74cf6f581cde46bb /Bootloaders/Incomplete/MassStorage | |
parent | 726b325c73d2f6a2a733e67d1dad9fa7aedef1c0 (diff) | |
download | lufa-d5d83b8e8f8238114426a0ca4476062cdc765ea1.tar.gz lufa-d5d83b8e8f8238114426a0ca4476062cdc765ea1.tar.bz2 lufa-d5d83b8e8f8238114426a0ca4476062cdc765ea1.zip |
Add LED flashing to the incomplete Mass Storage class bootloader. Clean up virtual FAT implementation.
Diffstat (limited to 'Bootloaders/Incomplete/MassStorage')
-rw-r--r-- | Bootloaders/Incomplete/MassStorage/BootloaderMassStorage.c | 13 | ||||
-rw-r--r-- | Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c | 40 |
2 files changed, 28 insertions, 25 deletions
diff --git a/Bootloaders/Incomplete/MassStorage/BootloaderMassStorage.c b/Bootloaders/Incomplete/MassStorage/BootloaderMassStorage.c index 14d1eb076..40f13b3e6 100644 --- a/Bootloaders/Incomplete/MassStorage/BootloaderMassStorage.c +++ b/Bootloaders/Incomplete/MassStorage/BootloaderMassStorage.c @@ -30,8 +30,7 @@ /** \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. + * Main source file for the Mass Storage class bootloader. This file contains the complete bootloader logic. */ #include "BootloaderMassStorage.h" @@ -96,6 +95,16 @@ void SetupHardware(void) /* Hardware Initialization */ LEDs_Init(); USB_Init(); + + /* Bootloader active LED toggle timer initialization */ + TIMSK1 = (1 << TOIE1); + TCCR1B = ((1 << CS11) | (1 << CS10)); +} + +/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */ +ISR(TIMER1_OVF_vect, ISR_BLOCK) +{ + LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2); } /** Event handler for the library USB Connection event. */ diff --git a/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c b/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c index 5d91cefaf..85f274bfa 100644 --- a/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c +++ b/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c @@ -57,14 +57,14 @@ static const FATBootBlock_t BootBlock = static FATDirectoryEntry_t FirmwareFileEntry = { - .Filename = "FIRMWARE", - .Extension = "BIN", - .Attributes = 0, - .Reserved = {0}, - .CreationTime = FAT_TIME(1, 1, 0), - .CreationDate = FAT_DATE(14, 2, 1989), - .StartingCluster = 2, - .FileSizeBytes = FIRMWARE_FILE_SIZE, + .Filename = "FIRMWARE", + .Extension = "BIN", + .Attributes = 0, + .Reserved = {0}, + .CreationTime = FAT_TIME(1, 1, 0), + .CreationDate = FAT_DATE(14, 2, 1989), + .StartingCluster = 2, + .FileSizeBytes = FIRMWARE_FILE_SIZE, }; @@ -94,10 +94,7 @@ static void WriteBlock(const uint16_t BlockNumber) { uint8_t BlockBuffer[SECTOR_SIZE_BYTES]; - /* Wait until endpoint is ready before continuing */ - if (Endpoint_WaitUntilReady()) - return; - + /* Buffer the entire block to be written from the host */ Endpoint_Read_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL); Endpoint_ClearOUT(); @@ -139,12 +136,12 @@ static void ReadBlock(const uint16_t BlockNumber) switch (BlockNumber) { - case 0: + case 0: /* Block 0: Boot block sector */ memcpy(BlockBuffer, &BootBlock, sizeof(FATBootBlock_t)); break; - case 1: - case 2: + case 1: /* Block 1: First FAT12 cluster chain copy */ + case 2: /* Block 2: Second FAT12 cluster chain copy */ /* Cluster 0: Media type/Reserved */ UpdateFAT12ClusterEntry(BlockBuffer, 0, 0xF00 | BootBlock.MediaDescriptor); @@ -159,11 +156,11 @@ static void ReadBlock(const uint16_t BlockNumber) UpdateFAT12ClusterEntry(BlockBuffer, FILE_CLUSTERS(FIRMWARE_FILE_SIZE) + 1, 0xFFF); break; - case 3: + case 3: /* Block 3: Root file entries */ memcpy(BlockBuffer, &FirmwareFileEntry, sizeof(FATDirectoryEntry_t)); break; - default: + default: /* Blocks 4 onwards: Data allocation section */ if ((BlockNumber >= 4) && (BlockNumber < (4 + (FIRMWARE_FILE_SIZE / SECTOR_SIZE_BYTES)))) { uint32_t ReadFlashAddress = (uint32_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES; @@ -175,10 +172,7 @@ static void ReadBlock(const uint16_t BlockNumber) break; } - /* Wait until endpoint is ready before continuing */ - if (Endpoint_WaitUntilReady()) - return; - + /* Write the entire read block Buffer to the host */ Endpoint_Write_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL); Endpoint_ClearIN(); } @@ -190,7 +184,7 @@ void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, uint16_t CurrentBlock = (uint16_t)BlockAddress; /* Emulated FAT is performed per-block, pass each requested block index - * to the emulation function */ + * to the emulated FAT block write function */ while (TotalBlocks--) WriteBlock(CurrentBlock++); } @@ -202,7 +196,7 @@ void VirtualFAT_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo, uint16_t CurrentBlock = (uint16_t)BlockAddress; /* Emulated FAT is performed per-block, pass each requested block index - * to the emulation function */ + * to the emulated FAT block read function */ while (TotalBlocks--) ReadBlock(CurrentBlock++); } |