summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/common/dir_uncached.c10
-rw-r--r--firmware/common/dircache.c79
-rw-r--r--firmware/common/file.c8
-rw-r--r--firmware/common/filefuncs.c9
-rw-r--r--firmware/export/audio.h5
-rw-r--r--firmware/export/config.h2
-rw-r--r--firmware/export/filefuncs.h3
-rw-r--r--firmware/export/kernel.h6
-rw-r--r--firmware/general.c2
-rw-r--r--firmware/include/dir.h13
-rw-r--r--firmware/include/dir_uncached.h26
-rw-r--r--firmware/include/dircache.h10
-rw-r--r--firmware/include/file.h2
-rw-r--r--firmware/kernel.c3
-rw-r--r--firmware/target/hosted/android/dir-target.h37
-rw-r--r--firmware/target/hosted/android/fs-android.c129
-rw-r--r--firmware/target/hosted/android/lc-android.c40
18 files changed, 297 insertions, 89 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index f83b78970e..8b71674b36 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1703,7 +1703,9 @@ target/coldfire/mpio/fmradio_i2c-mpio.c
1703 1703
1704 1704
1705#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 1705#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
1706target/hosted/android/fs-android.c
1706target/hosted/android/lcd-android.c 1707target/hosted/android/lcd-android.c
1708target/hosted/android/lc-android.c
1707target/hosted/android/button-android.c 1709target/hosted/android/button-android.c
1708target/hosted/android/kernel-android.c 1710target/hosted/android/kernel-android.c
1709target/hosted/android/pcm-android.c 1711target/hosted/android/pcm-android.c
diff --git a/firmware/common/dir_uncached.c b/firmware/common/dir_uncached.c
index e3e33a4c11..2ce23e8b8e 100644
--- a/firmware/common/dir_uncached.c
+++ b/firmware/common/dir_uncached.c
@@ -171,7 +171,7 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir)
171 if (fat_ismounted(dir->volumecounter)) 171 if (fat_ismounted(dir->volumecounter))
172 { 172 {
173 memset(theent, 0, sizeof(*theent)); 173 memset(theent, 0, sizeof(*theent));
174 theent->attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; 174 theent->info.attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME;
175 snprintf(theent->d_name, sizeof(theent->d_name), 175 snprintf(theent->d_name, sizeof(theent->d_name),
176 VOL_NAMES, dir->volumecounter); 176 VOL_NAMES, dir->volumecounter);
177 return theent; 177 return theent;
@@ -187,11 +187,11 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir)
187 return NULL; 187 return NULL;
188 188
189 strlcpy(theent->d_name, entry.name, sizeof(theent->d_name)); 189 strlcpy(theent->d_name, entry.name, sizeof(theent->d_name));
190 theent->attribute = entry.attr; 190 theent->info.attribute = entry.attr;
191 theent->size = entry.filesize; 191 theent->info.wrtdate = entry.wrtdate;
192 theent->info.wrttime = entry.wrttime;
193 theent->info.size = entry.filesize;
192 theent->startcluster = entry.firstcluster; 194 theent->startcluster = entry.firstcluster;
193 theent->wrtdate = entry.wrtdate;
194 theent->wrttime = entry.wrttime;
195 195
196 return theent; 196 return theent;
197} 197}
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 4ae8d805dd..509743bdbb 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -237,19 +237,19 @@ static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce
237 !strcmp("..", sab.direntry->name)) 237 !strcmp("..", sab.direntry->name))
238 continue; 238 continue;
239 239
240 ce->attribute = sab.direntry->attr;
241 ce->name_len = strlen(sab.direntry->name) + 1; 240 ce->name_len = strlen(sab.direntry->name) + 1;
242 ce->d_name = ((char *)dircache_root + dircache_size); 241 ce->d_name = ((char *)dircache_root + dircache_size);
243 ce->startcluster = sab.direntry->firstcluster; 242 ce->startcluster = sab.direntry->firstcluster;
244 ce->size = sab.direntry->filesize; 243 ce->info.size = sab.direntry->filesize;
245 ce->wrtdate = sab.direntry->wrtdate; 244 ce->info.attribute = sab.direntry->attr;
246 ce->wrttime = sab.direntry->wrttime; 245 ce->info.wrtdate = sab.direntry->wrtdate;
246 ce->info.wrttime = sab.direntry->wrttime;
247 memcpy(ce->d_name, sab.direntry->name, ce->name_len); 247 memcpy(ce->d_name, sab.direntry->name, ce->name_len);
248 248
249 dircache_size += ce->name_len; 249 dircache_size += ce->name_len;
250 entry_count++; 250 entry_count++;
251 251
252 if(ce->attribute & FAT_ATTR_DIRECTORY) 252 if(ce->info.attribute & FAT_ATTR_DIRECTORY)
253 dircache_gen_down(ce); 253 dircache_gen_down(ce);
254 254
255 ce = dircache_gen_next(ce); 255 ce = dircache_gen_next(ce);
@@ -269,18 +269,18 @@ static int sab_process_dir(unsigned long startcluster, struct dircache_entry *ce
269 /* add "." and ".." */ 269 /* add "." and ".." */
270 ce->d_name = "."; 270 ce->d_name = ".";
271 ce->name_len = 2; 271 ce->name_len = 2;
272 ce->attribute = FAT_ATTR_DIRECTORY; 272 ce->info.attribute = FAT_ATTR_DIRECTORY;
273 ce->startcluster = startcluster; 273 ce->startcluster = startcluster;
274 ce->size = 0; 274 ce->info.size = 0;
275 ce->down = first_ce; 275 ce->down = first_ce;
276 276
277 ce = dircache_gen_next(ce); 277 ce = dircache_gen_next(ce);
278 278
279 ce->d_name = ".."; 279 ce->d_name = "..";
280 ce->name_len = 3; 280 ce->name_len = 3;
281 ce->attribute = FAT_ATTR_DIRECTORY; 281 ce->info.attribute = FAT_ATTR_DIRECTORY;
282 ce->startcluster = (first_ce->up ? first_ce->up->startcluster : 0); 282 ce->startcluster = (first_ce->up ? first_ce->up->startcluster : 0);
283 ce->size = 0; 283 ce->info.size = 0;
284 ce->down = first_ce->up; 284 ce->down = first_ce->up;
285 285
286 /* second pass: recurse ! */ 286 /* second pass: recurse ! */
@@ -311,8 +311,8 @@ static int dircache_scan_and_build(IF_MV2(int volume,) struct dircache_entry *ce
311 snprintf(ce->d_name, VOL_ENUM_POS + 3, VOL_NAMES, volume); 311 snprintf(ce->d_name, VOL_ENUM_POS + 3, VOL_NAMES, volume);
312 ce->name_len = VOL_ENUM_POS + 3; 312 ce->name_len = VOL_ENUM_POS + 3;
313 dircache_size += ce->name_len; 313 dircache_size += ce->name_len;
314 ce->attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME; 314 ce->info.attribute = FAT_ATTR_DIRECTORY | FAT_ATTR_VOLUME;
315 ce->size = 0; 315 ce->info.size = 0;
316 append_position = dircache_gen_next(ce); 316 append_position = dircache_gen_next(ce);
317 ce = dircache_gen_down(ce); 317 ce = dircache_gen_down(ce);
318 } 318 }
@@ -347,18 +347,15 @@ static int sab_process_dir(struct dircache_entry *ce)
347 !strcmp("..", entry->d_name)) 347 !strcmp("..", entry->d_name))
348 continue; 348 continue;
349 349
350 ce->attribute = entry->attribute;
351 ce->name_len = strlen(entry->d_name) + 1; 350 ce->name_len = strlen(entry->d_name) + 1;
352 ce->d_name = ((char *)dircache_root + dircache_size); 351 ce->d_name = ((char *)dircache_root + dircache_size);
353 ce->size = entry->size; 352 ce->info = entry->info;
354 ce->wrtdate = entry->wrtdate;
355 ce->wrttime = entry->wrttime;
356 memcpy(ce->d_name, entry->d_name, ce->name_len); 353 memcpy(ce->d_name, entry->d_name, ce->name_len);
357 354
358 dircache_size += ce->name_len; 355 dircache_size += ce->name_len;
359 entry_count++; 356 entry_count++;
360 357
361 if(entry->attribute & ATTR_DIRECTORY) 358 if(entry->info.attribute & ATTR_DIRECTORY)
362 { 359 {
363 dircache_gen_down(ce); 360 dircache_gen_down(ce);
364 if(ce->down == NULL) 361 if(ce->down == NULL)
@@ -400,16 +397,16 @@ static int sab_process_dir(struct dircache_entry *ce)
400 /* add "." and ".." */ 397 /* add "." and ".." */
401 ce->d_name = "."; 398 ce->d_name = ".";
402 ce->name_len = 2; 399 ce->name_len = 2;
403 ce->attribute = ATTR_DIRECTORY; 400 ce->info.attribute = ATTR_DIRECTORY;
404 ce->size = 0; 401 ce->info.size = 0;
405 ce->down = first_ce; 402 ce->down = first_ce;
406 403
407 ce = dircache_gen_next(ce); 404 ce = dircache_gen_next(ce);
408 405
409 ce->d_name = ".."; 406 ce->d_name = "..";
410 ce->name_len = 3; 407 ce->name_len = 3;
411 ce->attribute = ATTR_DIRECTORY; 408 ce->info.attribute = ATTR_DIRECTORY;
412 ce->size = 0; 409 ce->info.size = 0;
413 ce->down = first_ce->up; 410 ce->down = first_ce->up;
414 411
415 closedir_uncached(dir); 412 closedir_uncached(dir);
@@ -1022,13 +1019,11 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute
1022 return NULL; 1019 return NULL;
1023 } 1020 }
1024 1021
1025 entry->attribute = attribute;
1026 entry->name_len = MIN(254, strlen(new)) + 1; 1022 entry->name_len = MIN(254, strlen(new)) + 1;
1027 entry->d_name = ((char *)dircache_root+dircache_size); 1023 entry->d_name = ((char *)dircache_root+dircache_size);
1028 entry->startcluster = 0; 1024 entry->startcluster = 0;
1029 entry->wrtdate = 0; 1025 memset(&entry->info, 0, sizeof(entry->info));
1030 entry->wrttime = 0; 1026 entry->info.attribute = attribute;
1031 entry->size = 0;
1032 memcpy(entry->d_name, new, entry->name_len); 1027 memcpy(entry->d_name, new, entry->name_len);
1033 dircache_size += entry->name_len; 1028 dircache_size += entry->name_len;
1034 1029
@@ -1086,7 +1081,7 @@ void dircache_update_filesize(int fd, long newsize, long startcluster)
1086 return ; 1081 return ;
1087 } 1082 }
1088 1083
1089 fd_bindings[fd]->size = newsize; 1084 fd_bindings[fd]->info.size = newsize;
1090 fd_bindings[fd]->startcluster = startcluster; 1085 fd_bindings[fd]->startcluster = startcluster;
1091} 1086}
1092void dircache_update_filetime(int fd) 1087void dircache_update_filetime(int fd)
@@ -1106,12 +1101,12 @@ void dircache_update_filetime(int fd)
1106 return ; 1101 return ;
1107 } 1102 }
1108 year = now->tm_year+1900-1980; 1103 year = now->tm_year+1900-1980;
1109 fd_bindings[fd]->wrtdate = (((year)&0x7f)<<9) | 1104 fd_bindings[fd]->info.wrtdate = (((year)&0x7f)<<9) |
1110 (((now->tm_mon+1)&0xf)<<5) | 1105 (((now->tm_mon+1)&0xf)<<5) |
1111 (((now->tm_mday)&0x1f)); 1106 (((now->tm_mday)&0x1f));
1112 fd_bindings[fd]->wrttime = (((now->tm_hour)&0x1f)<<11) | 1107 fd_bindings[fd]->info.wrttime = (((now->tm_hour)&0x1f)<<11) |
1113 (((now->tm_min)&0x3f)<<5) | 1108 (((now->tm_min)&0x3f)<<5) |
1114 (((now->tm_sec/2)&0x1f)); 1109 (((now->tm_sec/2)&0x1f));
1115#endif 1110#endif
1116} 1111}
1117 1112
@@ -1211,7 +1206,7 @@ void dircache_rename(const char *oldpath, const char *newpath)
1211 newpath = absolute_path; 1206 newpath = absolute_path;
1212 } 1207 }
1213 1208
1214 newentry = dircache_new_entry(newpath, entry->attribute); 1209 newentry = dircache_new_entry(newpath, entry->info.attribute);
1215 if (newentry == NULL) 1210 if (newentry == NULL)
1216 { 1211 {
1217 dircache_initialized = false; 1212 dircache_initialized = false;
@@ -1219,10 +1214,10 @@ void dircache_rename(const char *oldpath, const char *newpath)
1219 } 1214 }
1220 1215
1221 newentry->down = oldentry.down; 1216 newentry->down = oldentry.down;
1222 newentry->size = oldentry.size;
1223 newentry->startcluster = oldentry.startcluster; 1217 newentry->startcluster = oldentry.startcluster;
1224 newentry->wrttime = oldentry.wrttime; 1218 newentry->info.size = oldentry.info.size;
1225 newentry->wrtdate = oldentry.wrtdate; 1219 newentry->info.wrtdate = oldentry.info.wrtdate;
1220 newentry->info.wrttime = oldentry.info.wrttime;
1226} 1221}
1227 1222
1228void dircache_add_file(const char *path, long startcluster) 1223void dircache_add_file(const char *path, long startcluster)
@@ -1279,7 +1274,7 @@ DIR_CACHED* opendir_cached(const char* name)
1279 { 1274 {
1280 pdir->regulardir = NULL; 1275 pdir->regulardir = NULL;
1281 pdir->internal_entry = dircache_get_entry(name, true); 1276 pdir->internal_entry = dircache_get_entry(name, true);
1282 pdir->theent.attribute = -1; /* used to make readdir_cached aware of the first call */ 1277 pdir->theent.info.attribute = -1; /* used to make readdir_cached aware of the first call */
1283 } 1278 }
1284 1279
1285 if (pdir->internal_entry == NULL && pdir->regulardir == NULL) 1280 if (pdir->internal_entry == NULL && pdir->regulardir == NULL)
@@ -1306,11 +1301,8 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir)
1306 return NULL; 1301 return NULL;
1307 1302
1308 strlcpy(dir->theent.d_name, regentry->d_name, MAX_PATH); 1303 strlcpy(dir->theent.d_name, regentry->d_name, MAX_PATH);
1309 dir->theent.size = regentry->size;
1310 dir->theent.startcluster = regentry->startcluster; 1304 dir->theent.startcluster = regentry->startcluster;
1311 dir->theent.attribute = regentry->attribute; 1305 dir->theent.info = regentry->info;
1312 dir->theent.wrttime = regentry->wrttime;
1313 dir->theent.wrtdate = regentry->wrtdate;
1314 1306
1315 return &dir->theent; 1307 return &dir->theent;
1316 } 1308 }
@@ -1318,7 +1310,7 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir)
1318 /* if theent.attribute=-1 then this is the first call */ 1310 /* if theent.attribute=-1 then this is the first call */
1319 /* otherwise, this is is not so we first take the entry's ->next */ 1311 /* otherwise, this is is not so we first take the entry's ->next */
1320 /* NOTE: normal file can't have attribute=-1 */ 1312 /* NOTE: normal file can't have attribute=-1 */
1321 if(dir->theent.attribute != -1) 1313 if(dir->theent.info.attribute != -1)
1322 ce = ce->next; 1314 ce = ce->next;
1323 /* skip unused entries */ 1315 /* skip unused entries */
1324 while(ce != NULL && ce->name_len == 0) 1316 while(ce != NULL && ce->name_len == 0)
@@ -1330,11 +1322,8 @@ struct dirent_cached* readdir_cached(DIR_CACHED* dir)
1330 strlcpy(dir->theent.d_name, ce->d_name, MAX_PATH); 1322 strlcpy(dir->theent.d_name, ce->d_name, MAX_PATH);
1331 /* Can't do `dir->theent = *ce` 1323 /* Can't do `dir->theent = *ce`
1332 because that modifies the d_name pointer. */ 1324 because that modifies the d_name pointer. */
1333 dir->theent.size = ce->size;
1334 dir->theent.startcluster = ce->startcluster; 1325 dir->theent.startcluster = ce->startcluster;
1335 dir->theent.attribute = ce->attribute; 1326 dir->theent.info = ce->info;
1336 dir->theent.wrttime = ce->wrttime;
1337 dir->theent.wrtdate = ce->wrtdate;
1338 dir->internal_entry = ce; 1327 dir->internal_entry = ce;
1339 1328
1340 //logf("-> %s", ce->name); 1329 //logf("-> %s", ce->name);
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 6beec9f606..53a1a35b31 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -124,8 +124,8 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
124 ce->startcluster, 124 ce->startcluster,
125 &(file->fatfile), 125 &(file->fatfile),
126 NULL); 126 NULL);
127 file->size = ce->size; 127 file->size = ce->info.size;
128 file->attr = ce->attribute; 128 file->attr = ce->info.attribute;
129 file->cacheoffset = -1; 129 file->cacheoffset = -1;
130 file->fileoffset = 0; 130 file->fileoffset = 0;
131 131
@@ -169,8 +169,8 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
169 entry->startcluster, 169 entry->startcluster,
170 &(file->fatfile), 170 &(file->fatfile),
171 &(dir->fatdir)); 171 &(dir->fatdir));
172 file->size = file->trunc ? 0 : entry->size; 172 file->size = file->trunc ? 0 : entry->info.size;
173 file->attr = entry->attribute; 173 file->attr = entry->info.attribute;
174 break; 174 break;
175 } 175 }
176 } 176 }
diff --git a/firmware/common/filefuncs.c b/firmware/common/filefuncs.c
index 9fe07d69bb..c8ab468bcb 100644
--- a/firmware/common/filefuncs.c
+++ b/firmware/common/filefuncs.c
@@ -23,6 +23,7 @@
23#include "stdlib.h" 23#include "stdlib.h"
24#include "string.h" 24#include "string.h"
25#include "debug.h" 25#include "debug.h"
26#include "file.h"
26#include "filefuncs.h" 27#include "filefuncs.h"
27 28
28#ifdef HAVE_MULTIVOLUME 29#ifdef HAVE_MULTIVOLUME
@@ -87,4 +88,12 @@ bool dir_exists(const char *path)
87 closedir(d); 88 closedir(d);
88 return true; 89 return true;
89} 90}
91
92#if !(CONFIG_PLATFORM & PLATFORM_ANDROID)
93struct dirinfo dir_get_info(struct DIR* parent, struct dirent *entry)
94{
95 (void)parent;
96 return entry->info;
97}
98#endif
90#endif /* __PCTOOL__ */ 99#endif /* __PCTOOL__ */
diff --git a/firmware/export/audio.h b/firmware/export/audio.h
index b81597a892..34bcfb6b8f 100644
--- a/firmware/export/audio.h
+++ b/firmware/export/audio.h
@@ -35,11 +35,6 @@
35#endif /* HAVE_RECORDING */ 35#endif /* HAVE_RECORDING */
36#endif /* CONFIG_CODEC == SWCODEC */ 36#endif /* CONFIG_CODEC == SWCODEC */
37 37
38
39#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
40#define audio_play(x) sim_audio_play(x)
41#endif
42
43#define AUDIO_STATUS_PLAY 0x0001 38#define AUDIO_STATUS_PLAY 0x0001
44#define AUDIO_STATUS_PAUSE 0x0002 39#define AUDIO_STATUS_PAUSE 0x0002
45#define AUDIO_STATUS_RECORD 0x0004 40#define AUDIO_STATUS_RECORD 0x0004
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 83a9ea4feb..b81c684526 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -664,7 +664,7 @@ Lyre prototype 1 */
664/* Enable the directory cache and tagcache in RAM if we have 664/* Enable the directory cache and tagcache in RAM if we have
665 * plenty of RAM. Both features can be enabled independently. */ 665 * plenty of RAM. Both features can be enabled independently. */
666#if ((defined(MEMORYSIZE) && (MEMORYSIZE >= 8)) || MEM >= 8) && \ 666#if ((defined(MEMORYSIZE) && (MEMORYSIZE >= 8)) || MEM >= 8) && \
667 !defined(BOOTLOADER) && !defined(__PCTOOL__) 667 !defined(BOOTLOADER) && !defined(__PCTOOL__) && !defined(APPLICATION)
668#define HAVE_DIRCACHE 668#define HAVE_DIRCACHE
669#ifdef HAVE_TAGCACHE 669#ifdef HAVE_TAGCACHE
670#define HAVE_TC_RAMCACHE 670#define HAVE_TC_RAMCACHE
diff --git a/firmware/export/filefuncs.h b/firmware/export/filefuncs.h
index 3745c6bee3..f69c6da29c 100644
--- a/firmware/export/filefuncs.h
+++ b/firmware/export/filefuncs.h
@@ -22,7 +22,9 @@
22#ifndef __INCLUDE_FILEFUNCS_H_ 22#ifndef __INCLUDE_FILEFUNCS_H_
23#define __INCLUDE_FILEFUNCS_H_ 23#define __INCLUDE_FILEFUNCS_H_
24 24
25#include <stdbool.h>
25#include "config.h" 26#include "config.h"
27#include "dir.h"
26 28
27#ifdef HAVE_MULTIVOLUME 29#ifdef HAVE_MULTIVOLUME
28int strip_volume(const char* name, char* namecopy); 30int strip_volume(const char* name, char* namecopy);
@@ -32,5 +34,6 @@ int strip_volume(const char* name, char* namecopy);
32bool file_exists(const char *file); 34bool file_exists(const char *file);
33bool dir_exists(const char *path); 35bool dir_exists(const char *path);
34#endif 36#endif
37extern struct dirinfo dir_get_info(struct DIR* parent, struct dirent *entry);
35 38
36#endif /* __INCLUDE_FILEFUNCS_H_ */ 39#endif /* __INCLUDE_FILEFUNCS_H_ */
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index d256f31ab5..405f6b6838 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -203,14 +203,10 @@ static inline void call_tick_tasks(void)
203} 203}
204#endif 204#endif
205 205
206#if (CONFIG_PLATFORM & PLATFORM_HOSTED) && !defined(PLUGIN) && !defined(CODEC)
207#define sleep(x) sim_sleep(x)
208#endif
209
210/* kernel functions */ 206/* kernel functions */
211extern void kernel_init(void) INIT_ATTR; 207extern void kernel_init(void) INIT_ATTR;
212extern void yield(void); 208extern void yield(void);
213extern void sleep(int ticks); 209extern unsigned sleep(unsigned ticks);
214int tick_add_task(void (*f)(void)); 210int tick_add_task(void (*f)(void));
215int tick_remove_task(void (*f)(void)); 211int tick_remove_task(void (*f)(void));
216extern void tick_start(unsigned int interval_in_ms) INIT_ATTR; 212extern void tick_start(unsigned int interval_in_ms) INIT_ATTR;
diff --git a/firmware/general.c b/firmware/general.c
index 20b0277c09..3daf2f0a78 100644
--- a/firmware/general.c
+++ b/firmware/general.c
@@ -22,7 +22,7 @@
22#include "config.h" 22#include "config.h"
23#include <stdio.h> 23#include <stdio.h>
24#include "general.h" 24#include "general.h"
25 25#include "file.h"
26#include "dir.h" 26#include "dir.h"
27#include "limits.h" 27#include "limits.h"
28#include "stdlib.h" 28#include "stdlib.h"
diff --git a/firmware/include/dir.h b/firmware/include/dir.h
index 9ff96e3419..d143ed2664 100644
--- a/firmware/include/dir.h
+++ b/firmware/include/dir.h
@@ -41,6 +41,15 @@
41 41
42#endif 42#endif
43 43
44#define ATTR_READ_ONLY 0x01
45#define ATTR_HIDDEN 0x02
46#define ATTR_SYSTEM 0x04
47#define ATTR_VOLUME_ID 0x08
48#define ATTR_DIRECTORY 0x10
49#define ATTR_ARCHIVE 0x20
50#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
51
52#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_SDL))
44#ifdef HAVE_DIRCACHE 53#ifdef HAVE_DIRCACHE
45# include "dircache.h" 54# include "dircache.h"
46# define DIR DIR_CACHED 55# define DIR DIR_CACHED
@@ -62,5 +71,9 @@
62# define mkdir mkdir_uncached 71# define mkdir mkdir_uncached
63# define rmdir rmdir_uncached 72# define rmdir rmdir_uncached
64#endif 73#endif
74#else
75#include "dir_uncached.h"
76#include "dir-target.h"
77#endif
65 78
66#endif 79#endif
diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
index f225cf8e39..5c7ed14658 100644
--- a/firmware/include/dir_uncached.h
+++ b/firmware/include/dir_uncached.h
@@ -21,18 +21,20 @@
21#ifndef _DIR_UNCACHED_H_ 21#ifndef _DIR_UNCACHED_H_
22#define _DIR_UNCACHED_H_ 22#define _DIR_UNCACHED_H_
23 23
24#include "config.h"
25
26struct dirinfo {
27 int attribute;
28 long size;
29 unsigned short wrtdate;
30 unsigned short wrttime;
31};
32
33#ifndef APPLICATION
24#include <stdbool.h> 34#include <stdbool.h>
25#include "file.h" 35#include "file.h"
26 36
27#define ATTR_READ_ONLY 0x01 37#if (CONFIG_PLATFORM & PLATFORM_SDL)
28#define ATTR_HIDDEN 0x02
29#define ATTR_SYSTEM 0x04
30#define ATTR_VOLUME_ID 0x08
31#define ATTR_DIRECTORY 0x10
32#define ATTR_ARCHIVE 0x20
33#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
34
35#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
36#define dirent_uncached sim_dirent 38#define dirent_uncached sim_dirent
37#define DIR_UNCACHED SIM_DIR 39#define DIR_UNCACHED SIM_DIR
38#define opendir_uncached sim_opendir 40#define opendir_uncached sim_opendir
@@ -46,11 +48,8 @@
46 48
47struct dirent_uncached { 49struct dirent_uncached {
48 unsigned char d_name[MAX_PATH]; 50 unsigned char d_name[MAX_PATH];
49 int attribute; 51 struct dirinfo info;
50 long size;
51 long startcluster; 52 long startcluster;
52 unsigned short wrtdate; /* Last write date */
53 unsigned short wrttime; /* Last write time */
54}; 53};
55#endif 54#endif
56 55
@@ -92,5 +91,6 @@ extern struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir);
92extern int release_dirs(int volume); 91extern int release_dirs(int volume);
93 92
94#endif /* DIRFUNCTIONS_DEFINED */ 93#endif /* DIRFUNCTIONS_DEFINED */
94#endif
95 95
96#endif 96#endif
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h
index 650b92632d..37a803c63c 100644
--- a/firmware/include/dircache.h
+++ b/firmware/include/dircache.h
@@ -63,25 +63,19 @@ struct fdbind_queue {
63 63
64/* Exported structures. */ 64/* Exported structures. */
65struct dircache_entry { 65struct dircache_entry {
66 struct dirinfo info;
66 struct dircache_entry *next; 67 struct dircache_entry *next;
67 struct dircache_entry *up; 68 struct dircache_entry *up;
68 struct dircache_entry *down; 69 struct dircache_entry *down;
69 int attribute;
70 long size;
71 long startcluster; 70 long startcluster;
72 unsigned short wrtdate;
73 unsigned short wrttime;
74 unsigned long name_len; 71 unsigned long name_len;
75 char *d_name; 72 char *d_name;
76}; 73};
77 74
78struct dirent_cached { 75struct dirent_cached {
76 struct dirinfo info;
79 char *d_name; 77 char *d_name;
80 int attribute;
81 long size;
82 long startcluster; 78 long startcluster;
83 unsigned short wrtdate; /* Last write date */
84 unsigned short wrttime; /* Last write time */
85}; 79};
86 80
87typedef struct { 81typedef struct {
diff --git a/firmware/include/file.h b/firmware/include/file.h
index 8a084d6f39..8711124391 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -37,7 +37,7 @@
37#define MAX_OPEN_FILES 11 37#define MAX_OPEN_FILES 11
38 38
39#if !defined(PLUGIN) && !defined(CODEC) 39#if !defined(PLUGIN) && !defined(CODEC)
40#if (CONFIG_PLATFORM & PLATFORM_HOSTED) 40#if (CONFIG_PLATFORM & PLATFORM_SDL)
41#define open(x, ...) sim_open(x, __VA_ARGS__) 41#define open(x, ...) sim_open(x, __VA_ARGS__)
42#define creat(x,m) sim_creat(x,m) 42#define creat(x,m) sim_creat(x,m)
43#define remove(x) sim_remove(x) 43#define remove(x) sim_remove(x)
diff --git a/firmware/kernel.c b/firmware/kernel.c
index 1499402f40..9d72a7eeda 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -213,7 +213,7 @@ void timeout_register(struct timeout *tmo, timeout_cb_type callback,
213/**************************************************************************** 213/****************************************************************************
214 * Thread stuff 214 * Thread stuff
215 ****************************************************************************/ 215 ****************************************************************************/
216void sleep(int ticks) 216unsigned sleep(unsigned ticks)
217{ 217{
218#if defined(CPU_PP) && defined(BOOTLOADER) 218#if defined(CPU_PP) && defined(BOOTLOADER)
219 unsigned stop = USEC_TIMER + ticks * (1000000/HZ); 219 unsigned stop = USEC_TIMER + ticks * (1000000/HZ);
@@ -229,6 +229,7 @@ void sleep(int ticks)
229 sleep_thread(ticks); 229 sleep_thread(ticks);
230 switch_thread(); 230 switch_thread();
231#endif 231#endif
232 return 0;
232} 233}
233 234
234void yield(void) 235void yield(void)
diff --git a/firmware/target/hosted/android/dir-target.h b/firmware/target/hosted/android/dir-target.h
new file mode 100644
index 0000000000..4516215d62
--- /dev/null
+++ b/firmware/target/hosted/android/dir-target.h
@@ -0,0 +1,37 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __DIR_TARGET_H__
23#define __DIR_TARGET_H__
24
25#include <dirent.h>
26
27#define opendir _opendir
28#define mkdir _mkdir
29#define closedir _closedir
30#define readdir _readdir
31
32extern DIR* _opendir(const char* name);
33extern int _mkdir(const char* name);
34extern int _closedir(DIR* dir);
35extern struct dirent *_readdir(DIR* dir);
36
37#endif /* __DIR_TARGET_H__ */
diff --git a/firmware/target/hosted/android/fs-android.c b/firmware/target/hosted/android/fs-android.c
new file mode 100644
index 0000000000..5209458e54
--- /dev/null
+++ b/firmware/target/hosted/android/fs-android.c
@@ -0,0 +1,129 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <sys/stat.h> /* stat() */
24#include <stdio.h> /* snprintf */
25#include <string.h> /* size_t */
26#include <dirent.h>
27#include <time.h> /* localtime() */
28#include "system-target.h"
29#include "dir-target.h"
30#include "file.h"
31#include "dir.h"
32
33
34long filesize(int fd)
35{
36 struct stat buf;
37
38 if (!fstat(fd, &buf))
39 return buf.st_size;
40 else
41 return -1;
42}
43
44/* do we really need this in the app? */
45void fat_size(unsigned long* size, unsigned long* free)
46{
47 *size = *free = 0;
48}
49
50#undef opendir
51#undef closedir
52#undef mkdir
53#undef readdir
54
55/* need to wrap around DIR* because we need to save the parent's
56 * directory path in order to determine dirinfo */
57struct __dir {
58 DIR *dir;
59 char *path;
60};
61
62DIR* _opendir(const char *name)
63{
64 char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
65 if (!buf)
66 return NULL;
67
68 struct __dir *this = (struct __dir*)buf;
69
70 this->path = buf+sizeof(struct __dir);
71 /* definitely fits due to strlen() */
72 strcpy(this->path, name);
73
74 this->dir = opendir(name);
75
76 if (!this->dir)
77 {
78 free(buf);
79 return NULL;
80 }
81 return (DIR*)this;
82}
83
84int _mkdir(const char *name)
85{
86 return mkdir(name, 0777);
87}
88
89int _closedir(DIR *dir)
90{
91 struct __dir *this = (struct __dir*)dir;
92 int ret = closedir(this->dir);
93 free(this);
94 return ret;
95}
96
97struct dirent* _readdir(DIR* dir)
98{
99 struct __dir *d = (struct __dir*)dir;
100 return readdir(d->dir);
101}
102
103struct dirinfo dir_get_info(struct DIR* _parent, struct dirent *dir)
104{
105 struct __dir *parent = (struct __dir*)_parent;
106 struct stat s;
107 struct tm *tm;
108 struct dirinfo ret;
109 char path[MAX_PATH];
110
111 snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
112 stat(path, &s);
113 memset(&ret, 0, sizeof(ret));
114
115 if (S_ISDIR(s.st_mode))
116 {
117 ret.attribute = ATTR_DIRECTORY;
118 }
119
120 ret.size = s.st_size;
121 tm = localtime(&(s.st_mtime));
122 ret.wrtdate = ((tm->tm_year - 80) << 9) |
123 ((tm->tm_mon + 1) << 5) |
124 tm->tm_mday;
125 ret.wrttime = (tm->tm_hour << 11) |
126 (tm->tm_min << 5) |
127 (tm->tm_sec >> 1);
128 return ret;
129}
diff --git a/firmware/target/hosted/android/lc-android.c b/firmware/target/hosted/android/lc-android.c
new file mode 100644
index 0000000000..52ab08badb
--- /dev/null
+++ b/firmware/target/hosted/android/lc-android.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <string.h> /* size_t */
23#include "load_code.h"
24
25/* the load_code wrappers simply wrap, nothing to do */
26void *lc_open(const char *filename, char *buf, size_t buf_size)
27{
28 return _lc_open(filename, buf, buf_size);
29}
30
31void *lc_get_header(void *handle)
32{
33 return _lc_get_header(handle);
34}
35
36void lc_close(void *handle)
37{
38 _lc_close(handle);
39}
40