main.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Email Notes
  8. * 2023-09-16 luhuadong luhuadong@163.com First Release
  9. */
  10. #include <rtthread.h>
  11. #ifdef RT_USING_FINSH
  12. #include <finsh.h>
  13. #include <shell.h>
  14. #endif
  15. #include "atmel_start.h"
  16. #include <hal_gpio.h>
  17. #ifdef SAM_CAN_EXAMPLE
  18. #include "can_demo.h"
  19. #endif
  20. #ifdef SAM_I2C_EXAMPLE
  21. #include "i2c_demo.h"
  22. #endif
  23. #ifdef SAM_ADC_EXAMPLE
  24. #include "adc_demo.h"
  25. #endif
  26. #ifdef SAM_LWIP_EXAMPLE
  27. #include "lwip_demo.h"
  28. #endif
  29. static rt_uint8_t led_stack[512];
  30. static struct rt_thread led_thread;
  31. static void led_thread_entry(void* parameter)
  32. {
  33. unsigned int count=0;
  34. while (1)
  35. {
  36. /* toggle led */
  37. #ifndef RT_USING_FINSH
  38. rt_kprintf("led toggle, count : %d\n",count);
  39. #endif
  40. count++;
  41. gpio_toggle_pin_level(LED0);
  42. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  43. }
  44. }
  45. int main(void)
  46. {
  47. rt_err_t result;
  48. /* initialize led thread */
  49. result = rt_thread_init(&led_thread,
  50. "led",
  51. led_thread_entry,
  52. RT_NULL,
  53. (rt_uint8_t*)&led_stack[0],
  54. sizeof(led_stack),
  55. RT_THREAD_PRIORITY_MAX/3,
  56. 5);
  57. if (result == RT_EOK)
  58. {
  59. rt_thread_startup(&led_thread);
  60. }
  61. #ifdef SAM_I2C_EXAMPLE
  62. i2c_demo_run();
  63. #endif
  64. #ifdef SAM_ADC_EXAMPLE
  65. adc_demo_run();
  66. #endif
  67. return 0;
  68. }