Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

cop queue/cache tester
Friday, August 24th, 2007 at 12:52:04pm UTC 

  1. test_queue.c
  2. /***************************************************************************
  3.  *             __________               __   ___.
  4.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  5.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  6.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  7.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  8.  *                     \/            \/     \/    \/            \/
  9.  * $Id$
  10.  *
  11.  * Copyright (C) 2007 Michael Sevakis
  12.  *
  13.  * All files in this archive are subject to the GNU General Public License.
  14.  * See the file COPYING in the source tree root for full license agreement.
  15.  *
  16.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  17.  * KIND, either express or implied.
  18.  *
  19.  ****************************************************************************/
  20. #include "plugin.h"
  21. #include "oldmenuapi.h"
  22.  
  23. PLUGIN_HEADER
  24. PLUGIN_IRAM_DECLARE
  25.  
  26. static struct plugin_api *rb NOCACHEBSS_ATTR;
  27.  
  28. static struct event_queue cop_queue NOCACHEBSS_ATTR;
  29. static struct queue_sender_list cop_queue_senders NOCACHEBSS_ATTR;
  30.  
  31. static int cop_thread_stack[2*DEFAULT_STACK_SIZE/sizeof(int)];
  32.  
  33. #ifdef TOSHIBA_GIGABEAT_F
  34. #define invalidate_icache()
  35. #define flush_icache()
  36. #endif
  37.  
  38. #if CONFIG_KEYPAD == IRIVER_H100_PAD
  39. #define TEST_QUEUE_QUIT BUTTON_OFF
  40. #elif CONFIG_KEYPAD == SANSA_E200_PAD
  41. #define TEST_QUEUE_QUIT BUTTON_POWER
  42. #elif CONFIG_KEYPAD == GIGABEAT_PAD
  43. #define TEST_QUEUE_QUIT BUTTON_POWER
  44. #else
  45. #error Unsupported Keypad
  46. #endif
  47.  
  48. void cop_thread(void)
  49. {
  50.     struct queue_event ev;
  51.     int last_i = 0;
  52.  
  53.     while (1)
  54.     {
  55.         rb->queue_wait_w_tmo(&cop_queue, &ev, 3600*HZ);
  56.  
  57.         switch (ev.id)
  58.         {
  59.         case 0:
  60.             /* each data should be one greater than the last */
  61.             if (ev.data != last_i + 1)
  62.                 rb->queue_reply(&cop_queue, -1);
  63.          //   else
  64.          //       rb->splash(0, "%ld", ev.data);
  65.             last_i = ev.data;
  66.             break;
  67.         case 777:
  68.             /* commanded to exit - reply explicitly since we won't
  69.                wait here again */
  70.             rb->queue_reply(&cop_queue, 0);
  71.             invalidate_icache();
  72.             return;
  73.         default:
  74.             rb->queue_reply(&cop_queue, -2);
  75.         }
  76.     }
  77. }
  78.  
  79. enum plugin_status plugin_start(struct plugin_api *api, void *parameter)
  80. {
  81.     int i, ret = 0;
  82.  
  83.     PLUGIN_IRAM_INIT(api);
  84.  
  85.     rb = api;
  86.  
  87.     i = 0;
  88.  
  89.     rb->queue_init(&cop_queue, false);
  90.     rb->queue_enable_queue_send(&cop_queue, &cop_queue_senders);
  91.  
  92.     flush_icache();
  93.  
  94.     rb->create_thread(cop_thread, cop_thread_stack, sizeof(cop_thread_stack),
  95.                       0, "cop_thread", PRIORITY_SYSTEM IF_COP(, CPU));
  96.  
  97.     rb->lcd_setfont(FONT_SYSFIXED);
  98.  
  99.     rb->lcd_puts(0, 0, "Test running...");
  100.  
  101.     rb->lcd_update();
  102.  
  103.     i = 0;
  104.  
  105.     long tick = *rb->current_tick + 10*HZ;
  106.     int loops = 0;
  107.  
  108.     /* loop around sending last data+1 */
  109.     while (TIME_BEFORE(*rb->current_tick, tick)) //rb->button_get(false) != TEST_QUEUE_QUIT)
  110.     {
  111.         ret = rb->queue_send(&cop_queue, 0, ++i);
  112.  
  113.         if (ret == -1)
  114.         {
  115.             rb->lcd_clear_display();
  116.             rb->lcd_puts(0, 0, "Data miss");
  117.             break;
  118.         }
  119.         else if (ret == -2)
  120.         {
  121.             rb->lcd_clear_display();
  122.             rb->lcd_puts(0, 0, "Unexpected message");
  123.             break;
  124.         }
  125.         loops++;
  126.     }
  127.  
  128.     rb->splash(HZ*3, "%d.%d", loops/10, loops%10);
  129.  
  130.     if (ret < 0)
  131.     {
  132.          while (rb->button_get(true) == BUTTON_NONE);
  133.     }
  134.  
  135.     /* tell cop thread to exit */
  136.     rb->queue_send(&cop_queue, 777, 0);
  137.  
  138.     /* give it time to leave plugin code */
  139.     rb->sleep(HZ/10);
  140.  
  141.     invalidate_icache();
  142.    
  143.     return PLUGIN_OK;
  144.     (void)parameter;
  145. }
  146.  
  147.  
  148. test_cache.c
  149. /***************************************************************************
  150.  *             __________               __   ___.
  151.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  152.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  153.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  154.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  155.  *                     \/            \/     \/    \/            \/
  156.  * $Id$
  157.  *
  158.  * Copyright (C) 2007 Michael Sevakis
  159.  *
  160.  * All files in this archive are subject to the GNU General Public License.
  161.  * See the file COPYING in the source tree root for full license agreement.
  162.  *
  163.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  164.  * KIND, either express or implied.
  165.  *
  166.  ****************************************************************************/
  167. #include "plugin.h"
  168. #include "oldmenuapi.h"
  169.  
  170. PLUGIN_HEADER
  171. PLUGIN_IRAM_DECLARE
  172.  
  173. static struct plugin_api *rb NOCACHEBSS_ATTR;
  174.  
  175. static struct event_queue cop_queue NOCACHEBSS_ATTR;
  176. static struct queue_sender_list cop_queue_senders NOCACHEBSS_ATTR;
  177.  
  178. static int cop_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)];
  179.  
  180. static uint8_t cached_buf[16];
  181. static uint8_t uncached_buf[16] NOCACHEBSS_ATTR;
  182. static uint8_t cop_buf[16] NOCACHEBSS_ATTR;
  183.  
  184. #ifdef TOSHIBA_GIGABEAT_F
  185. #define invalidate_icache()
  186. #define flush_icache()
  187. #endif
  188.  
  189.  
  190. void cop_thread(void)
  191. {
  192.     int i;
  193.     struct queue_event ev;
  194.  
  195.     while (1)
  196.     {
  197.         invalidate_icache();
  198.  
  199.         rb->queue_wait_w_tmo(&cop_queue, &ev, 3600*HZ);
  200.  
  201.         switch (ev.id)
  202.         {
  203.         case 0:
  204.             /* avoid memcpy/memcmp to help localize code execution */
  205.             for (i = 0; i < 16; i++)
  206.             {
  207.                 if (cached_buf[i] != uncached_buf[i])
  208.                 {
  209.                     for (i = 0; i < 16; i++)
  210.                     {
  211.                         /* copy what COP sees to an uncacheable buffer */
  212.                         cop_buf[i] = cached_buf[i];
  213.                     }
  214.  
  215.                     /* return failure */
  216.                     rb->queue_reply(&cop_queue, -1);
  217.                     break;
  218.                 }
  219.             }
  220.             break;
  221.         case 666:
  222.             /* commanded to exit - reply explicitly since we won't
  223.                wait here again */
  224.             rb->queue_reply(&cop_queue, 0);
  225.             flush_icache();
  226.             return;
  227.         }
  228.     }
  229. }
  230.  
  231. enum plugin_status plugin_start(struct plugin_api *api, void *parameter)
  232. {
  233.     int ret;
  234.     unsigned char buf[64];
  235.     unsigned int rand;
  236.     unsigned int test_num = 0;
  237.  
  238.     PLUGIN_IRAM_INIT(api);
  239.  
  240.     rb = api;
  241.  
  242.     rand = *rb->current_tick;
  243.     ret = 0;
  244.  
  245.     rb->queue_init(&cop_queue, false);
  246.     rb->queue_enable_queue_send(&cop_queue, &cop_queue_senders);
  247.  
  248.     flush_icache();
  249.  
  250.     rb->create_thread(cop_thread, cop_thread_stack, sizeof(cop_thread_stack),
  251.                       0, "cop_thread", PRIORITY_SYSTEM IF_COP(, COP));
  252.  
  253.     rb->lcd_setfont(FONT_SYSFIXED);
  254.  
  255.     rb->lcd_puts(0, 0, "Test running...");
  256.     rb->lcd_puts(0, 1, "Will dump upon byte mismatch.");
  257.  
  258.     rb->lcd_update();
  259.  
  260.     while (rb->button_get(false) == BUTTON_NONE)
  261.     {
  262.         int i;
  263.  
  264.         test_num++;
  265.         for (i = 0; i < 16; i++)
  266.         {
  267.             unsigned val;
  268.             rand = rand*0x0019660dL + 0x3c6ef35fL;
  269.             val = rand & 0xff;
  270.             cached_buf[i] = val;
  271.             uncached_buf[i] = val;
  272.         }
  273.  
  274.         //rb->lcd_update();
  275.  
  276.         invalidate_icache();
  277.  
  278.         ret = rb->queue_send(&cop_queue, 0, 0);
  279.  
  280.         if (ret < 0)
  281.             break;
  282.  
  283.         rb->yield();
  284.     }
  285.  
  286.     if (ret < 0)
  287.     {
  288.         int i, x, y = 0;
  289.         rb->lcd_clear_display();
  290.         rb->snprintf(buf, 64, "Test #%u failed:", test_num);
  291.         rb->lcd_puts(0, y++, buf);
  292.  
  293.         rb->lcd_puts(0, y, "cached_buf");
  294.         rb->lcd_puts(0, y+3, "uncached_buf");
  295.         rb->lcd_puts(0, y+6, "cop_buf");
  296.  
  297.         for (i = 0, x = 0, y = 2; i < 16; i++, x += 3)
  298.         {
  299.             if (i % 8 == 0)
  300.                 x = 0, y++;
  301.             /* show bytes in the shared, cached buffer */
  302.             rb->snprintf(buf, 64, "%02X ", cached_buf[i]);
  303.             rb->lcd_puts(x, y+0, buf);
  304.             /* show bytes in the shared, uncached buffer */
  305.             rb->snprintf(buf, 64, "%02X ", uncached_buf[i]);
  306.             rb->lcd_puts(x, y+3, buf);
  307.             /* show bytes that cop saw in the shared, cached buffer */
  308.             rb->snprintf(buf, 64, "%02X ", cop_buf[i]);
  309.             rb->lcd_puts(x, y+6, buf);
  310.         }
  311.         rb->lcd_update();
  312.         while (rb->button_get(true) == BUTTON_NONE);
  313.     }
  314.  
  315.     /* tell cop thread to exit */
  316.     rb->queue_send(&cop_queue, 666, 0);
  317.  
  318.     /* give it time to leave plugin code */
  319.     rb->sleep(HZ/10);
  320.  
  321.     flush_icache();
  322.    
  323.     return PLUGIN_OK;
  324.     (void)parameter;
  325. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right