Skip to content

Commit

Permalink
Added FAT filesystem commands
Browse files Browse the repository at this point in the history
 For traversing directories and READING from the filesystem 'ls', 'cd', 'pwd' and 'cat. Also added visual code configuration project files for Lab20 console application.
  • Loading branch information
sean-lawless committed Sep 1, 2024
1 parent d507f05 commit 78e96b8
Show file tree
Hide file tree
Showing 18 changed files with 604 additions and 44 deletions.
30 changes: 30 additions & 0 deletions Lab20 Mass Storage/applications/console/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "GDB attach to openocd",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\console.elf",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "gdb-multiarch.exe",
"miDebuggerServerAddress": "127.0.0.1:3333"
}
]
}
3 changes: 3 additions & 0 deletions Lab20 Mass Storage/applications/console/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.makefilePath": "."
}
34 changes: 34 additions & 0 deletions Lab20 Mass Storage/applications/console/console.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"folders": [
{
"path": "."
},
{
"path": "../../boards"
},
{
"path": "../../fat"
},
{
"path": "../../include"
},
{
"path": "../../system"
},
{
"path": "../../usb"
}
],
"settings": {
"makefile.launchConfigurations": [
{
"cwd": "e:\\Source\\computersystems\\Lab20 Mass Storage\\applications\\console",
"binaryPath": "e:\\Source\\computersystems\\Lab20 Mass Storage\\applications\\console\\console.elf",
"binaryArgs": []
}
],
"files.associations": {
"system.h": "c"
}
}
}
12 changes: 2 additions & 10 deletions Lab20 Mass Storage/applications/console/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ i8 MountedPartition = 0;
i8 PartitionToMount = -1;
struct partition partitions[4];

void read_sector_callback(u8 *buffer, int buffLen, void *unused)
static void read_sector_callback(u8 *buffer, int buffLen, void *unused)
{
int i;

Expand Down Expand Up @@ -222,28 +222,20 @@ int MountFilesystem(char *command)
else
PartitionToMount = 0;

// Create the polling task and initialize the FAT file system
#if ENABLE_OS
TaskNew(MAX_TASKS - 4, FatPoll, NULL);
#endif
FatInit();

/*
// Seek to first block, the MBR
MassStorageSeek(0);

// Read the Master Boot Record (MBR)
if (MassStorageRead(ReadSector, 512, read_sector_callback, NULL) <= 0)
puts("MassStorageRead failed");
*/
}
else
puts("USB not initialized");

return TASK_FINISHED;
}

int ReadFilesystem(const char *command)
int ReadBlock(const char *command)
{
if (UsbUp)
{
Expand Down
41 changes: 41 additions & 0 deletions Lab20 Mass Storage/boards/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
],
"version": "2.0.0"
}
2 changes: 1 addition & 1 deletion Lab20 Mass Storage/boards/peripherals/dwc/transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void TransferStageDataAttach(TransferStageData *transfer, u32 channel,
assert (transfer->bufferPointer != 0);
else
transfer->bufferPointer = &transfer->TempBuffer;
assert (((u32) transfer->bufferPointer & 3) == 0);
assert (((uintptr_t)transfer->bufferPointer & 3) == 0);

if (transfer->splitTransaction)
{
Expand Down
28 changes: 28 additions & 0 deletions Lab20 Mass Storage/boards/rpi/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,31 @@ u32 __aeabi_uidiv(u32 value, u32 divisor)
// Use the division modulus, ignoring/truncating the remainder
return __aeabi_uidivmod(value, divisor);
};

// ARM EABI signed integer division support for GCC
i32 __aeabi_idiv(i32 value, i32 divisor)
{
u32 v, div;
int result;

// Remove the negative attributes and convert to u32
if (divisor < 0)
div = (u32)-divisor;
else
div = (u32)divisor;
if (value < 0)
v = (u32)-value;
else
v = (u32)value;

// Use the division modulus, ignoring/truncating the remainder
result = (i32)__aeabi_uidivmod(v, div);

// Add back the negative attribute
if (divisor < 0)
result = -result;
if (value < 0)
result = -result;

return result;
};
7 changes: 3 additions & 4 deletions Lab20 Mass Storage/fat/asyncfatfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ typedef enum {
} afatfsInitializationPhase_e;

typedef struct afatfs_t {
uint8_t cache[AFATFS_SECTOR_SIZE * AFATFS_NUM_CACHE_SECTORS];
afatfsCacheBlockDescriptor_t cacheDescriptor[AFATFS_NUM_CACHE_SECTORS];
fatFilesystemType_e filesystemType;

afatfsFilesystemState_e filesystemState;
Expand All @@ -440,8 +442,6 @@ typedef struct afatfs_t {
} initState;
#endif

uint8_t cache[AFATFS_SECTOR_SIZE * AFATFS_NUM_CACHE_SECTORS];
afatfsCacheBlockDescriptor_t cacheDescriptor[AFATFS_NUM_CACHE_SECTORS];
uint32_t cacheTimer;

int cacheDirtyEntries; // The number of cache entries in the AFATFS_CACHE_STATE_DIRTY state
Expand Down Expand Up @@ -1617,8 +1617,6 @@ static afatfsOperationStatus_e afatfs_appendRegularFreeCluster(afatfsFilePtr_t f
return afatfs_appendRegularFreeClusterContinue(file);
}

#ifdef AFATFS_USE_FREEFILE

/**
* Size of a AFATFS supercluster in bytes
*/
Expand All @@ -1628,6 +1626,7 @@ uint32_t afatfs_superClusterSize()
return afatfs_fatEntriesPerSector() * afatfs_clusterSize();
}

#ifdef AFATFS_USE_FREEFILE
/**
* Continue to attempt to add a supercluster to the end of the given file.
*
Expand Down
1 change: 1 addition & 0 deletions Lab20 Mass Storage/fat/asyncfatfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ 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_feof(afatfsFilePtr_t file);

bool afatfs_mkdir(const char *filename, afatfsFileCallback_t complete);
bool afatfs_chdir(afatfsFilePtr_t dirHandle);
Expand Down
Loading

0 comments on commit 78e96b8

Please sign in to comment.