diff options
Diffstat (limited to 'apps/plugins/battery_bench.c')
-rw-r--r-- | apps/plugins/battery_bench.c | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 3f9ecbc2b4..75c448bb27 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #define EV_EXIT 1337 | 31 | #define EV_EXIT 1337 |
32 | 32 | ||
33 | /* seems to work with 1300, but who knows... */ | 33 | /* seems to work with 1300, but who knows... */ |
34 | #define THREAD_STACK_SIZE DEFAULT_STACK_SIZE + 0x200 | 34 | #define MIN_THREAD_STACK_SIZE DEFAULT_STACK_SIZE + 0x200 |
35 | 35 | ||
36 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | 36 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ |
37 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | 37 | (CONFIG_KEYPAD == IRIVER_H300_PAD) |
@@ -317,13 +317,21 @@ static struct batt_info | |||
317 | 317 | ||
318 | #define BUF_ELEMENTS (sizeof(bat)/sizeof(struct batt_info)) | 318 | #define BUF_ELEMENTS (sizeof(bat)/sizeof(struct batt_info)) |
319 | 319 | ||
320 | static unsigned int thread_id; | 320 | |
321 | static struct | ||
322 | { | ||
323 | unsigned int id; /* worker thread id */ | ||
324 | long *stack; | ||
325 | ssize_t stacksize; | ||
326 | } gThread; | ||
327 | |||
321 | static struct event_queue thread_q SHAREDBSS_ATTR; | 328 | static struct event_queue thread_q SHAREDBSS_ATTR; |
322 | static bool in_usb_mode; | 329 | static bool in_usb_mode; |
323 | static unsigned int buf_idx; | 330 | static unsigned int buf_idx; |
324 | 331 | ||
325 | static bool exit_tsr(bool reenter) | 332 | static bool exit_tsr(bool reenter) |
326 | { | 333 | { |
334 | bool is_exit; | ||
327 | long button; | 335 | long button; |
328 | (void)reenter; | 336 | (void)reenter; |
329 | rb->lcd_clear_display(); | 337 | rb->lcd_clear_display(); |
@@ -342,13 +350,19 @@ static bool exit_tsr(bool reenter) | |||
342 | if (button == BATTERY_OFF) | 350 | if (button == BATTERY_OFF) |
343 | { | 351 | { |
344 | rb->queue_post(&thread_q, EV_EXIT, 0); | 352 | rb->queue_post(&thread_q, EV_EXIT, 0); |
345 | rb->thread_wait(thread_id); | 353 | rb->thread_wait(gThread.id); |
346 | /* remove the thread's queue from the broadcast list */ | 354 | /* remove the thread's queue from the broadcast list */ |
347 | rb->queue_delete(&thread_q); | 355 | rb->queue_delete(&thread_q); |
348 | return true; | 356 | is_exit = true; |
349 | } | 357 | } |
350 | else return false; | 358 | else is_exit = false; |
359 | |||
360 | break; | ||
351 | } | 361 | } |
362 | FOR_NB_SCREENS(idx) | ||
363 | rb->screens[idx]->scroll_stop(); | ||
364 | |||
365 | return is_exit; | ||
352 | } | 366 | } |
353 | 367 | ||
354 | #define BIT_CHARGER 0x1 | 368 | #define BIT_CHARGER 0x1 |
@@ -357,9 +371,6 @@ static bool exit_tsr(bool reenter) | |||
357 | 371 | ||
358 | #define HMS(x) (x)/3600,((x)%3600)/60,((x)%3600)%60 | 372 | #define HMS(x) (x)/3600,((x)%3600)/60,((x)%3600)%60 |
359 | 373 | ||
360 | /* use long for aligning */ | ||
361 | static unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)]; | ||
362 | |||
363 | #if CONFIG_CHARGING || defined(HAVE_USB_POWER) | 374 | #if CONFIG_CHARGING || defined(HAVE_USB_POWER) |
364 | static unsigned int charge_state(void) | 375 | static unsigned int charge_state(void) |
365 | { | 376 | { |
@@ -636,18 +647,39 @@ enum plugin_status plugin_start(const void* parameter) | |||
636 | HMS((unsigned)start_tick/HZ)); | 647 | HMS((unsigned)start_tick/HZ)); |
637 | rb->close(fd); | 648 | rb->close(fd); |
638 | } | 649 | } |
639 | 650 | ||
651 | rb->memset(&gThread, 0, sizeof(gThread)); | ||
652 | void *buf; | ||
653 | size_t buf_size; | ||
654 | buf = rb->plugin_get_buffer(&buf_size); | ||
655 | ALIGN_BUFFER(buf, buf_size, sizeof(long)); | ||
656 | rb->memset(buf, 0, buf_size); | ||
657 | |||
658 | gThread.stacksize = buf_size; | ||
659 | gThread.stack = (long *) buf + buf_size; /* stack grows towards *buf */ | ||
660 | |||
661 | ALIGN_BUFFER(gThread.stack, gThread.stacksize, sizeof(long)); | ||
662 | |||
663 | if (gThread.stacksize < MIN_THREAD_STACK_SIZE) | ||
664 | { | ||
665 | rb->splash(HZ*2, "Out of memory"); | ||
666 | gThread.id = UINT_MAX; | ||
667 | return PLUGIN_ERROR; | ||
668 | } | ||
669 | |||
640 | rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */ | 670 | rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */ |
641 | if ((thread_id = rb->create_thread(thread, thread_stack, | 671 | gThread.id = rb->create_thread(thread, gThread.stack, |
642 | sizeof(thread_stack), 0, "Battery Benchmark" | 672 | gThread.stacksize, 0, "Battery Benchmark" |
643 | IF_PRIO(, PRIORITY_BACKGROUND) | 673 | IF_PRIO(, PRIORITY_BACKGROUND) |
644 | IF_COP(, CPU))) == 0) | 674 | IF_COP(, CPU)); |
675 | |||
676 | if (gThread.id == 0 || gThread.id == UINT_MAX) | ||
645 | { | 677 | { |
646 | rb->splash(HZ, "Cannot create thread!"); | 678 | rb->splash(HZ, "Cannot create thread!"); |
647 | return PLUGIN_ERROR; | 679 | return PLUGIN_ERROR; |
648 | } | 680 | } |
649 | 681 | ||
650 | rb->plugin_tsr(exit_tsr); | 682 | rb->plugin_tsr(exit_tsr); |
651 | 683 | ||
652 | return PLUGIN_OK; | 684 | return PLUGIN_OK; |
653 | } | 685 | } |