main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-07-28 Yunkun Huang Init Project
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <board.h>
  13. #define LED_PIN BSP_LED_PIN
  14. static void led_blink_thread_entry(void *parameter)
  15. {
  16. rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
  17. rt_kprintf("LED blink thread started.\n");
  18. while (1)
  19. {
  20. rt_pin_write(LED_PIN, PIN_HIGH);
  21. rt_thread_mdelay(500);
  22. rt_pin_write(LED_PIN, PIN_LOW);
  23. rt_thread_mdelay(500);
  24. }
  25. }
  26. #define UART_DEVICE_NAME "uart0"
  27. static void uart_send_thread_entry(void *parameter)
  28. {
  29. rt_device_t console_dev;
  30. char msg[] = "hello rt-thread\r\n";
  31. console_dev = rt_console_get_device();
  32. if (!console_dev)
  33. {
  34. rt_kprintf("Failed to get console device.\n");
  35. return;
  36. }
  37. rt_kprintf("UART send thread started. Will send message every 2 seconds.\n");
  38. while (1)
  39. {
  40. rt_device_write(console_dev, 0, msg, (sizeof(msg) - 1));
  41. rt_thread_mdelay(2000);
  42. }
  43. }
  44. int main(void)
  45. {
  46. rt_thread_t led_tid = RT_NULL;
  47. rt_thread_t uart_tid = RT_NULL;
  48. led_tid = rt_thread_create("led_blink",
  49. led_blink_thread_entry,
  50. RT_NULL,
  51. 256,
  52. 20,
  53. 10);
  54. if (led_tid != RT_NULL)
  55. {
  56. rt_thread_startup(led_tid);
  57. }
  58. else
  59. {
  60. rt_kprintf("Failed to create led_blink thread.\n");
  61. }
  62. uart_tid = rt_thread_create("uart_send",
  63. uart_send_thread_entry,
  64. RT_NULL,
  65. 512,
  66. 21,
  67. 10);
  68. if (uart_tid != RT_NULL)
  69. {
  70. rt_kprintf("uart_send thread created successfully. Starting it up...\n");
  71. rt_thread_startup(uart_tid);
  72. }
  73. else
  74. {
  75. rt_kprintf("!!! FAILED to create uart_send thread. Not enough memory?\n");
  76. }
  77. return 0;
  78. }