main.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * 2022-04-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_I2C_EXAMPLE
  18. #include "i2c_demo.h"
  19. #endif
  20. #ifdef SAM_ADC_EXAMPLE
  21. #include "adc_demo.h"
  22. #endif
  23. static rt_uint8_t led_stack[ 512 ];
  24. static struct rt_thread led_thread;
  25. static void led_thread_entry(void* parameter)
  26. {
  27. unsigned int count=0;
  28. while (1)
  29. {
  30. /* toggle led */
  31. #ifndef RT_USING_FINSH
  32. rt_kprintf("led toggle, count : %d\r\n",count);
  33. #endif
  34. count++;
  35. gpio_toggle_pin_level(LED0);
  36. rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  37. }
  38. }
  39. int main(void)
  40. {
  41. rt_err_t result;
  42. /* initialize led thread */
  43. result = rt_thread_init(&led_thread,
  44. "led",
  45. led_thread_entry,
  46. RT_NULL,
  47. (rt_uint8_t*)&led_stack[0],
  48. sizeof(led_stack),
  49. RT_THREAD_PRIORITY_MAX/3,
  50. 5);
  51. if (result == RT_EOK)
  52. {
  53. rt_thread_startup(&led_thread);
  54. }
  55. #ifdef SAM_I2C_EXAMPLE
  56. i2c_demo_run();
  57. #endif
  58. #ifdef SAM_ADC_EXAMPLE
  59. adc_demo_run();
  60. #endif
  61. return 0;
  62. }
  63. /*@}*/