Rev 90 | Rev 119 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 90 | Rev 110 | ||
---|---|---|---|
Line 534... | Line 534... | ||
534 | VBR_Entry_t *VBR; |
534 | VBR_Entry_t *VBR; |
535 | MBR_Entry_t *MBR; |
535 | MBR_Entry_t *MBR; |
536 | File_t *file; |
536 | File_t *file; |
537 | u8 result = 0; |
537 | u8 result = 0; |
Line 538... | Line 538... | ||
538 | 538 | ||
539 | SerialPutString("\r\n FAT16 init..."); |
539 | UART1_PutString("\r\n FAT16 init..."); |
Line 540... | Line 540... | ||
540 | Partition.IsValid = 0; |
540 | Partition.IsValid = 0; |
541 | 541 | ||
542 | // declare the filepointers as unused. |
542 | // declare the filepointers as unused. |
Line 548... | Line 548... | ||
548 | file = &FilePointer[0]; |
548 | file = &FilePointer[0]; |
Line 549... | Line 549... | ||
549 | 549 | ||
550 | // try to initialise the sd-card. |
550 | // try to initialise the sd-card. |
551 | if(SD_SUCCESS != SDC_Init()) |
551 | if(SD_SUCCESS != SDC_Init()) |
552 | { |
552 | { |
553 | SerialPutString("SD-Card could not be initialized."); |
553 | UART1_PutString("SD-Card could not be initialized."); |
554 | result = 1; |
554 | result = 1; |
555 | goto end; |
555 | goto end; |
Line 556... | Line 556... | ||
556 | } |
556 | } |
557 | 557 | ||
558 | // SD-Card is initialized successfully |
558 | // SD-Card is initialized successfully |
559 | if(SD_SUCCESS != SDC_GetSector((u32)MBR_SECTOR,file->Cache)) // Read the MasterBootRecord |
559 | if(SD_SUCCESS != SDC_GetSector((u32)MBR_SECTOR,file->Cache)) // Read the MasterBootRecord |
560 | { |
560 | { |
561 | SerialPutString("Error reading the MBR."); |
561 | UART1_PutString("Error reading the MBR."); |
562 | result = 2; |
562 | result = 2; |
563 | goto end; |
563 | goto end; |
564 | } |
564 | } |
Line 570... | Line 570... | ||
570 | // get sector offset 1st partition |
570 | // get sector offset 1st partition |
571 | partitionfirstsector = MBR->PartitionEntry1.NoSectorsBeforePartition; |
571 | partitionfirstsector = MBR->PartitionEntry1.NoSectorsBeforePartition; |
572 | // Start of Partition is the Volume Boot Sector |
572 | // Start of Partition is the Volume Boot Sector |
573 | if(SD_SUCCESS != SDC_GetSector(partitionfirstsector,file->Cache)) // Read the volume boot record |
573 | if(SD_SUCCESS != SDC_GetSector(partitionfirstsector,file->Cache)) // Read the volume boot record |
574 | { |
574 | { |
575 | SerialPutString("Error reading the VBR."); |
575 | UART1_PutString("Error reading the VBR."); |
576 | result = 3; |
576 | result = 3; |
577 | goto end; |
577 | goto end; |
578 | } |
578 | } |
579 | } |
579 | } |
580 | else // maybe the medium has no partition assuming sector 0 is the vbr |
580 | else // maybe the medium has no partition assuming sector 0 is the vbr |
Line 583... | Line 583... | ||
583 | } |
583 | } |
Line 584... | Line 584... | ||
584 | 584 | ||
585 | VBR = (VBR_Entry_t *) file->Cache; // Enter the VBR using the structure VBR_Entry_t. |
585 | VBR = (VBR_Entry_t *) file->Cache; // Enter the VBR using the structure VBR_Entry_t. |
586 | if(VBR->BytesPerSector != BYTES_PER_SECTOR) |
586 | if(VBR->BytesPerSector != BYTES_PER_SECTOR) |
587 | { |
587 | { |
588 | SerialPutString("VBR: Sector size not supported."); |
588 | UART1_PutString("VBR: Sector size not supported."); |
589 | result = 4; |
589 | result = 4; |
590 | goto end; |
590 | goto end; |
591 | } |
591 | } |
592 | Partition.SectorsPerCluster = VBR->SectorsPerCluster; // Number of sectors per cluster. Depends on the memorysize of the sd-card. |
592 | Partition.SectorsPerCluster = VBR->SectorsPerCluster; // Number of sectors per cluster. Depends on the memorysize of the sd-card. |
Line 605... | Line 605... | ||
605 | // Start + # of Reserved + (# of Sectors Per FAT * # of FAT Copies) + ((Maximum Root Directory Entries * 32) / Bytes per Sector) |
605 | // Start + # of Reserved + (# of Sectors Per FAT * # of FAT Copies) + ((Maximum Root Directory Entries * 32) / Bytes per Sector) |
606 | Partition.FirstDataSector = Partition.FirstRootDirSector + (u32)(Partition.MaxRootEntries>>4); // assuming 512 Byte Per Sector |
606 | Partition.FirstDataSector = Partition.FirstRootDirSector + (u32)(Partition.MaxRootEntries>>4); // assuming 512 Byte Per Sector |
607 | // Calculate the last data sector |
607 | // Calculate the last data sector |
608 | if(VBR->NoSectors == 0) |
608 | if(VBR->NoSectors == 0) |
609 | { |
609 | { |
610 | SerialPutString("VBR: Bad number of sectors."); |
610 | UART1_PutString("VBR: Bad number of sectors."); |
611 | result = 5; |
611 | result = 5; |
612 | goto end; |
612 | goto end; |
613 | } |
613 | } |
614 | Partition.LastDataSector = Partition.FirstDataSector + VBR->NoSectors - 1; |
614 | Partition.LastDataSector = Partition.FirstDataSector + VBR->NoSectors - 1; |
615 | // check for FAT16 in VBR of first partition |
615 | // check for FAT16 in VBR of first partition |
616 | if(!((VBR->FATName[0]=='F') && (VBR->FATName[1]=='A') && (VBR->FATName[2]=='T') && (VBR->FATName[3]=='1')&&(VBR->FATName[4]=='6'))) |
616 | if(!((VBR->FATName[0]=='F') && (VBR->FATName[1]=='A') && (VBR->FATName[2]=='T') && (VBR->FATName[3]=='1')&&(VBR->FATName[4]=='6'))) |
617 | { |
617 | { |
618 | SerialPutString("VBR: Partition ist not FAT16 type."); |
618 | UART1_PutString("VBR: Partition ist not FAT16 type."); |
619 | result = 6; |
619 | result = 6; |
620 | goto end; |
620 | goto end; |
621 | } |
621 | } |
622 | Partition.IsValid = 1; // mark data in partition structure as valid |
622 | Partition.IsValid = 1; // mark data in partition structure as valid |
623 | result = 0; |
623 | result = 0; |
624 | end: |
624 | end: |
625 | if(result != 0) Fat16_Deinit(); |
625 | if(result != 0) Fat16_Deinit(); |
626 | else SerialPutString("ok"); |
626 | else UART1_PutString("ok"); |
627 | return(result); |
627 | return(result); |
628 | } |
628 | } |