1
0

application.c 2.3 KB

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