Conflicts resolved in simpgmspace.cpp

This commit is contained in:
bsongis@gmail.com
2013-07-13 10:58:46 +00:00
parent f3d38ab8e2
commit bd1f7b332d
+37 -33
View File
@@ -333,6 +333,16 @@ void *main_thread(void *)
#define getcwd _getcwd #define getcwd _getcwd
#endif #endif
#if defined(LUA)
extern void luaTask(void * pdata);
void *lua_thread(void *)
{
luaTask(NULL);
return NULL;
}
pthread_t lua_thread_pid;
#endif
pthread_t main_thread_pid; pthread_t main_thread_pid;
void StartMainThread(bool tests) void StartMainThread(bool tests)
{ {
@@ -340,14 +350,23 @@ void StartMainThread(bool tests)
if (strlen(simuSdDirectory) == 0) if (strlen(simuSdDirectory) == 0)
getcwd(simuSdDirectory, 1024); getcwd(simuSdDirectory, 1024);
#endif #endif
main_thread_running = (tests ? 1 : 2); main_thread_running = (tests ? 1 : 2);
pthread_create(&main_thread_pid, NULL, &main_thread, NULL); pthread_create(&main_thread_pid, NULL, &main_thread, NULL);
#if defined(LUA)
pthread_create(&lua_thread_pid, NULL, &lua_thread, NULL);
#endif
} }
void StopMainThread() void StopMainThread()
{ {
main_thread_running = 0; main_thread_running = 0;
pthread_join(main_thread_pid, NULL); pthread_join(main_thread_pid, NULL);
#if defined(LUA)
pthread_join(lua_thread_pid, NULL);
#endif
} }
pthread_t eeprom_thread_pid; pthread_t eeprom_thread_pid;
@@ -451,19 +470,21 @@ namespace simu {
FATFS g_FATFS_Obj; FATFS g_FATFS_Obj;
#endif #endif
char *convertSimuPath(const char *path)
{
static char result[1024];
if (path[0] == '/')
sprintf(result, "%s%s", simuSdDirectory, path);
else
strcpy(result, path);
return result;
}
FRESULT f_stat (const TCHAR * name, FILINFO *) FRESULT f_stat (const TCHAR * name, FILINFO *)
{ {
char path[1024];
#if defined(SDCARD)
if (name[0] == '/')
sprintf(path, "%s%s", simuSdDirectory, name);
else
strcpy(path, name);
#endif
struct stat tmp; struct stat tmp;
// printf("f_stat(%s)\n", path); fflush(stdout); // printf("f_stat(%s)\n", path); fflush(stdout);
return stat(path, &tmp) ? FR_INVALID_NAME : FR_OK; return stat(convertSimuPath(name), &tmp) ? FR_INVALID_NAME : FR_OK;
} }
FRESULT f_mount (BYTE, FATFS*) FRESULT f_mount (BYTE, FATFS*)
@@ -473,11 +494,9 @@ FRESULT f_mount (BYTE, FATFS*)
FRESULT f_open (FIL * fil, const TCHAR *name, BYTE flag) FRESULT f_open (FIL * fil, const TCHAR *name, BYTE flag)
{ {
char path[1024]; char *path = convertSimuPath(name);
if (name[0] == '/')
sprintf(path, "%s%s", simuSdDirectory, name); TRACE("f_open(%s)", path);
else
strcpy(path, name);
if (!(flag & FA_WRITE)) { if (!(flag & FA_WRITE)) {
struct stat tmp; struct stat tmp;
@@ -491,15 +510,13 @@ FRESULT f_open (FIL * fil, const TCHAR *name, BYTE flag)
FRESULT f_read (FIL* fil, void* data, UINT size, UINT* read) FRESULT f_read (FIL* fil, void* data, UINT size, UINT* read)
{ {
if (fil && fil->fs) fread(data, size, 1, (FILE*)fil->fs); if (fil && fil->fs) *read = fread(data, 1, size, (FILE*)fil->fs);
*read = size;
return FR_OK; return FR_OK;
} }
FRESULT f_write (FIL* fil, const void* data, UINT size, UINT* written) FRESULT f_write (FIL* fil, const void* data, UINT size, UINT* written)
{ {
if (fil && fil->fs) fwrite(data, size, 1, (FILE*)fil->fs); if (fil && fil->fs) *written = fwrite(data, 1, size, (FILE*)fil->fs);
*written = size;
return FR_OK; return FR_OK;
} }
@@ -520,26 +537,13 @@ FRESULT f_close (FIL * fil)
FRESULT f_chdir (const TCHAR *name) FRESULT f_chdir (const TCHAR *name)
{ {
char path[1024]; chdir(convertSimuPath(name));
if (name[0] == '/')
sprintf(path, "%s%s", simuSdDirectory, name);
else
strcpy(path, name);
chdir(path);
return FR_OK; return FR_OK;
} }
FRESULT f_opendir (DIR * rep, const TCHAR * name) FRESULT f_opendir (DIR * rep, const TCHAR * name)
{ {
char path[1024]; rep->fs = (FATFS *)simu::opendir(convertSimuPath(name));
if (name[0] == '/')
sprintf(path, "%s%s", simuSdDirectory, name);
else
strcpy(path, name);
rep->fs = (FATFS *)simu::opendir(path);
return FR_OK; return FR_OK;
} }