Browse Source

Fix FAT16 detection

main
PaulStoffregen 9 years ago
parent
commit
c4530cbc40
3 changed files with 12 additions and 8 deletions
  1. +1
    -1
      SD_t3.h
  2. +8
    -4
      cache_t3.cpp
  3. +3
    -3
      init_t3.cpp

+ 1
- 1
SD_t3.h View File

// This Teensy 3.x optimized version is a work-in-progress. // This Teensy 3.x optimized version is a work-in-progress.
// Uncomment this line to use the Teensy version. Otherwise, // Uncomment this line to use the Teensy version. Otherwise,
// the normal SD library is used. // the normal SD library is used.
#define USE_TEENSY3_OPTIMIZED_CODE
//#define USE_TEENSY3_OPTIMIZED_CODE


/* Why reinvent the SD library wheel... /* Why reinvent the SD library wheel...
* 1: Allow reading files from within interrupts * 1: Allow reading files from within interrupts

+ 8
- 4
cache_t3.cpp View File

#define CACHE_FLAG_IS_DIRTY 2 #define CACHE_FLAG_IS_DIRTY 2
#define CACHE_FLAG_IS_FAT 4 #define CACHE_FLAG_IS_FAT 4


/*
//#define PRINT_SECTORS

#ifdef PRINT_SECTORS
static void print_sector(const void *data) static void print_sector(const void *data)
{ {
const uint8_t *p = (const uint8_t *)data; const uint8_t *p = (const uint8_t *)data;
if ((i & 31) == 31) Serial.println(); if ((i & 31) == 31) Serial.println();
} }
} }
*/
#endif


// Read a sector into the cache. If the sector is already cached, // Read a sector into the cache. If the sector is already cached,
// of course no actual read occurs. This is the primary function // of course no actual read occurs. This is the primary function
c->flags = CACHE_FLAG_HAS_DATA; c->flags = CACHE_FLAG_HAS_DATA;
if (is_fat) c->flags |= CACHE_FLAG_IS_FAT; if (is_fat) c->flags |= CACHE_FLAG_IS_FAT;
ret = &c->data; ret = &c->data;
//Serial.printf("cache read %u\n", lba);
//print_sector(&c->data);
#ifdef PRINT_SECTORS
Serial.printf("cache read %u\n", lba);
print_sector(&c->data);
#endif
} }
} }
} }

+ 3
- 3
init_t3.cpp View File

//Serial.printf(" sectors_per_fat = %d\n", sectors_per_fat); //Serial.printf(" sectors_per_fat = %d\n", sectors_per_fat);
uint32_t root_dir_entries = unaligned_read16_align8(vol->u8 + BPB_RootEntCnt); uint32_t root_dir_entries = unaligned_read16_align8(vol->u8 + BPB_RootEntCnt);
//Serial.printf(" root_dir_entries = %d\n", root_dir_entries); //Serial.printf(" root_dir_entries = %d\n", root_dir_entries);
uint32_t root_dir_sectors = (root_dir_entries + 31) >> 5;
uint32_t root_dir_sectors = (root_dir_entries + 15) >> 4;
//Serial.printf(" root_dir_sectors = %d\n", root_dir_sectors); //Serial.printf(" root_dir_sectors = %d\n", root_dir_sectors);


uint32_t total_sectors = unaligned_read16_align8(vol->u8 + BPB_TotSec16); uint32_t total_sectors = unaligned_read16_align8(vol->u8 + BPB_TotSec16);


fat1_begin_lba = partition_lba + reserved_sectors; fat1_begin_lba = partition_lba + reserved_sectors;
fat2_begin_lba = fat1_begin_lba + sectors_per_fat; fat2_begin_lba = fat1_begin_lba + sectors_per_fat;
data_begin_lba = fat2_begin_lba + sectors_per_fat;
data_begin_lba = fat2_begin_lba + sectors_per_fat + root_dir_sectors;


uint32_t cluster_count = (total_sectors - reserved_sectors uint32_t cluster_count = (total_sectors - reserved_sectors
- root_dir_sectors - (sectors_per_fat << 1)) >> s2c; - root_dir_sectors - (sectors_per_fat << 1)) >> s2c;
} else if (cluster_count < 65525) { } else if (cluster_count < 65525) {
fat_type = 16; fat_type = 16;
rootDir.length = root_dir_entries << 5; rootDir.length = root_dir_entries << 5;
rootDir.start_cluster = partition_lba + reserved_sectors;
rootDir.start_cluster = partition_lba + reserved_sectors + sectors_per_fat * 2;
rootDir.type = FILE_DIR_ROOT16; rootDir.type = FILE_DIR_ROOT16;
} else { } else {
fat_type = 32; fat_type = 32;

Loading…
Cancel
Save