application.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * 2011-08-06 Magicoe first release
  13. *
  14. */
  15. /**
  16. * @addtogroup PK40X256LVQ100
  17. */
  18. /*@{*/
  19. #include <rtthread.h>
  20. #include "tc_comm.h"
  21. #include "SLCD_Driver.h"
  22. /*
  23. * This is an example for delay thread
  24. */
  25. static struct rt_thread thread;
  26. static char thread_stack[THREAD_STACK_SIZE];
  27. static void thread_entry(void* parameter)
  28. {
  29. rt_tick_t tick;
  30. rt_uint8_t *dispchar[4] = {"INITED",
  31. "TICK10",
  32. "TICK15",
  33. " EXIT "};
  34. rt_kprintf("thread inited ok\n");
  35. SLCD_PrintString(dispchar[0], 0);
  36. tick = rt_tick_get();
  37. rt_kprintf("thread tick %d\n", tick);
  38. rt_kprintf("thread delay 10 tick\n");
  39. rt_thread_delay(1000);
  40. if (rt_tick_get() - tick > 1000)
  41. {
  42. tc_done(TC_STAT_FAILED);
  43. return;
  44. }
  45. SLCD_PrintString(dispchar[1], 0);
  46. tick = rt_tick_get();
  47. rt_kprintf("thread delay 15 tick\n");
  48. rt_thread_delay(1500);
  49. if (rt_tick_get() - tick > 1500)
  50. {
  51. tc_done(TC_STAT_FAILED);
  52. return;
  53. }
  54. SLCD_PrintString(dispchar[2], 0);
  55. rt_thread_delay(1000);
  56. rt_kprintf("thread exit\n");
  57. SLCD_PrintString(dispchar[3], 0);
  58. tc_done(TC_STAT_PASSED);
  59. }
  60. rt_err_t thread_delay_init()
  61. {
  62. rt_err_t result;
  63. result = rt_thread_init(&thread,
  64. "test",
  65. thread_entry, RT_NULL,
  66. &thread_stack[0], sizeof(thread_stack),
  67. THREAD_PRIORITY, 10);
  68. if (result == RT_EOK)
  69. rt_thread_startup(&thread);
  70. else
  71. tc_stat(TC_STAT_END | TC_STAT_FAILED);
  72. return result;
  73. }
  74. int rt_application_init()
  75. {
  76. thread_delay_init();
  77. return 0;
  78. }
  79. /*@}*/