application.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * File : app.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-06-25 Bernard first version
  13. */
  14. /**
  15. * @addtogroup Loongson SoC3210
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include <soc3210.h>
  20. struct rt_thread thread;
  21. ALIGN(4)
  22. rt_uint8_t thread_stack[1024];
  23. #include <finsh.h>
  24. void thread_entry(void* parameter)
  25. {
  26. int i = 0;
  27. while (1)
  28. {
  29. rt_kprintf("i = %d, cause: 0x%08x, config: 0x%08x\n", i++, read_c0_cause(), read_c0_config());
  30. rt_kprintf("HSB_MISC_CFG 0x%08x\n", HSB_MISC_REG);
  31. rt_thread_delay(100);
  32. }
  33. }
  34. void thread_test()
  35. {
  36. rt_err_t result = rt_thread_init(&thread,
  37. "tid",
  38. thread_entry, RT_NULL,
  39. &thread_stack, sizeof(thread_stack),
  40. 200,
  41. 5);
  42. if (result == RT_EOK)
  43. rt_thread_startup(&thread);
  44. else
  45. rt_kprintf("init thread failed\n");
  46. }
  47. FINSH_FUNCTION_EXPORT(thread_test, test thread!!);
  48. #include <rtgui/rtgui.h>
  49. #include <rtgui/event.h>
  50. #include <rtgui/rtgui_server.h>
  51. int rt_application_init()
  52. {
  53. rtgui_rect_t rect;
  54. rtgui_system_server_init();
  55. /* register dock panel */
  56. rect.x1 = 0;
  57. rect.y1 = 0;
  58. rect.x2 = 400;
  59. rect.y2 = 480;
  60. rtgui_panel_register("panel", &rect);
  61. /* register main panel */
  62. rect.x1 = 400;
  63. rect.y1 = 0;
  64. rect.x2 = 800;
  65. rect.y2 = 480;
  66. rtgui_panel_register("main", &rect);
  67. rtgui_panel_set_default_focused("main");
  68. rt_hw_lcd_init();
  69. /* init example workbench */
  70. // workbench_init();
  71. return 0;
  72. }
  73. /* key simulator */
  74. static struct rtgui_event_kbd kbd_event;
  75. void key_simulator(int key)
  76. {
  77. /* init keyboard event */
  78. RTGUI_EVENT_KBD_INIT(&kbd_event);
  79. kbd_event.mod = RTGUI_KMOD_NONE;
  80. kbd_event.unicode = 0;
  81. kbd_event.type = RTGUI_KEYDOWN;
  82. kbd_event.key = key;
  83. /* post down event */
  84. rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
  85. /* delay to post up event */
  86. rt_thread_delay(50);
  87. /* post up event */
  88. kbd_event.type = RTGUI_KEYUP;
  89. rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event));
  90. }
  91. void left()
  92. {
  93. key_simulator(RTGUIK_LEFT);
  94. }
  95. FINSH_FUNCTION_EXPORT(left, left key);
  96. void right()
  97. {
  98. key_simulator(RTGUIK_LEFT);
  99. }
  100. FINSH_FUNCTION_EXPORT(right, right key);
  101. void down()
  102. {
  103. key_simulator(RTGUIK_DOWN);
  104. }
  105. FINSH_FUNCTION_EXPORT(down, down key);
  106. void up()
  107. {
  108. key_simulator(RTGUI_KEYUP);
  109. }
  110. FINSH_FUNCTION_EXPORT(up, up key);
  111. /*@}*/