main.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Email Notes
  8. * 2019-07-16 Kevin.Liu kevin.liu.mchp@gmail.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. static rt_uint8_t led_stack[ 512 ];
  21. static struct rt_thread led_thread;
  22. static void led_thread_entry(void* parameter)
  23. {
  24. unsigned int count=0;
  25. while (1)
  26. {
  27. /* toggle led */
  28. #ifndef RT_USING_FINSH
  29. rt_kprintf("led toggle, count : %d\r\n",count);
  30. #endif
  31. count++;
  32. gpio_toggle_pin_level(LED0);
  33. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  34. }
  35. }
  36. int main(void)
  37. {
  38. rt_err_t result;
  39. /* initialize led thread */
  40. result = rt_thread_init(&led_thread,
  41. "led",
  42. led_thread_entry,
  43. RT_NULL,
  44. (rt_uint8_t*)&led_stack[0],
  45. sizeof(led_stack),
  46. RT_THREAD_PRIORITY_MAX/3,
  47. 5);
  48. if (result == RT_EOK)
  49. {
  50. rt_thread_startup(&led_thread);
  51. }
  52. #ifdef SAM_CAN_EXAMPLE
  53. can_demo_run();
  54. #endif
  55. return 0;
  56. }
  57. /*@}*/