1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

Updated PIOS_Settings_CheckForFiles routine to work with DFS.

Startup procedure now waits for SD Card with the correct settings files on it.
Refactored a few global PIOS_SDCARD names.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@140 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
gussy 2010-01-25 16:30:31 +00:00 committed by gussy
parent b2c23c5473
commit 53ea65bb2f
6 changed files with 63 additions and 51 deletions

View File

@ -3,15 +3,15 @@
#include "minGlue.h"
/* Global Variables */
extern uint8_t Sector[SECTOR_SIZE];
extern VOLINFO VolInfo;
extern uint8_t PIOS_SDCARD_Sector[SECTOR_SIZE];
extern VOLINFO PIOS_SDCARD_VolInfo;
/* Local Variables */
static uint32_t SuccessCount;
int dosfs_ini_openread(const char *filename, PFILEINFO file)
{
if(DFS_OpenFile(&VolInfo, (uint8_t *)filename, DFS_READ, Sector, file)) {
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, DFS_READ, PIOS_SDCARD_Sector, file)) {
/* Error opening file */
return 0;
}
@ -23,7 +23,7 @@ int dosfs_ini_openread(const char *filename, PFILEINFO file)
int dosfs_ini_openwrite(const char *filename, PFILEINFO file)
{
/* TODO: Check this works */
if(DFS_OpenFile(&VolInfo, (uint8_t *)filename, DFS_WRITE, Sector, file)) {
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, DFS_WRITE, PIOS_SDCARD_Sector, file)) {
/* Error opening file */
return 0;
}
@ -56,7 +56,7 @@ int dosfs_ini_read(char *buffer, int size, PFILEINFO file)
int dosfs_ini_write(char *buffer, PFILEINFO file)
{
/* TODO: Check this works */
DFS_WriteFile(file, Sector, (uint8_t *)buffer, &SuccessCount, sizeof(buffer));
DFS_WriteFile(file, PIOS_SDCARD_Sector, (uint8_t *)buffer, &SuccessCount, sizeof(buffer));
/* No errors */
return 1;
@ -88,7 +88,7 @@ int dosfs_ini_remove(const char *filename)
int dosfs_ini_rewind(PFILEINFO file)
{
/* TODO: Check this works */
DFS_Seek(file, 0, Sector);
DFS_Seek(file, 0, PIOS_SDCARD_Sector);
/* No errors */
return 1;
}

View File

@ -30,10 +30,8 @@
#include "pios.h"
/* Global Variables */
VOLINFO VolInfo;
uint32_t pstart, psize;
uint8_t pactive, ptype;
uint8_t Sector[SECTOR_SIZE];
VOLINFO PIOS_SDCARD_VolInfo;
uint8_t PIOS_SDCARD_Sector[SECTOR_SIZE];
/* Local Definitions */
#if !defined(SDCARD_MUTEX_TAKE)
@ -770,21 +768,21 @@ int32_t PIOS_SDCARD_StartupLog(void)
uint32_t Cache;
/* Delete the file if it exists - ignore errors */
DFS_UnlinkFile(&VolInfo, (uint8_t *)LOG_FILENAME, Sector);
DFS_UnlinkFile(&PIOS_SDCARD_VolInfo, (uint8_t *)LOG_FILENAME, PIOS_SDCARD_Sector);
if(DFS_OpenFile(&VolInfo, (uint8_t *)LOG_FILENAME, DFS_WRITE, Sector, &File)) {
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)LOG_FILENAME, DFS_WRITE, PIOS_SDCARD_Sector, &File)) {
/* Error opening file */
return -2;
}
sprintf(Buffer, "PiOS Startup Log\r\n\r\nLog file creation completed.\r\n");
if(DFS_WriteFile(&File, Sector, (uint8_t *)Buffer, &Cache, strlen(Buffer))) {
if(DFS_WriteFile(&File, PIOS_SDCARD_Sector, (uint8_t *)Buffer, &Cache, strlen(Buffer))) {
/* Error writing to file */
return -3;
}
sprintf(Buffer, "------------------------------\r\nSD Card Information\r\n------------------------------\r\n");
if(DFS_WriteFile(&File, Sector, (uint8_t *)Buffer, &Cache, strlen(Buffer))) {
if(DFS_WriteFile(&File, PIOS_SDCARD_Sector, (uint8_t *)Buffer, &Cache, strlen(Buffer))) {
/* Error writing to file */
return -2;
}
@ -792,8 +790,8 @@ int32_t PIOS_SDCARD_StartupLog(void)
/* Disabled because it takes ca. 7 seconds with my 2GB card */
/* sprintf(Buffer, "Total Space: %u MB\r\nFree Space: %u MB\r\n", (uint16_t)((VolInfo.numclusters * (VolInfo.secperclus / 2)) / 1024), (uint16_t)(PIOS_SDCARD_GetFree() / 1048576)); */
sprintf(Buffer, "Total Space: %u MB\r\n\r\n", (uint16_t)((VolInfo.numclusters * (VolInfo.secperclus / 2)) / 1024));
if(DFS_WriteFile(&File, Sector, (uint8_t *)Buffer, &Cache, strlen(Buffer))) {
sprintf(Buffer, "Total Space: %u MB\r\n\r\n", (uint16_t)((PIOS_SDCARD_VolInfo.numclusters * (PIOS_SDCARD_VolInfo.secperclus / 2)) / 1024));
if(DFS_WriteFile(&File, PIOS_SDCARD_Sector, (uint8_t *)Buffer, &Cache, strlen(Buffer))) {
/* Error writing to file */
return -2;
}
@ -813,7 +811,10 @@ int32_t PIOS_SDCARD_StartupLog(void)
*/
int32_t PIOS_SDCARD_MountFS(uint32_t CreateStartupLog)
{
uint32_t pstart, psize;
uint8_t pactive, ptype;
uint8_t sdcard_available = 0;
sdcard_available = PIOS_SDCARD_CheckAvailable(0);
if(!sdcard_available) {
@ -821,13 +822,13 @@ int32_t PIOS_SDCARD_MountFS(uint32_t CreateStartupLog)
return -1;
}
pstart = DFS_GetPtnStart(0, Sector, 0, &pactive, &ptype, &psize);
pstart = DFS_GetPtnStart(0, PIOS_SDCARD_Sector, 0, &pactive, &ptype, &psize);
if (pstart == 0xffffffff) {
/* Cannot find first partition */
return -2;
}
if(DFS_GetVolInfo(0, Sector, pstart, &VolInfo) != DFS_OK) {
if(DFS_GetVolInfo(0, PIOS_SDCARD_Sector, pstart, &PIOS_SDCARD_VolInfo) != DFS_OK) {
/* No volume information */
return -3;
}
@ -856,9 +857,9 @@ int32_t PIOS_SDCARD_GetFree(void)
/* It takes ca. 7 seconds to determine free clusters out of ~47000 (2Gb) */
/* Scan all the clusters */
for(uint32_t i = 2; i < VolInfo.numclusters; ++i) {
if(!DFS_GetFAT(&VolInfo, Sector, &ScratchCache, i)) {
VolFreeBytes += VolInfo.secperclus * SECTOR_SIZE;
for(uint32_t i = 2; i < PIOS_SDCARD_VolInfo.numclusters; ++i) {
if(!DFS_GetFAT(&PIOS_SDCARD_VolInfo, PIOS_SDCARD_Sector, &ScratchCache, i)) {
VolFreeBytes += PIOS_SDCARD_VolInfo.secperclus * SECTOR_SIZE;
}
}
@ -875,7 +876,7 @@ int32_t PIOS_SDCARD_ReadBuffer(PFILEINFO fileinfo, uint8_t *buffer, uint32_t len
{
uint32_t SuccessCount;
if(DFS_ReadFile(fileinfo, Sector, buffer, &SuccessCount, len)) {
if(DFS_ReadFile(fileinfo, PIOS_SDCARD_Sector, buffer, &SuccessCount, len)) {
/* DFS_ReadFile failed */
return -1;
}
@ -939,14 +940,14 @@ int32_t PIOS_SDCARD_FileCopy(char *Source, char *Destination)
/* Disable caching to avoid file inconsistencies while using different sector buffers! */
DFS_CachingEnabledSet(0);
if(DFS_OpenFile(&VolInfo, (uint8_t *)Source, DFS_READ, Sector, &SourceFile)) {
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)Source, DFS_READ, PIOS_SDCARD_Sector, &SourceFile)) {
/* Source file doesn't exist */
return -1;
} else {
/* Delete destination file if it already exists - ignore errors */
DFS_UnlinkFile(&VolInfo, (uint8_t *)Destination, Sector);
DFS_UnlinkFile(&PIOS_SDCARD_VolInfo, (uint8_t *)Destination, PIOS_SDCARD_Sector);
if(DFS_OpenFile(&VolInfo, (uint8_t *)Destination, DFS_WRITE, Sector, &DestFile)) {
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)Destination, DFS_WRITE, PIOS_SDCARD_Sector, &DestFile)) {
/* Failed to create destination file */
return -2;
}
@ -957,10 +958,10 @@ int32_t PIOS_SDCARD_FileCopy(char *Source, char *Destination)
uint32_t SuccessCountRead;
uint32_t SuccessCountWrite;
do {
if(DFS_ReadFile(&SourceFile, Sector, WriteBuffer, &SuccessCountRead, SECTOR_SIZE)) {
if(DFS_ReadFile(&SourceFile, PIOS_SDCARD_Sector, WriteBuffer, &SuccessCountRead, SECTOR_SIZE)) {
/* DFS_ReadFile failed */
return -3;
} else if(DFS_WriteFile(&DestFile, Sector, WriteBuffer, &SuccessCountWrite, SuccessCountRead)) {
} else if(DFS_WriteFile(&DestFile, PIOS_SDCARD_Sector, WriteBuffer, &SuccessCountWrite, SuccessCountRead)) {
/* DFS_WriteFile failed */
return -4;
}
@ -978,7 +979,7 @@ int32_t PIOS_SDCARD_FileCopy(char *Source, char *Destination)
*/
int32_t PIOS_SDCARD_FileDelete(char *Filename)
{
if(DFS_UnlinkFile(&VolInfo, (uint8_t *)Filename, Sector)) {
if(DFS_UnlinkFile(&PIOS_SDCARD_VolInfo, (uint8_t *)Filename, PIOS_SDCARD_Sector)) {
/* Error deleting file */
return -1;
}

View File

@ -48,7 +48,7 @@ void PIOS_Settings_Load(void)
char StrBuffer[100];
long Result;
*/
/* Section: GPS */
Settings.GPS.Baudrate = (uint32_t) ini_getl("GPS", "Baudrate", GPS_BAUDRATE, SETTINGS_FILE);
@ -80,20 +80,33 @@ void PIOS_Settings_Dump(USART_TypeDef* USARTx)
*/
int32_t PIOS_Settings_CheckForFiles(void)
{
// FILINFO DummyVar;
// int MissingCount = 0;
//
// /* Check for existence of SETTINGS_FILE */
// if(f_stat(SETTINGS_FILE, &DummyVar) != FR_OK) {
// MissingCount++;
// }
//
// /* If one or more files are missing, return the number of missing files */
// if(MissingCount > 0)
// {
// return MissingCount;
// }
//
DIRINFO di;
DIRENT de;
int FoundCount = 0;
di.scratch = PIOS_SDCARD_Sector;
/* Open the root directory */
DFS_OpenDir(&PIOS_SDCARD_VolInfo, (uint8_t *)"", &di);
/* Scan the directory for all files */
while(!DFS_GetNext(&PIOS_SDCARD_VolInfo, &di, &de)) {
if(de.name[0]) {
uint8_t file_name[13];
DFS_DirToCanonical((char *)file_name, (char *)de.name);
if(strcmp((char *)file_name, SETTINGS_FILE) == 0) {
FoundCount++;
}
}
}
/* If one or more files are missing, return the number of missing files */
if(FoundCount != 1)
{
return FoundCount;
}
/* All files found */
return 0;
}

View File

@ -32,12 +32,12 @@
/* Compile Time Macros */
/* Defaults for Logging */
#define LOG_FILENAME "pios.log"
#define LOG_FILENAME "PIOS.LOG"
#define STARTUP_LOG_ENABLED 1
/* Defaults for MinIni */
#define SETTINGS_FILE "Settings.ini"
#define SETTINGS_FILE "SETTINGS.INI"
/* COM Module */
#define GPS_BAUDRATE 19200

View File

@ -81,10 +81,8 @@ typedef struct {
} SDCARDCidTypeDef;
/* Global Variables */
extern VOLINFO VolInfo;
extern uint32_t pstart, psize;
extern uint8_t pactive, ptype;
extern uint8_t Sector[SECTOR_SIZE];
extern VOLINFO PIOS_SDCARD_VolInfo;
extern uint8_t PIOS_SDCARD_Sector[SECTOR_SIZE];
/* Prototypes */
extern int32_t PIOS_SDCARD_Init(void);

View File

@ -68,8 +68,8 @@ int main()
/* Wait for SD card for ever */
for(;;)
{
/* Check if we have an SD Card */
if(!PIOS_SDCARD_MountFS(STARTUP_LOG_ENABLED)) {
/* Check if we have an SD Card with the correct settings files on it */
if(!PIOS_SDCARD_MountFS(STARTUP_LOG_ENABLED) && !PIOS_Settings_CheckForFiles()) {
/* Found one without errors */
break;
}