summaryrefslogtreecommitdiff
path: root/firmware/rolo.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
commitd1322b71595336740eb5e18e5deed056ddb71c7a (patch)
tree812db6a9c2e9d78405ec0ed38465fd88dc5be748 /firmware/rolo.c
parent9b9bd73dfb212d4192fccc5fc5e269fc6499139c (diff)
downloadrockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.tar.gz
rockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.zip
GSoC/Buflib: Replace all direct accesses to audiobuf with buffer API functions.
Namely, introduce buffer_get_buffer() and buffer_release_buffer(). buffer_get_buffer() aquires all available and grabs a lock, attempting to call buffer_alloc() or buffer_get_buffer() while this lock is locked will cause a panicf() (doesn't actually happen, but is for debugging purpose). buffer_release_buffer() unlocks that lock and can additionally increment the audiobuf buffer to make an allocation. Pass 0 to only unlock if buffer was used temporarily only. buffer_available() is a replacement function to query audiobuflen, i.e. what's left in the buffer. Buffer init is moved up in the init chain and handles ipodvideo64mb internally. Further changes happened to mp3data.c and talk.c as to not call the above API functions, but get the buffer from callers. The caller is the audio system which has the buffer lock while mp3data.c and talk mess with the buffer. mpeg.c now implements some buffer related functions of playback.h, especially audio_get_buffer(), allowing to reduce #ifdef hell a tiny bit. audiobuf and audiobufend are local to buffer.c now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30308 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/rolo.c')
-rw-r--r--firmware/rolo.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 078a4e9827..9b6f4fec4a 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -99,6 +99,7 @@ void rolo_restart_cop(void)
99 99
100static void rolo_error(const char *text) 100static void rolo_error(const char *text)
101{ 101{
102 buffer_release_buffer(0);
102 lcd_clear_display(); 103 lcd_clear_display();
103 lcd_puts(0, 0, "ROLO error:"); 104 lcd_puts(0, 0, "ROLO error:");
104 lcd_puts_scroll(0, 1, text); 105 lcd_puts_scroll(0, 1, text);
@@ -213,6 +214,8 @@ int rolo_load(const char* filename)
213 unsigned short checksum,file_checksum; 214 unsigned short checksum,file_checksum;
214#endif 215#endif
215 unsigned char* ramstart = (void*)&loadaddress; 216 unsigned char* ramstart = (void*)&loadaddress;
217 unsigned char* filebuf;
218 size_t filebuf_size;
216 219
217 lcd_clear_display(); 220 lcd_clear_display();
218 lcd_puts(0, 0, "ROLO..."); 221 lcd_puts(0, 0, "ROLO...");
@@ -235,6 +238,10 @@ int rolo_load(const char* filename)
235 238
236 length = filesize(fd) - FIRMWARE_OFFSET_FILE_DATA; 239 length = filesize(fd) - FIRMWARE_OFFSET_FILE_DATA;
237 240
241 /* get the system buffer. release only in case of error, otherwise
242 * we don't return anyway */
243 filebuf = buffer_get_buffer(&filebuf_size);
244
238#if CONFIG_CPU != SH7034 245#if CONFIG_CPU != SH7034
239 /* Read and save checksum */ 246 /* Read and save checksum */
240 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); 247 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
@@ -260,7 +267,14 @@ int rolo_load(const char* filename)
260 267
261 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); 268 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
262 269
263 if (read(fd, audiobuf, length) != length) { 270 /* this shouldn't happen, but well */
271 if ((long)filebuf_size < length)
272 {
273 rolo_error("File too big");
274 return -1;
275 }
276
277 if (read(fd, filebuf, length) != length) {
264 rolo_error("Error Reading File"); 278 rolo_error("Error Reading File");
265 return -1; 279 return -1;
266 } 280 }
@@ -268,12 +282,12 @@ int rolo_load(const char* filename)
268#ifdef MI4_FORMAT 282#ifdef MI4_FORMAT
269 /* Check CRC32 to see if we have a valid file */ 283 /* Check CRC32 to see if we have a valid file */
270 chksum_crc32gentab(); 284 chksum_crc32gentab();
271 checksum = chksum_crc32 (audiobuf, length); 285 checksum = chksum_crc32 (filebuf, length);
272#else 286#else
273 checksum = MODEL_NUMBER; 287 checksum = MODEL_NUMBER;
274 288
275 for(i = 0;i < length;i++) { 289 for(i = 0;i < length;i++) {
276 checksum += audiobuf[i]; 290 checksum += filebuf[i];
277 } 291 }
278#endif 292#endif
279 293
@@ -329,12 +343,12 @@ int rolo_load(const char* filename)
329 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); 343 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
330 344
331 /* verify that file can be read and descrambled */ 345 /* verify that file can be read and descrambled */
332 if ((audiobuf + (2*length)+4) >= audiobufend) { 346 if ((size_t)((2*length)+4) >= filebuf_size) {
333 rolo_error("Not enough room to load file"); 347 rolo_error("Not enough room to load file");
334 return -1; 348 return -1;
335 } 349 }
336 350
337 if (read(fd, &audiobuf[length], length) != (int)length) { 351 if (read(fd, &filebuf[length], length) != (int)length) {
338 rolo_error("Error Reading File"); 352 rolo_error("Error Reading File");
339 return -1; 353 return -1;
340 } 354 }
@@ -342,7 +356,7 @@ int rolo_load(const char* filename)
342 lcd_puts(0, 1, "Descramble"); 356 lcd_puts(0, 1, "Descramble");
343 lcd_update(); 357 lcd_update();
344 358
345 checksum = descramble(audiobuf + length, audiobuf, length); 359 checksum = descramble(filebuf + length, filebuf, length);
346 360
347 /* Verify checksum against file header */ 361 /* Verify checksum against file header */
348 if (checksum != file_checksum) { 362 if (checksum != file_checksum) {
@@ -374,7 +388,7 @@ int rolo_load(const char* filename)
374 PAIOR = 0x0FA0; 388 PAIOR = 0x0FA0;
375#endif 389#endif
376#endif 390#endif
377 rolo_restart(audiobuf, ramstart, length); 391 rolo_restart(filebuf, ramstart, length);
378 392
379 return 0; /* this is never reached */ 393 return 0; /* this is never reached */
380 (void)checksum; (void)file_checksum; 394 (void)checksum; (void)file_checksum;