Commit bb7314b8 authored by Martin Budden's avatar Martin Budden Committed by GitHub
Browse files

Merge pull request #278 from martinbudden/inav_target_mk

Converted to using target.mk files
parents 9cda676b 5faaae24
This diff is collapsed.
This diff is collapsed.
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
typedef struct sdcardMetadata_t {
uint8_t manufacturerID;
uint16_t oemID;
char productName[5];
uint8_t productRevisionMajor;
uint8_t productRevisionMinor;
uint32_t productSerial;
uint16_t productionYear;
uint8_t productionMonth;
uint32_t numBlocks; /* Card capacity in 512-byte blocks*/
} sdcardMetadata_t;
typedef enum {
SDCARD_BLOCK_OPERATION_READ,
SDCARD_BLOCK_OPERATION_WRITE,
SDCARD_BLOCK_OPERATION_ERASE,
} sdcardBlockOperation_e;
typedef enum {
SDCARD_OPERATION_IN_PROGRESS,
SDCARD_OPERATION_BUSY,
SDCARD_OPERATION_SUCCESS,
SDCARD_OPERATION_FAILURE
} sdcardOperationStatus_e;
typedef void(*sdcard_operationCompleteCallback_c)(sdcardBlockOperation_e operation, uint32_t blockIndex, uint8_t *buffer, uint32_t callbackData);
typedef void(*sdcard_profilerCallback_c)(sdcardBlockOperation_e operation, uint32_t blockIndex, uint32_t duration);
void sdcard_init(bool useDMA);
bool sdcard_readBlock(uint32_t blockIndex, uint8_t *buffer, sdcard_operationCompleteCallback_c callback, uint32_t callbackData);
sdcardOperationStatus_e sdcard_beginWriteBlocks(uint32_t blockIndex, uint32_t blockCount);
sdcardOperationStatus_e sdcard_writeBlock(uint32_t blockIndex, uint8_t *buffer, sdcard_operationCompleteCallback_c callback, uint32_t callbackData);
void sdcardInsertionDetectDeinit(void);
void sdcardInsertionDetectInit(void);
bool sdcard_isInserted();
bool sdcard_isInitialized();
bool sdcard_isFunctional();
bool sdcard_poll();
const sdcardMetadata_t* sdcard_getMetadata();
void sdcard_setProfilerCallback(sdcard_profilerCallback_c callback);
#include <stdint.h>
#include "sdcard_standard.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/**
* Read a bitfield from an array of bits (the bit at index 0 being the most-significant bit of the first byte in
* the buffer).
*/
uint32_t readBitfield(uint8_t *buffer, unsigned bitIndex, unsigned bitLen)
{
uint32_t result = 0;
unsigned bitInByteOffset = bitIndex % 8;
uint8_t bufferByte;
buffer += bitIndex / 8;
// Align the bitfield to be read to the top of the buffer
bufferByte = *buffer << bitInByteOffset;
while (bitLen > 0) {
unsigned bitsThisLoop = MIN(8 - bitInByteOffset, bitLen);
result = (result << bitsThisLoop) | (bufferByte >> (8 - bitsThisLoop));
buffer++;
bufferByte = *buffer;
bitLen -= bitsThisLoop;
bitInByteOffset = 0;
}
return result;
}
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
typedef struct sdcardCSD_t {
uint8_t data[16];
} sdcardCSD_t;
#define SDCARD_GET_CSD_FIELD(csd, version, fieldname) \
readBitfield(csd.data, SDCARD_CSD_V ## version ## _ ## fieldname ## _OFFSET, SDCARD_CSD_V ## version ## _ ## fieldname ## _LEN)
// For v1 and Standard Capacity cards
#define SDCARD_CSD_V1_CSD_STRUCTURE_VER_OFFSET 0
#define SDCARD_CSD_V1_CSD_STRUCTURE_VER_LEN 2
#define SDCARD_CSD_V1_TAAC_OFFSET 8
#define SDCARD_CSD_V1_TAAC_LEN 8
#define SDCARD_CSD_V1_NSAC_OFFSET 16
#define SDCARD_CSD_V1_NSAC_LEN 8
#define SDCARD_CSD_V1_TRAN_SPEED_OFFSET 24
#define SDCARD_CSD_V1_TRAN_SPEED_LEN 8
#define SDCARD_CSD_V1_CCC_OFFSET 32
#define SDCARD_CSD_V1_CCC_LEN 12
#define SDCARD_CSD_V1_READ_BLOCK_LEN_OFFSET 44
#define SDCARD_CSD_V1_READ_BLOCK_LEN_LEN 4
#define SDCARD_CSD_V1_READ_BLOCK_PARTIAL_ALLOWED_OFFSET 48
#define SDCARD_CSD_V1_READ_BLOCK_PARTIAL_ALLOWED_LEN 1
#define SDCARD_CSD_V1_WRITE_BLOCK_MISALIGN_OFFSET 49
#define SDCARD_CSD_V1_WRITE_BLOCK_MISALIGN_LEN 1
#define SDCARD_CSD_V1_READ_BLOCK_MISALIGN_OFFSET 50
#define SDCARD_CSD_V1_READ_BLOCK_MISALIGN_LEN 1
#define SDCARD_CSD_V1_DSR_IMPLEMENTED_OFFSET 51
#define SDCARD_CSD_V1_DSR_IMPLEMENTED_LEN 1
#define SDCARD_CSD_V1_CSIZE_OFFSET 54
#define SDCARD_CSD_V1_CSIZE_LEN 12
#define SDCARD_CSD_V1_VDD_READ_CURR_MIN_OFFSET 66
#define SDCARD_CSD_V1_VDD_READ_CURR_MIN_LEN 3
#define SDCARD_CSD_V1_VDD_READ_CURR_MAX_OFFSET 69
#define SDCARD_CSD_V1_VDD_READ_CURR_MAX_LEN 3
#define SDCARD_CSD_V1_VDD_WRITE_CURR_MIN_OFFSET 72
#define SDCARD_CSD_V1_VDD_WRITE_CURR_MIN_LEN 3
#define SDCARD_CSD_V1_VDD_WRITE_CURR_MAX_OFFSET 75
#define SDCARD_CSD_V1_VDD_WRITE_CURR_MAX_LEN 3
#define SDCARD_CSD_V1_CSIZE_MULT_OFFSET 78
#define SDCARD_CSD_V1_CSIZE_MULT_LEN 3
#define SDCARD_CSD_V1_ERASE_SINGLE_BLOCK_ALLOWED_OFFSET 81
#define SDCARD_CSD_V1_ERASE_SINGLE_BLOCK_ALLOWED_LEN 1
#define SDCARD_CSD_V1_SECTOR_SIZE_OFFSET 82
#define SDCARD_CSD_V1_SECTOR_SIZE_LEN 7
#define SDCARD_CSD_V1_WRITE_PROTECT_GROUP_SIZE_OFFSET 89
#define SDCARD_CSD_V1_WRITE_PROTECT_GROUP_SIZE_LEN 7
#define SDCARD_CSD_V1_WRITE_PROTECT_GROUP_ENABLE_OFFSET 96
#define SDCARD_CSD_V1_WRITE_PROTECT_GROUP_ENABLE_LEN 1
#define SDCARD_CSD_V1_R2W_FACTOR_OFFSET 99
#define SDCARD_CSD_V1_R2W_FACTOR_LEN 3
#define SDCARD_CSD_V1_WRITE_BLOCK_LEN_OFFSET 102
#define SDCARD_CSD_V1_WRITE_BLOCK_LEN_LEN 4
#define SDCARD_CSD_V1_WRITE_BLOCK_PARTIAL_ALLOWED_OFFSET 106
#define SDCARD_CSD_V1_WRITE_BLOCK_PARTIAL_ALLOWED_LEN 1
#define SDCARD_CSD_V1_FILE_FORMAT_GROUP_OFFSET 112
#define SDCARD_CSD_V1_FILE_FORMAT_GROUP_LEN 1
#define SDCARD_CSD_V1_COPY_OFFSET 113
#define SDCARD_CSD_V1_COPY_LEN 1
#define SDCARD_CSD_V1_PERMANENT_WRITE_PROTECT_OFFSET 114
#define SDCARD_CSD_V1_PERMANENT_WRITE_PROTECT_LEN 1
#define SDCARD_CSD_V1_TEMPORARY_WRITE_PROTECT_OFFSET 115
#define SDCARD_CSD_V1_TEMPORARY_WRITE_PROTECT_LEN 1
#define SDCARD_CSD_V1_FILE_FORMAT_OFFSET 116
#define SDCARD_CSD_V1_FILE_FORMAT_LEN 2
#define SDCARD_CSD_V1_CRC_OFFSET 120
#define SDCARD_CSD_V1_CRC_LEN 7
#define SDCARD_CSD_V1_TRAILER_OFFSET 127
#define SDCARD_CSD_V1_TRAILER_LEN 1
// For v2 High Capacity cards
#define SDCARD_CSD_V2_CSD_STRUCTURE_VER_OFFSET 0
#define SDCARD_CSD_V2_CSD_STRUCTURE_VER_LEN 2
#define SDCARD_CSD_V2_TAAC_OFFSET 8
#define SDCARD_CSD_V2_TAAC_LEN 8
#define SDCARD_CSD_V2_NSAC_OFFSET 16
#define SDCARD_CSD_V2_NSAC_LEN 8
#define SDCARD_CSD_V2_TRAN_SPEED_OFFSET 24
#define SDCARD_CSD_V2_TRAN_SPEED_LEN 8
#define SDCARD_CSD_V2_CCC_OFFSET 32
#define SDCARD_CSD_V2_CCC_LEN 12
#define SDCARD_CSD_V2_READ_BLOCK_LEN_OFFSET 44
#define SDCARD_CSD_V2_READ_BLOCK_LEN_LEN 4
#define SDCARD_CSD_V2_READ_BLOCK_PARTIAL_ALLOWED_OFFSET 48
#define SDCARD_CSD_V2_READ_BLOCK_PARTIAL_ALLOWED_LEN 1
#define SDCARD_CSD_V2_WRITE_BLOCK_MISALIGN_OFFSET 49
#define SDCARD_CSD_V2_WRITE_BLOCK_MISALIGN_LEN 1
#define SDCARD_CSD_V2_READ_BLOCK_MISALIGN_OFFSET 50
#define SDCARD_CSD_V2_READ_BLOCK_MISALIGN_LEN 1
#define SDCARD_CSD_V2_DSR_IMPLEMENTED_OFFSET 51
#define SDCARD_CSD_V2_DSR_IMPLEMENTED_LEN 1
#define SDCARD_CSD_V2_CSIZE_OFFSET 58
#define SDCARD_CSD_V2_CSIZE_LEN 22
#define SDCARD_CSD_V2_ERASE_SINGLE_BLOCK_ALLOWED_OFFSET 81
#define SDCARD_CSD_V2_ERASE_SINGLE_BLOCK_ALLOWED_LEN 1
#define SDCARD_CSD_V2_SECTOR_SIZE_OFFSET 82
#define SDCARD_CSD_V2_SECTOR_SIZE_LEN 7
#define SDCARD_CSD_V2_WRITE_PROTECT_GROUP_SIZE_OFFSET 89
#define SDCARD_CSD_V2_WRITE_PROTECT_GROUP_SIZE_LEN 7
#define SDCARD_CSD_V2_WRITE_PROTECT_GROUP_ENABLE_OFFSET 96
#define SDCARD_CSD_V2_WRITE_PROTECT_GROUP_ENABLE_LEN 1
#define SDCARD_CSD_V2_R2W_FACTOR_OFFSET 99
#define SDCARD_CSD_V2_R2W_FACTOR_LEN 3
#define SDCARD_CSD_V2_WRITE_BLOCK_LEN_OFFSET 102
#define SDCARD_CSD_V2_WRITE_BLOCK_LEN_LEN 4
#define SDCARD_CSD_V2_WRITE_BLOCK_PARTIAL_ALLOWED_OFFSET 106
#define SDCARD_CSD_V2_WRITE_BLOCK_PARTIAL_ALLOWED_LEN 1
#define SDCARD_CSD_V2_FILE_FORMAT_GROUP_OFFSET 112
#define SDCARD_CSD_V2_FILE_FORMAT_GROUP_LEN 1
#define SDCARD_CSD_V2_COPY_OFFSET 113
#define SDCARD_CSD_V2_COPY_LEN 1
#define SDCARD_CSD_V2_PERMANENT_WRITE_PROTECT_OFFSET 114
#define SDCARD_CSD_V2_PERMANENT_WRITE_PROTECT_LEN 1
#define SDCARD_CSD_V2_TEMPORARY_WRITE_PROTECT_OFFSET 115
#define SDCARD_CSD_V2_TEMPORARY_WRITE_PROTECT_LEN 1
#define SDCARD_CSD_V2_FILE_FORMAT_OFFSET 116
#define SDCARD_CSD_V2_FILE_FORMAT_LEN 2
#define SDCARD_CSD_V2_CRC_OFFSET 120
#define SDCARD_CSD_V2_CRC_LEN 7
#define SDCARD_CSD_V2_TRAILER_OFFSET 127
#define SDCARD_CSD_V2_TRAILER_LEN 1
#define SDCARD_SINGLE_BLOCK_READ_START_TOKEN 0xFE
#define SDCARD_SINGLE_BLOCK_WRITE_START_TOKEN 0xFE
#define SDCARD_MULTIPLE_BLOCK_WRITE_START_TOKEN 0xFC
#define SDCARD_MULTIPLE_BLOCK_WRITE_STOP_TOKEN 0xFD
#define SDCARD_BLOCK_SIZE 512
// Idle bit is set to 1 only when idle during intialization phase:
#define SDCARD_R1_STATUS_BIT_IDLE 1
#define SDCARD_R1_STATUS_BIT_ERASE_RESET 2
#define SDCARD_R1_STATUS_BIT_ILLEGAL_COMMAND 4
#define SDCARD_R1_STATUS_BIT_COM_CRC_ERROR 8
#define SDCARD_R1_STATUS_BIT_ERASE_SEQUENCE_ERROR 16
#define SDCARD_R1_STATUS_BIT_ADDRESS_ERROR 32
#define SDCARD_R1_STATUS_BIT_PARAMETER_ERROR 64
#define SDCARD_CSD_STRUCTURE_VERSION_1 0
#define SDCARD_CSD_STRUCTURE_VERSION_2 1
#define SDCARD_VOLTAGE_ACCEPTED_2_7_to_3_6 0x01
#define SDCARD_VOLTAGE_ACCEPTED_LVR 0x02
#define SDCARD_COMMAND_GO_IDLE_STATE 0
#define SDCARD_COMMAND_SEND_OP_COND 1
#define SDCARD_COMMAND_SEND_IF_COND 8
#define SDCARD_COMMAND_SEND_CSD 9
#define SDCARD_COMMAND_SEND_CID 10
#define SDCARD_COMMAND_STOP_TRANSMISSION 12
#define SDCARD_COMMAND_SEND_STATUS 13
#define SDCARD_COMMAND_SET_BLOCKLEN 16
#define SDCARD_COMMAND_READ_SINGLE_BLOCK 17
#define SDCARD_COMMAND_READ_MULTIPLE_BLOCK 18
#define SDCARD_COMMAND_WRITE_BLOCK 24
#define SDCARD_COMMAND_WRITE_MULTIPLE_BLOCK 25
#define SDCARD_COMMAND_APP_CMD 55
#define SDCARD_COMMAND_READ_OCR 58
#define SDCARD_ACOMMAND_SEND_OP_COND 41
#define SDCARD_ACOMMAND_SET_WR_BLOCK_ERASE_COUNT 23
// These are worst-case timeouts defined for High Speed cards
#define SDCARD_TIMEOUT_READ_MSEC 100
#define SDCARD_TIMEOUT_WRITE_MSEC 250
uint32_t readBitfield(uint8_t *buffer, unsigned bitIndex, unsigned bitLen);
This diff is collapsed.
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "fat_standard.h"
typedef struct afatfsFile_t *afatfsFilePtr_t;
typedef enum {
AFATFS_FILESYSTEM_STATE_UNKNOWN,
AFATFS_FILESYSTEM_STATE_FATAL,
AFATFS_FILESYSTEM_STATE_INITIALIZATION,
AFATFS_FILESYSTEM_STATE_READY,
} afatfsFilesystemState_e;
typedef enum {
AFATFS_OPERATION_IN_PROGRESS,
AFATFS_OPERATION_SUCCESS,
AFATFS_OPERATION_FAILURE,
} afatfsOperationStatus_e;
typedef enum {
AFATFS_ERROR_NONE = 0,
AFATFS_ERROR_GENERIC = 1,
AFATFS_ERROR_BAD_MBR = 2,
AFATFS_ERROR_BAD_FILESYSTEM_HEADER = 3
} afatfsError_e;
typedef struct afatfsDirEntryPointer_t {
uint32_t sectorNumberPhysical;
int16_t entryIndex;
} afatfsDirEntryPointer_t;
typedef afatfsDirEntryPointer_t afatfsFinder_t;
typedef enum {
AFATFS_SEEK_SET,
AFATFS_SEEK_CUR,
AFATFS_SEEK_END,
} afatfsSeek_e;
typedef void (*afatfsFileCallback_t)(afatfsFilePtr_t file);
typedef void (*afatfsCallback_t)();
bool afatfs_fopen(const char *filename, const char *mode, afatfsFileCallback_t complete);
bool afatfs_ftruncate(afatfsFilePtr_t file, afatfsFileCallback_t callback);
bool afatfs_fclose(afatfsFilePtr_t file, afatfsCallback_t callback);
bool afatfs_funlink(afatfsFilePtr_t file, afatfsCallback_t callback);
bool afatfs_feof(afatfsFilePtr_t file);
void afatfs_fputc(afatfsFilePtr_t file, uint8_t c);
uint32_t afatfs_fwrite(afatfsFilePtr_t file, const uint8_t *buffer, uint32_t len);
uint32_t afatfs_fread(afatfsFilePtr_t file, uint8_t *buffer, uint32_t len);
afatfsOperationStatus_e afatfs_fseek(afatfsFilePtr_t file, int32_t offset, afatfsSeek_e whence);
bool afatfs_ftell(afatfsFilePtr_t file, uint32_t *position);
bool afatfs_mkdir(const char *filename, afatfsFileCallback_t complete);
bool afatfs_chdir(afatfsFilePtr_t dirHandle);
void afatfs_findFirst(afatfsFilePtr_t directory, afatfsFinder_t *finder);
afatfsOperationStatus_e afatfs_findNext(afatfsFilePtr_t directory, afatfsFinder_t *finder, fatDirectoryEntry_t **dirEntry);
void afatfs_findLast(afatfsFilePtr_t directory);
bool afatfs_flush();
void afatfs_init();
bool afatfs_destroy(bool dirty);
void afatfs_poll();
uint32_t afatfs_getFreeBufferSpace();
uint32_t afatfs_getContiguousFreeSpace();
bool afatfs_isFull();
afatfsFilesystemState_e afatfs_getFilesystemState();
afatfsError_e afatfs_getLastError();
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include "fat_standard.h"
bool fat16_isEndOfChainMarker(uint16_t clusterNumber)
{
return clusterNumber >= 0xFFF8;
}
// Pass the cluster number after fat32_decodeClusterNumber().
bool fat32_isEndOfChainMarker(uint32_t clusterNumber)
{
return clusterNumber >= 0x0FFFFFF8;
}
/**
* FAT32 cluster numbers are really only 28 bits, and the top 4 bits must be left alone and not treated as part of the
* cluster number (so various FAT drivers can use those bits for their own purposes, or they can be used in later
* extensions)
*/
uint32_t fat32_decodeClusterNumber(uint32_t clusterNumber)
{
return clusterNumber & 0x0FFFFFFF;
}
// fat32 needs fat32_decodeClusterNumber() applied first.
bool fat_isFreeSpace(uint32_t clusterNumber)
{
return clusterNumber == 0;
}
bool fat_isDirectoryEntryTerminator(fatDirectoryEntry_t *entry)
{
return entry->filename[0] == 0x00;
}
bool fat_isDirectoryEntryEmpty(fatDirectoryEntry_t *entry)
{
return (unsigned char) entry->filename[0] == FAT_DELETED_FILE_MARKER;
}
/**
* Convert the given "prefix.ext" style filename to the FAT format to be stored on disk.
*
* fatFilename must point to a buffer which is FAT_FILENAME_LENGTH bytes long. The buffer is not null-terminated.
*/
void fat_convertFilenameToFATStyle(const char *filename, uint8_t *fatFilename)
{
for (int i = 0; i < 8; i++) {
if (*filename == '\0' || *filename == '.') {
*fatFilename = ' ';
} else {
*fatFilename = toupper((unsigned char)*filename);
filename++;
}
fatFilename++;
}
if (*filename == '.') {
filename++;
}
for (int i = 0; i < 3; i++) {
if (*filename == '\0') {
*fatFilename = ' ';
} else {
*fatFilename = toupper((unsigned char)*filename);
filename++;
}
fatFilename++;
}
}
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#define MBR_PARTITION_TYPE_FAT16 0x06
#define MBR_PARTITION_TYPE_FAT32 0x0B
#define MBR_PARTITION_TYPE_FAT32_LBA 0x0C
#define MBR_PARTITION_TYPE_FAT16_LBA 0x0E
// Signature bytes found at index 510 and 511 in the volume ID sector
#define FAT_VOLUME_ID_SIGNATURE_1 0x55
#define FAT_VOLUME_ID_SIGNATURE_2 0xAA
#define FAT_DIRECTORY_ENTRY_SIZE 32
#define FAT_SMALLEST_LEGAL_CLUSTER_NUMBER 2
#define FAT_MAXIMUM_FILESIZE 0xFFFFFFFF
#define FAT12_MAX_CLUSTERS 4084
#define FAT16_MAX_CLUSTERS 65524
#define FAT_FILE_ATTRIBUTE_READ_ONLY 0x01
#define FAT_FILE_ATTRIBUTE_HIDDEN 0x02
#define FAT_FILE_ATTRIBUTE_SYSTEM 0x04
#define FAT_FILE_ATTRIBUTE_VOLUME_ID 0x08
#define FAT_FILE_ATTRIBUTE_DIRECTORY 0x10
#define FAT_FILE_ATTRIBUTE_ARCHIVE 0x20
#define FAT_FILENAME_LENGTH 11
#define FAT_DELETED_FILE_MARKER 0xE5
#define FAT_MAKE_DATE(year, month, day) (day | (month << 5) | ((year - 1980) << 9))
#define FAT_MAKE_TIME(hour, minute, second) ((second / 2) | (minute << 5) | (hour << 11))
typedef enum {
FAT_FILESYSTEM_TYPE_INVALID,
FAT_FILESYSTEM_TYPE_FAT12,
FAT_FILESYSTEM_TYPE_FAT16,
FAT_FILESYSTEM_TYPE_FAT32,
} fatFilesystemType_e;
typedef struct mbrPartitionEntry_t {
uint8_t bootFlag;
uint8_t chsBegin[3];
uint8_t type;
uint8_t chsEnd[3];
uint32_t lbaBegin;
uint32_t numSectors;
} __attribute__((packed)) mbrPartitionEntry_t;
typedef struct fat16Descriptor_t {
uint8_t driveNumber;
uint8_t reserved1;
uint8_t bootSignature;
uint32_t volumeID;
char volumeLabel[11];
char fileSystemType[8];
} __attribute__((packed)) fat16Descriptor_t;
typedef struct fat32Descriptor_t {
uint32_t FATSize32;
uint16_t extFlags;
uint16_t fsVer;
uint32_t rootCluster;
uint16_t fsInfo;
uint16_t backupBootSector;