application.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 led_stack[LED_STACK_SIZE];
  20. static struct rt_thread led_thread;
  21. #endif
  22. static int led_app();
  23. int main(void)
  24. {
  25. rt_kprintf("Hello RT-Thread!\n");
  26. while(1)
  27. {
  28. rt_thread_mdelay(1000);
  29. }
  30. return 0;
  31. }
  32. /*******************************************************************************
  33. * Function Name : assert_failed
  34. * Description : Reports the name of the source file and the source line number
  35. * where the assert error has occurred.
  36. * Input : - file: pointer to the source file name
  37. * - line: assert error line source number
  38. * Output : None
  39. * Return : None
  40. *******************************************************************************/
  41. void assert_failed(uint8_t* file, uint32_t line)
  42. {
  43. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  44. rt_kprintf(" file %s\r\n", file);
  45. rt_kprintf(" line %d\r\n", line);
  46. while (1) ;
  47. }
  48. void rt_led_thread_entry(void *parameter)
  49. {
  50. /* Initialize GPIO */
  51. Chip_GPIO_Init(LPC_GPIO_PORT);
  52. Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 7, 1);
  53. Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true);
  54. while (1)
  55. {
  56. Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true);
  57. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  58. Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, false);
  59. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  60. }
  61. }
  62. static int led_app()
  63. {
  64. rt_thread_t tid;
  65. #ifdef RT_USING_HEAP
  66. tid = rt_thread_create("led",
  67. rt_led_thread_entry, RT_NULL,
  68. LED_STACK_SIZE, RT_THREAD_PRIORITY_MAX/3, 20);
  69. #else
  70. {
  71. rt_err_t result;
  72. tid = &led_thread;
  73. result = rt_thread_init(tid, "led", rt_led_thread_entry, RT_NULL,
  74. led_stack, sizeof(led_stack), RT_THREAD_PRIORITY_MAX / 4, 20);
  75. RT_ASSERT(result == RT_EOK);
  76. }
  77. #endif
  78. if (tid != RT_NULL)
  79. rt_thread_startup(tid);
  80. return 0;
  81. }