application.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * File : application.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. * 2009-01-05 Bernard the first version
  13. * 2014-04-27 Bernard make code cleanup.
  14. */
  15. #include <board.h>
  16. #include <rtthread.h>
  17. #include "peri_driver.h"
  18. #define INIT_STACK_SIZE 512
  19. #define LED_STACK_SIZE 256
  20. #ifndef RT_USING_HEAP
  21. /* if there is not enable heap, we should use static thread and stack. */
  22. ALIGN(8)
  23. static rt_uint8_t init_stack[INIT_STACK_SIZE];
  24. static struct rt_thread init_thread;
  25. ALIGN(8)
  26. static rt_uint8_t led_stack[LED_STACK_SIZE];
  27. static struct rt_thread led_thread;
  28. #endif
  29. void rt_init_thread_entry(void* parameter)
  30. {
  31. /* initialization RT-Thread Components */
  32. #ifdef RT_USING_COMPONENTS_INIT
  33. rt_components_init();
  34. #endif
  35. }
  36. void rt_led_thread_entry(void *parameter)
  37. {
  38. /* Initialize GPIO */
  39. Chip_GPIO_Init(LPC_GPIO_PORT);
  40. Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 7, 1);
  41. Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true);
  42. while (1)
  43. {
  44. Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true);
  45. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  46. Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, false);
  47. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  48. }
  49. }
  50. int rt_application_init()
  51. {
  52. rt_thread_t tid;
  53. #ifdef RT_USING_HEAP
  54. tid = rt_thread_create("init",
  55. rt_init_thread_entry, RT_NULL,
  56. INIT_STACK_SIZE, RT_THREAD_PRIORITY_MAX/3, 20);
  57. #else
  58. {
  59. rt_err_t result;
  60. tid = &init_thread;
  61. result = rt_thread_init(tid, "init", rt_init_thread_entry, RT_NULL,
  62. init_stack, sizeof(init_stack), RT_THREAD_PRIORITY_MAX / 3, 20);
  63. RT_ASSERT(result == RT_EOK);
  64. }
  65. #endif
  66. if (tid != RT_NULL)
  67. rt_thread_startup(tid);
  68. #ifdef RT_USING_HEAP
  69. tid = rt_thread_create("led",
  70. rt_led_thread_entry, RT_NULL,
  71. LED_STACK_SIZE, RT_THREAD_PRIORITY_MAX/3, 20);
  72. #else
  73. {
  74. rt_err_t result;
  75. tid = &led_thread;
  76. result = rt_thread_init(tid, "led", rt_led_thread_entry, RT_NULL,
  77. led_stack, sizeof(led_stack), RT_THREAD_PRIORITY_MAX / 4, 20);
  78. RT_ASSERT(result == RT_EOK);
  79. }
  80. #endif
  81. if (tid != RT_NULL)
  82. rt_thread_startup(tid);
  83. return 0;
  84. }